svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / FFrameGraphics.java @ 28368
History | View | Annotate | Download (22.8 KB)
1 |
/*
|
---|---|
2 |
* Created on 22-jun-2004
|
3 |
*
|
4 |
*/
|
5 |
/* 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 |
package com.iver.cit.gvsig.project.documents.layout.fframes; |
46 |
|
47 |
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 |
|
55 |
import javax.print.attribute.PrintRequestAttributeSet; |
56 |
|
57 |
import com.iver.andami.PluginServices; |
58 |
import com.iver.cit.gvsig.fmap.core.FShape; |
59 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
60 |
import com.iver.cit.gvsig.fmap.core.adapter.CircleAdapter; |
61 |
import com.iver.cit.gvsig.fmap.core.adapter.GeometryAdapter; |
62 |
import com.iver.cit.gvsig.fmap.core.adapter.PointAdapter; |
63 |
import com.iver.cit.gvsig.fmap.core.adapter.PolyLineAdapter; |
64 |
import com.iver.cit.gvsig.fmap.core.adapter.PolygonAdapter; |
65 |
import com.iver.cit.gvsig.fmap.core.adapter.RectangleAdapter; |
66 |
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
67 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
68 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol; |
69 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
70 |
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameGraphicsDialog; |
71 |
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog; |
72 |
import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
73 |
import com.iver.utiles.XMLEntity; |
74 |
|
75 |
|
76 |
/**
|
77 |
* FFrame para contener un gr?fico.
|
78 |
*
|
79 |
* @author Vicente Caballero Navarro
|
80 |
*/
|
81 |
public class FFrameGraphics extends FFrame implements IFFrameEditableVertex { |
82 |
private static double TOL = 0.2; |
83 |
public static final int POINT = 21; |
84 |
public static final int LINE = 22; |
85 |
public static final int POLYLINE = 23; |
86 |
public static final int RECTANGLE = 24; |
87 |
public static final int CIRCLE = 25; |
88 |
public static final int POLYGON = 26; |
89 |
public static final int RECTANGLEGROUP = 16; |
90 |
public static final int RECTANGLESYMBOL = 17; |
91 |
private int m_type = POINT; |
92 |
private ISymbol m_symbol = null; |
93 |
private Color m_color = null; |
94 |
private GeometryAdapter geometry;
|
95 |
private GeometryAdapter geometryEdit;
|
96 |
private boolean editing = false; |
97 |
private double size = 0.5; |
98 |
private BitSet index = new BitSet(); |
99 |
|
100 |
/**
|
101 |
* Crea un nuevo FFrameGraphics.
|
102 |
*/
|
103 |
public FFrameGraphics() {
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* DOCUMENT ME!
|
108 |
*
|
109 |
* @param geom DOCUMENT ME!
|
110 |
*/
|
111 |
public void setGeometryAdapter(GeometryAdapter geom) { |
112 |
geometry = geom; |
113 |
} |
114 |
|
115 |
/**
|
116 |
* Rellena el color que se utlizar? para dibujar el s?mbolo.
|
117 |
*
|
118 |
* @param color
|
119 |
*/
|
120 |
public void setColor(Color color) { |
121 |
m_color = color; |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Actualiza el Fsymbol a partir del tipo de Gr?fico que se pase como
|
126 |
* par?metro.
|
127 |
*
|
128 |
* @param type tipo de gr?fico.
|
129 |
* @param at Transformada.
|
130 |
*/
|
131 |
public void update(int type, AffineTransform at) { |
132 |
m_type = type; |
133 |
|
134 |
//aT = at;
|
135 |
if (m_color == null) { |
136 |
m_color = Color.black;
|
137 |
} |
138 |
int shapeType = -1; |
139 |
/*
|
140 |
* (jaume) moved to ISymbol
|
141 |
* switch (m_type) {
|
142 |
case (POINT):
|
143 |
|
144 |
FSymbol symbolPoint= new FSymbol(FConstant.SHAPE_TYPE_POINT, m_color);
|
145 |
symbolPoint.setSize((int) FLayoutUtilities.fromSheetDistance(
|
146 |
size, at));
|
147 |
m_symbol=symbolPoint;
|
148 |
break;
|
149 |
|
150 |
case (RECTANGLE):
|
151 |
FSymbol symbolRectangle= new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
|
152 |
symbolRectangle.setColor(null);
|
153 |
m_symbol=symbolRectangle;
|
154 |
break;
|
155 |
|
156 |
case (LINE):
|
157 |
FSymbol symbolLine= new FSymbol(FConstant.SYMBOL_TYPE_LINE, m_color);
|
158 |
m_symbol=symbolLine;
|
159 |
break;
|
160 |
|
161 |
case (POLYLINE):
|
162 |
FSymbol symbolPolyline= new FSymbol(FConstant.SYMBOL_TYPE_LINE, m_color);
|
163 |
m_symbol=symbolPolyline;
|
164 |
break;
|
165 |
|
166 |
case (POLYGON):
|
167 |
FSymbol symbolPolygon= new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
|
168 |
symbolPolygon.setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
|
169 |
symbolPolygon.setOutlined(true);
|
170 |
symbolPolygon.setOutlineColor(m_color);
|
171 |
symbolPolygon.setColor(null);
|
172 |
m_symbol=symbolPolygon;
|
173 |
break;
|
174 |
|
175 |
case (CIRCLE):
|
176 |
FSymbol symbolCircle= new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
|
177 |
symbolCircle.setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
|
178 |
symbolCircle.setOutlined(true);
|
179 |
symbolCircle.setOutlineColor(m_color);
|
180 |
symbolCircle.setColor(null);
|
181 |
m_symbol=symbolCircle;
|
182 |
break;
|
183 |
}
|
184 |
*/
|
185 |
switch (m_type) {
|
186 |
case (POINT):
|
187 |
shapeType = FShape.POINT; |
188 |
break;
|
189 |
|
190 |
case (RECTANGLE):
|
191 |
case (POLYGON):
|
192 |
case (CIRCLE):
|
193 |
shapeType = FShape.POLYGON; |
194 |
break;
|
195 |
|
196 |
case (LINE):
|
197 |
case (POLYLINE):
|
198 |
shapeType = FShape.LINE; |
199 |
break;
|
200 |
} |
201 |
m_symbol = SymbologyFactory.createDefaultSymbolByShapeType(shapeType); |
202 |
if (shapeType==FShape.POLYGON){
|
203 |
((SimpleFillSymbol)m_symbol).setFillColor(null);
|
204 |
} |
205 |
} |
206 |
|
207 |
/**
|
208 |
* Devuelve el FSymbol que se representa.
|
209 |
*
|
210 |
* @return DOCUMENT ME!
|
211 |
*/
|
212 |
public ISymbol getFSymbol() {
|
213 |
return m_symbol;
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* Rellena el FSymbol que se representara al dibujar.
|
218 |
*
|
219 |
* @param fs2d
|
220 |
*/
|
221 |
public void setFSymbol(ISymbol symbol) { |
222 |
m_symbol = symbol; |
223 |
} |
224 |
|
225 |
/**
|
226 |
* M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
227 |
* la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
228 |
* de dibujar.
|
229 |
*
|
230 |
* @param g Graphics
|
231 |
* @param at Transformada afin.
|
232 |
* @param rv rect?ngulo sobre el que hacer un clip.
|
233 |
* @param imgBase DOCUMENT ME!
|
234 |
*/
|
235 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
236 |
BufferedImage imgBase) {
|
237 |
Rectangle2D.Double rect = getBoundingBox(at);
|
238 |
g.rotate(Math.toRadians(getRotation()), rect.x + (rect.width / 2), |
239 |
rect.y + (rect.height / 2));
|
240 |
if (intersects(rv, rect)) {
|
241 |
g.setColor(Color.black);
|
242 |
|
243 |
if (m_type == POINT) {
|
244 |
((IMarkerSymbol)m_symbol).setSize((int) (rect.getWidth() * 0.7)); |
245 |
} |
246 |
// float stroke=0;
|
247 |
// if (((FSymbol)m_symbol).getStroke() != null) {
|
248 |
// stroke=((BasicStroke)((FSymbol)m_symbol).getStroke()).getLineWidth();
|
249 |
// BasicStroke basicStroke = new BasicStroke((float)FLayoutUtilities.fromSheetDistance(stroke,at)/100);
|
250 |
// ((FSymbol)m_symbol).setStroke(basicStroke);
|
251 |
// }
|
252 |
geometry.draw(g, at, m_symbol); |
253 |
|
254 |
// if (((FSymbol)m_symbol).getStroke() != null) {
|
255 |
// BasicStroke basicStroke = new BasicStroke(stroke);
|
256 |
// ((FSymbol)m_symbol).setStroke(basicStroke);
|
257 |
// }
|
258 |
|
259 |
if (editing) {
|
260 |
g.setColor(Color.red);
|
261 |
geometry.drawVertex(g, at); |
262 |
} |
263 |
} |
264 |
|
265 |
g.rotate(Math.toRadians(-getRotation()), rect.x + (rect.width / 2), |
266 |
rect.y + (rect.height / 2));
|
267 |
} |
268 |
|
269 |
/**
|
270 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
|
271 |
*/
|
272 |
public XMLEntity getXMLEntity() throws SaveException { |
273 |
XMLEntity xml = super.getXMLEntity();
|
274 |
|
275 |
try {
|
276 |
// xml.putProperty("type", Layout.GRAPHICS);
|
277 |
xml.putProperty("m_type", m_type);
|
278 |
xml.addChild(m_symbol.getXMLEntity()); |
279 |
if (geometry!=null) { |
280 |
xml.addChild(geometry.getXMLEntity()); |
281 |
} |
282 |
// xml.addChild(geometryEdit.getXMLEntity());
|
283 |
} catch (Exception e) { |
284 |
throw new SaveException(e, this.getClass().getName()); |
285 |
} |
286 |
|
287 |
return xml;
|
288 |
} |
289 |
|
290 |
/**
|
291 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#updateNum()
|
292 |
*/
|
293 |
public void updateNum() { |
294 |
} |
295 |
|
296 |
/**
|
297 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNum()
|
298 |
*/
|
299 |
public int getNum() { |
300 |
return 0; |
301 |
} |
302 |
|
303 |
/**
|
304 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
305 |
* com.iver.cit.gvsig.project.Project)
|
306 |
*/
|
307 |
public void setXMLEntity(XMLEntity xml) { |
308 |
m_Selected = xml.getIntProperty("m_Selected");
|
309 |
|
310 |
setRotation(xml.getDoubleProperty("m_rotation"));
|
311 |
// jaume; m_symbol = FSymbol.createFromXML(xml.getChild(0));
|
312 |
m_symbol = SymbologyFactory.createSymbolFromXML(xml.getChild(0), null); |
313 |
if (xml.contains("m_type")) { |
314 |
m_type = xml.getIntProperty("m_type");
|
315 |
// return;
|
316 |
} |
317 |
if (m_type==RECTANGLESYMBOL)
|
318 |
return;
|
319 |
if (xml.getChildrenCount() ==1) { |
320 |
Rectangle2D r = (Rectangle2D) getBoundBox().clone(); |
321 |
|
322 |
if (m_type == LINE) {
|
323 |
geometry = new PolyLineAdapter();
|
324 |
} else if (m_type == RECTANGLE || |
325 |
m_type == RECTANGLEGROUP) { |
326 |
geometry = new RectangleAdapter();
|
327 |
geometry.addPoint(new Point2D.Double(r.getX(), r.getY())); |
328 |
geometry.addPoint(new Point2D.Double(r.getMaxX(), r.getMaxY())); |
329 |
} else if (m_type == POLYLINE) { |
330 |
geometry = new PolyLineAdapter();
|
331 |
} else if (m_type == POLYGON) { |
332 |
geometry = new PolygonAdapter();
|
333 |
} else if (m_type == CIRCLE) { |
334 |
geometry = new CircleAdapter();
|
335 |
geometry.addPoint(new Point2D.Double(r.getCenterX(), |
336 |
r.getCenterY())); |
337 |
|
338 |
if (r.getWidth() < r.getHeight()) {
|
339 |
geometry.addPoint(new Point2D.Double(r.getMaxX(), |
340 |
r.getCenterY())); |
341 |
} else {
|
342 |
geometry.addPoint(new Point2D.Double(r.getCenterX(), |
343 |
r.getY())); |
344 |
} |
345 |
} else if (m_type == POINT) { |
346 |
geometry = new PointAdapter();
|
347 |
geometry.addPoint(new Point2D.Double(r.getCenterX(), |
348 |
r.getCenterY())); |
349 |
} |
350 |
|
351 |
geometry.end(); |
352 |
} else {
|
353 |
geometry = GeometryAdapter.createFromXML(xml.getChild(1));
|
354 |
// geometryEdit = GeometryAdapter.createFromXML(xml.getChild(2));
|
355 |
} |
356 |
} |
357 |
|
358 |
/**
|
359 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
360 |
* com.iver.cit.gvsig.project.Project)
|
361 |
*/
|
362 |
public void setXMLEntity03(XMLEntity xml, Layout p) { |
363 |
m_Selected = xml.getIntProperty("m_Selected");
|
364 |
m_type = xml.getIntProperty("m_type");
|
365 |
// jaume; m_symbol = FSymbol.createFromXML(xml.getChild(0));
|
366 |
m_symbol = SymbologyFactory.createSymbolFromXML(xml.getChild(0), null); |
367 |
|
368 |
Rectangle2D r = (Rectangle2D) getBoundBox().clone(); |
369 |
|
370 |
if (m_type == LINE) {
|
371 |
geometry = new PolyLineAdapter();
|
372 |
} else if (m_type == RECTANGLE) { |
373 |
geometry = new RectangleAdapter();
|
374 |
geometry.addPoint(new Point2D.Double(r.getX(), r.getY())); |
375 |
geometry.addPoint(new Point2D.Double(r.getMaxX(), r.getMaxY())); |
376 |
} else if (m_type == POLYLINE) { |
377 |
geometry = new PolyLineAdapter();
|
378 |
} else if (m_type == POLYGON) { |
379 |
geometry = new PolygonAdapter();
|
380 |
} else if (m_type == CIRCLE) { |
381 |
geometry = new CircleAdapter();
|
382 |
geometry.addPoint(new Point2D.Double(r.getCenterX(), r.getCenterY())); |
383 |
|
384 |
if (r.getWidth() < r.getHeight()) {
|
385 |
geometry.addPoint(new Point2D.Double(r.getMaxX(), r.getCenterY())); |
386 |
} else {
|
387 |
geometry.addPoint(new Point2D.Double(r.getCenterX(), r.getY())); |
388 |
} |
389 |
} else if (m_type == POINT) { |
390 |
geometry = new PointAdapter();
|
391 |
geometry.addPoint(new Point2D.Double(r.getCenterX(), r.getCenterY())); |
392 |
} |
393 |
|
394 |
geometry.end(); |
395 |
} |
396 |
|
397 |
/**
|
398 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
|
399 |
*/
|
400 |
public String getNameFFrame() { |
401 |
return PluginServices.getText(this, "Graficos")+ num; |
402 |
} |
403 |
|
404 |
/**
|
405 |
* Inserta el tama?o del punto.
|
406 |
*
|
407 |
* @param size entero que representa el tama?o del punto.
|
408 |
*/
|
409 |
public void setSize(double size) { |
410 |
this.size = size;
|
411 |
if (m_type==RECTANGLESYMBOL) {
|
412 |
return;
|
413 |
} |
414 |
Rectangle2D r = geometry.getBounds2D();
|
415 |
super.setBoundBox(new Rectangle2D.Double(r.getX() - size, |
416 |
r.getY() - size, size * 2, size * 2)); |
417 |
} |
418 |
|
419 |
/**
|
420 |
* Devuelve el tipo de gr?fico que contiene el fframe.
|
421 |
*
|
422 |
* @return tipo de
|
423 |
*/
|
424 |
public int getType() { |
425 |
return m_type;
|
426 |
} |
427 |
public void setType(int type) { |
428 |
m_type = type; |
429 |
} |
430 |
/**
|
431 |
* DOCUMENT ME!
|
432 |
*
|
433 |
* @param r DOCUMENT ME!
|
434 |
*/
|
435 |
public void setBoundBox(Rectangle2D r) { |
436 |
if (m_type==RECTANGLESYMBOL) {
|
437 |
super.setBoundBox(r);
|
438 |
return;
|
439 |
} |
440 |
AffineTransform aT = new AffineTransform(); |
441 |
|
442 |
if (getBoundBox().getWidth() != 0) { |
443 |
double w = r.getWidth() / getBoundBox().getWidth();
|
444 |
double h = r.getHeight() / getBoundBox().getHeight();
|
445 |
|
446 |
AffineTransform trans2 = AffineTransform.getTranslateInstance(r.getX(), |
447 |
r.getY()); |
448 |
aT.concatenate(trans2); |
449 |
|
450 |
AffineTransform scale1 = AffineTransform.getScaleInstance(w, h); |
451 |
aT.concatenate(scale1); |
452 |
|
453 |
AffineTransform trans1 = AffineTransform.getTranslateInstance(-getBoundBox() |
454 |
.getX(), |
455 |
-getBoundBox().getY()); |
456 |
aT.concatenate(trans1); |
457 |
geometry.applyTransform(aT); |
458 |
|
459 |
size = aT.getScaleX() * size; |
460 |
} |
461 |
|
462 |
super.setBoundBox(r);
|
463 |
} |
464 |
|
465 |
/**
|
466 |
* DOCUMENT ME!
|
467 |
*/
|
468 |
public void startEditing() { |
469 |
editing = true;
|
470 |
} |
471 |
|
472 |
/**
|
473 |
* DOCUMENT ME!
|
474 |
*/
|
475 |
public void stopEditing() { |
476 |
editing = false;
|
477 |
} |
478 |
|
479 |
/**
|
480 |
* DOCUMENT ME!
|
481 |
*
|
482 |
* @return DOCUMENT ME!
|
483 |
*/
|
484 |
public boolean isEditing() { |
485 |
return editing;
|
486 |
} |
487 |
|
488 |
/**
|
489 |
* DOCUMENT ME!
|
490 |
*
|
491 |
* @param point DOCUMENT ME!
|
492 |
* @param geom DOCUMENT ME!
|
493 |
*/
|
494 |
public void pointReleased(Point2D point, GeometryAdapter geom) { |
495 |
index.clear(); |
496 |
geometry = geom; |
497 |
|
498 |
Rectangle2D r = geometry.getBounds2D();
|
499 |
super.setBoundBox(r);
|
500 |
} |
501 |
|
502 |
/**
|
503 |
* DOCUMENT ME!
|
504 |
*
|
505 |
* @param point DOCUMENT ME!
|
506 |
*/
|
507 |
public void pointPressed(Point2D point) { |
508 |
Rectangle2D.Double rect = getBoundBox();
|
509 |
Point2D[] points = geometry.getPoints(); |
510 |
geometryEdit = geometry.cloneAdapter();//GeometryAdapter.createFromXML(geometry.getXMLEntity());
|
511 |
|
512 |
Point2D pAux1 = new Point2D.Double(); |
513 |
index.clear(); |
514 |
for (int i = 0; i < points.length; i++) { |
515 |
if (getRotation() != 0) { |
516 |
AffineTransform af = AffineTransform.getRotateInstance(Math.toRadians( |
517 |
-getRotation()), rect.x + (rect.width / 2),
|
518 |
rect.y + (rect.height / 2));
|
519 |
af.transform(point, pAux1); |
520 |
|
521 |
if (points[i].distance(pAux1) <= TOL) {
|
522 |
index.set(i); |
523 |
} |
524 |
} else {
|
525 |
if (points[i].distance(point) <= TOL) {
|
526 |
index.set(i); |
527 |
} |
528 |
} |
529 |
} |
530 |
} |
531 |
|
532 |
/**
|
533 |
* DOCUMENT ME!
|
534 |
*
|
535 |
* @param point DOCUMENT ME!
|
536 |
*/
|
537 |
public void pointDragged(Point2D point) { |
538 |
//Point2D[] points = geometry.getPoints();
|
539 |
|
540 |
for (int j = index.nextSetBit(0); j >= 0; |
541 |
j = index.nextSetBit(j + 1)) {
|
542 |
if (getRotation() != 0) { |
543 |
Rectangle2D.Double rect = getBoundBox();
|
544 |
AffineTransform af = AffineTransform.getRotateInstance(Math.toRadians( |
545 |
-getRotation()), rect.x + (rect.width / 2),
|
546 |
rect.y + (rect.height / 2));
|
547 |
af.transform(point, point); |
548 |
} |
549 |
|
550 |
//points[j] = new Point2D.Double(point.getX(), point.getY());
|
551 |
geometryEdit.changePoint(j,point); |
552 |
} |
553 |
//geometryEdit.setPoints(points);
|
554 |
geometryEdit.end(); |
555 |
} |
556 |
|
557 |
/**
|
558 |
* DOCUMENT ME!
|
559 |
*
|
560 |
* @param g DOCUMENT ME!
|
561 |
* @param at DOCUMENT ME!
|
562 |
*/
|
563 |
public void paint(Graphics2D g, AffineTransform at) { |
564 |
if (geometryEdit != null) { |
565 |
Rectangle2D.Double rect = getBoundingBox(at);
|
566 |
if (getRotation()!=0){ |
567 |
g.rotate(Math.toRadians(getRotation()), rect.x + (rect.width / 2), |
568 |
rect.y + (rect.height / 2));
|
569 |
geometryEdit.paint(g,at,false);
|
570 |
/* FShape m_shape = null;
|
571 |
GeneralPathX polyLine = new GeneralPathX(geometryEdit.getShape());
|
572 |
polyLine.transform(at);
|
573 |
m_shape = new FPolyline2D(polyLine);
|
574 |
FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
|
575 |
*/
|
576 |
g.rotate(Math.toRadians(-getRotation()), rect.x + (rect.width / 2), |
577 |
rect.y + (rect.height / 2));
|
578 |
}else{
|
579 |
geometryEdit.paint(g,at,false);
|
580 |
} |
581 |
} |
582 |
} |
583 |
|
584 |
/**
|
585 |
* DOCUMENT ME!
|
586 |
*
|
587 |
* @return DOCUMENT ME!
|
588 |
*/
|
589 |
public GeometryAdapter getGeometry() {
|
590 |
return geometryEdit;
|
591 |
} |
592 |
|
593 |
public void initialize() { |
594 |
// TODO Auto-generated method stub
|
595 |
|
596 |
} |
597 |
/**
|
598 |
* Devuelve un entero que representa donde esta contenido el punto que se
|
599 |
* pasa como par?metro.
|
600 |
*
|
601 |
* @param p punto a comparar.
|
602 |
*
|
603 |
* @return entero que representa como esta contenido el punto.
|
604 |
*/
|
605 |
public int getContains(Point2D p) { |
606 |
if (geometry instanceof CircleAdapter) { |
607 |
if (ne.contains(p.getX(), p.getY())) {
|
608 |
return NE;
|
609 |
} else if (se.contains(p.getX(), p.getY())) { |
610 |
return SE;
|
611 |
} else if (so.contains(p.getX(), p.getY())) { |
612 |
return SO;
|
613 |
} else if (no.contains(p.getX(), p.getY())) { |
614 |
return NO;
|
615 |
} else if (getBoundingBox(null).contains(p.getX(), p.getY())) { |
616 |
return RECT;
|
617 |
} |
618 |
return NOSELECT;
|
619 |
} |
620 |
return super.getContains(p); |
621 |
} |
622 |
|
623 |
/**
|
624 |
* Dibuja los handlers sobre el boundingBox en el graphics que se pasa como
|
625 |
* par?metro.
|
626 |
*
|
627 |
* @param g
|
628 |
* Graphics sobre el que dibujar.
|
629 |
*/
|
630 |
public void drawHandlers(Graphics2D g) { |
631 |
if (geometry instanceof CircleAdapter) { |
632 |
int size = 10; |
633 |
Rectangle2D r = getBoundingBox(null); |
634 |
Point2D p = new Point2D.Double(); |
635 |
g.rotate(Math.toRadians(getRotation()), r.getX()
|
636 |
+ (r.getWidth() / 2), r.getY() + (r.getHeight() / 2)); |
637 |
|
638 |
AffineTransform atRotate = new AffineTransform(); |
639 |
atRotate.rotate(Math.toRadians(getRotation()), r.getX()
|
640 |
+ (r.getWidth() / 2), r.getY() + (r.getHeight() / 2)); |
641 |
|
642 |
g.fillRect((int) r.getX() - size, (int) r.getY() - size, |
643 |
size, size); |
644 |
atRotate.transform(new Point2D.Double(r.getX() - size, r.getY() |
645 |
- size), p); |
646 |
no.setRect((int) p.getX(), (int) p.getY(), size, size); |
647 |
|
648 |
g.fillRect((int) r.getMaxX(), (int) r.getY() - size, size, size); |
649 |
atRotate.transform( |
650 |
new Point2D.Double(r.getMaxX(), r.getY() - size), p); |
651 |
ne.setRect((int) p.getX(), (int) p.getY(), size, size); |
652 |
|
653 |
g.fillRect((int) r.getX() - size, (int) r.getMaxY(), size, size); |
654 |
atRotate.transform( |
655 |
new Point2D.Double(r.getX() - size, r.getMaxY()), p); |
656 |
so.setRect((int) p.getX(), (int) p.getY(), size, size); |
657 |
|
658 |
g.fillRect((int) r.getMaxX(), (int) r.getMaxY(), size, size); |
659 |
atRotate.transform(new Point2D.Double(r.getMaxX(), r.getMaxY()), p); |
660 |
se.setRect((int) p.getX(), (int) p.getY(), size, size); |
661 |
|
662 |
g.rotate(Math.toRadians(-getRotation()), r.getX()
|
663 |
+ (r.getWidth() / 2), r.getY() + (r.getHeight() / 2)); |
664 |
} |
665 |
else
|
666 |
super.drawHandlers(g);
|
667 |
} |
668 |
|
669 |
public void cloneActions(IFFrame frame) { |
670 |
// TODO Auto-generated method stub
|
671 |
|
672 |
} |
673 |
|
674 |
public IFFrameDialog getPropertyDialog() {
|
675 |
return new FFrameGraphicsDialog(getLayout(),this); |
676 |
} |
677 |
public int getShapeType(){ |
678 |
int shapeType=0; |
679 |
switch (m_type) {
|
680 |
case (POINT):
|
681 |
shapeType = FShape.POINT; |
682 |
break;
|
683 |
|
684 |
case (RECTANGLE):
|
685 |
case (POLYGON):
|
686 |
case (CIRCLE):
|
687 |
shapeType = FShape.POLYGON; |
688 |
break;
|
689 |
|
690 |
case (LINE):
|
691 |
case (POLYLINE):
|
692 |
shapeType = FShape.LINE; |
693 |
break;
|
694 |
} |
695 |
return shapeType;
|
696 |
} |
697 |
public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet printingProperties) { |
698 |
Rectangle2D.Double rect = getBoundingBox(at);
|
699 |
g.rotate(Math.toRadians(getRotation()), rect.x + (rect.width / 2), |
700 |
rect.y + (rect.height / 2));
|
701 |
g.setColor(Color.black);
|
702 |
|
703 |
if (m_type == POINT) {
|
704 |
((IMarkerSymbol)m_symbol).setSize((int) (rect.getWidth() * 0.7)); |
705 |
} |
706 |
m_symbol.print(g,at,geometry.getShape(at),printingProperties); |
707 |
//geometry.print(g, at, m_symbol, printingProperties);
|
708 |
g.rotate(Math.toRadians(-getRotation()), rect.x + (rect.width / 2), |
709 |
rect.y + (rect.height / 2));
|
710 |
} |
711 |
|
712 |
|
713 |
} |