root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / PointCADTool.java @ 38539
History | View | Annotate | Download (4.42 KB)
1 | 36370 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | 3730 | fjp | *
|
3 | 36370 | cordinyana | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | 3730 | fjp | * 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 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | 36370 | cordinyana | *
|
11 | 3730 | fjp | * 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 | 36370 | cordinyana | *
|
16 | 3730 | fjp | * 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 | 36370 | cordinyana | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | 3730 | fjp | */
|
22 | 29616 | jpiera | package org.gvsig.editing.gui.cad.tools; |
23 | 3782 | caballero | |
24 | 4313 | fjp | import java.awt.event.InputEvent; |
25 | 3832 | caballero | |
26 | 29616 | jpiera | import org.gvsig.andami.PluginServices; |
27 | import org.gvsig.editing.gui.cad.DefaultCADTool; |
||
28 | import org.gvsig.editing.gui.cad.exception.CommandException; |
||
29 | import org.gvsig.editing.gui.cad.tools.smc.PointCADToolContext; |
||
30 | import org.gvsig.editing.gui.cad.tools.smc.PointCADToolContext.PointCADToolState; |
||
31 | 37328 | cordinyana | import org.gvsig.fmap.dal.feature.Feature; |
32 | 21668 | vcaballero | import org.gvsig.fmap.geom.Geometry; |
33 | 37328 | cordinyana | import org.gvsig.fmap.geom.aggregate.MultiPoint; |
34 | import org.gvsig.fmap.geom.primitive.Point; |
||
35 | 30335 | jpiera | import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
36 | 21668 | vcaballero | |
37 | 3782 | caballero | /**
|
38 | 36370 | cordinyana | *
|
39 | 3782 | caballero | * @author Vicente Caballero Navarro
|
40 | */
|
||
41 | 3730 | fjp | public class PointCADTool extends DefaultCADTool { |
42 | 36370 | cordinyana | |
43 | 26921 | jpiera | protected PointCADToolContext _fsm;
|
44 | 27270 | vcaballero | |
45 | 37328 | cordinyana | private static final int TYPE_MULTIPOINT = 1; |
46 | 3883 | caballero | |
47 | 3730 | fjp | /**
|
48 | * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
||
49 | * carga previa a la utilizaci?n de la herramienta.
|
||
50 | */
|
||
51 | public void init() { |
||
52 | 36370 | cordinyana | _fsm = new PointCADToolContext(this); |
53 | 3782 | caballero | } |
54 | 3730 | fjp | |
55 | 4313 | fjp | public void transition(double x, double y, InputEvent event) { |
56 | 4324 | caballero | _fsm.addPoint(x, y, event); |
57 | 3730 | fjp | } |
58 | 3782 | caballero | |
59 | 3832 | caballero | public void transition(double d) { |
60 | 5735 | caballero | _fsm.addValue(d); |
61 | 3782 | caballero | } |
62 | 3766 | caballero | |
63 | 5735 | caballero | public void transition(String s) throws CommandException { |
64 | 36370 | cordinyana | if (!super.changeCommand(s)) { |
65 | _fsm.addOption(s); |
||
66 | } |
||
67 | 3782 | caballero | } |
68 | 3766 | caballero | |
69 | 3730 | fjp | /**
|
70 | * Equivale al transition del prototipo pero sin pasarle como par? metro el
|
||
71 | * editableFeatureSource que ya estar? creado.
|
||
72 | 36370 | cordinyana | *
|
73 | * @param sel
|
||
74 | * Bitset con las geometr?as que est?n seleccionadas.
|
||
75 | * @param x
|
||
76 | * par?metro x del punto que se pase en esta transici?n.
|
||
77 | * @param y
|
||
78 | * par?metro y del punto que se pase en esta transici?n.
|
||
79 | 3730 | fjp | */
|
80 | 36370 | cordinyana | public void addPoint(double x, double y, InputEvent event) { |
81 | PointCADToolState actualState = |
||
82 | (PointCADToolState) _fsm.getPreviousState(); |
||
83 | 3730 | fjp | String status = actualState.getName();
|
84 | 3782 | caballero | |
85 | 3978 | caballero | if (status.equals("Point.FirstPoint")) { |
86 | 27270 | vcaballero | insertAndSelectGeometry(createPoint(x, y)); |
87 | 3782 | caballero | } |
88 | 3730 | fjp | } |
89 | |||
90 | 37328 | cordinyana | @Override
|
91 | public Feature insertAndSelectGeometry(Geometry geometry) {
|
||
92 | if (getSupportedTypes()[TYPE_MULTIPOINT].isTypeOf(getGeometryType())) {
|
||
93 | MultiPoint multiPoint = createMultiPoint(); |
||
94 | multiPoint.addPoint((Point) geometry);
|
||
95 | return super.insertAndSelectGeometry(multiPoint); |
||
96 | } else {
|
||
97 | return super.insertAndSelectGeometry(geometry); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | 3730 | fjp | /**
|
102 | 3782 | caballero | * M?todo para dibujar la lo necesario para el estado en el que nos
|
103 | * encontremos.
|
||
104 | 36370 | cordinyana | *
|
105 | * @param g
|
||
106 | * Graphics sobre el que dibujar.
|
||
107 | * @param selectedGeometries
|
||
108 | * BitSet con las geometr?as seleccionadas.
|
||
109 | * @param x
|
||
110 | * par?metro x del punto que se pase para dibujar.
|
||
111 | * @param y
|
||
112 | * par?metro x del punto que se pase para dibujar.
|
||
113 | 3730 | fjp | */
|
114 | 36370 | cordinyana | public void drawOperation(MapControlDrawer renderer, double x, double y) { |
115 | 3782 | caballero | } |
116 | 3730 | fjp | |
117 | /**
|
||
118 | * Add a diferent option.
|
||
119 | 36370 | cordinyana | *
|
120 | * @param sel
|
||
121 | * DOCUMENT ME!
|
||
122 | * @param s
|
||
123 | * Diferent option.
|
||
124 | 3730 | fjp | */
|
125 | 3832 | caballero | public void addOption(String s) { |
126 | 36370 | cordinyana | // Nothing to do
|
127 | 3730 | fjp | } |
128 | |||
129 | 3832 | caballero | public void addValue(double d) { |
130 | 36370 | cordinyana | // Nothing to do
|
131 | 3782 | caballero | } |
132 | 3883 | caballero | |
133 | 36370 | cordinyana | public String getName() { |
134 | return PluginServices.getText(this, "point_"); |
||
135 | } |
||
136 | 4118 | caballero | |
137 | 36370 | cordinyana | public String toString() { |
138 | return "_point"; |
||
139 | } |
||
140 | |||
141 | 37328 | cordinyana | @Override
|
142 | protected int[] getSupportedGeometryTypes() { |
||
143 | return new int[] { POINT, MULTIPOINT }; |
||
144 | 36370 | cordinyana | } |
145 | 37328 | cordinyana | |
146 | 3730 | fjp | } |