Revision 37641

View differences:

tags/v_2_0_0_Build_2043/libraries/libFMap_controls/src-test/org/gvsig/fmap/mapcontrol/tools/AreaListenerTest.java
1
package org.gvsig.fmap.mapcontrol.tools;
2

  
3
import java.awt.geom.Point2D;
4

  
5
import org.cresques.cts.IProjection;
6
import org.gvsig.fmap.crs.CRSFactory;
7
import org.gvsig.fmap.mapcontext.MapContext;
8
import org.gvsig.fmap.mapcontext.ViewPort;
9
import org.gvsig.fmap.mapcontrol.MapControl;
10
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
11

  
12

  
13
public class AreaListenerTest extends AbstractLibraryAutoInitTestCase {
14
	private IProjection projectionUTM = CRSFactory.getCRS("EPSG:23030");
15
	private IProjection projectionGeo = CRSFactory.getCRS("EPSG:4230");
16
		
17
	@Override
18
	protected void doSetUp() throws Exception {
19
		// Nothing to do	
20
	}
21

  
22
	public void test1() {
23
		AreaListenerImpl areaListenerUTM=new AreaListenerImpl(newMapControlUTM());
24
		AreaListenerImpl areaListenerGeo=new AreaListenerImpl(newMapControlGeo());
25
		Double[] xsUTM=new Double[] {new Double(731292),new Double(731901),new Double(730138)};
26
		Double[] ysUTM=new Double[] {new Double(4351223),new Double(4350768),new Double(4349232)};
27
		double areaUTM=areaListenerUTM.returnCoordsArea(xsUTM,ysUTM,new Point2D.Double(730138,4349232));
28
		Double[] xsGeo=new Double[] {new Double(-0.31888183),new Double(-0.31173131),new Double(-0.33268401)};
29
		Double[] ysGeo=new Double[] {new Double(39.27871741),new Double(39.27464327),new Double(39.26117368)};
30
		double areaGeo=areaListenerGeo.returnGeoCArea(xsGeo,ysGeo,new Point2D.Double(-0.33268401,39.26117368));
31
		assertTrue("Area UTM igual a Geo",areaUTM<(areaGeo+1000)&& areaUTM>(areaGeo-1000));
32
	}
33
	private MapControl newMapControlUTM() {
34
		ViewPort vp = new ViewPort(projectionUTM);
35
		MapControl mc=new MapControl();
36
		mc.setMapContext(new MapContext(vp));
37
		return mc;
38
	}
39
	private MapControl newMapControlGeo() {
40
		ViewPort vp = new ViewPort(projectionGeo);
41
		MapControl mc=new MapControl();
42
		mc.setMapContext(new MapContext(vp));
43
		return mc;
44
	}
45
}
tags/v_2_0_0_Build_2043/libraries/libFMap_controls/src/org/gvsig/app/gui/JComboBoxUnits.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.app.gui;
42

  
43
import org.gvsig.fmap.mapcontext.MapContext;
44
import org.gvsig.i18n.Messages;
45
import org.gvsig.utils.swing.JComboBox;
46

  
47

  
48
/**
49
 * <p>Class representing a JComboBox with the measure units handled by the application.
50
 * It takes values from Attributes.NAMES and Attributes.CHANGE static fields. So, to
51
 * add more measure units, you must edit Attributes class and change will be automatically
52
 * reflected in the combo box.</p>
53
 *
54
 * <p>The internatiolanization of the field is automatically handled by the system</p>
55
 * @author jaume dominguez faus - jaume.dominguez@iver.es
56
 */
57
public class JComboBoxUnits extends JComboBox {
58
	private static final long serialVersionUID = 8015263853737441433L;
59

  
60
	/**
61
	 * Creates a new instance of JUnitComboBox including "pixel" units and
62
	 * setting them as automatically pre-selected.
63
	 */
64
	public JComboBoxUnits() {
65
		this(true);
66
	}
67

  
68
	/**
69
	 *
70
	 * Creates a new instance of JUnitComboBox. If includePixel is true
71
	 * then pixel units are included in the list and they are automatically
72
	 * pre-selected. Otherwise, meters are preselected.
73
	 *
74
	 */
75
	public JComboBoxUnits(boolean includePixel) {
76
		super();
77
		String[] names=MapContext.getDistanceNames();
78

  
79
		for (int i = 0; i < names.length; i++) {
80
			super.addItem(Messages.getText(names[i]));
81
		}
82
		if (includePixel) {
83
			super.addItem(Messages.getText("pixels"));
84
			setSelectedItem(Messages.getText("pixels"));
85
		} else {
86
			setSelectedIndex(1);
87
		}
88
		setMaximumRowCount(10);
89
	}
90

  
91

  
92
	/**
93
	 * Returns the conversion factor from the <b>unit selected in the combo box</b>
94
	 * to <b>meters</b> or <b>0</b> if pixels have been selected as the size unit.
95
	 * @return
96
	 */
97
	public double getUnitConversionFactor() {
98
			double unitFactor;
99
			try {
100
				unitFactor = MapContext.getDistanceTrans2Meter()[getSelectedIndex()];
101
			} catch (ArrayIndexOutOfBoundsException aioobEx) { //jijiji
102
				unitFactor = 0; // which represents size in pixel
103
			}
104
			return unitFactor;
105

  
106
	}
107

  
108
	/**
109
	 * the use of this method is not allowed in this combo box.
110
	 * @deprecated
111
	 */
112
	public void addItem(Object anObject) {
113
		throw new Error("Operation not allowed");
114
	}
115

  
116
	/**
117
	 * the use of this method is not allowed for this combo box.
118
	 * @deprecated
119
	 */
120
	public void removeAllItems() {
121
		throw new Error("Operation not allowed");
122
	}
123

  
124
	public int getSelectedUnitIndex() {
125
		int i = getSelectedIndex();
126
		if (i>MapContext.getDistanceNames().length-1)
127
			return -1;
128
		else return i;
129
	}
130

  
131
	public void setSelectedUnitIndex(int unitIndex) {
132
		if (unitIndex == -1) {
133
			setSelectedIndex(getItemCount()-1);
134
		} else {
135
			setSelectedIndex(unitIndex);
136
		}
137
	}
138

  
139

  
140

  
141
}
0 142

  
tags/v_2_0_0_Build_2043/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/impl/DefaultMapControlLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.mapcontrol.impl;
29

  
30
import org.gvsig.fmap.mapcontrol.MapControlLibrary;
31
import org.gvsig.fmap.mapcontrol.MapControlLocator;
32
import org.gvsig.fmap.mapcontrol.MapControlManager;
33
import org.gvsig.tools.library.AbstractLibrary;
34
import org.gvsig.tools.library.LibraryException;
35
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
36

  
37
/**
38
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
39
 */
