Revision 37999

View differences:

tags/v2_0_0_Build_2045/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/v2_0_0_Build_2045/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/v2_0_0_Build_2045/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/v2_0_0_Build_2045/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/v2_0_0_Build_2045/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_2045/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_2045/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/v2_0_0_Build_2045/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/v2_0_0_Build_2045/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_2045/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_2045/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.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

  
37
import org.gvsig.fmap.mapcontrol.swing.dynobject.LayersDynObjectSetComponent;
38
import org.gvsig.tools.dynobject.DynObjectSet;
39
import org.gvsig.tools.exception.BaseException;
40
import org.gvsig.tools.swing.api.ToolsSwingLocator;
41
import org.gvsig.tools.swing.api.dynobject.set.JDynObjectSetComponent;
42

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

  
51
    private static final long serialVersionUID = 5864674721657215264L;
52

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

  
56
    private final LayersDynObjectSetComponentModel model;
57

  
58
    private JDynObjectSetComponent component;
59

  
60
    private JList layersList;
61

  
62
    private final boolean writable;
63

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

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

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

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

  
96
        add(layersList, BorderLayout.WEST);
97

  
98
        layersList.setSelectedIndex(0);
99
    }
100

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

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

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

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

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

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

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

  
146
}
tags/v2_0_0_Build_2045/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

  
40
import org.gvsig.i18n.Messages;
41
import org.gvsig.tools.dynobject.DynClass;
42
import org.gvsig.tools.dynobject.DynField;
43
import org.gvsig.tools.dynobject.DynObject;
44

  
45

  
46
public class DynObjectViewer extends JPanel {
47

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

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

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

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

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

  
75
		paramsListValueConstraint.ipadx = 3;
76
		paramsListValueConstraint.ipady = 3;
77
		paramsListValueConstraint.anchor = GridBagConstraints.FIRST_LINE_END;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff