svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / gui / cad / tools / PointCADTool.java @ 40557
History | View | Annotate | Download (4.47 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.editing.gui.cad.tools; |
25 |
|
26 |
import java.awt.event.InputEvent; |
27 |
|
28 |
import org.gvsig.andami.PluginServices; |
29 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
30 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
31 |
import org.gvsig.editing.gui.cad.tools.smc.PointCADToolContext; |
32 |
import org.gvsig.editing.gui.cad.tools.smc.PointCADToolContext.PointCADToolState; |
33 |
import org.gvsig.fmap.dal.feature.Feature; |
34 |
import org.gvsig.fmap.geom.Geometry; |
35 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
36 |
import org.gvsig.fmap.geom.primitive.Point; |
37 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
38 |
|
39 |
/**
|
40 |
*
|
41 |
* @author Vicente Caballero Navarro
|
42 |
*/
|
43 |
public class PointCADTool extends DefaultCADTool { |
44 |
|
45 |
protected PointCADToolContext _fsm;
|
46 |
|
47 |
private static final int TYPE_MULTIPOINT = 1; |
48 |
|
49 |
/**
|
50 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
51 |
* carga previa a la utilizaci?n de la herramienta.
|
52 |
*/
|
53 |
public void init() { |
54 |
_fsm = new PointCADToolContext(this); |
55 |
} |
56 |
|
57 |
public void transition(double x, double y, InputEvent event) { |
58 |
_fsm.addPoint(x, y, event); |
59 |
} |
60 |
|
61 |
public void transition(double d) { |
62 |
_fsm.addValue(d); |
63 |
} |
64 |
|
65 |
public void transition(String s) throws CommandException { |
66 |
if (!super.changeCommand(s)) { |
67 |
_fsm.addOption(s); |
68 |
} |
69 |
} |
70 |
|
71 |
/**
|
72 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el
|
73 |
* editableFeatureSource que ya estar? creado.
|
74 |
*
|
75 |
* @param sel
|
76 |
* Bitset con las geometr?as que est?n seleccionadas.
|
77 |
* @param x
|
78 |
* par?metro x del punto que se pase en esta transici?n.
|
79 |
* @param y
|
80 |
* par?metro y del punto que se pase en esta transici?n.
|
81 |
*/
|
82 |
public void addPoint(double x, double y, InputEvent event) { |
83 |
PointCADToolState actualState = |
84 |
(PointCADToolState) _fsm.getPreviousState(); |
85 |
String status = actualState.getName();
|
86 |
|
87 |
if (status.equals("Point.FirstPoint")) { |
88 |
insertAndSelectGeometry(createPoint(x, y)); |
89 |
} |
90 |
} |
91 |
|
92 |
@Override
|
93 |
public Feature insertAndSelectGeometry(Geometry geometry) {
|
94 |
if (getSupportedTypes()[TYPE_MULTIPOINT].isTypeOf(getGeometryType())) {
|
95 |
MultiPoint multiPoint = createMultiPoint(); |
96 |
multiPoint.addPoint((Point) geometry);
|
97 |
return super.insertAndSelectGeometry(multiPoint); |
98 |
} else {
|
99 |
return super.insertAndSelectGeometry(geometry); |
100 |
} |
101 |
} |
102 |
|
103 |
/**
|
104 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
105 |
* encontremos.
|
106 |
*
|
107 |
* @param g
|
108 |
* Graphics sobre el que dibujar.
|
109 |
* @param selectedGeometries
|
110 |
* BitSet con las geometr?as seleccionadas.
|
111 |
* @param x
|
112 |
* par?metro x del punto que se pase para dibujar.
|
113 |
* @param y
|
114 |
* par?metro x del punto que se pase para dibujar.
|
115 |
*/
|
116 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
117 |
} |
118 |
|
119 |
/**
|
120 |
* Add a diferent option.
|
121 |
*
|
122 |
* @param sel
|
123 |
* DOCUMENT ME!
|
124 |
* @param s
|
125 |
* Diferent option.
|
126 |
*/
|
127 |
public void addOption(String s) { |
128 |
// Nothing to do
|
129 |
} |
130 |
|
131 |
public void addValue(double d) { |
132 |
// Nothing to do
|
133 |
} |
134 |
|
135 |
public String getName() { |
136 |
return PluginServices.getText(this, "point_"); |
137 |
} |
138 |
|
139 |
public String toString() { |
140 |
return "_point"; |
141 |
} |
142 |
|
143 |
@Override
|
144 |
protected int[] getSupportedGeometryTypes() { |
145 |
return new int[] { POINT, MULTIPOINT }; |
146 |
} |
147 |
|
148 |
} |