root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / StartEditing.java @ 6312
History | View | Annotate | Download (7.31 KB)
1 |
package com.iver.cit.gvsig; |
---|---|
2 |
|
3 |
import java.awt.event.ActionEvent; |
4 |
|
5 |
import javax.swing.AbstractAction; |
6 |
|
7 |
import com.iver.andami.PluginServices; |
8 |
import com.iver.andami.messages.NotificationManager; |
9 |
import com.iver.andami.plugins.Extension; |
10 |
import com.iver.cit.gvsig.fmap.FMap; |
11 |
import com.iver.cit.gvsig.fmap.MapControl; |
12 |
import com.iver.cit.gvsig.fmap.core.FShape; |
13 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
14 |
import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver; |
15 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
16 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
17 |
import com.iver.cit.gvsig.fmap.edition.rules.IRule; |
18 |
import com.iver.cit.gvsig.fmap.edition.rules.RulePolygon; |
19 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
20 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
21 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
22 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
23 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
24 |
import com.iver.cit.gvsig.gui.Table; |
25 |
import com.iver.cit.gvsig.gui.View; |
26 |
import com.iver.cit.gvsig.gui.cad.CADTool; |
27 |
import com.iver.cit.gvsig.gui.tokenmarker.ConsoleToken; |
28 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
29 |
import com.iver.cit.gvsig.project.ProjectTable; |
30 |
import com.iver.cit.gvsig.project.ProjectView; |
31 |
import com.iver.utiles.console.jedit.KeywordMap; |
32 |
import com.iver.utiles.console.jedit.Token; |
33 |
|
34 |
/**
|
35 |
* DOCUMENT ME!
|
36 |
*
|
37 |
* @author Vicente Caballero Navarro
|
38 |
*/
|
39 |
public class StartEditing extends Extension { |
40 |
|
41 |
private class MyAction extends AbstractAction |
42 |
{ |
43 |
|
44 |
public void actionPerformed(ActionEvent e) { |
45 |
System.err.println("F3"); |
46 |
} |
47 |
|
48 |
} |
49 |
|
50 |
View vista;
|
51 |
/**
|
52 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
53 |
*/
|
54 |
public void initialize() { |
55 |
} |
56 |
|
57 |
/**
|
58 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
59 |
*/
|
60 |
public void execute(String actionCommand) { |
61 |
CADExtension.initFocus(); |
62 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
63 |
.getActiveView(); |
64 |
|
65 |
if (f instanceof View) { |
66 |
vista = (View) f;
|
67 |
|
68 |
vista.showConsole(); |
69 |
MapControl mapControl = (MapControl) vista.getMapControl(); |
70 |
EditionManager editionManager=CADExtension.getEditionManager(); |
71 |
editionManager.setMapControl(mapControl); |
72 |
|
73 |
ProjectView model = vista.getModel(); |
74 |
FMap mapa = model.getMapContext(); |
75 |
FLayers layers = mapa.getLayers(); |
76 |
|
77 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
78 |
if (layers.getLayer(i) instanceof FLyrVect |
79 |
&& layers.getLayer(i).isActive()) { |
80 |
/*
|
81 |
* for (int j = 0; j < i; j++) {
|
82 |
* layers.getLayer(j).setVisible(false); }
|
83 |
*/
|
84 |
|
85 |
FLyrVect lv = (FLyrVect) layers.getLayer(i); |
86 |
// lv.setVisible(true);
|
87 |
lv.addLayerListener(editionManager); |
88 |
try {
|
89 |
Legend legendOriginal=lv.getLegend().cloneLegend(); |
90 |
|
91 |
lv.setEditing(true);
|
92 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) lv |
93 |
.getSource(); |
94 |
vea.getRules().clear(); |
95 |
if (vea.getShapeType() == FShape.POLYGON)
|
96 |
{ |
97 |
IRule rulePol = new RulePolygon();
|
98 |
vea.getRules().add(rulePol); |
99 |
} |
100 |
|
101 |
if (!(lv.getSource().getDriver() instanceof IndexedShpDriver)){ |
102 |
VectorialLayerEdited vle=(VectorialLayerEdited)editionManager.getLayerEdited(lv); |
103 |
vle.setLegend(legendOriginal); |
104 |
} |
105 |
vea.getCommandRecord().addCommandListener(mapControl); |
106 |
// Si existe una tabla asociada a esta capa se cambia su
|
107 |
// modelo por el VectorialEditableAdapter.
|
108 |
ProjectExtension pe = (ProjectExtension) PluginServices |
109 |
.getExtension(ProjectExtension.class); |
110 |
ProjectTable pt = pe.getProject().getTable(lv); |
111 |
if (pt != null){ |
112 |
pt.setModel(vea); |
113 |
changeModelTable(pt); |
114 |
} |
115 |
startCommandsApplicable(vista,lv); |
116 |
vista.repaintMap(); |
117 |
} catch (EditionException e) {
|
118 |
e.printStackTrace(); |
119 |
NotificationManager.addError(e); |
120 |
} catch (DriverIOException e) {
|
121 |
e.printStackTrace(); |
122 |
NotificationManager.addError(e); |
123 |
} catch (XMLException e) {
|
124 |
e.printStackTrace(); |
125 |
} |
126 |
|
127 |
// return;
|
128 |
} |
129 |
} |
130 |
|
131 |
/*
|
132 |
* PluginServices.getMDIManager().setWaitCursor(); try { if
|
133 |
* (((FLyrVect) capa).getSource().getDriver().getClass() ==
|
134 |
* DXFCadDriver.class) { if (JOptionPane.showConfirmDialog(
|
135 |
* (Component) PluginServices.getMainFrame(), "Todas las geometr?as
|
136 |
* del formato DXF no se pueden editar, de momento podemos editar:
|
137 |
* Line, Point, Polyline, Arc, Circle y Ellipse. \n El resto de
|
138 |
* geometr?as se perder?n con la edici?n. \n ?Desea continuar?") ==
|
139 |
* JOptionPane.YES_OPTION) { capa.startEdition();
|
140 |
* vista.getMapControl().setCadTool("selection"); } else { } } else {
|
141 |
* capa.startEdition();
|
142 |
* vista.getMapControl().setCadTool("selection"); } } catch
|
143 |
* (EditionException e) { // TODO Auto-generated catch block
|
144 |
* e.printStackTrace(); }
|
145 |
* PluginServices.getMDIManager().restoreCursor();
|
146 |
*/
|
147 |
// vista.getMapControl().drawMap(false);
|
148 |
} |
149 |
} |
150 |
// private void registerKeyStrokes() {
|
151 |
// JComponent theComponent = vista.getConsolePanel().getTxt();
|
152 |
//
|
153 |
// // The actions
|
154 |
// Action F3Action = new AbstractAction("REFENT") {
|
155 |
// public void actionPerformed(ActionEvent evt) {
|
156 |
// System.err.println("SOY F3");
|
157 |
// }
|
158 |
// };
|
159 |
//
|
160 |
// InputMap inputMap = theComponent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
|
161 |
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), F3Action.getValue(Action.NAME));
|
162 |
//
|
163 |
// ActionMap actionMap = theComponent.getActionMap();
|
164 |
// // actionMap.put("REFENT", new MyAction());
|
165 |
// actionMap.put(F3Action.getValue(Action.NAME), F3Action);
|
166 |
//
|
167 |
// }
|
168 |
|
169 |
public static void startCommandsApplicable(View vista,FLyrVect lv) { |
170 |
if (vista==null) |
171 |
vista=(View)PluginServices.getMDIManager().getActiveView();
|
172 |
CADTool[] cadtools = CADExtension.getCADTools();
|
173 |
KeywordMap keywordMap = new KeywordMap(true); |
174 |
for (int i = 0; i < cadtools.length; i++) { |
175 |
try {
|
176 |
if (cadtools[i].isApplicable(lv.getShapeType())){
|
177 |
keywordMap.add(cadtools[i].getName(), Token.KEYWORD2); |
178 |
keywordMap.add(cadtools[i].toString(), Token.KEYWORD3); |
179 |
} |
180 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) {
|
181 |
e.printStackTrace(); |
182 |
} |
183 |
|
184 |
} |
185 |
ConsoleToken consoletoken = new ConsoleToken(keywordMap);
|
186 |
vista.getConsolePanel().setTokenMarker(consoletoken); |
187 |
|
188 |
} |
189 |
|
190 |
private void changeModelTable(ProjectTable pt){ |
191 |
com.iver.andami.ui.mdiManager.View[] views = (com.iver.andami.ui.mdiManager.View[]) PluginServices.getMDIManager().getAllViews(); |
192 |
|
193 |
for (int i=0 ; i<views.length ; i++){ |
194 |
if (views[i] instanceof Table){ |
195 |
Table table=(Table)views[i]; |
196 |
ProjectTable model =table.getModel(); |
197 |
if (model.equals(pt)){
|
198 |
table.setModel(pt); |
199 |
} |
200 |
} |
201 |
} |
202 |
} |
203 |
/**
|
204 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
205 |
*/
|
206 |
public boolean isEnabled() { |
207 |
View f = (View) PluginServices.getMDIManager().getActiveView(); |
208 |
|
209 |
if (f == null) { |
210 |
return false; |
211 |
} |
212 |
|
213 |
FLayer[] selected = f.getModel().getMapContext().getLayers()
|
214 |
.getActives(); |
215 |
if (selected.length == 1 && selected[0] instanceof FLyrVect) { |
216 |
if (selected[0].isEditing()) |
217 |
return false; |
218 |
else
|
219 |
return true; |
220 |
} |
221 |
return false; |
222 |
} |
223 |
|
224 |
/**
|
225 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
226 |
*/
|
227 |
public boolean isVisible() { |
228 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
229 |
.getActiveView(); |
230 |
|
231 |
if (f == null) { |
232 |
return false; |
233 |
} |
234 |
|
235 |
if (f instanceof View) { |
236 |
return true; |
237 |
} else {
|
238 |
return false; |
239 |
} |
240 |
} |
241 |
} |