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