svn-gvsig-desktop / tags / v1_0_2_Build_914 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / MoveCADTool.java @ 12200
History | View | Annotate | Download (8.28 KB)
1 | 4434 | caballero | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package com.iver.cit.gvsig.gui.cad.tools; |
||
42 | |||
43 | import java.awt.Graphics; |
||
44 | 4637 | caballero | import java.awt.Image; |
45 | 4434 | caballero | import java.awt.event.InputEvent; |
46 | import java.awt.geom.Point2D; |
||
47 | import java.io.IOException; |
||
48 | 4458 | caballero | import java.util.ArrayList; |
49 | 4434 | caballero | |
50 | import com.iver.andami.PluginServices; |
||
51 | import com.iver.cit.gvsig.CADExtension; |
||
52 | 4637 | caballero | import com.iver.cit.gvsig.fmap.ViewPort; |
53 | 4458 | caballero | import com.iver.cit.gvsig.fmap.core.IFeature; |
54 | 4434 | caballero | import com.iver.cit.gvsig.fmap.core.IGeometry; |
55 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
56 | 5884 | caballero | import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
57 | 5184 | caballero | import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
58 | 4458 | caballero | import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
59 | 4434 | caballero | import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
60 | import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
||
61 | import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
||
62 | 5735 | caballero | import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
63 | 4434 | caballero | import com.iver.cit.gvsig.gui.cad.tools.smc.MoveCADToolContext; |
64 | import com.iver.cit.gvsig.gui.cad.tools.smc.MoveCADToolContext.MoveCADToolState; |
||
65 | 4637 | caballero | import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
66 | 4434 | caballero | |
67 | |||
68 | /**
|
||
69 | * DOCUMENT ME!
|
||
70 | *
|
||
71 | * @author Vicente Caballero Navarro
|
||
72 | */
|
||
73 | public class MoveCADTool extends DefaultCADTool { |
||
74 | private MoveCADToolContext _fsm;
|
||
75 | private Point2D firstPoint; |
||
76 | private Point2D lastPoint; |
||
77 | |||
78 | /**
|
||
79 | * Crea un nuevo PolylineCADTool.
|
||
80 | */
|
||
81 | public MoveCADTool() {
|
||
82 | } |
||
83 | |||
84 | /**
|
||
85 | * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
||
86 | * carga previa a la utilizaci?n de la herramienta.
|
||
87 | */
|
||
88 | public void init() { |
||
89 | _fsm = new MoveCADToolContext(this); |
||
90 | } |
||
91 | |||
92 | /* (non-Javadoc)
|
||
93 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
||
94 | */
|
||
95 | public void transition(double x, double y, InputEvent event) { |
||
96 | _fsm.addPoint(x, y, event); |
||
97 | } |
||
98 | |||
99 | /* (non-Javadoc)
|
||
100 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
||
101 | */
|
||
102 | public void transition(double d) { |
||
103 | 5735 | caballero | _fsm.addValue(d); |
104 | 4434 | caballero | } |
105 | |||
106 | /* (non-Javadoc)
|
||
107 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
||
108 | */
|
||
109 | 5735 | caballero | public void transition(String s) throws CommandException { |
110 | 4892 | caballero | if (!super.changeCommand(s)){ |
111 | _fsm.addOption(s); |
||
112 | } |
||
113 | 4434 | caballero | } |
114 | |||
115 | /**
|
||
116 | * DOCUMENT ME!
|
||
117 | */
|
||
118 | public void selection() { |
||
119 | 4584 | caballero | ArrayList selectedRow=getSelectedRows();
|
120 | if (selectedRow.size() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
||
121 | 5071 | caballero | CADExtension.setCADTool("_selection",false); |
122 | 4584 | caballero | ((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
123 | 5071 | caballero | "_move");
|
124 | 4434 | caballero | } |
125 | } |
||
126 | |||
127 | /**
|
||
128 | * Equivale al transition del prototipo pero sin pasarle como par?metro el
|
||
129 | * editableFeatureSource que ya estar? creado.
|
||
130 | *
|
||
131 | * @param x par?metro x del punto que se pase en esta transici?n.
|
||
132 | * @param y par?metro y del punto que se pase en esta transici?n.
|
||
133 | */
|
||
134 | public void addPoint(double x, double y,InputEvent event) { |
||
135 | MoveCADToolState actualState = (MoveCADToolState) _fsm.getPreviousState(); |
||
136 | String status = actualState.getName();
|
||
137 | 4637 | caballero | VectorialLayerEdited vle=getVLE(); |
138 | VectorialEditableAdapter vea = vle.getVEA(); |
||
139 | 4584 | caballero | ArrayList selectedRow=getSelectedRows();
|
140 | 5884 | caballero | ArrayList selectedRowAux=new ArrayList(); |
141 | 4458 | caballero | if (status.equals("Move.FirstPointToMove")) { |
142 | 4434 | caballero | firstPoint = new Point2D.Double(x, y); |
143 | } else if (status.equals("Move.SecondPointToMove")) { |
||
144 | PluginServices.getMDIManager().setWaitCursor(); |
||
145 | 4637 | caballero | lastPoint = new Point2D.Double(x, y); |
146 | 4434 | caballero | vea.startComplexRow(); |
147 | |||
148 | try {
|
||
149 | 4458 | caballero | for (int i = 0; i < selectedRow.size(); i++) { |
150 | IRowEdited edRow = (IRowEdited) selectedRow.get(i); |
||
151 | IFeature feat = (IFeature) edRow.getLinkedRow().cloneRow(); |
||
152 | IGeometry ig = feat.getGeometry(); |
||
153 | if (ig == null) |
||
154 | continue;
|
||
155 | // Movemos la geometr?a
|
||
156 | UtilFunctions.moveGeom(ig, lastPoint.getX() - |
||
157 | 4434 | caballero | firstPoint.getX(), lastPoint.getY() - firstPoint.getY()); |
158 | |||
159 | 5908 | caballero | vea.modifyRow(edRow.getIndex(),feat,getName(),EditionEvent.GRAPHIC); |
160 | selectedRowAux.add(new DefaultRowEdited(feat,IRowEdited.STATUS_MODIFIED,edRow.getIndex()));
|
||
161 | 4637 | caballero | } |
162 | 6071 | caballero | vea.endComplexRow(getName()); |
163 | 5985 | caballero | vle.setSelectionCache(selectedRowAux); |
164 | //clearSelection();
|
||
165 | //selectedRow.addAll(selectedRowAux);
|
||
166 | 4584 | caballero | |
167 | 4434 | caballero | } catch (DriverIOException e) {
|
168 | e.printStackTrace(); |
||
169 | } catch (IOException e) { |
||
170 | e.printStackTrace(); |
||
171 | } |
||
172 | PluginServices.getMDIManager().restoreCursor(); |
||
173 | } |
||
174 | } |
||
175 | |||
176 | /**
|
||
177 | * M?todo para dibujar la lo necesario para el estado en el que nos
|
||
178 | * encontremos.
|
||
179 | *
|
||
180 | * @param g Graphics sobre el que dibujar.
|
||
181 | * @param x par?metro x del punto que se pase para dibujar.
|
||
182 | * @param y par?metro x del punto que se pase para dibujar.
|
||
183 | */
|
||
184 | public void drawOperation(Graphics g, double x, double y) { |
||
185 | MoveCADToolState actualState = ((MoveCADToolContext) _fsm).getState(); |
||
186 | String status = actualState.getName();
|
||
187 | 4637 | caballero | VectorialLayerEdited vle=getVLE(); |
188 | //ArrayList selectedRow=getSelectedRows();
|
||
189 | /*drawHandlers(g, selectedRow,
|
||
190 | 4458 | caballero | getCadToolAdapter().getMapControl().getViewPort()
|
191 | .getAffineTransform());
|
||
192 | 4637 | caballero | */
|
193 | 4434 | caballero | if (status.equals("Move.SecondPointToMove")) { |
194 | 6881 | cesar | ViewPort vp=vle.getLayer().getMapContext().getViewPort(); |
195 | 4637 | caballero | int dx = vp.fromMapDistance(x - firstPoint.getX());
|
196 | int dy = -vp.fromMapDistance(y - firstPoint.getY());
|
||
197 | Image img = vle.getSelectionImage();
|
||
198 | g.drawImage(img, dx, dy, null);
|
||
199 | /*for (int i = 0; i < selectedRow.size(); i++) {
|
||
200 | 4458 | caballero | IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
201 | IFeature feat = (IFeature) edRow.getLinkedRow();
|
||
202 | IGeometry ig = feat.getGeometry().cloneGeometry();
|
||
203 | if (ig == null)
|
||
204 | continue;
|
||
205 | // Movemos la geometr?a
|
||
206 | UtilFunctions.moveGeom(ig, x - firstPoint.getX(), y - firstPoint.getY());
|
||
207 | ig.draw((Graphics2D) g,
|
||
208 | getCadToolAdapter().getMapControl().getViewPort(),
|
||
209 | CADTool.drawingSymbol);
|
||
210 | 4637 | caballero | }*/
|
211 | }else{
|
||
212 | 7541 | caballero | if (!vle.getLayer().isVisible())
|
213 | return;
|
||
214 | 4637 | caballero | Image imgSel = vle.getSelectionImage();
|
215 | g.drawImage(imgSel, 0, 0, null); |
||
216 | Image imgHand = vle.getHandlersImage();
|
||
217 | g.drawImage(imgHand, 0, 0, null); |
||
218 | 4434 | caballero | } |
219 | } |
||
220 | |||
221 | /**
|
||
222 | * Add a diferent option.
|
||
223 | *
|
||
224 | * @param s Diferent option.
|
||
225 | */
|
||
226 | public void addOption(String s) { |
||
227 | } |
||
228 | |||
229 | /* (non-Javadoc)
|
||
230 | * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
||
231 | */
|
||
232 | public void addValue(double d) { |
||
233 | } |
||
234 | |||
235 | public String getName() { |
||
236 | 4584 | caballero | return PluginServices.getText(this,"move_"); |
237 | 4434 | caballero | } |
238 | 4892 | caballero | |
239 | public String toString() { |
||
240 | return "_move"; |
||
241 | } |
||
242 | 5170 | caballero | |
243 | 4434 | caballero | } |