40
public class DefaultMapControlLibrary extends AbstractLibrary{
41
	
42
    @Override
43
    public void doRegistration() {
44
        registerAsImplementationOf(MapControlLibrary.class);
45
    }
46

  
47
	@Override
48
	protected void doInitialize() throws LibraryException {
49
		MapControlLocator.registerMapControlManager(DefaultMapControlManager.class);
50
	}
51

  
52
	@Override
53
	protected void doPostInitialize() throws LibraryException {
54
		// Validate there is any implementation registered.
55
		MapControlManager mapControlManager = MapControlLocator.getMapControlManager();
56
		if (mapControlManager == null) {
57
			throw new ReferenceNotRegisteredException(
58
					MapControlLocator.MAPCONTROL_MANAGER_NAME, 
59
					MapControlLocator.getInstance());
60
		}
61
		
62
		//Register the default implementation for a view, that will be
63
		//the 2D MapControlDrawer.
64
		mapControlManager.registerDefaultMapControlDrawer(MapControlDrawer2D.class);
65
	}
66
}
67

  
0 68

  
tags/v_2_0_0_Build_2043/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/impl/MapControlDrawer2D.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28
package org.gvsig.fmap.mapcontrol.impl;
29

  
30
import java.awt.Color;
31
import java.awt.Composite;
32
import java.awt.Image;
33
import java.awt.geom.AffineTransform;
34
import java.awt.geom.Point2D;
35

  
36
import org.gvsig.fmap.geom.Geometry;
37
import org.gvsig.fmap.geom.GeometryLocator;
38
import org.gvsig.fmap.geom.GeometryManager;
39
import org.gvsig.fmap.geom.handler.Handler;
40
import org.gvsig.fmap.geom.operation.Draw;
41
import org.gvsig.fmap.geom.operation.DrawOperationContext;
42
import org.gvsig.fmap.geom.operation.GeometryOperationException;
43
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
44
import org.gvsig.fmap.geom.primitive.Curve;
45
import org.gvsig.fmap.geom.primitive.GeneralPathX;
46
import org.gvsig.fmap.mapcontext.MapContextLocator;
47
import org.gvsig.fmap.mapcontext.ViewPort;
48
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
49
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
50
import org.slf4j.Logger;
51
import org.slf4j.LoggerFactory;
52

  
53
/**
54
 * MapControlDrawer for a 2D view.
55
 * 
56
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
57
 */
58
public class MapControlDrawer2D extends DefaultPrimitivesDrawer implements MapControlDrawer{
59
    private static final Logger LOG = LoggerFactory.getLogger(MapControlDrawer2D.class);
60
    
61
	protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
62
	private ViewPort viewPort = null;
63

  
64
	/**
65
	 * @param graphics
66
	 * @param viewPort
67
	 */
68
	public MapControlDrawer2D() {
69
		super();		
70
	}
71

  
72
	/* (non-Javadoc)
73
	 * @see org.gvsig.fmap.mapcontrol.tools.renderer.Renderer#draw(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol)
74
	 */
75
	public void draw(Geometry geometry, ISymbol symbol) {
76
		if (geometry != null) {
77
		    symbol.draw(graphics, viewPort.getAffineTransform(), geometry, null, null);             
78
		}		
79
	}
80

  
81
	/*
82
	 * (non-Javadoc)
83
	 * @see org.gvsig.fmap.mapcontrol.tools.renderer.Renderer#drawHandlers(org.gvsig.fmap.geom.Geometry, java.awt.geom.AffineTransform, org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol)
84
	 */
85
	public void drawHandlers(Handler[] handlers, AffineTransform at, ISymbol symbol) {
86
		for (int i = 0; i < handlers.length; i++) {
87
			Point2D point = handlers[i].getPoint();
88
			at.transform(point, point);
89

  
90
			graphics.setPaintMode();
91
			graphics.setColor(symbol.getColor());
92
			graphics.fillRect((int) (point.getX() - 3), (int) (point.getY() - 3), 7, 7);
93
			graphics.drawRect((int) (point.getX() - 5), (int) (point.getY() - 5), 10, 10);
94
			graphics.drawString( "" + i, (int) (point.getX() - 5), (int) (point.getY() - 5));
95
		}
96
	}
97

  
98
	/* (non-Javadoc)
99
	 * @see org.gvsig.fmap.mapcontrol.tools.renderer.Renderer#drawLine(java.awt.geom.Point2D, java.awt.geom.Point2D, org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol)
100
	 */
101
	public void drawLine(Point2D firstPoint, Point2D endPoint, ISymbol symbol) {
102
		GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2);
103
		elShape.moveTo(firstPoint.getX(), firstPoint.getY());
104
		elShape.lineTo(endPoint.getX(), endPoint.getY());
105
		DrawOperationContext doc = new DrawOperationContext();
106
		doc.setGraphics(graphics);
107
		doc.setViewPort(viewPort);
108
		doc.setSymbol(symbol);
109
		try {
110
			Curve curve = (Curve)geomManager.create(Geometry.TYPES.CURVE, Geometry.SUBTYPES.GEOM2D);
111
			curve.setGeneralPath(elShape);
112
			curve.invokeOperation(Draw.CODE, doc);
113
		} catch (GeometryOperationNotSupportedException e) {
114
			e.printStackTrace();
115
		} catch (GeometryOperationException e) {
116
			e.printStackTrace();
117
		} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
118
			e.printStackTrace();
119
		}		
