Revision 39308

View differences:

tags/v2_0_0_Build_2059/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/v2_0_0_Build_2059/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
}
tags/v2_0_0_Build_2059/libraries/libFMap_controls/src/org/gvsig/fmap/IconThemeHelper.java
1
package org.gvsig.fmap;
2

  
3
import java.awt.Image;
4

  
5
import javax.swing.ImageIcon;
6

  
7
import org.gvsig.tools.swing.api.ToolsSwingLocator;
8
import org.gvsig.tools.swing.icontheme.IconTheme;
9
import org.slf4j.Logger;
10
import org.slf4j.LoggerFactory;
11

  
12
public class IconThemeHelper {
13

  
14
	private static Logger logger = LoggerFactory.getLogger(IconThemeHelper.class);
15
	
16
	public static void registerIcon(String group, String name, Object obj) {
17
		String resourceName;
18
		ClassLoader loader;
19
		IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
20
		if( group == null || group.trim().length()==0 ) {
21
			resourceName = "images/"+name+".png";
22
		} else {
23
			resourceName = "images/"+group+"/"+name+".png";
24
		}
25
		if( obj instanceof Class ) {
26
			loader = ((Class) obj).getClassLoader();
27
		} else {
28
			loader = obj.getClass().getClassLoader();
29
		}
30
		try {
31
			iconTheme.registerDefault("mapcontrol", group, name, null, loader.getResource(resourceName));
32
		} catch( Throwable e) {
33
			logger.info(e.getMessage());
34
		}
35
	}
36

  
37
	public static ImageIcon getImageIcon(String iconName) {
38
		IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
39
		return iconTheme.get(iconName);
40
	}
41
	
42
	public static Image getImage(String iconName) {
43
		IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
44
		return iconTheme.get(iconName).getImage();
45
	}
46
}
0 47

  
tags/v2_0_0_Build_2059/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/v2_0_0_Build_2059/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/v2_0_0_Build_2059/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.RenderingHints;
34
import java.awt.Stroke;
35
import java.awt.geom.AffineTransform;
36
import java.awt.geom.Point2D;
37

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

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

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

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

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

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

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

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

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

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

  
152
    /**
153
     * @param at
154
     */
155
    public void transform(AffineTransform at);
156

  
157
    /**
158
     * @param instance
159
     */
160
    public void setComposite(Composite instance);
161
    
162
    /**
163
     * Replaces the values of all preferences for the rendering algorithms with the specified hints. The existing 
164
     * values for all rendering hints are discarded and the new set of known hints and values are initialized 
165
     * from the specified Map object. Hint categories include controls for rendering quality and overall time/
166
     * quality trade-off in the rendering process. Refer to the RenderingHints class for definitions of some 
167
     * common keys and values.
168
     * @param hints  the rendering hints to be set
169
     */
170
    public void setRenderingHints(RenderingHints hints);
171
    
172
    /**
173
     * Sets the Stroke for the Graphics2D context.
174
     * @param stroke the Stroke object to be used to stroke a Shape during the rendering 
175
     */
176
    public void setStroke(Stroke stroke);
177
    
178
    /**
179
     * Cleans the graphics using the image of the MapControl
180
     * @param mapCtrl
181
     */
182
    public void cleanCanvas(MapControl mapCtrl);
183

  
184
}
0 185

  
tags/v2_0_0_Build_2059/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.IconThemeHelper;
32
import org.gvsig.fmap.mapcontext.MapContextLibrary;
33
import org.gvsig.fmap.mapcontrol.swing.dynfield.factory.GeometryDynFieldComponentFactory;
34
import org.gvsig.i18n.Messages;
35
import org.gvsig.tools.library.AbstractLibrary;
36
import org.gvsig.tools.library.LibraryException;
37
import org.gvsig.tools.service.spi.ServiceManager;
38
import org.gvsig.tools.swing.spi.ToolsSwingServiceLocator;
39

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

  
47
    @Override
48
    public void doRegistration() {
49
        registerAsAPI(MapControlLibrary.class);
50
        require(MapContextLibrary.class);
51
    }
52

  
53
	@Override
