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