120
	}
121

  
122
	/* (non-Javadoc)
123
	 * @see org.gvsig.fmap.mapcontrol.tools.renderer.Renderer#drawImage(java.awt.Image, int, int)
124
	 */
125
	public void drawImage(Image img, int x, int y) {
126
		if (img != null){
127
			graphics.drawImage(img, x, y, null);
128
		}		
129
	}	
130

  
131
	/*
132
	 * (non-Javadoc)
133
	 * @see org.gvsig.fmap.mapcontrol.MapControlDrawer#drawHandler(org.gvsig.fmap.geom.handler.Handler, java.awt.geom.AffineTransform)
134
	 */
135
	public void drawHandler(Handler handler, AffineTransform at) {
136
		Point2D point = handler.getPoint();
137
		Point2D dest = (Point2D) point.clone();
138
		at.transform(point, dest);
139
		graphics.setColor(Color.black);
140
		graphics.drawLine((int)dest.getX()-2,(int)dest.getY()-10,(int)dest.getX()-2,(int)dest.getY()+10);
141
		graphics.drawLine((int)dest.getX()+2,(int)dest.getY()-10,(int)dest.getX()+2,(int)dest.getY()+10);
142
		graphics.drawLine((int)dest.getX()-10,(int)dest.getY()-2,(int)dest.getX()+10,(int)dest.getY()-2);
143
		graphics.drawLine((int)dest.getX()-10,(int)dest.getY()+2,(int)dest.getX()+10,(int)dest.getY()+2);
144
		graphics.setColor(Color.red);
145
		graphics.drawLine((int)dest.getX()-1,(int)dest.getY()-10,(int)dest.getX()-1,(int)dest.getY()+10);
146
		graphics.drawLine((int)dest.getX()+1,(int)dest.getY()-10,(int)dest.getX()+1,(int)dest.getY()+10);
147
		graphics.drawLine((int)dest.getX()-10,(int)dest.getY()-1,(int)dest.getX()+10,(int)dest.getY()-1);
148
		graphics.drawLine((int)dest.getX()-10,(int)dest.getY()+1,(int)dest.getX()+10,(int)dest.getY()+1);
149
	}
150

  
151
	/* (non-Javadoc)
152
	 * @see org.gvsig.fmap.mapcontrol.tools.renderer.Renderer#drawImage(java.awt.Image, java.awt.geom.AffineTransform)
153
	 */
154
	public void drawImage(Image img, AffineTransform xform) {
155
		graphics.drawImage(img, xform, null);		
156
	}
157

  
158
	/* (non-Javadoc)
159
	 * @see org.gvsig.fmap.mapcontext.rendering.Renderer#setViewPort(org.gvsig.fmap.mapcontext.ViewPort)
160
	 */
161
	public void setViewPort(ViewPort viewPort) {
162
		this.viewPort = viewPort;		
163
	}
164

  
165
	/* (non-Javadoc)
166
	 * @see org.gvsig.fmap.mapcontrol.MapControlDrawer#draw(org.gvsig.fmap.geom.Geometry)
167
	 */
168
	public void draw(Geometry geometry) {
169
		draw(geometry, MapContextLocator.getSymbolManager().createSymbol(geometry.getType()));
170
	}
171

  
172
	/* (non-Javadoc)
173
	 * @see org.gvsig.fmap.mapcontrol.MapControlDrawer#setComposite(java.awt.AlphaComposite)
174
	 */
175
	public void setComposite(Composite composite) {
176
		graphics.setComposite(composite);
177
	}
178

  
179
	/* (non-Javadoc)
180
	 * @see org.gvsig.fmap.mapcontrol.MapControlDrawer#transform(java.awt.geom.AffineTransform)
181
	 */
182
	public void transform(AffineTransform at) {
183
		graphics.transform(at);		
184
	}
185

  
186
}
187

  
0 188

  
tags/v_2_0_0_Build_2043/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/impl/DefaultMapControlManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28
package org.gvsig.fmap.mapcontrol.impl;
29

  
30
import java.awt.Color;
31
import java.util.ArrayList;
32
import java.util.Iterator;
33
import java.util.Map;
34
import java.util.prefs.Preferences;
35

  
36
import org.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38

  
39
import org.gvsig.fmap.geom.Geometry;
40
import org.gvsig.fmap.mapcontext.MapContextLocator;
41
import org.gvsig.fmap.mapcontext.MapContextManager;
42
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
43
import org.gvsig.fmap.mapcontrol.MapControl;
44
import org.gvsig.fmap.mapcontrol.MapControlCreationException;
45
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
46
import org.gvsig.fmap.mapcontrol.MapControlManager;
47
import org.gvsig.fmap.mapcontrol.swing.dynobject.LayersDynObjectSetComponent;
48
import org.gvsig.fmap.mapcontrol.swing.dynobject.impl.DefaultLayersDynObjectSetComponent;
49
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapper;
50
import org.gvsig.tools.ToolsLocator;
51
import org.gvsig.tools.dynobject.DynObjectSet;
52
import org.gvsig.tools.extensionpoint.ExtensionPoint;
53
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension;
54
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
55

  
56
/**
57
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
58
 */