54
	protected void doInitialize() throws LibraryException {
55
		if (!Messages.hasLocales()) {
56
			Messages.addLocale(Locale.getDefault());
57
		}
58
		Messages.addResourceFamily(
59
				"org.gvsig.fmap.mapcontrol.i18n.text",
60
				MapControlLibrary.class.getClassLoader(),
61
				MapControlLibrary.class.getClass().getName());
62
	}
63
	
64
	@Override
65
	protected void doPostInitialize() throws LibraryException {
66
	   	IconThemeHelper.registerIcon("cursor", "cursor-crux", this);
67
	   	IconThemeHelper.registerIcon("cursor", "cursor-info-by-point",this);
68
	   	IconThemeHelper.registerIcon("cursor", "cursor-pan", this);
69
	   	IconThemeHelper.registerIcon("cursor", "cursor-query-area", this);
70
	   	IconThemeHelper.registerIcon("cursor", "cursor-select-by-point", this);
71
	   	IconThemeHelper.registerIcon("cursor", "cursor-select-by-polygon", this);
72
	   	IconThemeHelper.registerIcon("cursor", "cursor-zoom-in", this);
73
	   	IconThemeHelper.registerIcon("cursor", "cursor-zoom-out", this);
74

  
75
	   	IconThemeHelper.registerIcon("layer", "layer-icon", this);
76
	   	IconThemeHelper.registerIcon("layer", "layer-icon-group", this);
77
	   	IconThemeHelper.registerIcon("layer", "layer-icon-vectorial", this);
78
	   	
79
	   	// =================================================
80
	   	// Add factory for creation of
81
	   	// swing component representing geometry
82
        ServiceManager dsManager = ToolsSwingServiceLocator.getServiceManager();
83
        dsManager.addServiceFactory(new GeometryDynFieldComponentFactory());
84
	}
85
}
tags/v2_0_0_Build_2059/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynfield/factory/GeometryDynFieldComponentFactory.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2012 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.mapcontrol.swing.dynfield.factory;
24

  
25
import org.gvsig.fmap.geom.DataTypes;
26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.fmap.mapcontrol.swing.dynfield.GeometryDynFieldComponent;
28
import org.gvsig.tools.dynobject.DynField;
29
import org.gvsig.tools.service.ServiceException;
30
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
31
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
32
import org.gvsig.tools.swing.spi.AbstractJDynFieldComponentFactory;
33

  
34

  
35
/**
36
 * This factory will create a swing component to represent
37
 * a {@link Geometry} object (for example when opening
38
 * a info by point dialog)
39
 * 
40
 * @author jldominguez
41
 *
42
 */
43
public class GeometryDynFieldComponentFactory extends
44
AbstractJDynFieldComponentFactory {
45

  
46
    public JDynFieldComponent createJDynFieldComponent(DynField child,
47
        ValueField dynObject, boolean writable) throws ServiceException {
48

  
49
        return new GeometryDynFieldComponent(child, dynObject, writable);
50
    }
51

  
52
    public String getFactoryDescription() {
53
        // TODO Auto-generated method stub
54
        return null;
55
    }
56

  
57
    public String getFactorySubType() {
58
        // TODO Auto-generated method stub
59
        return null;
60
    }
61

  
62
    public Integer getFactoryType() {
63
        return DataTypes.GEOMETRY;
64
    }
65

  
66
}
tags/v2_0_0_Build_2059/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynfield/GeometryDynFieldComponent.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2012 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.mapcontrol.swing.dynfield;
24

  
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27

  
28
import javax.swing.BoxLayout;
29
import javax.swing.JCheckBox;
30
import javax.swing.JComponent;
31
import javax.swing.JPanel;
32
import javax.swing.JTextField;
33

  
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

  
37
import org.gvsig.fmap.geom.Geometry;
38
import org.gvsig.i18n.Messages;
39
import org.gvsig.tools.dynobject.DynField;
40
import org.gvsig.tools.service.ServiceException;
41
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
42
import org.gvsig.tools.swing.spi.AbstractJDynFieldComponent;
43

  
44

  
45
/**
46
 * 
47
 * This class provides a swing component
48
 * to represent {@link Geometry} objects in dialogs/forms
49
 * 
50
 * 
51
 * @author jldominguez
52
 *
53
 */
