svn-gvsig-desktop / tags / v1_0_2_RELEASE / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / CopyCADTool.java @ 11432
History | View | Annotate | Download (8.28 KB)
1 | 3883 | 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 | 3978 | caballero | import java.awt.Graphics; |
44 | 4637 | caballero | import java.awt.Image; |
45 | 4313 | fjp | import java.awt.event.InputEvent; |
46 | 3978 | caballero | import java.awt.geom.Point2D; |
47 | import java.io.IOException; |
||
48 | 4458 | caballero | import java.util.ArrayList; |
49 | 3883 | caballero | |
50 | 3978 | caballero | import com.iver.andami.PluginServices; |
51 | 3883 | caballero | import com.iver.cit.gvsig.CADExtension; |
52 | 4637 | caballero | import com.iver.cit.gvsig.fmap.ViewPort; |
53 | 3883 | caballero | import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
54 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
55 | 4584 | caballero | import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
56 | 5184 | caballero | import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
57 | 5884 | caballero | import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
58 | 3904 | fjp | import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
59 | 3883 | caballero | import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
60 | import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
||
61 | 5735 | caballero | import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
62 | 3883 | caballero | import com.iver.cit.gvsig.gui.cad.tools.smc.CopyCADToolContext; |
63 | import com.iver.cit.gvsig.gui.cad.tools.smc.CopyCADToolContext.CopyCADToolState; |
||
64 | 4637 | caballero | import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
65 | 3883 | caballero | |
66 | |||
67 | /**
|
||
68 | * DOCUMENT ME!
|
||
69 | *
|
||
70 | * @author Vicente Caballero Navarro
|
||
71 | */
|
||
72 | public class CopyCADTool extends DefaultCADTool { |
||
73 | private CopyCADToolContext _fsm;
|
||
74 | private Point2D firstPoint; |
||
75 | private Point2D lastPoint; |
||
76 | |||
77 | /**
|
||
78 | * Crea un nuevo PolylineCADTool.
|
||
79 | */
|
||
80 | public CopyCADTool() {
|
||
81 | } |
||
82 | |||
83 | /**
|
||
84 | * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
||
85 | * carga previa a la utilizaci?n de la herramienta.
|
||
86 | */
|
||
87 | public void init() { |
||
88 | _fsm = new CopyCADToolContext(this); |
||
89 | } |
||
90 | |||
91 | /* (non-Javadoc)
|
||
92 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
||
93 | */
|
||
94 | 4313 | fjp | public void transition(double x, double y, InputEvent event) { |
95 | 4324 | caballero | _fsm.addPoint(x, y, event); |
96 | 3883 | caballero | } |
97 | |||
98 | /* (non-Javadoc)
|
||
99 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
||
100 | */
|
||
101 | public void transition(double d) { |
||
102 | 5735 | caballero | _fsm.addValue(d); |
103 | 3883 | caballero | } |
104 | |||
105 | /* (non-Javadoc)
|
||
106 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
||
107 | */
|
||
108 | 5735 | caballero | public void transition(String s) throws CommandException { |
109 | 4892 | caballero | if (!super.changeCommand(s)){ |
110 | _fsm.addOption(s); |
||
111 | } |
||
112 | 3883 | caballero | } |
113 | |||
114 | /**
|
||
115 | * DOCUMENT ME!
|
||
116 | */
|
||
117 | public void selection() { |
||
118 | 4584 | caballero | ArrayList selectedRow=getSelectedRows();
|
119 | if (selectedRow.size() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
||
120 | 5071 | caballero | CADExtension.setCADTool("_selection",false); |
121 | 4584 | caballero | ((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
122 | 5071 | caballero | "_copy");
|
123 | 3883 | caballero | } |
124 | } |
||
125 | |||
126 | /**
|
||
127 | * Equivale al transition del prototipo pero sin pasarle como par?metro el
|
||
128 | * editableFeatureSource que ya estar? creado.
|
||
129 | *
|
||
130 | * @param x par?metro x del punto que se pase en esta transici?n.
|
||
131 | * @param y par?metro y del punto que se pase en esta transici?n.
|
||
132 | */
|
||
133 | 4365 | caballero | public void addPoint(double x, double y,InputEvent event) { |
134 | 3883 | caballero | CopyCADToolState actualState = (CopyCADToolState) _fsm.getPreviousState(); |
135 | String status = actualState.getName();
|
||
136 | 4637 | caballero | VectorialLayerEdited vle=getVLE(); |
137 | VectorialEditableAdapter vea = vle.getVEA(); |
||
138 | 4584 | caballero | ArrayList selectedRow=getSelectedRows();
|
139 | 5884 | caballero | ArrayList selectedRowAux=new ArrayList(); |
140 | 3978 | caballero | if (status.equals("Copy.FirstPointToMove")) { |
141 | 3883 | caballero | firstPoint = new Point2D.Double(x, y); |
142 | 3978 | caballero | } else if (status.equals("Copy.SecondPointToMove")) { |
143 | 3883 | caballero | PluginServices.getMDIManager().setWaitCursor(); |
144 | lastPoint = new Point2D.Double(x, y); |
||
145 | vea.startComplexRow(); |
||
146 | |||
147 | try {
|
||
148 | 4522 | caballero | for (int i = 0; i < selectedRow.size(); i++) { |
149 | 5908 | caballero | DefaultRowEdited dre=(DefaultRowEdited)selectedRow.get(i); |
150 | DefaultFeature fea = (DefaultFeature)dre.getLinkedRow() |
||
151 | 3883 | caballero | .cloneRow(); |
152 | 3904 | fjp | // Movemos la geometr?a
|
153 | UtilFunctions.moveGeom(fea.getGeometry(), lastPoint.getX() - |
||
154 | firstPoint.getX(), lastPoint.getY() - firstPoint.getY()); |
||
155 | 3883 | caballero | |
156 | 6024 | caballero | int index=vea.addRow(fea,getName(),EditionEvent.GRAPHIC);
|
157 | selectedRowAux.add(new DefaultRowEdited(fea,IRowEdited.STATUS_ADDED,vea.getInversedIndex(index)));
|
||
158 | 3883 | caballero | } |
159 | 6071 | caballero | vea.endComplexRow(getName()); |
160 | 5985 | caballero | //clearSelection();
|
161 | //selectedRow.addAll(selectedRowAux);
|
||
162 | vle.setSelectionCache(selectedRowAux); |
||
163 | 3883 | caballero | } catch (DriverIOException e) {
|
164 | e.printStackTrace(); |
||
165 | } catch (IOException e) { |
||
166 | e.printStackTrace(); |
||
167 | } |
||
168 | 4637 | caballero | |
169 | 3883 | caballero | PluginServices.getMDIManager().restoreCursor(); |
170 | } |
||
171 | } |
||
172 | |||
173 | /**
|
||
174 | * M?todo para dibujar la lo necesario para el estado en el que nos
|
||
175 | * encontremos.
|
||
176 | *
|
||
177 | * @param g Graphics sobre el que dibujar.
|
||
178 | * @param x par?metro x del punto que se pase para dibujar.
|
||
179 | * @param y par?metro x del punto que se pase para dibujar.
|
||
180 | */
|
||
181 | public void drawOperation(Graphics g, double x, double y) { |
||
182 | CopyCADToolState actualState = ((CopyCADToolContext) _fsm).getState(); |
||
183 | String status = actualState.getName();
|
||
184 | 4637 | caballero | VectorialLayerEdited vle=getVLE(); |
185 | //ArrayList selectedRow=getSelectedRows();
|
||
186 | // drawHandlers(g, selectedRow,
|
||
187 | // getCadToolAdapter().getMapControl().getViewPort()
|
||
188 | // .getAffineTransform());
|
||
189 | 3978 | caballero | if (status.equals("Copy.SecondPointToMove")) { |
190 | 6881 | cesar | ViewPort vp=vle.getLayer().getMapContext().getViewPort(); |
191 | 4637 | caballero | int dx = vp.fromMapDistance(x - firstPoint.getX());
|
192 | int dy = -vp.fromMapDistance(y - firstPoint.getY());
|
||
193 | Image img = vle.getSelectionImage();
|
||
194 | g.drawImage(img, dx, dy, null);
|
||
195 | /* for (int i = 0; i < selectedRow.size(); i++) {
|
||
196 | 4584 | caballero | IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
197 | IFeature feat = (IFeature) edRow.getLinkedRow();
|
||
198 | IGeometry geometry = feat.getGeometry().cloneGeometry();
|
||
199 | // Movemos la geometr?a
|
||
200 | 3904 | fjp | UtilFunctions.moveGeom(geometry, x - firstPoint.getX(), y - firstPoint.getY());
|
201 | 3883 | caballero | geometry.draw((Graphics2D) g,
|
202 | getCadToolAdapter().getMapControl().getViewPort(),
|
||
203 | CADTool.drawingSymbol);
|
||
204 | }
|
||
205 | 4637 | caballero | */
|
206 | }else{
|
||
207 | 7541 | caballero | if (!vle.getLayer().isVisible())
|
208 | return;
|
||
209 | 4637 | caballero | Image imgSel = vle.getSelectionImage();
|
210 | g.drawImage(imgSel, 0, 0, null); |
||
211 | Image imgHand = vle.getHandlersImage();
|
||
212 | g.drawImage(imgHand, 0, 0, null); |
||
213 | 3883 | caballero | } |
214 | } |
||
215 | |||
216 | /**
|
||
217 | * Add a diferent option.
|
||
218 | *
|
||
219 | * @param s Diferent option.
|
||
220 | */
|
||
221 | public void addOption(String s) { |
||
222 | } |
||
223 | |||
224 | /* (non-Javadoc)
|
||
225 | * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
||
226 | */
|
||
227 | public void addValue(double d) { |
||
228 | } |
||
229 | 4118 | caballero | |
230 | public String getName() { |
||
231 | 4584 | caballero | return PluginServices.getText(this,"copy_"); |
232 | 4118 | caballero | } |
233 | 4892 | caballero | |
234 | public String toString() { |
||
235 | return "_copy"; |
||
236 | } |
||
237 | 5170 | caballero | |
238 | |||
239 | 3883 | caballero | } |