59
public class DefaultMapControlManager implements MapControlManager{
60
	private static final Logger logger = LoggerFactory.getLogger(MapControlManager.class);
61
	private static final String MAPCONTROL_MANAGER_EXTENSION_POINT = "MapControlManagerExtensionPoint";
62
	private static final String DEFAULT_MAPCONTROLMANAGER_NAME = null;
63
	private static final String SNAPPING_EXTENSION_POINT = "Snapper";
64

  
65
	private ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
66
	private int snappingTolerance = 4;
67
	private ISymbol selectionSymbol = null;	
68
	private ISymbol axisReferencesSymbol = null;
69
	private ISymbol geometrySelectionSymbol = null;
70
	private ISymbol handlerSymbol = null;
71
	private static MapContextManager mapContextManager = MapContextLocator
72
	.getMapContextManager();
73
	private Preferences prefs = Preferences.userRoot().node( "cadtooladapter" );
74
	private static Preferences prefSnappers = Preferences.userRoot().node("snappers");
75
	private ArrayList<ISnapper> snappers = null;	
76

  
77
	public DefaultMapControlManager() {
78
		super();
79
		snappers = new ArrayList<ISnapper>();
80
	}
81

  
82
	/* (non-Javadoc)
83
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#createDefaultMapControlDrawer()
84
	 */
85
	public MapControlDrawer createDefaultMapControlDrawer() throws MapControlCreationException {
86
		ExtensionPoint ep = extensionPoints.add(MAPCONTROL_MANAGER_EXTENSION_POINT);
87
		try {
88
			return (MapControlDrawer)ep.create(DEFAULT_MAPCONTROLMANAGER_NAME);			
89
		} catch (Exception e) {
90
			throw new MapControlCreationException(e);
91
		}	
92
	}
93

  
94
	/*
95
	 * (non-Javadoc)
96
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#createMapControlDrawer(java.lang.String)
97
	 */
98
	public MapControlDrawer createMapControlDrawer(String name) throws MapControlCreationException {
99
		ExtensionPoint ep = extensionPoints.add(MAPCONTROL_MANAGER_EXTENSION_POINT);
100
		try {
101
			return (MapControlDrawer)ep.create(name);			
102
		} catch (Exception e) {
103
			throw new MapControlCreationException(e);
104
		}
105
	}
106

  
107
	/* (non-Javadoc)
108
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#registerDefaultMapControlDrawer(java.lang.Class)
109
	 */
110
	public void registerDefaultMapControlDrawer(Class mapControlDrawerClass) {
111
		if (!MapControlDrawer.class.isAssignableFrom(mapControlDrawerClass)) {
112
			throw new IllegalArgumentException(mapControlDrawerClass.getName()
113
					+ " must implement the MapControlDrawer interface");
114
		}
115

  
116
		ExtensionPoint extensionPoint = extensionPoints.add(MAPCONTROL_MANAGER_EXTENSION_POINT, "");
117
		extensionPoint.append(DEFAULT_MAPCONTROLMANAGER_NAME, "Default MapControl", mapControlDrawerClass);		
118
	}
119

  
120
	/* (non-Javadoc)
121
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#registerMapControlDrawer(int, java.lang.Class)
122
	 */
123
	public void registerMapControlDrawer(String name,
124
			Class mapControlDrawerClass) {
125

  
126
		if (!MapControlDrawer.class.isAssignableFrom(mapControlDrawerClass)) {
127
			throw new IllegalArgumentException(mapControlDrawerClass.getName()
128
					+ " must implement the MapControlDrawer interface");
129
		}
130

  
131
		ExtensionPoint extensionPoint = extensionPoints.add(MAPCONTROL_MANAGER_EXTENSION_POINT, "");
132
		extensionPoint.append(name, "Default MapControl", mapControlDrawerClass);		
133
	}
134

  
135
	/* (non-Javadoc)
136
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getSnappingTolerance()
137
	 */
138
	public int getTolerance() {
139
		return snappingTolerance;
140
	}
141

  
142
	/* (non-Javadoc)
143
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#setSnappingTolerance(int)
144
	 */
145
	public void setTolerance(int tolerance) {
146
		snappingTolerance = tolerance;		
147
	}
148

  
149
	/* (non-Javadoc)
150
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#clearSnappers()
151
	 */
152
	public void clearSnappers() {
153
		snappers.clear();		
154
	}
155

  
156
	/* (non-Javadoc)
157
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getAxisReferenceSymbol()
158
	 */
159
	public ISymbol getAxisReferenceSymbol() {
160
		if (axisReferencesSymbol == null){
161
			axisReferencesSymbol =
162
					mapContextManager.getSymbolManager()
163
			.createSymbol(Geometry.TYPES.GEOMETRY,
164
					new Color(100, 100, 100, 100));
165
		}
166
		return axisReferencesSymbol;
167
	}
168

  
169
	/* (non-Javadoc)
170
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getGeometrySelectionSymbol()
171
	 */
172
	public ISymbol getGeometrySelectionSymbol() {
173
		if (geometrySelectionSymbol == null){
174
			geometrySelectionSymbol =
175
					mapContextManager.getSymbolManager()
176
			.createSymbol(Geometry.TYPES.GEOMETRY, Color.RED);
177
		}		
178
		return geometrySelectionSymbol;
179
	}
180

  
181
	/* (non-Javadoc)
182
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getHandlerSymbol()
183
	 */
184
	public ISymbol getHandlerSymbol() {
185
		if (handlerSymbol == null){
186
			handlerSymbol =
187
					mapContextManager.getSymbolManager().createSymbol(
188
					Geometry.TYPES.GEOMETRY, Color.ORANGE);
189
		}
190
		return handlerSymbol;
191
	}
192

  
193
	/* (non-Javadoc)
194
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getSelectionSymbol()
195
	 */
196
	public ISymbol getSelectionSymbol() {
197
		if (selectionSymbol == null){
198
			selectionSymbol =
199
					mapContextManager.getSymbolManager().createSymbol(
200
					Geometry.TYPES.GEOMETRY, new Color(255, 0, 0, 100)); 
201
		}
202
		return selectionSymbol;
203
	}
204

  
205
	/*
206
	 * (non-Javadoc)
207
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#setAxisReferenceSymbol(org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol)
208
	 */
209
	public void setAxisReferenceSymbol(ISymbol axisReferencesSymbol) {
210
		this.axisReferencesSymbol = axisReferencesSymbol;		
211
	}
212

  
213
	/*
214
	 * (non-Javadoc)
215
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#setGeometrySelectionSymbol(org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol)
216
	 */
217
	public void setGeometrySelectionSymbol(ISymbol geometrySelectionSymbol) {
218
		this.geometrySelectionSymbol = geometrySelectionSymbol;		
219
	}
220

  
221
	/*
222
	 * (non-Javadoc)
223
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#setHandlerSymbol(org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol)
224
	 */
225
	public void setHandlerSymbol(ISymbol handlerSymbol) {
226
		this.handlerSymbol = handlerSymbol;		
227
	}
228

  
229
	/*
230
	 * (non-Javadoc)
231
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#setSelectionSymbol(org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol)
232
	 */
233
	public void setSelectionSymbol(ISymbol selectionSymbol) {
234
		this.selectionSymbol = selectionSymbol;		
235
	}
236

  
237
	/* (non-Javadoc)
238
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#addSnapper(org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapper)
239
	 */
240
	public void registerSnapper(String name, Class snapperClass) {
241
		if (!ISnapper.class.isAssignableFrom(snapperClass)) {
242
			throw new IllegalArgumentException(snapperClass.getName()
243
					+ " must implement the ISnapper interface");
244
		}		
245

  
246
		ExtensionPoint extensionPoint = extensionPoints.add(SNAPPING_EXTENSION_POINT, "");
247
		Extension extension = extensionPoint.append(name, "", snapperClass);
248

  
249
		ISnapper snapper;
250
		try {
251
			snapper = (ISnapper)extension.create();
252
			snappers.add(snapper);
253
            String nameClass=snapper.getClass().getName();
254
	        nameClass=nameClass.substring(nameClass.lastIndexOf('.'));
255
	        boolean select = prefSnappers.getBoolean("snapper_activated" + nameClass, false);
256
	        int priority = prefs.getInt("snapper_priority" + nameClass,3);
257
	        snapper.setPriority(priority);
258
	        if (select){
259
	          	snapper.setEnabled(select);   
260
	        }           
261
			
262
		} catch (Exception e) {
263
			logger.error("It is not possible to create the snapper");
264
		}       
265
	}
266

  
267
	/* (non-Javadoc)
268
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getSnapperAt(int)
269
	 */
270
	public ISnapper getSnapperAt(int index) {
271
		return snappers.get(index);
272
	}
273

  
274
	/* (non-Javadoc)
275
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getSnapperCount()
276
	 */
277
	public int getSnapperCount() {
278
		return snappers.size();
279
	}
280

  
281
	/* (non-Javadoc)
282
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#disableSnapping()
283
	 */
284
	public void disableSnapping() {
285
		snappers.clear();		
286
	}
287

  
288
	/* (non-Javadoc)
289
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#enableSnapping()
290
	 */
291
	public void enableSnapping() {
292
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
293
		ExtensionPoint ep = extensionPoints.get(SNAPPING_EXTENSION_POINT);
294
		Iterator iterator = ep.iterator();
295

  
296
		while (iterator.hasNext()) {
297
			try {
298
				Extension obj= (Extension)iterator.next();
299
				ISnapper snapper = (ISnapper) ep.create(obj.getName());
300
				snappers.add(snapper);
301
			} catch (Exception e) {
302
				logger.error("Creating a snapper", e);
303
			}
304
		}
305

  
306
		for (int n = 0; n < getSnapperCount(); n++) {
307
			ISnapper snp = getSnapperAt(n);
308
			String nameClass = snp.getClass().getName();
309
			nameClass = nameClass.substring(nameClass.lastIndexOf('.'));
310
			boolean select = prefs.getBoolean("snapper_activated" + nameClass, false);
311
			if (select) {
312
				snp.setEnabled(select);				
313
			}
314
			int priority = prefs.getInt("snapper_priority" + nameClass, 3);
315
			snp.setPriority(priority);
316
		}
317

  
318
	}
319

  
320
	/* (non-Javadoc)
321
	 * @see org.gvsig.fmap.mapcontrol.MapControlManager#getEditionPreferences()
322
	 */
323
	public Preferences getEditionPreferences() {
324
		return prefs;
325
	}
326

  
327
	public MapControl createJMapControlPanel() throws MapControlCreationException {
328
		MapControl mapControl = new MapControl();
329
		mapControl.setMapControlDrawer(this.createDefaultMapControlDrawer());
330
		return mapControl;
331
	}
332

  
333
    public LayersDynObjectSetComponent createLayersDynObjectSetComponent(
334
        Map<String, DynObjectSet> layerName2InfoByPoint) {
335
        return createLayersDynObjectSetComponent(layerName2InfoByPoint, false);
336
    }
337

  
338
    public LayersDynObjectSetComponent createLayersDynObjectSetComponent(
339
        Map<String, DynObjectSet> layerName2InfoByPoint, boolean writable) {
340
        return new DefaultLayersDynObjectSetComponent(layerName2InfoByPoint,
341
            writable);
342
    }
343
}
0 344

  
tags/v_2_0_0_Build_2043/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/impl/DefaultPrimitivesDrawer.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22
package org.gvsig.fmap.mapcontrol.impl;
23

  
24
import java.awt.Color;
25
import java.awt.Graphics;
26
import java.awt.Graphics2D;
27

  
28
import org.slf4j.Logger;
29
import org.slf4j.LoggerFactory;
30

  
31
import org.gvsig.fmap.mapcontrol.PrimitivesDrawer;
32

  
33
/**
34
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
35
 */
