svn-gvsig-desktop / tags / v1_1_Build_1000 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / MultiPointCADTool.java @ 11885
History | View | Annotate | Download (5.65 KB)
1 | 6024 | 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 | import java.awt.Graphics2D; |
||
45 | import java.awt.event.InputEvent; |
||
46 | import java.util.ArrayList; |
||
47 | |||
48 | import com.iver.andami.PluginServices; |
||
49 | import com.iver.cit.gvsig.fmap.core.FShape; |
||
50 | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
||
51 | import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
||
52 | import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
||
53 | import com.iver.cit.gvsig.gui.cad.tools.smc.MultiPointCADToolContext; |
||
54 | import com.iver.cit.gvsig.gui.cad.tools.smc.MultiPointCADToolContext.MultiPointCADToolState; |
||
55 | |||
56 | |||
57 | /**
|
||
58 | * DOCUMENT ME!
|
||
59 | *
|
||
60 | * @author Vicente Caballero Navarro
|
||
61 | */
|
||
62 | public class MultiPointCADTool extends DefaultCADTool { |
||
63 | private MultiPointCADToolContext _fsm;
|
||
64 | private ArrayList points=new ArrayList(); |
||
65 | /**
|
||
66 | * Crea un nuevo PointCADTool.
|
||
67 | */
|
||
68 | public MultiPointCADTool() {
|
||
69 | |||
70 | } |
||
71 | |||
72 | /**
|
||
73 | * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
||
74 | * carga previa a la utilizaci?n de la herramienta.
|
||
75 | */
|
||
76 | public void init() { |
||
77 | _fsm = new MultiPointCADToolContext(this); |
||
78 | } |
||
79 | |||
80 | /**
|
||
81 | * DOCUMENT ME!
|
||
82 | * @param x DOCUMENT ME!
|
||
83 | * @param y DOCUMENT ME!
|
||
84 | * @param sel DOCUMENT ME!
|
||
85 | */
|
||
86 | public void transition(double x, double y, InputEvent event) { |
||
87 | _fsm.addPoint(x, y, event); |
||
88 | } |
||
89 | |||
90 | /* (non-Javadoc)
|
||
91 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
||
92 | */
|
||
93 | public void transition(double d) { |
||
94 | _fsm.addValue(d); |
||
95 | } |
||
96 | |||
97 | /* (non-Javadoc)
|
||
98 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
||
99 | */
|
||
100 | public void transition(String s) throws CommandException { |
||
101 | if (!super.changeCommand(s)){ |
||
102 | _fsm.addOption(s); |
||
103 | } |
||
104 | } |
||
105 | |||
106 | /**
|
||
107 | * Equivale al transition del prototipo pero sin pasarle como par? metro el
|
||
108 | * editableFeatureSource que ya estar? creado.
|
||
109 | *
|
||
110 | * @param sel Bitset con las geometr?as que est?n seleccionadas.
|
||
111 | * @param x par?metro x del punto que se pase en esta transici?n.
|
||
112 | * @param y par?metro y del punto que se pase en esta transici?n.
|
||
113 | */
|
||
114 | public void addPoint(double x, double y,InputEvent event) { |
||
115 | MultiPointCADToolState actualState = (MultiPointCADToolState) _fsm.getPreviousState(); |
||
116 | String status = actualState.getName();
|
||
117 | |||
118 | if (status.equals("MultiPoint.InsertPoint")) { |
||
119 | points.add(new double[] {x,y}); |
||
120 | //addGeometry(ShapeFactory.createPoint2D(x, y));
|
||
121 | } |
||
122 | } |
||
123 | |||
124 | /**
|
||
125 | * M?todo para dibujar la lo necesario para el estado en el que nos
|
||
126 | * encontremos.
|
||
127 | *
|
||
128 | * @param g Graphics sobre el que dibujar.
|
||
129 | * @param selectedGeometries BitSet con las geometr?as seleccionadas.
|
||
130 | * @param x par?metro x del punto que se pase para dibujar.
|
||
131 | * @param y par?metro x del punto que se pase para dibujar.
|
||
132 | */
|
||
133 | public void drawOperation(Graphics g, double x, |
||
134 | double y) {
|
||
135 | int num=points.size();
|
||
136 | double[] xs=new double[num]; |
||
137 | double[] ys=new double[num]; |
||
138 | for (int i=0;i<num;i++) { |
||
139 | double[] p=(double[])points.get(i); |
||
140 | xs[i]=p[0];
|
||
141 | ys[i]=p[1];
|
||
142 | } |
||
143 | ShapeFactory.createMultipoint2D(xs,ys).draw((Graphics2D) g,
|
||
144 | getCadToolAdapter().getMapControl().getViewPort(), |
||
145 | 11436 | caballero | DefaultCADTool.geometrySelectSymbol); |
146 | 6024 | caballero | ShapeFactory.createPoint2D(x,y).draw((Graphics2D) g,
|
147 | getCadToolAdapter().getMapControl().getViewPort(), |
||
148 | 11436 | caballero | DefaultCADTool.geometrySelectSymbol); |
149 | 6024 | caballero | } |
150 | |||
151 | /**
|
||
152 | * Add a diferent option.
|
||
153 | *
|
||
154 | * @param sel DOCUMENT ME!
|
||
155 | * @param s Diferent option.
|
||
156 | */
|
||
157 | public void addOption(String s) { |
||
158 | // TODO Auto-generated method stub
|
||
159 | } |
||
160 | |||
161 | /* (non-Javadoc)
|
||
162 | * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
||
163 | */
|
||
164 | public void addValue(double d) { |
||
165 | // TODO Auto-generated method stub
|
||
166 | } |
||
167 | |||
168 | public String getName() { |
||
169 | return PluginServices.getText(this,"multipoint_"); |
||
170 | } |
||
171 | |||
172 | public String toString() { |
||
173 | return "_multipoint"; |
||
174 | } |
||
175 | public boolean isApplicable(int shapeType) { |
||
176 | switch (shapeType) {
|
||
177 | case FShape.MULTIPOINT:
|
||
178 | return true; |
||
179 | } |
||
180 | return false; |
||
181 | } |
||
182 | |||
183 | public void endGeometry() { |
||
184 | int num=points.size();
|
||
185 | double[] xs=new double[num]; |
||
186 | double[] ys=new double[num]; |
||
187 | for (int i=0;i<num;i++) { |
||
188 | double[] p=(double[])points.get(i); |
||
189 | xs[i]=p[0];
|
||
190 | ys[i]=p[1];
|
||
191 | } |
||
192 | addGeometry(ShapeFactory.createMultipoint2D(xs,ys)); |
||
193 | end(); |
||
194 | } |
||
195 | 9247 | caballero | public void end() { |
196 | points.clear(); |
||
197 | super.end();
|
||
198 | } |
||
199 | 6024 | caballero | } |