root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGraphics.java @ 6117
History | View | Annotate | Download (19 KB)
1 | 312 | fernando | /*
|
---|---|---|---|
2 | * Created on 22-jun-2004
|
||
3 | *
|
||
4 | */
|
||
5 | 1103 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
6 | *
|
||
7 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
8 | *
|
||
9 | * This program is free software; you can redistribute it and/or
|
||
10 | * modify it under the terms of the GNU General Public License
|
||
11 | * as published by the Free Software Foundation; either version 2
|
||
12 | * of the License, or (at your option) any later version.
|
||
13 | *
|
||
14 | * This program is distributed in the hope that it will be useful,
|
||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
17 | * GNU General Public License for more details.
|
||
18 | *
|
||
19 | * You should have received a copy of the GNU General Public License
|
||
20 | * along with this program; if not, write to the Free Software
|
||
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
22 | *
|
||
23 | * For more information, contact:
|
||
24 | *
|
||
25 | * Generalitat Valenciana
|
||
26 | * Conselleria d'Infraestructures i Transport
|
||
27 | * Av. Blasco Ib??ez, 50
|
||
28 | * 46010 VALENCIA
|
||
29 | * SPAIN
|
||
30 | *
|
||
31 | * +34 963862235
|
||
32 | * gvsig@gva.es
|
||
33 | * www.gvsig.gva.es
|
||
34 | *
|
||
35 | * or
|
||
36 | *
|
||
37 | * IVER T.I. S.A
|
||
38 | * Salamanca 50
|
||
39 | * 46005 Valencia
|
||
40 | * Spain
|
||
41 | *
|
||
42 | * +34 963163400
|
||
43 | * dac@iver.es
|
||
44 | */
|
||
45 | 312 | fernando | package com.iver.cit.gvsig.gui.layout.fframes; |
46 | |||
47 | 3679 | caballero | import java.awt.Color; |
48 | import java.awt.Graphics2D; |
||
49 | import java.awt.geom.AffineTransform; |
||
50 | import java.awt.geom.Point2D; |
||
51 | import java.awt.geom.Rectangle2D; |
||
52 | import java.awt.image.BufferedImage; |
||
53 | import java.util.BitSet; |
||
54 | 3553 | caballero | |
55 | 3679 | caballero | import com.iver.andami.PluginServices; |
56 | 1073 | vcaballero | import com.iver.cit.gvsig.fmap.DriverException; |
57 | 3553 | caballero | import com.iver.cit.gvsig.fmap.core.adapter.CircleAdapter; |
58 | import com.iver.cit.gvsig.fmap.core.adapter.GeometryAdapter; |
||
59 | import com.iver.cit.gvsig.fmap.core.adapter.PointAdapter; |
||
60 | import com.iver.cit.gvsig.fmap.core.adapter.PolyLineAdapter; |
||
61 | import com.iver.cit.gvsig.fmap.core.adapter.PolygonAdapter; |
||
62 | import com.iver.cit.gvsig.fmap.core.adapter.RectangleAdapter; |
||
63 | 1073 | vcaballero | import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
64 | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
||
65 | 2745 | caballero | import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
66 | 1073 | vcaballero | import com.iver.cit.gvsig.gui.layout.Layout; |
67 | 3185 | caballero | import com.iver.cit.gvsig.gui.project.SaveException; |
68 | 1073 | vcaballero | import com.iver.utiles.XMLEntity; |
69 | |||
70 | 312 | fernando | |
71 | /**
|
||
72 | * FFrame para contener un gr?fico.
|
||
73 | *
|
||
74 | * @author Vicente Caballero Navarro
|
||
75 | */
|
||
76 | 4845 | caballero | public class FFrameGraphics extends FFrame implements IFFrameEditableVertex { |
77 | 3679 | caballero | private static double TOL = 0.2; |
78 | 3610 | caballero | private int m_type = FConstant.SHAPE_TYPE_POINT; |
79 | 2745 | caballero | private FSymbol m_symbol = null; |
80 | private Color m_color = null; |
||
81 | 3553 | caballero | private GeometryAdapter geometry;
|
82 | private GeometryAdapter geometryEdit;
|
||
83 | 3610 | caballero | private boolean editing = false; |
84 | private double size = 0.5; |
||
85 | private BitSet index = new BitSet(); |
||
86 | |||
87 | /**
|
||
88 | * Crea un nuevo FFrameGraphics.
|
||
89 | */
|
||
90 | public FFrameGraphics() {
|
||
91 | 2745 | caballero | } |
92 | 3610 | caballero | |
93 | /**
|
||
94 | * DOCUMENT ME!
|
||
95 | *
|
||
96 | * @param geom DOCUMENT ME!
|
||
97 | */
|
||
98 | public void setGeometryAdapter(GeometryAdapter geom) { |
||
99 | geometry = geom; |
||
100 | 3115 | caballero | } |
101 | 3553 | caballero | |
102 | 2745 | caballero | /**
|
103 | * Rellena el color que se utlizar? para dibujar el s?mbolo.
|
||
104 | *
|
||
105 | * @param color
|
||
106 | */
|
||
107 | public void setColor(Color color) { |
||
108 | m_color = color; |
||
109 | } |
||
110 | 312 | fernando | |
111 | 2745 | caballero | /**
|
112 | * Actualiza el Fsymbol a partir del tipo de Gr?fico que se pase como
|
||
113 | * par?metro.
|
||
114 | *
|
||
115 | * @param type tipo de gr?fico.
|
||
116 | * @param at Transformada.
|
||
117 | */
|
||
118 | public void update(int type, AffineTransform at) { |
||
119 | m_type = type; |
||
120 | 312 | fernando | |
121 | 2745 | caballero | //aT = at;
|
122 | if (m_color == null) { |
||
123 | 3679 | caballero | m_color = Color.black;
|
124 | 2745 | caballero | } |
125 | 1073 | vcaballero | |
126 | 2745 | caballero | switch (m_type) {
|
127 | case (Layout.POINT):
|
||
128 | m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, m_color);
|
||
129 | 3610 | caballero | m_symbol.setSize((int) FLayoutUtilities.fromSheetDistance(
|
130 | size, at)); |
||
131 | |||
132 | 2745 | caballero | break;
|
133 | 1073 | vcaballero | |
134 | 2745 | caballero | case (Layout.RECTANGLESIMPLE):
|
135 | m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
|
||
136 | m_symbol.setColor(null);
|
||
137 | 1073 | vcaballero | |
138 | 2745 | caballero | break;
|
139 | 1073 | vcaballero | |
140 | 2745 | caballero | case (Layout.LINE):
|
141 | m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, m_color);
|
||
142 | 3610 | caballero | |
143 | 2745 | caballero | break;
|
144 | 1073 | vcaballero | |
145 | 2745 | caballero | case (Layout.POLYLINE):
|
146 | 3553 | caballero | m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, m_color);
|
147 | 1073 | vcaballero | |
148 | 2745 | caballero | break;
|
149 | 1073 | vcaballero | |
150 | 2745 | caballero | case (Layout.POLYGON):
|
151 | 3610 | caballero | m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
|
152 | m_symbol.setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID); |
||
153 | m_symbol.setOutlined(true);
|
||
154 | 3679 | caballero | m_symbol.setOutlineColor(m_color); |
155 | 3610 | caballero | m_symbol.setColor(null);
|
156 | 1073 | vcaballero | |
157 | 2745 | caballero | break;
|
158 | 1073 | vcaballero | |
159 | 2745 | caballero | case (Layout.CIRCLE):
|
160 | m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
|
||
161 | 3553 | caballero | m_symbol.setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID); |
162 | 2745 | caballero | m_symbol.setOutlined(true);
|
163 | 3679 | caballero | m_symbol.setOutlineColor(m_color); |
164 | 2745 | caballero | m_symbol.setColor(null);
|
165 | 312 | fernando | |
166 | 2745 | caballero | break;
|
167 | } |
||
168 | } |
||
169 | 312 | fernando | |
170 | 2745 | caballero | /**
|
171 | * Devuelve el FSymbol que se representa.
|
||
172 | *
|
||
173 | * @return DOCUMENT ME!
|
||
174 | */
|
||
175 | public FSymbol getFSymbol() {
|
||
176 | return m_symbol;
|
||
177 | } |
||
178 | 312 | fernando | |
179 | 2745 | caballero | /**
|
180 | * Rellena el FSymbol que se representara al dibujar.
|
||
181 | *
|
||
182 | * @param symbol
|
||
183 | */
|
||
184 | public void setFSymbol(FSymbol symbol) { |
||
185 | m_symbol = symbol; |
||
186 | } |
||
187 | 312 | fernando | |
188 | 2745 | caballero | /**
|
189 | * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
||
190 | * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
||
191 | * de dibujar.
|
||
192 | *
|
||
193 | * @param g Graphics
|
||
194 | * @param at Transformada afin.
|
||
195 | * @param rv rect?ngulo sobre el que hacer un clip.
|
||
196 | * @param imgBase DOCUMENT ME!
|
||
197 | */
|
||
198 | public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
||
199 | BufferedImage imgBase) {
|
||
200 | Rectangle2D.Double rect = getBoundingBox(at);
|
||
201 | g.rotate(Math.toRadians(getRotation()), rect.x + (rect.width / 2), |
||
202 | rect.y + (rect.height / 2));
|
||
203 | 1073 | vcaballero | |
204 | 2745 | caballero | if (intersects(rv, rect)) {
|
205 | g.setColor(Color.black);
|
||
206 | 3610 | caballero | |
207 | if (m_type == Layout.POINT) {
|
||
208 | m_symbol.setSize((int) (rect.getWidth() * 0.7)); |
||
209 | } |
||
210 | |||
211 | geometry.draw(g, at, m_symbol); |
||
212 | 4203 | caballero | |
213 | 3610 | caballero | if (editing) {
|
214 | 3679 | caballero | g.setColor(Color.red);
|
215 | geometry.drawVertex(g, at); |
||
216 | 3610 | caballero | } |
217 | 2745 | caballero | } |
218 | 398 | vcaballero | |
219 | 2745 | caballero | g.rotate(Math.toRadians(-getRotation()), rect.x + (rect.width / 2), |
220 | rect.y + (rect.height / 2));
|
||
221 | } |
||
222 | 2183 | fernando | |
223 | 2745 | caballero | /**
|
224 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
||
225 | */
|
||
226 | 3610 | caballero | public XMLEntity getXMLEntity() throws SaveException { |
227 | XMLEntity xml = super.getXMLEntity();
|
||
228 | |||
229 | try {
|
||
230 | xml.putProperty("type", Layout.GRAPHICS);
|
||
231 | xml.putProperty("m_type", m_type);
|
||
232 | xml.addChild(m_symbol.getXMLEntity()); |
||
233 | 6031 | caballero | if (geometry!=null) { |
234 | xml.addChild(geometry.getXMLEntity()); |
||
235 | } |
||
236 | 4845 | caballero | // xml.addChild(geometryEdit.getXMLEntity());
|
237 | 3610 | caballero | } catch (Exception e) { |
238 | throw new SaveException(e, this.getClass().getName()); |
||
239 | } |
||
240 | |||
241 | 2745 | caballero | return xml;
|
242 | } |
||
243 | |||
244 | /**
|
||
245 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#updateNum()
|
||
246 | */
|
||
247 | public void updateNum() { |
||
248 | } |
||
249 | |||
250 | /**
|
||
251 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNum()
|
||
252 | */
|
||
253 | public int getNum() { |
||
254 | return 0; |
||
255 | } |
||
256 | |||
257 | /**
|
||
258 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
||
259 | * com.iver.cit.gvsig.project.Project)
|
||
260 | */
|
||
261 | 3135 | caballero | public void setXMLEntity(XMLEntity xml) { |
262 | 2745 | caballero | m_Selected = xml.getIntProperty("m_Selected");
|
263 | 6031 | caballero | |
264 | 2745 | caballero | setRotation(xml.getDoubleProperty("m_rotation"));
|
265 | m_symbol = FSymbol.createFromXML(xml.getChild(0));
|
||
266 | 6031 | caballero | if (xml.contains("m_type")) { |
267 | m_type = xml.getIntProperty("m_type");
|
||
268 | 6071 | caballero | // return;
|
269 | 6031 | caballero | } |
270 | if (m_type==Layout.RECTANGLESYMBOL)
|
||
271 | return;
|
||
272 | 5476 | caballero | if (xml.getNumChild() ==1) { |
273 | 3610 | caballero | Rectangle2D r = (Rectangle2D) getBoundBox().clone(); |
274 | |||
275 | 3553 | caballero | if (m_type == Layout.LINE) {
|
276 | 3610 | caballero | geometry = new PolyLineAdapter();
|
277 | 5591 | jaume | } else if (m_type == Layout.RECTANGLESIMPLE || |
278 | m_type == Layout.RECTANGLEGROUP) { |
||
279 | 3610 | caballero | geometry = new RectangleAdapter();
|
280 | geometry.addPoint(new Point2D.Double(r.getX(), r.getY())); |
||
281 | geometry.addPoint(new Point2D.Double(r.getMaxX(), r.getMaxY())); |
||
282 | 3553 | caballero | } else if (m_type == Layout.POLYLINE) { |
283 | 3610 | caballero | geometry = new PolyLineAdapter();
|
284 | 3553 | caballero | } else if (m_type == Layout.POLYGON) { |
285 | 3610 | caballero | geometry = new PolygonAdapter();
|
286 | 3553 | caballero | } else if (m_type == Layout.CIRCLE) { |
287 | 3610 | caballero | geometry = new CircleAdapter();
|
288 | geometry.addPoint(new Point2D.Double(r.getCenterX(), |
||
289 | r.getCenterY())); |
||
290 | |||
291 | if (r.getWidth() < r.getHeight()) {
|
||
292 | geometry.addPoint(new Point2D.Double(r.getMaxX(), |
||
293 | r.getCenterY())); |
||
294 | } else {
|
||
295 | geometry.addPoint(new Point2D.Double(r.getCenterX(), |
||
296 | r.getY())); |
||
297 | } |
||
298 | 3553 | caballero | } else if (m_type == Layout.POINT) { |
299 | 3610 | caballero | geometry = new PointAdapter();
|
300 | geometry.addPoint(new Point2D.Double(r.getCenterX(), |
||
301 | r.getCenterY())); |
||
302 | } |
||
303 | |||
304 | 3553 | caballero | geometry.end(); |
305 | 3610 | caballero | } else {
|
306 | geometry = GeometryAdapter.createFromXML(xml.getChild(1));
|
||
307 | 4845 | caballero | // geometryEdit = GeometryAdapter.createFromXML(xml.getChild(2));
|
308 | 3553 | caballero | } |
309 | 2745 | caballero | } |
310 | |||
311 | /**
|
||
312 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
||
313 | * com.iver.cit.gvsig.project.Project)
|
||
314 | */
|
||
315 | 3610 | caballero | public void setXMLEntity03(XMLEntity xml, Layout p) { |
316 | 2745 | caballero | m_Selected = xml.getIntProperty("m_Selected");
|
317 | m_type = xml.getIntProperty("m_type");
|
||
318 | m_symbol = FSymbol.createFromXML03(xml.getChild(0));
|
||
319 | 3610 | caballero | |
320 | Rectangle2D r = (Rectangle2D) getBoundBox().clone(); |
||
321 | |||
322 | 3553 | caballero | if (m_type == Layout.LINE) {
|
323 | 3610 | caballero | geometry = new PolyLineAdapter();
|
324 | 3553 | caballero | } else if (m_type == Layout.RECTANGLESIMPLE) { |
325 | 3610 | caballero | geometry = new RectangleAdapter();
|
326 | geometry.addPoint(new Point2D.Double(r.getX(), r.getY())); |
||
327 | geometry.addPoint(new Point2D.Double(r.getMaxX(), r.getMaxY())); |
||
328 | 3553 | caballero | } else if (m_type == Layout.POLYLINE) { |
329 | 3610 | caballero | geometry = new PolyLineAdapter();
|
330 | 3553 | caballero | } else if (m_type == Layout.POLYGON) { |
331 | 3610 | caballero | geometry = new PolygonAdapter();
|
332 | 3553 | caballero | } else if (m_type == Layout.CIRCLE) { |
333 | 3610 | caballero | geometry = new CircleAdapter();
|
334 | geometry.addPoint(new Point2D.Double(r.getCenterX(), r.getCenterY())); |
||
335 | |||
336 | if (r.getWidth() < r.getHeight()) {
|
||
337 | geometry.addPoint(new Point2D.Double(r.getMaxX(), r.getCenterY())); |
||
338 | } else {
|
||
339 | geometry.addPoint(new Point2D.Double(r.getCenterX(), r.getY())); |
||
340 | } |
||
341 | 3553 | caballero | } else if (m_type == Layout.POINT) { |
342 | 3610 | caballero | geometry = new PointAdapter();
|
343 | geometry.addPoint(new Point2D.Double(r.getCenterX(), r.getCenterY())); |
||
344 | } |
||
345 | |||
346 | 3553 | caballero | geometry.end(); |
347 | 2745 | caballero | } |
348 | |||
349 | /**
|
||
350 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
|
||
351 | */
|
||
352 | public String getNameFFrame() { |
||
353 | 5476 | caballero | return PluginServices.getText(this, "Graficos")+ num; |
354 | 2745 | caballero | } |
355 | |||
356 | /**
|
||
357 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
||
358 | * java.awt.geom.AffineTransform)
|
||
359 | */
|
||
360 | public void print(Graphics2D g, AffineTransform at) |
||
361 | throws DriverException {
|
||
362 | draw(g, at, null, null); |
||
363 | } |
||
364 | |||
365 | /**
|
||
366 | * Inserta el tama?o del punto.
|
||
367 | *
|
||
368 | * @param size entero que representa el tama?o del punto.
|
||
369 | */
|
||
370 | 3553 | caballero | public void setSize(double size) { |
371 | 3610 | caballero | this.size = size;
|
372 | |||
373 | 3679 | caballero | Rectangle2D r = geometry.getBounds2D();
|
374 | 3610 | caballero | super.setBoundBox(new Rectangle2D.Double(r.getX() - size, |
375 | r.getY() - size, size * 2, size * 2)); |
||
376 | 2745 | caballero | } |
377 | 2847 | caballero | |
378 | /**
|
||
379 | * Devuelve el tipo de gr?fico que contiene el fframe.
|
||
380 | *
|
||
381 | * @return tipo de
|
||
382 | */
|
||
383 | public int getType() { |
||
384 | return m_type;
|
||
385 | } |
||
386 | 6031 | caballero | public void setType(int type) { |
387 | m_type = type; |
||
388 | } |
||
389 | 3610 | caballero | /**
|
390 | * DOCUMENT ME!
|
||
391 | *
|
||
392 | * @param r DOCUMENT ME!
|
||
393 | */
|
||
394 | 3553 | caballero | public void setBoundBox(Rectangle2D r) { |
395 | 6031 | caballero | if (m_type==Layout.RECTANGLESYMBOL) {
|
396 | super.setBoundBox(r);
|
||
397 | return;
|
||
398 | } |
||
399 | AffineTransform aT = new AffineTransform(); |
||
400 | 3610 | caballero | |
401 | if (getBoundBox().getWidth() != 0) { |
||
402 | double w = r.getWidth() / getBoundBox().getWidth();
|
||
403 | double h = r.getHeight() / getBoundBox().getHeight();
|
||
404 | 4845 | caballero | |
405 | 3610 | caballero | AffineTransform trans2 = AffineTransform.getTranslateInstance(r.getX(), |
406 | r.getY()); |
||
407 | aT.concatenate(trans2); |
||
408 | |||
409 | AffineTransform scale1 = AffineTransform.getScaleInstance(w, h); |
||
410 | aT.concatenate(scale1); |
||
411 | |||
412 | AffineTransform trans1 = AffineTransform.getTranslateInstance(-getBoundBox() |
||
413 | .getX(), |
||
414 | -getBoundBox().getY()); |
||
415 | aT.concatenate(trans1); |
||
416 | geometry.applyTransform(aT); |
||
417 | 4845 | caballero | |
418 | 3610 | caballero | size = aT.getScaleX() * size; |
419 | } |
||
420 | |||
421 | super.setBoundBox(r);
|
||
422 | 3553 | caballero | } |
423 | |||
424 | 3610 | caballero | /**
|
425 | * DOCUMENT ME!
|
||
426 | */
|
||
427 | public void startEditing() { |
||
428 | editing = true;
|
||
429 | } |
||
430 | 3553 | caballero | |
431 | 3610 | caballero | /**
|
432 | * DOCUMENT ME!
|
||
433 | */
|
||
434 | public void stopEditing() { |
||
435 | editing = false;
|
||
436 | } |
||
437 | |||
438 | /**
|
||
439 | * DOCUMENT ME!
|
||
440 | *
|
||
441 | * @return DOCUMENT ME!
|
||
442 | */
|
||
443 | public boolean isEditing() { |
||
444 | return editing;
|
||
445 | } |
||
446 | |||
447 | /**
|
||
448 | * DOCUMENT ME!
|
||
449 | *
|
||
450 | * @param point DOCUMENT ME!
|
||
451 | * @param geom DOCUMENT ME!
|
||
452 | */
|
||
453 | public void pointReleased(Point2D point, GeometryAdapter geom) { |
||
454 | index.clear(); |
||
455 | geometry = geom; |
||
456 | |||
457 | 3679 | caballero | Rectangle2D r = geometry.getBounds2D();
|
458 | 3610 | caballero | super.setBoundBox(r);
|
459 | } |
||
460 | |||
461 | /**
|
||
462 | * DOCUMENT ME!
|
||
463 | *
|
||
464 | * @param point DOCUMENT ME!
|
||
465 | */
|
||
466 | public void pointPressed(Point2D point) { |
||
467 | Rectangle2D.Double rect = getBoundBox();
|
||
468 | Point2D[] points = geometry.getPoints(); |
||
469 | 3679 | caballero | geometryEdit = geometry.cloneAdapter();//GeometryAdapter.createFromXML(geometry.getXMLEntity());
|
470 | 3610 | caballero | |
471 | Point2D pAux1 = new Point2D.Double(); |
||
472 | 4845 | caballero | index.clear(); |
473 | 3610 | caballero | for (int i = 0; i < points.length; i++) { |
474 | if (getRotation() != 0) { |
||
475 | AffineTransform af = AffineTransform.getRotateInstance(Math.toRadians( |
||
476 | -getRotation()), rect.x + (rect.width / 2),
|
||
477 | rect.y + (rect.height / 2));
|
||
478 | af.transform(point, pAux1); |
||
479 | |||
480 | if (points[i].distance(pAux1) <= TOL) {
|
||
481 | index.set(i); |
||
482 | } |
||
483 | } else {
|
||
484 | if (points[i].distance(point) <= TOL) {
|
||
485 | index.set(i); |
||
486 | } |
||
487 | } |
||
488 | } |
||
489 | } |
||
490 | |||
491 | /**
|
||
492 | * DOCUMENT ME!
|
||
493 | *
|
||
494 | * @param point DOCUMENT ME!
|
||
495 | */
|
||
496 | public void pointDragged(Point2D point) { |
||
497 | 4845 | caballero | //Point2D[] points = geometry.getPoints();
|
498 | 3610 | caballero | |
499 | for (int j = index.nextSetBit(0); j >= 0; |
||
500 | j = index.nextSetBit(j + 1)) {
|
||
501 | if (getRotation() != 0) { |
||
502 | Rectangle2D.Double rect = getBoundBox();
|
||
503 | AffineTransform af = AffineTransform.getRotateInstance(Math.toRadians( |
||
504 | -getRotation()), rect.x + (rect.width / 2),
|
||
505 | rect.y + (rect.height / 2));
|
||
506 | af.transform(point, point); |
||
507 | } |
||
508 | |||
509 | 4845 | caballero | //points[j] = new Point2D.Double(point.getX(), point.getY());
|
510 | geometryEdit.changePoint(j,point); |
||
511 | 3610 | caballero | } |
512 | 3679 | caballero | //geometryEdit.setPoints(points);
|
513 | 3610 | caballero | geometryEdit.end(); |
514 | } |
||
515 | |||
516 | /**
|
||
517 | * DOCUMENT ME!
|
||
518 | *
|
||
519 | * @param g DOCUMENT ME!
|
||
520 | * @param at DOCUMENT ME!
|
||
521 | */
|
||
522 | public void paint(Graphics2D g, AffineTransform at) { |
||
523 | if (geometryEdit != null) { |
||
524 | Rectangle2D.Double rect = getBoundingBox(at);
|
||
525 | 3679 | caballero | if (getRotation()!=0){ |
526 | 3610 | caballero | g.rotate(Math.toRadians(getRotation()), rect.x + (rect.width / 2), |
527 | rect.y + (rect.height / 2));
|
||
528 | 3679 | caballero | geometryEdit.paint(g,at,false);
|
529 | /* FShape m_shape = null;
|
||
530 | 3610 | caballero | GeneralPathX polyLine = new GeneralPathX(geometryEdit.getShape());
|
531 | polyLine.transform(at);
|
||
532 | m_shape = new FPolyline2D(polyLine);
|
||
533 | FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
|
||
534 | 3679 | caballero | */
|
535 | 3610 | caballero | g.rotate(Math.toRadians(-getRotation()), rect.x + (rect.width / 2), |
536 | rect.y + (rect.height / 2));
|
||
537 | 3679 | caballero | }else{
|
538 | geometryEdit.paint(g,at,false);
|
||
539 | } |
||
540 | 3610 | caballero | } |
541 | } |
||
542 | |||
543 | /**
|
||
544 | * DOCUMENT ME!
|
||
545 | *
|
||
546 | * @return DOCUMENT ME!
|
||
547 | */
|
||
548 | public GeometryAdapter getGeometry() {
|
||
549 | return geometryEdit;
|
||
550 | } |
||
551 | 4203 | caballero | |
552 | public void initialize() { |
||
553 | // TODO Auto-generated method stub
|
||
554 | |||
555 | } |
||
556 | 4845 | caballero | /**
|
557 | * Devuelve un entero que representa donde esta contenido el punto que se
|
||
558 | * pasa como par?metro.
|
||
559 | *
|
||
560 | * @param p punto a comparar.
|
||
561 | *
|
||
562 | * @return entero que representa como esta contenido el punto.
|
||
563 | */
|
||
564 | public int getContains(Point2D p) { |
||
565 | if (geometry instanceof CircleAdapter) { |
||
566 | if (ne.contains(p.getX(), p.getY())) {
|
||
567 | return NE;
|
||
568 | } else if (se.contains(p.getX(), p.getY())) { |
||
569 | return SE;
|
||
570 | } else if (so.contains(p.getX(), p.getY())) { |
||
571 | return SO;
|
||
572 | } else if (no.contains(p.getX(), p.getY())) { |
||
573 | return NO;
|
||
574 | } else if (getBoundingBox(null).contains(p.getX(), p.getY())) { |
||
575 | return RECT;
|
||
576 | } |
||
577 | return NOSELECT;
|
||
578 | } else
|
||
579 | return super.getContains(p); |
||
580 | } |
||
581 | |||
582 | /**
|
||
583 | * Dibuja los handlers sobre el boundingBox en el graphics que se pasa como
|
||
584 | * par?metro.
|
||
585 | *
|
||
586 | * @param g
|
||
587 | * Graphics sobre el que dibujar.
|
||
588 | */
|
||
589 | public void drawHandlers(Graphics2D g) { |
||
590 | if (geometry instanceof CircleAdapter) { |
||
591 | int size = 10; |
||
592 | Rectangle2D r = getBoundingBox(null); |
||
593 | Point2D p = new Point2D.Double(); |
||
594 | g.rotate(Math.toRadians(getRotation()), r.getX()
|
||
595 | + (r.getWidth() / 2), r.getY() + (r.getHeight() / 2)); |
||
596 | |||
597 | AffineTransform atRotate = new AffineTransform(); |
||
598 | atRotate.rotate(Math.toRadians(getRotation()), r.getX()
|
||
599 | + (r.getWidth() / 2), r.getY() + (r.getHeight() / 2)); |
||
600 | |||
601 | g.fillRect((int) r.getX() - size, (int) r.getY() - size, |
||
602 | size, size); |
||
603 | atRotate.transform(new Point2D.Double(r.getX() - size, r.getY() |
||
604 | - size), p); |
||
605 | no.setRect((int) p.getX(), (int) p.getY(), size, size); |
||
606 | |||
607 | g.fillRect((int) r.getMaxX(), (int) r.getY() - size, size, size); |
||
608 | atRotate.transform( |
||
609 | new Point2D.Double(r.getMaxX(), r.getY() - size), p); |
||
610 | ne.setRect((int) p.getX(), (int) p.getY(), size, size); |
||
611 | |||
612 | g.fillRect((int) r.getX() - size, (int) r.getMaxY(), size, size); |
||
613 | atRotate.transform( |
||
614 | new Point2D.Double(r.getX() - size, r.getMaxY()), p); |
||
615 | so.setRect((int) p.getX(), (int) p.getY(), size, size); |
||
616 | |||
617 | g.fillRect((int) r.getMaxX(), (int) r.getMaxY(), size, size); |
||
618 | atRotate.transform(new Point2D.Double(r.getMaxX(), r.getMaxY()), p); |
||
619 | se.setRect((int) p.getX(), (int) p.getY(), size, size); |
||
620 | |||
621 | g.rotate(Math.toRadians(-getRotation()), r.getX()
|
||
622 | + (r.getWidth() / 2), r.getY() + (r.getHeight() / 2)); |
||
623 | } |
||
624 | else
|
||
625 | super.drawHandlers(g);
|
||
626 | } |
||
627 | |||
628 | 312 | fernando | } |