36
public class DefaultPrimitivesDrawer implements PrimitivesDrawer {
37

  
38
    private static final Logger LOG = LoggerFactory
39
        .getLogger(DefaultPrimitivesDrawer.class);
40

  
41
    protected Graphics2D graphics = null;
42
    protected Color color = Color.BLACK;
43
    protected Color xorColor = Color.WHITE;
44
    private Object lockObject = null;
45

  
46
    public DefaultPrimitivesDrawer() {
47
        super();
48
    }
49

  
50
    public DefaultPrimitivesDrawer(Graphics2D graphics) {
51
        super();
52
        this.graphics = graphics;
53
    }
54

  
55
    public void drawLine(int x1, int y1, int x2, int y2) {
56
        graphics.setXORMode(xorColor);
57
        graphics.drawLine(x1, y1, x2, y2);
58
        graphics.setPaintMode();
59
    }
60

  
61
    public void drawOval(int x, int y, int width, int height) {
62
        graphics.setXORMode(xorColor);
63
        graphics.drawOval(x, y, width, height);
64
        graphics.setPaintMode();
65
    }
66

  
67
    public void drawRect(int x, int y, int width, int height) {
68
        graphics.setXORMode(xorColor);
69
        graphics.drawRect(x, y, width, height);
70
        graphics.setPaintMode();
71
    }
72

  
73
    public void fillRect(int x, int y, int width, int height) {
74
        graphics.setColor(color);
75
        graphics.fillRect(x, y, width, height);
76
    }
77

  
78
    public void setColor(Color color) {
79
        this.color = color;
80
    }
81

  
82
    public void setGraphics(Graphics graphics) {
83
        this.graphics = (Graphics2D) graphics;
84
    }
85

  
86
    public void stopDrawing(Object obj) {
87
        if (lockObject != obj) {
88
            LOG.warn("Trying to unlock a resource that is not locked");
89
            return;
90
        }
91
        lockObject = null;
92
    }
93

  
94
    public void startDrawing(Object obj) throws InterruptedException {
95
        while ((lockObject != null) && (obj != lockObject)) {
96
            Thread.sleep(100);
97
        }
98
        lockObject = obj;
99
    }
100
}
0 101

  
tags/v_2_0_0_Build_2043/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/MapControlCreationException.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.mapcontrol;
29
/**
30
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
31
 */