54
public class GeometryDynFieldComponent extends
55
AbstractJDynFieldComponent implements ActionListener {
56
    
57
    private static Logger logger =
58
        LoggerFactory.getLogger(GeometryDynFieldComponent.class);
59
    
60
    private JCheckBox wktCheckBox = null; 
61
    private JTextField txtField = null; 
62
    private JPanel panel = null;
63

  
64
    public GeometryDynFieldComponent(
65
        DynField definition,
66
        ValueField value,
67
        boolean writeable) throws ServiceException {
68
        
69
        super(definition, value, false /* cannot edit geometry. writeable*/);
70
        init();
71
    }
72

  
73

  
74

  
75

  
76

  
77
    public void setEnabled(boolean isEnabled) {
78
    }
79

  
80
    public void requestFocus() {
81
    }
82

  
83
    public JComponent asJComponent() {
84
        return panel;
85
    }
86

  
87
    public Object getValue() {
88
        return this.getFieldValue();
89
    }
90

  
91
    protected void setJDynFieldComponentListeners() {
92
    }
93

  
94
    protected void afterUI() {
95
    }
96

  
97
    protected void initData() {
98
    }
99
    
100
    private String getValueText(boolean wkt) {
101
        Object val = this.getFieldValue();
102
        String txt = null;
103
        
104
        if (val == null || (!(val instanceof Geometry))) {
105
            txt = "[" + Messages.getText("_Invalid_value") + "]";
106
        } else {
107
            Geometry geom = (Geometry) val;
108
            if (wkt) {
109
                try {
110
                    txt = geom.convertToWKT();
111
                } catch (Exception e) {
112
                    logger.info("Error while getting WKT: " + e.getMessage(), e);
113
                    txt = "[" + Messages.getText("_Unable_to_show_value") + "]";
114
                }
115
            } else {
116
                txt = geom.getGeometryType().getName();
117
            }
118
        }
119
        return txt;
120
    }
121

  
122
    protected void initUI() {
123
        
124
        wktCheckBox =
125
            new JCheckBox(Messages.getText("_Show_as_text") + "  ");
126
        wktCheckBox.setSelected(false);
127
        wktCheckBox.addActionListener(this);
128
        txtField = new JTextField();
129
        // txtField.setEditable(false);
130
        txtField.setText(this.getValueText(wktCheckBox.isSelected()));
131
        txtField.setHorizontalAlignment(JTextField.LEFT);
132
        
133
        panel = new JPanel(); // new GridBagLayout());
134
        panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
135
        
136
        /*
137
        GridBagConstraints constr = new GridBagConstraints();
138
        constr.insets = new Insets(3, 3, 3, 3);
139
        constr.gridx = 0;
140
        constr.gridy = 0;
141
        constr.fill = GridBagConstraints.NONE;
142
        */
143
        
144
        panel.add(wktCheckBox); // , constr);
145
        /*
146
        constr.gridx = 1;
147
        constr.fill = GridBagConstraints.HORIZONTAL;
148
        */
149
        panel.add(txtField); // , constr);
150
    }
151

  
152
    protected void setNonNullValue(Object value) {
153
    }
154

  
155
    protected void setNullValue() {
156
    }
157

  
158
    protected void setReadOnly() {
159
    }
160

  
161

  
162
    public void actionPerformed(ActionEvent e) {
163
        // update txt field when check box state changes
164
        if (txtField != null && wktCheckBox != null) {
165
            txtField.setText(this.getValueText(wktCheckBox.isSelected()));
166
            txtField.setHorizontalAlignment(JTextField.LEFT);
167
        }
168
    }
169

  
170
}
tags/v2_0_0_Build_2059/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynobject/LayersDynObjectSetComponent.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.swing.dynobject;
23

  
24
import org.gvsig.tools.dispose.Disposable;
25
import org.gvsig.tools.swing.api.Component;
26

  
27
/**
28
 * Interface for components to show information of a list of layers.
29
 * 
30
 * @author gvSIG Team
31
 * @version $Id$
32
 */
