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