32
public class MapControlCreationException extends MapControlException {
33
	private static final long serialVersionUID = -7886043430856453161L;
34
	private static final String KEY = "mapcontrol_creatioon_exception";
35
	private static final String MESSAGE = "Error creating a MapControl";
36
    
37
	public MapControlCreationException(Throwable cause) {
38
		super(MESSAGE, cause, KEY, serialVersionUID);
39
	}
40

  
41
}
42

  
0 43

  
tags/v_2_0_0_Build_2043/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/MapControlLocator.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.mapcontrol;
29

  
30
import org.gvsig.tools.locator.AbstractLocator;
31
import org.gvsig.tools.locator.Locator;
32
import org.gvsig.tools.locator.LocatorException;
33

  
34
/**
35
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
36
 */
37
public class MapControlLocator extends AbstractLocator {
38
	private static final String LOCATOR_NAME = "MapContolLocator";
39
	
40
	/**
41
	 * MapControlManager name used by the locator to access the instance
42
	 */
43
	public static final String MAPCONTROL_MANAGER_NAME = "MapControlManager";
44
	private static final String MAPCONTROL_MANAGER_DESCRIPTION = "MapControlManager of gvSIG";
45

  
46
	/**
47
	 * Unique instance.
48
	 */
49
	private static final MapControlLocator instance = new MapControlLocator();
50
	
51
	/* (non-Javadoc)
52
	 * @see org.gvsig.tools.locator.Locator#getLocatorName()
53
	 */
54
	public String getLocatorName() {
55
		return LOCATOR_NAME;
56
	}
57
	
58
	/**
59
	 * Return a reference to {@link MapControlManager}.
60
	 *
61
	 * @return a reference to MapControlManager
62
	 * @throws LocatorException
63
	 *             if there is no access to the class or the class cannot be
64
	 *             instantiated
65
	 * @see Locator#get(String)
66
	 */
67
	public static MapControlManager getMapControlManager() throws LocatorException {
68
		return (MapControlManager) getInstance().get(MAPCONTROL_MANAGER_NAME);
69
	}
70
	
71
	/**
72
	 * Return the singleton instance.
73
	 *
74
	 * @return the singleton instance
75
	 */
76
	public static MapControlLocator getInstance() {
77
		return instance;
78
	}
79
	
80
	/**
81
	 * Registers the Class implementing the {@link MapControlManager} interface.
82
	 *
83
	 * @param clazz
84
	 *            implementing the MapControlManager interface
85
	 */
86
	public static void registerMapControlManager(Class clazz) {
87
		getInstance().register(MAPCONTROL_MANAGER_NAME, 
88
				MAPCONTROL_MANAGER_DESCRIPTION,
89
				clazz);
90
	}
91
}
92

  
93

  
0 94

  
tags/v_2_0_0_Build_2043/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/MapControlDrawer.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28
package org.gvsig.fmap.mapcontrol;
29

  
30
import java.awt.Color;
31
import java.awt.Composite;
32
import java.awt.Image;
33
import java.awt.geom.AffineTransform;
34
import java.awt.geom.Point2D;
35

  
36
import org.gvsig.fmap.geom.Geometry;
37
import org.gvsig.fmap.geom.handler.Handler;
38
import org.gvsig.fmap.mapcontext.ViewPort;
39
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
40

  
41
/**
42
 * <p>
43
 * Represents a class that can write objects in a map like a raster image, a
44
 * {@link Geometry} or other graphical objects. This class doesn't depend of the
45
 * dimension of the map (2D or 3D).
46
 * </p>
47
 * <p>
48
 * The Map Control has to have an instance of this class that can be accessed
49
 * using the {@link MapControl#getMapControlDrawer()} method. When a Map Control
50
 * is created some tools are added to this component using the
51
 * {@link MapControl#addBehavior(String, org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior)}
52
 * method. Some of these tools need to draw some objects in the map and they use
53
 * the MapControlDrawer class to do that.
54
 * </p>
55
 * 
56
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
57
 */
58
public interface MapControlDrawer extends PrimitivesDrawer {
59

  
60
    /**
61
     * The <code>ViewPort</code> is used to transform the map
62
     * coordinates in the screen coordinates.
63
     * 
64
     * @param viewPort
65
     *            The <code>ViewPort</code>
66
     */
67
    public void setViewPort(ViewPort viewPort);
68

  
69
    /**
70
     * It draws a <code>Geometry</code> on the map using the color
71
     * specified using the {@link #setColor(Color)} method.
72
     * 
73
     * @param geometry
74
     *            The <code>Geometry</code> to draw.
75
     */
76
    public void draw(Geometry geometry);
77

  
78
    /**
79
     * It draws a <code>Geometry</code> on the map using a concrete
80
     * symbol.
81
     * 
82
     * @param geometry
83
     *            The <code>Geometry</code> to draw.
84
     * @param symbol
85
     *            The symbol used to draw the geometry.
86
     */
87
    public void draw(Geometry geometry, ISymbol symbol);
88

  
89
    /**
90
     * It draws the <code>Handler</code>'s that compose a geometry
91
     * on the map.
92
     * 
93
     * @param handlers
94
     *            An array of <code>Handler</code>'s.
95
     * @param at
96
     *            A transformation that has to be applied to the
97
     *            <code>Handler</code>'s.
98
     * @param symbol
99
     *            The symbol used to draw the handlers.
100
     */
101
    public void drawHandlers(Handler[] handlers, AffineTransform at,
102
        ISymbol symbol);
103

  
104
    /**
105
     * It draws a line using a concrete symbol.
106
     * 
107
     * @param firstPoint
108
     *            The first point of the line.
109
     * @param endPoint
110
     *            The end point of the line.
111
     * @param symbol
112
     *            The symbol used to draw the line.
113
     */
114
    public void drawLine(Point2D firstPoint, Point2D endPoint, ISymbol symbol);
115

  
116
    /**
117
     * It draws an image on a map in a concrete position.
118
     * 
119
     * @param img
120
     *            The image to draw.
121
     * @param x
122
     *            The X coordinate,
123
     * @param y
124
     *            The Y coordinate.
125
     */
126
    public void drawImage(Image img, int x, int y);
127

  
128
    /**
129
     * It draws image, applying a transform from image space
130
     * into user space before drawing.
131
     * 
132
     * @param img
133
     *            The image to draw.
134
     * @param xform
135
     *            The transform to apply.
136
     */
137
    public void drawImage(Image img, AffineTransform xform);
138

  
139
    /**
140
     * It draws a <code>Handler</code> on the map.
141
     * 
142
     * @param handler
143
     *            The <code>Handler</code> to draw.
144
     * @param at
145
     *            A transformation that has to be applied to the
146
     *            <code>Handler</code>.
147
     */
148
    public void drawHandler(Handler handler, AffineTransform at);
149

  
150
    /**
151
     * @param at
152
     */
153
    public void transform(AffineTransform at);
154

  
155
    /**
156
     * @param instance
157
     */
158
    public void setComposite(Composite instance);
159

  
160
}
0 161

  
tags/v_2_0_0_Build_2043/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/MapControlLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {DiSiD Technologies}  {Create Library class to initialize the MapControls library}
26
 */
27
package org.gvsig.fmap.mapcontrol;
28

  
29
import java.util.Locale;
30

  
31
import org.gvsig.fmap.mapcontext.MapContextLibrary;
32
import org.gvsig.i18n.Messages;
33
import org.gvsig.tools.library.AbstractLibrary;
34
import org.gvsig.tools.library.LibraryException;
35

  
36
/**
37
 * Initialization of the MapControls library.
38
 * 
39
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
40
 */