33
public interface LayersDynObjectSetComponent extends Component, Disposable {
34

  
35

  
36
}
tags/v2_0_0_Build_2059/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynobject/impl/DefaultLayersDynObjectSetComponent.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.swing.dynobject.impl;
23

  
24
import java.awt.BorderLayout;
25
import java.util.Map;
26

  
27
import javax.swing.JComponent;
28
import javax.swing.JList;
29
import javax.swing.JPanel;
30
import javax.swing.ListSelectionModel;
31
import javax.swing.event.ListSelectionEvent;
32
import javax.swing.event.ListSelectionListener;
33

  
34
import org.gvsig.fmap.mapcontrol.swing.dynobject.LayersDynObjectSetComponent;
35
import org.gvsig.tools.dynobject.DynObjectSet;
36
import org.gvsig.tools.exception.BaseException;
37
import org.gvsig.tools.swing.api.ToolsSwingLocator;
38
import org.gvsig.tools.swing.api.dynobject.set.JDynObjectSetComponent;
39
import org.slf4j.Logger;
40
import org.slf4j.LoggerFactory;
41

  
42
/**
43
 * @author gvSIG Team
44
 * @version $Id$
45
 * 
46
 */
47
public class DefaultLayersDynObjectSetComponent extends JPanel implements
48
    LayersDynObjectSetComponent, ListSelectionListener {
49

  
50
    private static final long serialVersionUID = 5864674721657215264L;
51

  
52
    private static final Logger LOG = LoggerFactory
53
        .getLogger(DefaultLayersDynObjectSetComponent.class);
54

  
55
    private final LayersDynObjectSetComponentModel model;
56

  
57
    private JDynObjectSetComponent component;
58

  
59
    private JList layersList;
60

  
61
    private final boolean writable;
62

  
63
    /**
64
     * Creates a new {@link DefaultLayersDynObjectSetComponent} with the given
65
     * information for a list of layers.
66
     */
67
    public DefaultLayersDynObjectSetComponent(
68
        Map<String, DynObjectSet> layerName2InfoByPoint) {
69
        this(layerName2InfoByPoint, true);
70
    }
71

  
72
    /**
73
     * @param isDoubleBuffered
74
     */
75
    public DefaultLayersDynObjectSetComponent(
76
        Map<String, DynObjectSet> layerName2InfoByPoint,
77
 boolean writable) {
78
        super(new BorderLayout());
79
        this.writable = writable;
80
        model = new LayersDynObjectSetComponentModel(layerName2InfoByPoint);
81
        initializeUI();
82
    }
83

  
84
    private void initializeUI() {
85
        addLayerList();
86
    }
87

  
88
    private void addLayerList() {
89
        layersList = new JList(model);
90
        layersList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
91
        layersList.setLayoutOrientation(JList.VERTICAL);
92
        // list.setVisibleRowCount(20);
93
        layersList.addListSelectionListener(this);
94

  
95
        add(layersList, BorderLayout.WEST);
96

  
97
        layersList.setSelectedIndex(0);
98
    }
99

  
100
    public void valueChanged(ListSelectionEvent e) {
101
        if (!e.getValueIsAdjusting()) {
102
            String layerName = (String) layersList.getSelectedValue();
103
            setCurrentLayerInfoByPoint(layerName);
104
        }
105
    }
106

  
107
    private void setCurrentLayerInfoByPoint(String layerName) {
108
        JDynObjectSetComponent newComponent = null;
109

  
110
        DynObjectSet dynObjectSet = model.getLayerInfoByPoint(layerName);
111
        try {
112
            newComponent =
113
                ToolsSwingLocator.getDynObjectSwingManager()
114
                    .createJDynObjectSetComponent(dynObjectSet, writable);
115
        } catch (BaseException e) {
116
            LOG.error("Error creating the JDynObjectSetComponent for "
117
                + "the DynObjectSet: " + dynObjectSet, e);
118
        }
119

  
120
        if (newComponent != null) {
121
            removeCurrentDynObjectSetComponent();
122
            component = newComponent;
123
            add(component.asJComponent(), BorderLayout.CENTER);
124
            revalidate();
125
            repaint();
126
        }
127
    }
128

  
129
    public JComponent asJComponent() {
130
        return this;
131
    }
132

  
133
    public void dispose() {
134
        removeCurrentDynObjectSetComponent();
135
        model.dispose();
136
    }
137

  
138
    private void removeCurrentDynObjectSetComponent() {
139
        if (component != null) {
140
            remove(component.asJComponent());
141
            component.dispose();
142
        }
143
    }
144

  
145
}
tags/v2_0_0_Build_2059/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynobject/impl/LayersDynObjectSetComponentModel.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.swing.dynobject.impl;
23

  
24
import java.util.Iterator;
25
import java.util.Map;
26
import java.util.Set;
27

  
28
import javax.swing.AbstractListModel;
29

  
30
import org.gvsig.fmap.mapcontrol.swing.dynobject.LayersDynObjectSetComponent;
31
import org.gvsig.tools.dispose.Disposable;
32
import org.gvsig.tools.dynobject.DynObjectSet;
33

  
34
/**
35
 * Model for a {@link LayersDynObjectSetComponent}.
36
 * 
37
 * @author gvSIG Team
38
 * @version $Id$
39
 */
