svn-gvsig-desktop / branches / pilotoDWG / libraries / libFMap / src / com / iver / cit / gvsig / fmap / CadMapControl.java @ 1392
History | View | Annotate | Download (8.54 KB)
1 |
/*
|
---|---|
2 |
* Created on 04-feb-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
21 |
USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package com.iver.cit.gvsig.fmap; |
46 |
|
47 |
import java.awt.BorderLayout; |
48 |
import java.util.HashMap; |
49 |
|
50 |
import javax.swing.JPanel; |
51 |
import javax.swing.JSplitPane; |
52 |
|
53 |
import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource; |
54 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
55 |
import com.iver.cit.gvsig.fmap.edition.cad.CADToolAdapter; |
56 |
import com.iver.cit.gvsig.fmap.edition.cad.CadTool; |
57 |
import com.iver.cit.gvsig.fmap.edition.cad.cadTools.LineCadTool; |
58 |
import com.iver.cit.gvsig.fmap.edition.cad.cadTools.PointCadTool; |
59 |
import com.iver.cit.gvsig.fmap.edition.cad.cadTools.PolyLineCadTool; |
60 |
import com.iver.cit.gvsig.fmap.edition.cad.cadTools.RectangleCadTool; |
61 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
62 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
63 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent; |
64 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener; |
65 |
import com.iver.cit.gvsig.fmap.layers.LayerEvent; |
66 |
import com.iver.cit.gvsig.fmap.layers.LayerListener; |
67 |
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent; |
68 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.EditableVectorialLayer; |
69 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
70 |
import com.iver.utiles.console.JConsole; |
71 |
public class CadMapControl extends JPanel { |
72 |
private HashMap namesCadTools = new HashMap(); |
73 |
private CADToolAdapter cadToolAdapter = new CADToolAdapter(); |
74 |
private LayerActivationListener layerActivationListener = new LayerActivationListener(); |
75 |
private LayerColListener layerListener = new LayerColListener(); |
76 |
private MapControl mapControl = null; |
77 |
private JConsole jConsole = null; |
78 |
private JSplitPane jSplitPane = null; |
79 |
/**
|
80 |
* This is the default constructor
|
81 |
*/
|
82 |
public CadMapControl() {
|
83 |
super();
|
84 |
initialize(); |
85 |
} |
86 |
/**
|
87 |
* This method initializes this
|
88 |
*
|
89 |
* @return void
|
90 |
*/
|
91 |
private void initialize() { |
92 |
// Herramienta de edici?n de CAD
|
93 |
getMapControl().addMapTool("cadEdition", cadToolAdapter);
|
94 |
|
95 |
cadToolAdapter.setConsole(getConsole()); |
96 |
|
97 |
//Herramienta de CAD de a?adir punto
|
98 |
PointCadTool pointCADTool = new PointCadTool();
|
99 |
addCadTool("point", pointCADTool);
|
100 |
//Herramienta de CAD de a?adir l?nea
|
101 |
LineCadTool lineCADTool = new LineCadTool();
|
102 |
addCadTool("line", lineCADTool);
|
103 |
//Herramienta de CAD de a?adir polyl?nea
|
104 |
PolyLineCadTool polylineCADTool = new PolyLineCadTool();
|
105 |
addCadTool("polyline", polylineCADTool);
|
106 |
//Herramienta de CAD de a?adir rect?ngulo.
|
107 |
RectangleCadTool rectangleCADTool = new RectangleCadTool();
|
108 |
addCadTool("rectangle", rectangleCADTool);
|
109 |
|
110 |
this.setLayout(new BorderLayout()); |
111 |
this.setSize(300,200); |
112 |
this.add(getJSplitPane(), java.awt.BorderLayout.CENTER);
|
113 |
} |
114 |
/**
|
115 |
* This method initializes mapControl
|
116 |
*
|
117 |
* @return com.iver.cit.gvsig.fmap.MapControl
|
118 |
*/
|
119 |
public MapControl getMapControl() {
|
120 |
if (mapControl == null) { |
121 |
mapControl = new MapControl();
|
122 |
} |
123 |
return mapControl;
|
124 |
} |
125 |
/**
|
126 |
* This method initializes jConsole
|
127 |
*
|
128 |
* @return com.iver.utiles.console.JConsole
|
129 |
*/
|
130 |
public JConsole getConsole() {
|
131 |
if (jConsole == null) { |
132 |
jConsole = new JConsole();
|
133 |
jConsole.setPreferredSize(new java.awt.Dimension(3,35)); |
134 |
} |
135 |
return jConsole;
|
136 |
} |
137 |
/**
|
138 |
* This method initializes jSplitPane
|
139 |
*
|
140 |
* @return javax.swing.JSplitPane
|
141 |
*/
|
142 |
private JSplitPane getJSplitPane() { |
143 |
if (jSplitPane == null) { |
144 |
jSplitPane = new JSplitPane(); |
145 |
jSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); |
146 |
jSplitPane.setTopComponent(getMapControl()); |
147 |
jSplitPane.setBottomComponent(getConsole()); |
148 |
jSplitPane.setDividerLocation(130);
|
149 |
} |
150 |
return jSplitPane;
|
151 |
} |
152 |
public FMap getMapContext() {
|
153 |
return mapControl.getMapContext();
|
154 |
} |
155 |
|
156 |
public void addMapTool(String name, Behavior tool) { |
157 |
mapControl.addMapTool(name, tool); |
158 |
} |
159 |
|
160 |
public void addMapTool(String name, Behavior[] tools) { |
161 |
mapControl.addMapTool(name, tools); |
162 |
} |
163 |
public void setMapContext(FMap model) { |
164 |
mapControl.getMapContext().getLayers().removeLayerCollectionListener(layerListener); |
165 |
mapControl.setMapContext(model); |
166 |
mapControl.getMapContext().getLayers().addLayerCollectionListener(layerListener); |
167 |
} |
168 |
|
169 |
public void addCadTool(String name, CadTool c){ |
170 |
namesCadTools.put(name, c); |
171 |
} |
172 |
|
173 |
public void setCadTool(String text){ |
174 |
CadTool ct = (CadTool) namesCadTools.get(text); |
175 |
if (ct == null) throw new RuntimeException("No such cad tool"); |
176 |
|
177 |
cadToolAdapter.setCadTool(ct); |
178 |
getMapControl().setTool("cadEdition");
|
179 |
} |
180 |
|
181 |
private class LayerColListener implements LayerCollectionListener{ |
182 |
|
183 |
/**
|
184 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
185 |
*/
|
186 |
public void layerAdded(LayerCollectionEvent e) { |
187 |
if (e.getAffectedLayer() instanceof EditableVectorialLayer){ |
188 |
e.getAffectedLayer().addLayerListener(layerActivationListener); |
189 |
} |
190 |
} |
191 |
|
192 |
/**
|
193 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
194 |
*/
|
195 |
public void layerMoved(LayerPositionEvent e) { |
196 |
} |
197 |
|
198 |
/**
|
199 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
200 |
*/
|
201 |
public void layerRemoved(LayerCollectionEvent e) { |
202 |
if (e.getAffectedLayer() instanceof EditableVectorialLayer){ |
203 |
e.getAffectedLayer().removeLayerListener(layerActivationListener); |
204 |
} |
205 |
} |
206 |
|
207 |
/**
|
208 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
209 |
*/
|
210 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
211 |
} |
212 |
|
213 |
/**
|
214 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
215 |
*/
|
216 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
217 |
} |
218 |
|
219 |
/**
|
220 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
221 |
*/
|
222 |
public void layerRemoving(LayerCollectionEvent e) throws CancelationException { |
223 |
} |
224 |
|
225 |
/**
|
226 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
227 |
*/
|
228 |
public void activationChanged(LayerCollectionEvent e) throws CancelationException { |
229 |
} |
230 |
|
231 |
/**
|
232 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
233 |
*/
|
234 |
public void visibilityChanged(LayerCollectionEvent e) throws CancelationException { |
235 |
} |
236 |
|
237 |
} |
238 |
|
239 |
private class LayerActivationListener implements LayerListener{ |
240 |
|
241 |
/**
|
242 |
* @see com.iver.cit.gvsig.fmap.layers.LayerListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerEvent)
|
243 |
*/
|
244 |
public void visibilityChanged(LayerEvent e) { |
245 |
} |
246 |
|
247 |
/**
|
248 |
* @see com.iver.cit.gvsig.fmap.layers.LayerListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerEvent)
|
249 |
*/
|
250 |
public void activationChanged(LayerEvent e) { |
251 |
FLayer lyr = e.getSource(); |
252 |
if (lyr.isActive()){
|
253 |
EditableVectorialLayer editable = (EditableVectorialLayer) lyr; |
254 |
EditableFeatureSource efs; |
255 |
try {
|
256 |
efs = editable.startEdition(); |
257 |
cadToolAdapter.setEditableFeatureSource(efs); |
258 |
} catch (EditionException e1) {
|
259 |
e1.printStackTrace(); |
260 |
} |
261 |
} |
262 |
} |
263 |
|
264 |
/**
|
265 |
* @see com.iver.cit.gvsig.fmap.layers.LayerListener#nameChanged(com.iver.cit.gvsig.fmap.layers.LayerEvent)
|
266 |
*/
|
267 |
public void nameChanged(LayerEvent e) { |
268 |
} |
269 |
|
270 |
} |
271 |
} |