41
public class MapControlLibrary extends AbstractLibrary {
42

  
43
    @Override
44
    public void doRegistration() {
45
        registerAsAPI(MapControlLibrary.class);
46
        require(MapContextLibrary.class);
47
    }
48

  
49
	@Override
50
	protected void doInitialize() throws LibraryException {
51
		if (!Messages.hasLocales()) {
52
			Messages.addLocale(Locale.getDefault());
53
		}
54
		Messages.addResourceFamily(
55
				"org.gvsig.fmap.mapcontrol.i18n.text",
56
				MapControlLibrary.class.getClassLoader(),
57
				MapControlLibrary.class.getClass().getName());
58
	}
59
	
60
	@Override
61
	protected void doPostInitialize() throws LibraryException {
62
	}
63
}
tags/v_2_0_0_Build_2043/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynobject/DynObjectEditor.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 IVER T.I. S.A.   {{Task}}
26
 */
27

  
28
/**
29
 *
30
 */
31
package org.gvsig.fmap.mapcontrol.swing.dynobject;
32

  
33
import java.awt.BorderLayout;
34
import java.awt.Component;
35
import java.awt.GridBagConstraints;
36
import java.awt.GridBagLayout;
37
import java.awt.Insets;
38
import java.awt.event.ActionEvent;
39
import java.awt.event.ActionListener;
40

  
41
import javax.swing.JButton;
42
import javax.swing.JLabel;
43
import javax.swing.JPanel;
44

  
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

  
48
import org.gvsig.i18n.Messages;
49
import org.gvsig.tools.dynobject.DynObject;
50
import org.gvsig.tools.service.ServiceException;
51
import org.gvsig.tools.swing.api.ToolsSwingLocator;
52
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent;
53
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
54

  
55
/**
56
 * Editor for a store parameters.
57
 * 
58
 * @author gvSIG Team
59
 * @version $Id$
60
 */
61
public class DynObjectEditor extends JPanel implements ActionListener {
62

  
63
    private static final long serialVersionUID = 23898787077741411L;
64

  
65
    private static final Logger LOG = LoggerFactory
66
        .getLogger(DynObjectEditor.class);
67
    
68
    private static final WindowManager WINDOW_MANAGER =
69
        ToolsSwingLocator.getWindowManager();
70
    
71
    private String title;
72

  
73
    private JButton botAcept;
74
    private JButton botCancel;
75
    private JButton botRestoreDefaults;
76
    private JPanel panButtons;
77

  
78
    private boolean modal;
79

  
80
    private JDynObjectComponent component;
81

  
82
    public DynObjectEditor(DynObject parameters) throws ServiceException {
83
        component =
84
            ToolsSwingLocator.getDynObjectSwingManager()
85
                .createJDynObjectComponent(parameters, true);
86
        this.setLayout(new BorderLayout());
87
        this.add(component.asJComponent(), BorderLayout.CENTER);
88
        this.add(getButtonsPanel(), BorderLayout.SOUTH);
89
    }
90

  
91
    private JPanel getButtonsPanel() {
92
        if (this.panButtons == null) {
93
            this.panButtons = new JPanel();
94
            this.panButtons.setLayout(new GridBagLayout());
95
            GridBagConstraints constr = new GridBagConstraints();
96
            constr.anchor = GridBagConstraints.LAST_LINE_END;
97
            constr.fill = GridBagConstraints.HORIZONTAL;
98
            constr.weightx = 1;
99
            constr.weighty = 0;
100
            this.panButtons.add(new JLabel(), constr);
101

  
102
            constr = this.getDefaultParametersConstraints();
103
            constr.fill = GridBagConstraints.NONE;
104
            constr.weightx = 0;
105
            constr.weighty = 0;
106

  
107
            this.panButtons.add(this.getAcceptButton(), constr);
108
            this.panButtons.add(this.getCancelButton(), constr);
109
            this.panButtons.add(this.getRestoreDefaults(), constr);
110
        }
111
        return this.panButtons;
112
    }
113

  
114
    private GridBagConstraints getDefaultParametersConstraints() {
115
        GridBagConstraints constr = new GridBagConstraints();
116
        constr.insets = new Insets(2, 2, 2, 2);
117
        constr.ipadx = 2;
118
        constr.ipady = 2;
119
        constr.anchor = GridBagConstraints.PAGE_START;
120
        return constr;
121

  
122
    }
123

  
124
    private JButton getRestoreDefaults() {
125
        if (this.botRestoreDefaults == null) {
126
            this.botRestoreDefaults =
127
                ToolsSwingLocator.getUsabilitySwingManager().createJButton(
128
                    Messages.getText("restoreDefaults"));
129
            this.botRestoreDefaults.addActionListener(this);
130
        }
131
        return this.botRestoreDefaults;
132
    }
133

  
134
    private JButton getCancelButton() {
135
        if (this.botCancel == null) {
136
            this.botCancel =
137
                ToolsSwingLocator.getUsabilitySwingManager().createJButton(
138
                    Messages.getText("cancel"));
139
            this.botCancel.addActionListener(this);
140
        }
141
        return this.botCancel;
142
    }
143

  
144
    private JButton getAcceptButton() {
145
        if (this.botAcept == null) {
146
            this.botAcept =
147
                ToolsSwingLocator.getUsabilitySwingManager().createJButton(
148
                    Messages.getText("accept"));
149
            this.botAcept.addActionListener(this);
150
        }
151
        return this.botAcept;
152
    }
153

  
154
    public void actionPerformed(ActionEvent e) {
155
        Component source = (Component) e.getSource();
156
        if (source == this.botAcept) {
157
            this.component.saveStatus();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff