Revision 36314
tags/v2_0_0_Build_2035/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 |
|
|
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.Graphics; |
|
32 |
import java.awt.Graphics2D; |
|
33 |
|
|
34 |
import org.slf4j.Logger; |
|
35 |
import org.slf4j.LoggerFactory; |
|
36 |
|
|
37 |
import org.gvsig.fmap.mapcontrol.PrimitivesDrawer; |
|
38 |
|
|
39 |
/** |
|
40 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
41 |
*/ |
|
42 |
public class DefaultPrimitivesDrawer implements PrimitivesDrawer{ |
|
43 |
|
|
44 |
private static final Logger LOG = LoggerFactory |
|
45 |
.getLogger(DefaultPrimitivesDrawer.class); |
|
46 |
|
|
47 |
protected Graphics2D graphics = null; |
|
48 |
protected Color color = Color.BLACK; |
|
49 |
protected Color xorColor = Color.WHITE; |
|
50 |
private Object lockObject = null; |
|
51 |
|
|
52 |
public DefaultPrimitivesDrawer() { |
|
53 |
super(); |
|
54 |
} |
|
55 |
|
|
56 |
public DefaultPrimitivesDrawer(Graphics2D graphics) { |
|
57 |
super(); |
|
58 |
this.graphics = graphics; |
|
59 |
} |
|
60 |
|
|
61 |
/* |
|
62 |
* (non-Javadoc) |
|
63 |
* @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#drawLine(int, int, int, int) |
|
64 |
*/ |
|
65 |
public void drawLine(int x1, int y1, int x2, int y2) { |
|
66 |
graphics.setXORMode(xorColor); |
|
67 |
graphics.drawLine(x1, y1, x2, y2); |
|
68 |
graphics.setPaintMode(); |
|
69 |
} |
|
70 |
|
|
71 |
/* |
|
72 |
* (non-Javadoc) |
|
73 |
* @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#drawOval(int, int, int, int) |
|
74 |
*/ |
|
75 |
public void drawOval(int x, int y, int width, int height) { |
|
76 |
graphics.setXORMode(xorColor); |
|
77 |
graphics.drawOval(x, y, width, height); |
|
78 |
graphics.setPaintMode(); |
|
79 |
} |
|
80 |
|
|
81 |
/* |
|
82 |
* (non-Javadoc) |
|
83 |
* @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#drawRect(int, int, int, int) |
|
84 |
*/ |
|
85 |
public void drawRect(int x, int y, int width, int height) { |
|
86 |
graphics.setXORMode(xorColor); |
|
87 |
graphics.drawRect(x, y, width, height); |
|
88 |
graphics.setPaintMode(); |
|
89 |
} |
|
90 |
|
|
91 |
/* |
|
92 |
* (non-Javadoc) |
|
93 |
* @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#fillRect(int, int, int, int) |
|
94 |
*/ |
|
95 |
public void fillRect(int x, int y, int width, int height) { |
|
96 |
graphics.setXORMode(xorColor); |
|
97 |
graphics.fillRect(x, y, width, height); |
|
98 |
graphics.setPaintMode(); |
|
99 |
} |
|
100 |
|
|
101 |
/* |
|
102 |
* (non-Javadoc) |
|
103 |
* @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#setColor(java.awt.Color) |
|
104 |
*/ |
|
105 |
public void setColor(Color color) { |
|
106 |
this.color = color; |
|
107 |
} |
|
108 |
|
|
109 |
/* |
|
110 |
* (non-Javadoc) |
|
111 |
* @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#setGraphics(java.awt.Graphics) |
|
112 |
*/ |
|
113 |
public void setGraphics(Graphics graphics) { |
|
114 |
this.graphics = (Graphics2D)graphics; |
|
115 |
} |
|
116 |
|
|
117 |
/* |
|
118 |
* (non-Javadoc) |
|
119 |
* @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#stopDrawing(java.lang.Object) |
|
120 |
*/ |
|
121 |
public void stopDrawing(Object obj) { |
|
122 |
if (lockObject != obj){ |
|
123 |
LOG.warn("Trying to unlock a resource that is not locked"); |
|
124 |
return; |
|
125 |
} |
|
126 |
lockObject = null; |
|
127 |
} |
|
128 |
|
|
129 |
/* |
|
130 |
* (non-Javadoc) |
|
131 |
* @see org.gvsig.fmap.mapcontrol.PrimitivesDrawer#startDrawing(java.lang.Object) |
|
132 |
*/ |
|
133 |
public void startDrawing(Object obj) throws InterruptedException { |
|
134 |
while ((lockObject != null) && (obj != lockObject)){ |
|
135 |
Thread.sleep(100); |
|
136 |
} |
|
137 |
lockObject = obj; |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
0 | 141 |
tags/v2_0_0_Build_2035/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_2035/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 |
|
|
51 |
/** |
|
52 |
* MapControlDrawer for a 2D view. |
|
53 |
* |
|
54 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
55 |
*/ |
|
56 |
public class MapControlDrawer2D extends DefaultPrimitivesDrawer implements MapControlDrawer{ |
|
57 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
58 |
private ViewPort viewPort = null; |
|
59 |
|
|
60 |
/** |
|
61 |
* @param graphics |
|
62 |
* @param viewPort |
|
63 |
*/ |
|
64 |
public MapControlDrawer2D() { |
|
65 |
super(); |
|
66 |
} |
|
67 |
|
|
68 |
/* (non-Javadoc) |
|
69 |
* @see org.gvsig.fmap.mapcontrol.tools.renderer.Renderer#draw(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol) |
|
70 |
*/ |
|
71 |
public void draw(Geometry geometry, ISymbol symbol) { |
|
72 |
if (geometry != null) { |
|
73 |
DrawOperationContext doc = new DrawOperationContext(); |
|
74 |
doc.setGraphics(graphics); |
|
75 |
doc.setViewPort(viewPort); |
|
76 |
doc.setSymbol(symbol); |
|
77 |
try { |
|
78 |
geometry.cloneGeometry().invokeOperation(Draw.CODE, doc); |
|
79 |
} catch (GeometryOperationNotSupportedException e) { |
|
80 |
e.printStackTrace(); |
|
81 |
} catch (GeometryOperationException e) { |
|
82 |
e.printStackTrace(); |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
/* |
|
88 |
* (non-Javadoc) |
|
89 |
* @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) |
|
90 |
*/ |
|
91 |
public void drawHandlers(Handler[] handlers, AffineTransform at, ISymbol symbol) { |
|
92 |
for (int i = 0; i < handlers.length; i++) { |
|
93 |
Point2D point = handlers[i].getPoint(); |
|
94 |
at.transform(point, point); |
|
95 |
|
|
96 |
graphics.setPaintMode(); |
|
97 |
graphics.setColor(symbol.getColor()); |
|
98 |
graphics.fillRect((int) (point.getX() - 3), (int) (point.getY() - 3), 7, 7); |
|
99 |
graphics.drawRect((int) (point.getX() - 5), (int) (point.getY() - 5), 10, 10); |
|
100 |
graphics.drawString( "" + i, (int) (point.getX() - 5), (int) (point.getY() - 5)); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
/* (non-Javadoc) |
|
105 |
* @see org.gvsig.fmap.mapcontrol.tools.renderer.Renderer#drawLine(java.awt.geom.Point2D, java.awt.geom.Point2D, org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol) |
|
106 |
*/ |
|
107 |
public void drawLine(Point2D firstPoint, Point2D endPoint, ISymbol symbol) { |
|
108 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2); |
|
109 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
|
110 |
elShape.lineTo(endPoint.getX(), endPoint.getY()); |
|
111 |
DrawOperationContext doc = new DrawOperationContext(); |
|
112 |
doc.setGraphics(graphics); |
|
113 |
doc.setViewPort(viewPort); |
|
114 |
doc.setSymbol(symbol); |
|
115 |
try { |
|
116 |
Curve curve = (Curve)geomManager.create(Geometry.TYPES.CURVE, Geometry.SUBTYPES.GEOM2D); |
|
117 |
curve.setGeneralPath(elShape); |
|
118 |
curve.invokeOperation(Draw.CODE, doc); |
|
119 |
} catch (GeometryOperationNotSupportedException e) { |
|
120 |
e.printStackTrace(); |
|
121 |
} catch (GeometryOperationException e) { |
|
122 |
e.printStackTrace(); |
|
123 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) { |
|
124 |
e.printStackTrace(); |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
/* (non-Javadoc) |
|
129 |
* @see org.gvsig.fmap.mapcontrol.tools.renderer.Renderer#drawImage(java.awt.Image, int, int) |
|
130 |
*/ |
|
131 |
public void drawImage(Image img, int x, int y) { |
|
132 |
if (img != null){ |
|
133 |
graphics.drawImage(img, x, y, null); |
|
134 |
} |
|
135 |
} |
|
136 |
|
|
137 |
/* |
|
138 |
* (non-Javadoc) |
|
139 |
* @see org.gvsig.fmap.mapcontrol.MapControlDrawer#drawHandler(org.gvsig.fmap.geom.handler.Handler, java.awt.geom.AffineTransform) |
|
140 |
*/ |
|
141 |
public void drawHandler(Handler handler, AffineTransform at) { |
|
142 |
Point2D point = handler.getPoint(); |
|
143 |
at.transform(point, point); |
|
144 |
graphics.setColor(Color.black); |
|
145 |
graphics.drawLine((int)point.getX()-2,(int)point.getY()-10,(int)point.getX()-2,(int)point.getY()+10); |
|
146 |
graphics.drawLine((int)point.getX()+2,(int)point.getY()-10,(int)point.getX()+2,(int)point.getY()+10); |
|
147 |
graphics.drawLine((int)point.getX()-10,(int)point.getY()-2,(int)point.getX()+10,(int)point.getY()-2); |
|
148 |
graphics.drawLine((int)point.getX()-10,(int)point.getY()+2,(int)point.getX()+10,(int)point.getY()+2); |
|
149 |
graphics.setColor(Color.red); |
|
150 |
graphics.drawLine((int)point.getX()-1,(int)point.getY()-10,(int)point.getX()-1,(int)point.getY()+10); |
|
151 |
graphics.drawLine((int)point.getX()+1,(int)point.getY()-10,(int)point.getX()+1,(int)point.getY()+10); |
|
152 |
graphics.drawLine((int)point.getX()-10,(int)point.getY()-1,(int)point.getX()+10,(int)point.getY()-1); |
|
153 |
graphics.drawLine((int)point.getX()-10,(int)point.getY()+1,(int)point.getX()+10,(int)point.getY()+1); |
|
154 |
} |
|
155 |
|
|
156 |
/* (non-Javadoc) |
|
157 |
* @see org.gvsig.fmap.mapcontrol.tools.renderer.Renderer#drawImage(java.awt.Image, java.awt.geom.AffineTransform) |
|
158 |
*/ |
|
159 |
public void drawImage(Image img, AffineTransform xform) { |
|
160 |
graphics.drawImage(img, xform, null); |
|
161 |
} |
|
162 |
|
|
163 |
/* (non-Javadoc) |
|
164 |
* @see org.gvsig.fmap.mapcontext.rendering.Renderer#setViewPort(org.gvsig.fmap.mapcontext.ViewPort) |
|
165 |
*/ |
|
166 |
public void setViewPort(ViewPort viewPort) { |
|
167 |
this.viewPort = viewPort; |
|
168 |
} |
|
169 |
|
|
170 |
/* (non-Javadoc) |
|
171 |
* @see org.gvsig.fmap.mapcontrol.MapControlDrawer#draw(org.gvsig.fmap.geom.Geometry) |
|
172 |
*/ |
|
173 |
public void draw(Geometry geometry) { |
|
174 |
draw(geometry, MapContextLocator.getSymbolManager().createSymbol(geometry.getType())); |
|
175 |
} |
|
176 |
|
|
177 |
/* (non-Javadoc) |
|
178 |
* @see org.gvsig.fmap.mapcontrol.MapControlDrawer#setComposite(java.awt.AlphaComposite) |
|
179 |
*/ |
|
180 |
public void setComposite(Composite composite) { |
|
181 |
graphics.setComposite(composite); |
|
182 |
} |
|
183 |
|
|
184 |
/* (non-Javadoc) |
|
185 |
* @see org.gvsig.fmap.mapcontrol.MapControlDrawer#transform(java.awt.geom.AffineTransform) |
|
186 |
*/ |
|
187 |
public void transform(AffineTransform at) { |
|
188 |
graphics.transform(at); |
|
189 |
} |
|
190 |
|
|
191 |
} |
|
192 |
|
|
0 | 193 |
tags/v2_0_0_Build_2035/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_2035/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_2035/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_2035/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.Graphics; |
|
33 |
import java.awt.Image; |
|
34 |
import java.awt.geom.AffineTransform; |
|
35 |
import java.awt.geom.Point2D; |
|
36 |
|
|
37 |
import org.gvsig.fmap.geom.Geometry; |
|
38 |
import org.gvsig.fmap.geom.handler.Handler; |
|
39 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
40 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
41 |
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
|
42 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
43 |
|
|
44 |
/** |
|
45 |
* <p> |
|
46 |
* Represents a class that can write objects in a map like |
|
47 |
* a raster image, a {@link Geometry} or other graphical |
|
48 |
* objects. This class doesn't depend of the dimension of |
|
49 |
* the map (2D or 3D). |
|
50 |
* </p> |
|
51 |
* <p> |
|
52 |
* The Map Control has to have an instance of this class |
|
53 |
* that can be accessed using the {@link MapControl#getMapControlDrawer()} |
|
54 |
* method. When a Map Control is created some tools are |
|
55 |
* added to this component using the {@link MapControl#addBehavior(String, org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior)} |
|
56 |
* method. Some of these tools need to draw some objects in |
|
57 |
* the map and they use the MapControlDrawer class to do that. |
|
58 |
* </p> |
|
59 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
60 |
*/ |
|
61 |
public interface MapControlDrawer extends PrimitivesDrawer { |
|
62 |
|
|
63 |
/** |
|
64 |
* The <code>ViewPort</code> is used to transform the map |
|
65 |
* coordinates in the screen coordinates. |
|
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 |
* @param geometry |
|
75 |
* The <code>Geometry</code> to draw. |
|
76 |
*/ |
|
77 |
public void draw(Geometry geometry); |
|
78 |
|
|
79 |
/** |
|
80 |
* It draws a <code>Geometry</code> on the map using a concrete |
|
81 |
* symbol. |
|
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 |
* @param handlers |
|
93 |
* An array of <code>Handler</code>'s. |
|
94 |
* @param at |
|
95 |
* A transformation that has to be applied to the <code>Handler</code>'s. |
|
96 |
* @param symbol |
|
97 |
* The symbol used to draw the handlers. |
|
98 |
*/ |
|
99 |
public void drawHandlers(Handler[] handlers, AffineTransform at, ISymbol symbol); |
|
100 |
|
|
101 |
/** |
|
102 |
* It draws a line using a concrete symbol. |
|
103 |
* @param firstPoint |
|
104 |
* The first point of the line. |
|
105 |
* @param endPoint |
|
106 |
* The end point of the line. |
|
107 |
* @param symbol |
|
108 |
* The symbol used to draw the line. |
|
109 |
*/ |
|
110 |
public void drawLine(Point2D firstPoint, Point2D endPoint, ISymbol symbol); |
|
111 |
|
|
112 |
/** |
|
113 |
* It draws an image on a map in a concrete position. |
|
114 |
* @param img |
|
115 |
* The image to draw. |
|
116 |
* @param x |
|
117 |
* The X coordinate, |
|
118 |
* @param y |
|
119 |
* The Y coordinate. |
|
120 |
*/ |
|
121 |
public void drawImage(Image img, int x, int y); |
|
122 |
|
|
123 |
/** |
|
124 |
* It draws image, applying a transform from image space |
|
125 |
* into user space before drawing. |
|
126 |
* @param img |
|
127 |
* The image to draw. |
|
128 |
* @param xform |
|
129 |
* The transform to apply. |
|
130 |
*/ |
|
131 |
public void drawImage(Image img, AffineTransform xform); |
|
132 |
|
|
133 |
/** |
|
134 |
* It draws a <code>Handler</code> on the map. |
|
135 |
* @param handler |
|
136 |
* The <code>Handler</code> to draw. |
|
137 |
* @param at |
|
138 |
* A transformation that has to be applied to the <code>Handler</code>. |
|
139 |
*/ |
|
140 |
public void drawHandler(Handler handler, AffineTransform at); |
|
141 |
|
|
142 |
/** |
|
143 |
* @param at |
|
144 |
*/ |
|
145 |
public void transform(AffineTransform at); |
|
146 |
|
|
147 |
/** |
|
148 |
* @param instance |
|
149 |
*/ |
|
150 |
public void setComposite(Composite instance); |
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
} |
|
155 |
|
|
0 | 156 |
tags/v2_0_0_Build_2035/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_2035/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynobject/DynObjectEditor.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 IVER T.I. S.A. {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
*/ |
|
31 |
package org.gvsig.fmap.mapcontrol.swing.dynobject; |
|
32 |
|
|
33 |
import java.awt.BorderLayout; |
|
34 |
import java.awt.Component; |
|
35 |
import java.awt.GridBagConstraints; |
|
36 |
import java.awt.GridBagLayout; |
|
37 |
import java.awt.Insets; |
|
38 |
import java.awt.event.ActionEvent; |
|
39 |
import java.awt.event.ActionListener; |
|
40 |
|
|
41 |
import javax.swing.JButton; |
|
42 |
import javax.swing.JLabel; |
|
43 |
import javax.swing.JPanel; |
|
44 |
|
|
45 |
import org.slf4j.Logger; |
|
46 |
import org.slf4j.LoggerFactory; |
|
47 |
|
|
48 |
import org.gvsig.i18n.Messages; |
|
49 |
import org.gvsig.tools.dynobject.DynObject; |
|
50 |
import org.gvsig.tools.service.ServiceException; |
|
51 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
52 |
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent; |
|
53 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
54 |
|
|
55 |
/** |
|
56 |
* Editor for a store parameters. |
|
57 |
* |
|
58 |
* @author gvSIG Team |
|
59 |
* @version $Id$ |
|
60 |
*/ |
|
61 |
public class DynObjectEditor extends JPanel implements ActionListener { |
|
62 |
|
|
63 |
private static final long serialVersionUID = 23898787077741411L; |
|
64 |
|
|
65 |
private static final Logger LOG = LoggerFactory |
|
66 |
.getLogger(DynObjectEditor.class); |
|
67 |
|
|
68 |
private static final WindowManager WINDOW_MANAGER = |
|
69 |
ToolsSwingLocator.getWindowManager(); |
|
70 |
|
|
71 |
private String title; |
|
72 |
|
|
73 |
private JButton botAcept; |
|
74 |
private JButton botCancel; |
|
75 |
private JButton botRestoreDefaults; |
|
76 |
private JPanel panButtons; |
|
77 |
|
|
78 |
private boolean modal; |
|
79 |
|
|
80 |
private JDynObjectComponent component; |
|
81 |
|
|
82 |
public DynObjectEditor(DynObject parameters) throws ServiceException { |
|
83 |
component = |
|
84 |
ToolsSwingLocator.getDynObjectSwingManager() |
|
85 |
.createJDynObjectComponent(parameters, true); |
|
86 |
this.setLayout(new BorderLayout()); |
|
87 |
this.add(component.asJComponent(), BorderLayout.CENTER); |
|
88 |
this.add(getButtonsPanel(), BorderLayout.SOUTH); |
|
89 |
} |
|
90 |
|
|
91 |
private JPanel getButtonsPanel() { |
|
92 |
if (this.panButtons == null) { |
|
93 |
this.panButtons = new JPanel(); |
|
94 |
this.panButtons.setLayout(new GridBagLayout()); |
|
95 |
GridBagConstraints constr = new GridBagConstraints(); |
|
96 |
constr.anchor = GridBagConstraints.LAST_LINE_END; |
|
97 |
constr.fill = GridBagConstraints.HORIZONTAL; |
|
98 |
constr.weightx = 1; |
|
99 |
constr.weighty = 0; |
|
100 |
this.panButtons.add(new JLabel(), constr); |
|
101 |
|
|
102 |
constr = this.getDefaultParametersConstraints(); |
|
103 |
constr.fill = GridBagConstraints.NONE; |
|
104 |
constr.weightx = 0; |
|
105 |
constr.weighty = 0; |
|
106 |
|
|
107 |
this.panButtons.add(this.getAcceptButton(), constr); |
|
108 |
this.panButtons.add(this.getCancelButton(), constr); |
|
109 |
this.panButtons.add(this.getRestoreDefaults(), constr); |
|
110 |
} |
|
111 |
return this.panButtons; |
|
112 |
} |
|
113 |
|
|
114 |
private GridBagConstraints getDefaultParametersConstraints() { |
|
115 |
GridBagConstraints constr = new GridBagConstraints(); |
|
116 |
constr.insets = new Insets(2, 2, 2, 2); |
|
117 |
constr.ipadx = 2; |
|
118 |
constr.ipady = 2; |
|
119 |
constr.anchor = GridBagConstraints.PAGE_START; |
|
120 |
return constr; |
|
121 |
|
|
122 |
} |
|
123 |
|
|
124 |
private JButton getRestoreDefaults() { |
|
125 |
if (this.botRestoreDefaults == null) { |
|
126 |
this.botRestoreDefaults = |
|
127 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
|
128 |
Messages.getText("restoreDefaults")); |
|
129 |
this.botRestoreDefaults.addActionListener(this); |
|
130 |
} |
|
131 |
return this.botRestoreDefaults; |
|
132 |
} |
|
133 |
|
|
134 |
private JButton getCancelButton() { |
|
135 |
if (this.botCancel == null) { |
|
136 |
this.botCancel = |
|
137 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
|
138 |
Messages.getText("cancel")); |
|
139 |
this.botCancel.addActionListener(this); |
|
140 |
} |
|
141 |
return this.botCancel; |
|
142 |
} |
|
143 |
|
|
144 |
private JButton getAcceptButton() { |
|
145 |
if (this.botAcept == null) { |
|
146 |
this.botAcept = |
|
147 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
|
148 |
Messages.getText("accept")); |
|
149 |
this.botAcept.addActionListener(this); |
|
150 |
} |
|
151 |
return this.botAcept; |
|
152 |
} |
|
153 |
|
|
154 |
public void actionPerformed(ActionEvent e) { |
|
155 |
Component source = (Component) e.getSource(); |
|
156 |
if (source == this.botAcept) { |
|
157 |
this.component.saveStatus(); |
|
158 |
this.closeWindow(); |
|
159 |
|
|
160 |
} else |
|
161 |
if (source == this.botCancel) { |
|
162 |
// TODO Close windows |
|
163 |
this.closeWindow(); |
|
164 |
} else |
|
165 |
if (source == this.botRestoreDefaults) { |
|
166 |
// TODO: implement |
|
167 |
// this.component.restore(); |
|
168 |
|
|
169 |
} |
|
170 |
} |
|
171 |
|
|
172 |
protected void closeWindow() { |
|
173 |
LOG.debug("Closing window, values edited: ", component.getDynObject()); |
|
174 |
this.setVisible(false); |
|
175 |
} |
|
176 |
|
|
177 |
public void editObject(boolean modal) { |
|
178 |
this.modal = modal; |
|
179 |
|
|
180 |
WINDOW_MANAGER.showWindow(this, |
|
181 |
Messages.getText("explorer_parameters"), |
|
182 |
WindowManager.MODE.DIALOG); |
|
183 |
} |
|
184 |
|
|
185 |
public String getTitle() { |
|
186 |
return title; |
|
187 |
} |
|
188 |
|
|
189 |
public void setTitle(String title) { |
|
190 |
this.title = title; |
|
191 |
} |
|
192 |
|
|
193 |
public DynObject getParameters() { |
|
194 |
return component.getDynObject(); |
|
195 |
} |
|
196 |
} |
|
0 | 197 |
tags/v2_0_0_Build_2035/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_2035/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 |
} |
Also available in: Unified diff