40
public class LayersDynObjectSetComponentModel extends AbstractListModel
41
    implements Disposable {
42

  
43
    private static final long serialVersionUID = -7978388308830573063L;
44

  
45
    private final Map<String, DynObjectSet> layerName2InfoByPoint;
46
    private final String[] layerNames;
47

  
48
    public LayersDynObjectSetComponentModel(
49
        Map<String, DynObjectSet> layerName2InfoByPoint) {
50
        this.layerName2InfoByPoint = layerName2InfoByPoint;
51
        Set<String> keyset = layerName2InfoByPoint.keySet();
52
        layerNames = keyset.toArray(new String[keyset.size()]);
53
    }
54

  
55
    public String[] getLayerNames() {
56
        Set<String> keyset = layerName2InfoByPoint.keySet();
57
        return keyset.toArray(new String[keyset.size()]);
58
    }
59

  
60
    public DynObjectSet getLayerInfoByPoint(String layerName) {
61
        return layerName2InfoByPoint.get(layerName);
62
    }
63

  
64
    public int getSize() {
65
        return layerName2InfoByPoint.size();
66
    }
67

  
68
    public Object getElementAt(int index) {
69
        return layerNames[index];
70
    }
71

  
72
    public void dispose() {
73
        for (Iterator<DynObjectSet> iterator =
74
            layerName2InfoByPoint.values().iterator(); iterator.hasNext();) {
75
            iterator.next().dispose();
76
        }
77
        layerName2InfoByPoint.clear();
78
    }
79
}
tags/v2_0_0_Build_2059/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynobject/DynObjectViewer.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. S.A.   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.mapcontrol.swing.dynobject;
29

  
30
import java.awt.Color;
31
import java.awt.GridBagConstraints;
32
import java.awt.GridBagLayout;
33

  
34
import javax.swing.JLabel;
35
import javax.swing.JPanel;
36
import javax.swing.JTextField;
37

  
38
import org.cresques.cts.IProjection;
39
import org.gvsig.i18n.Messages;
40
import org.gvsig.tools.dynobject.DynClass;
41
import org.gvsig.tools.dynobject.DynField;
42
import org.gvsig.tools.dynobject.DynObject;
43

  
44

  
45
public class DynObjectViewer extends JPanel {
46

  
47
	/**
48
	 *
49
	 */
50
	private static final long serialVersionUID = -5277036770491043233L;
51
	private GridBagConstraints paramsListLabelConstraint;
52
	private GridBagConstraints paramsListValueConstraint;
53
	private GridBagConstraints paramsListFillConstraint;
54

  
55
	public DynObjectViewer() {
56
		super();
57
		this.intialize();
58
	}
59

  
60
	private void intialize() {
61
		this.setLayout(new GridBagLayout());
62

  
63
		paramsListLabelConstraint = new GridBagConstraints();
64
		paramsListValueConstraint = new GridBagConstraints();
65
		paramsListFillConstraint = new GridBagConstraints();
66

  
67
		paramsListLabelConstraint.ipadx = 3;
68
		paramsListLabelConstraint.ipady = 3;
69
		paramsListLabelConstraint.anchor = GridBagConstraints.FIRST_LINE_START;
70
		paramsListLabelConstraint.gridwidth = GridBagConstraints.RELATIVE;
71
		paramsListLabelConstraint.fill = GridBagConstraints.HORIZONTAL;
72
		paramsListLabelConstraint.weightx = 0.5;
73

  
74
		paramsListValueConstraint.ipadx = 3;
75
		paramsListValueConstraint.ipady = 3;
76
		paramsListValueConstraint.anchor = GridBagConstraints.FIRST_LINE_END;
77
		paramsListValueConstraint.gridwidth = GridBagConstraints.REMAINDER;
78
		paramsListValueConstraint.fill = GridBagConstraints.HORIZONTAL;
79
		paramsListValueConstraint.weightx = 0.5;
80

  
81
		paramsListFillConstraint.ipadx = 3;
82
		paramsListFillConstraint.ipady = 3;
83
		paramsListFillConstraint.anchor = GridBagConstraints.FIRST_LINE_END;
84
		paramsListFillConstraint.gridwidth = GridBagConstraints.REMAINDER;
85
		paramsListFillConstraint.fill = GridBagConstraints.BOTH;
86
		paramsListFillConstraint.weightx = 1;
87
		paramsListFillConstraint.weighty = 1;
88
	}
89

  
90
	private String getLocalizedText(String txt) {
91
		try {
92
			return Messages.getText(txt);
93
		} catch (Exception e) {
94
			return txt;
95
		}
96
	}
97

  
98
	public void load(DynObject dynObj) {
99
		this.removeAll();
100

  
101
		if (dynObj == null) {
102
			this.doLayout();
103
			return;
104
		}
105
		DynClass dynClass = dynObj.getDynClass();
106

  
107
		JTextField label;
108
		JTextField text;
109
		Object value;
110
		String strValue;
111

  
112
		//		label = new JLabel();
113
		//		label.setText(getLocalizedText("parameter"));
114
		//		label.setBackground(Color.LIGHT_GRAY);
115
		//		this.add(label, paramsListLabelConstraint);
116

  
117
		text = new JTextField();
118
		text.setText(getLocalizedText("parameter"));
119
		text.setEditable(false);
120
		text.setBackground(Color.LIGHT_GRAY);
121
		this.add(text, paramsListLabelConstraint);
122

  
123
		text = new JTextField();
124
		text.setText(getLocalizedText("value"));
125
		text.setEditable(false);
126
		text.setBackground(Color.LIGHT_GRAY);
127
		this.add(text, paramsListValueConstraint);
128

  
129
		for (DynField field : dynClass.getDynFields()) {
130
			label = new JTextField();
131
			label.setText(field.getDescription());
132
			label.setEditable(false);
133
			this.add(label, paramsListLabelConstraint);
134

  
135
			strValue = "";
136
			value = dynObj.getDynValue(field.getName());
137
			if (value != null) {
138
				if (value instanceof String) {
139
					strValue = (String) value;
140
				} else if (value instanceof IProjection) {
141
					strValue = ((IProjection) value).getAbrev();
142
				} else {
143
					strValue = value.toString();
144
				}
145

  
146
			}
147
			text = new JTextField();
148
			text.setText(strValue);
149
			text.setEditable(false);
150
			this.add(text, paramsListValueConstraint);
151
		}
152

  
153
		this.add(new JLabel(), paramsListFillConstraint);
154

  
155
		this.doLayout();
156
		this.repaint();
157

  
158
	}
159
}
0 160

  
tags/v2_0_0_Build_2059/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, boolean showDefaultsButton)
83
        throws ServiceException {
84
        component =
85
            ToolsSwingLocator.getDynObjectSwingManager()
86
                .createJDynObjectComponent(parameters, true);
87
        this.setLayout(new BorderLayout());
88
        this.add(component.asJComponent(), BorderLayout.CENTER);
89
        this.add(getButtonsPanel(showDefaultsButton), BorderLayout.SOUTH);
90
    }
91
    
92
    public DynObjectEditor(DynObject parameters) throws ServiceException {
93
        this(parameters, false);
94
    }
95

  
96

  
97
    private JPanel getButtonsPanel(boolean add_defaults_button) {
98
        if (this.panButtons == null) {
99
            this.panButtons = new JPanel();
100
            this.panButtons.setLayout(new GridBagLayout());
101
            GridBagConstraints constr = new GridBagConstraints();
102
            constr.anchor = GridBagConstraints.LAST_LINE_END;
103
            constr.fill = GridBagConstraints.HORIZONTAL;
104
            constr.weightx = 1;
105
            constr.weighty = 0;
106
            this.panButtons.add(new JLabel(), constr);
107

  
108
            constr = this.getDefaultParametersConstraints();
109
            constr.fill = GridBagConstraints.NONE;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff