root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / DefaultCADTool.java @ 3883
History | View | Annotate | Download (6.09 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; |
42 |
|
43 |
import java.awt.Graphics; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.geom.AffineTransform; |
46 |
import java.awt.geom.Point2D; |
47 |
import java.awt.image.BufferedImage; |
48 |
import java.io.IOException; |
49 |
|
50 |
import com.hardcode.gdbms.engine.values.Value; |
51 |
import com.iver.andami.PluginServices; |
52 |
import com.iver.cit.gvsig.CADExtension; |
53 |
import com.iver.cit.gvsig.fmap.ViewPort; |
54 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
55 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
56 |
import com.iver.cit.gvsig.fmap.core.Handler; |
57 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
58 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
59 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
60 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
61 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
62 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
63 |
|
64 |
|
65 |
/**
|
66 |
* DOCUMENT ME!
|
67 |
*
|
68 |
* @author Vicente Caballero Navarro
|
69 |
*/
|
70 |
public abstract class DefaultCADTool implements CADTool { |
71 |
private CADToolAdapter cadToolAdapter;
|
72 |
private String question; |
73 |
private String[] currentdescriptions; |
74 |
|
75 |
/**
|
76 |
* DOCUMENT ME!
|
77 |
*/
|
78 |
public void draw(IGeometry geometry) { |
79 |
if (geometry != null) { |
80 |
BufferedImage img = getCadToolAdapter().getMapControl().getImage();
|
81 |
Graphics2D gImag = (Graphics2D) img.getGraphics(); |
82 |
ViewPort vp = getCadToolAdapter().getMapControl().getViewPort(); |
83 |
geometry.draw(gImag, vp, CADTool.drawingSymbol); |
84 |
} |
85 |
} |
86 |
|
87 |
/**
|
88 |
* DOCUMENT ME!
|
89 |
*
|
90 |
* @param cta DOCUMENT ME!
|
91 |
*/
|
92 |
public void setCadToolAdapter(CADToolAdapter cta) { |
93 |
cadToolAdapter = cta; |
94 |
} |
95 |
|
96 |
/**
|
97 |
* DOCUMENT ME!
|
98 |
*
|
99 |
* @return DOCUMENT ME!
|
100 |
*/
|
101 |
public CADToolAdapter getCadToolAdapter() {
|
102 |
return cadToolAdapter;
|
103 |
} |
104 |
|
105 |
/**
|
106 |
* DOCUMENT ME!
|
107 |
*
|
108 |
* @param g DOCUMENT ME!
|
109 |
* @param firstPoint DOCUMENT ME!
|
110 |
* @param endPoint DOCUMENT ME!
|
111 |
*/
|
112 |
public void drawLine(Graphics2D g, Point2D firstPoint, Point2D endPoint) { |
113 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, 2); |
114 |
elShape.moveTo(firstPoint.getX(), firstPoint.getY()); |
115 |
elShape.lineTo(endPoint.getX(), endPoint.getY()); |
116 |
ShapeFactory.createPolyline2D(elShape).draw(g, |
117 |
getCadToolAdapter().getMapControl().getViewPort(), |
118 |
CADTool.drawingSymbol); |
119 |
} |
120 |
|
121 |
|
122 |
/**
|
123 |
* DOCUMENT ME!
|
124 |
*
|
125 |
* @param geometry DOCUMENT ME!
|
126 |
*/
|
127 |
public void addGeometry(IGeometry geometry) { |
128 |
DefaultFeature df = new DefaultFeature(geometry, null); |
129 |
|
130 |
try {
|
131 |
getCadToolAdapter().getVectorialAdapter().addRow(df); |
132 |
} catch (DriverIOException e) {
|
133 |
// TODO Auto-generated catch block
|
134 |
e.printStackTrace(); |
135 |
} catch (IOException e) { |
136 |
// TODO Auto-generated catch block
|
137 |
e.printStackTrace(); |
138 |
} |
139 |
|
140 |
draw(geometry.cloneGeometry()); |
141 |
} |
142 |
/**
|
143 |
* DOCUMENT ME!
|
144 |
*
|
145 |
* @param geometry DOCUMENT ME!
|
146 |
*/
|
147 |
public void modifyFeature(int index,DefaultFeature row) { |
148 |
try {
|
149 |
getCadToolAdapter().getVectorialAdapter().modifyRow(index, row); |
150 |
} catch (IOException e1) { |
151 |
// TODO Auto-generated catch block
|
152 |
e1.printStackTrace(); |
153 |
} catch (DriverIOException e1) {
|
154 |
// TODO Auto-generated catch block
|
155 |
e1.printStackTrace(); |
156 |
} |
157 |
draw(row.getGeometry().cloneGeometry()); |
158 |
} |
159 |
/**
|
160 |
* DOCUMENT ME!
|
161 |
*
|
162 |
* @param geometry DOCUMENT ME!
|
163 |
* @param values DOCUMENT ME!
|
164 |
*/
|
165 |
public void addGeometry(IGeometry geometry, Value[] values) { |
166 |
} |
167 |
|
168 |
/**
|
169 |
* Devuelve la cadena que corresponde al estado en el que nos encontramos.
|
170 |
*
|
171 |
* @return Cadena para mostrar por consola.
|
172 |
*/
|
173 |
public String getQuestion() { |
174 |
return question;
|
175 |
} |
176 |
|
177 |
/**
|
178 |
* Actualiza la cadena que corresponde al estado actual.
|
179 |
*
|
180 |
* @param s Cadena que aparecer? en consola.
|
181 |
*/
|
182 |
public void setQuestion(String s) { |
183 |
question = s; |
184 |
} |
185 |
|
186 |
/**
|
187 |
* DOCUMENT ME!
|
188 |
*/
|
189 |
public void refresh() { |
190 |
getCadToolAdapter().getMapControl().drawMap(false);
|
191 |
} |
192 |
|
193 |
public void drawHandlers(Graphics g,FBitSet sel,AffineTransform at) throws DriverIOException{ |
194 |
for (int i = sel.nextSetBit(0); i >= 0; |
195 |
i = sel.nextSetBit(i + 1)) {
|
196 |
IGeometry ig = getCadToolAdapter().getVectorialAdapter().getShape(i).cloneGeometry(); |
197 |
if (ig == null) continue; |
198 |
Handler[] handlers=ig.getHandlers(IGeometry.SELECTHANDLER); |
199 |
FGraphicUtilities.DrawHandlers((Graphics2D)g,at,handlers);
|
200 |
} |
201 |
} |
202 |
|
203 |
public void setDescription(String[] currentdescriptions) { |
204 |
this.currentdescriptions = currentdescriptions;
|
205 |
} |
206 |
public String[] getDescriptions(){ |
207 |
return currentdescriptions;
|
208 |
} |
209 |
/* (non-Javadoc)
|
210 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#end()
|
211 |
*/
|
212 |
public void end() { |
213 |
CADExtension.setCADTool("selection");
|
214 |
PluginServices.getMainFrame().setSelectedTool("SELCAD");
|
215 |
} |
216 |
|
217 |
} |