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