root / branches / gvSIG_03_SLD / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGraphics.java @ 2106
History | View | Annotate | Download (8.71 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 | 1073 | vcaballero | import com.iver.andami.PluginServices; |
48 | import com.iver.cit.gvsig.fmap.DriverException; |
||
49 | import com.iver.cit.gvsig.fmap.core.FPoint2D; |
||
50 | import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
||
51 | import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
||
52 | import com.iver.cit.gvsig.fmap.core.FShape; |
||
53 | import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
||
54 | import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
||
55 | import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
||
56 | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
||
57 | import com.iver.cit.gvsig.gui.layout.Layout; |
||
58 | |||
59 | import com.iver.utiles.XMLEntity; |
||
60 | |||
61 | 312 | fernando | import java.awt.Color; |
62 | import java.awt.Graphics2D; |
||
63 | import java.awt.geom.AffineTransform; |
||
64 | 1073 | vcaballero | import java.awt.geom.Line2D; |
65 | import java.awt.geom.Point2D; |
||
66 | 312 | fernando | import java.awt.geom.Rectangle2D; |
67 | import java.awt.image.BufferedImage; |
||
68 | |||
69 | |||
70 | /**
|
||
71 | * FFrame para contener un gr?fico.
|
||
72 | *
|
||
73 | * @author Vicente Caballero Navarro
|
||
74 | */
|
||
75 | public class FFrameGraphics extends FFrame { |
||
76 | 1073 | vcaballero | private int m_type = FConstant.SHAPE_TYPE_POINT; |
77 | private FSymbol m_symbol = null; |
||
78 | 649 | vcaballero | private Color m_color = null; |
79 | private AffineTransform mT = null; |
||
80 | private AffineTransform aT = null; |
||
81 | 312 | fernando | |
82 | 649 | vcaballero | /**
|
83 | * Crea un nuevo FFrameGraphics.
|
||
84 | */
|
||
85 | public FFrameGraphics() {
|
||
86 | mT = new AffineTransform(); |
||
87 | mT.setToIdentity(); |
||
88 | } |
||
89 | 312 | fernando | |
90 | 649 | vcaballero | /**
|
91 | 1073 | vcaballero | * Rellena el color que se utlizar? para dibujar el s?mbolo.
|
92 | 649 | vcaballero | *
|
93 | * @param color
|
||
94 | */
|
||
95 | public void setColor(Color color) { |
||
96 | m_color = color; |
||
97 | } |
||
98 | 312 | fernando | |
99 | 649 | vcaballero | /**
|
100 | * Actualiza el Fsymbol a partir del tipo de Gr?fico que se pase como
|
||
101 | * par?metro.
|
||
102 | *
|
||
103 | * @param type tipo de gr?fico.
|
||
104 | * @param at Transformada.
|
||
105 | */
|
||
106 | public void update(int type, AffineTransform at) { |
||
107 | 1073 | vcaballero | m_type = type; |
108 | 649 | vcaballero | aT = at; |
109 | 312 | fernando | |
110 | 649 | vcaballero | if (m_color == null) { |
111 | m_color = Color.red;
|
||
112 | } |
||
113 | 312 | fernando | |
114 | 1073 | vcaballero | switch (m_type) {
|
115 | case (Layout.POINT):
|
||
116 | m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, m_color);
|
||
117 | |||
118 | break;
|
||
119 | |||
120 | case (Layout.RECTANGLESIMPLE):
|
||
121 | 1321 | vcaballero | m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
|
122 | 1073 | vcaballero | m_symbol.setColor(null);
|
123 | |||
124 | break;
|
||
125 | |||
126 | case (Layout.LINE):
|
||
127 | m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, m_color);
|
||
128 | |||
129 | break;
|
||
130 | |||
131 | case (Layout.POLYLINE):
|
||
132 | m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
|
||
133 | |||
134 | break;
|
||
135 | |||
136 | case (Layout.POLYGON):
|
||
137 | m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
|
||
138 | |||
139 | break;
|
||
140 | |||
141 | case (Layout.CIRCLE):
|
||
142 | m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
|
||
143 | m_symbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE); |
||
144 | m_symbol.setOutlined(true);
|
||
145 | m_symbol.setOutlineColor(Color.red);
|
||
146 | m_symbol.setColor(null);
|
||
147 | |||
148 | break;
|
||
149 | } |
||
150 | 649 | vcaballero | } |
151 | 312 | fernando | |
152 | 649 | vcaballero | /**
|
153 | * Devuelve el FSymbol que se representa.
|
||
154 | *
|
||
155 | 1073 | vcaballero | * @return DOCUMENT ME!
|
156 | 649 | vcaballero | */
|
157 | 1073 | vcaballero | public FSymbol getFSymbol() {
|
158 | return m_symbol;
|
||
159 | } |
||
160 | 312 | fernando | |
161 | 649 | vcaballero | /**
|
162 | * Rellena el FSymbol que se representara al dibujar.
|
||
163 | *
|
||
164 | 1073 | vcaballero | * @param symbol
|
165 | 649 | vcaballero | */
|
166 | 1073 | vcaballero | public void setFSymbol(FSymbol symbol) { |
167 | m_symbol = symbol; |
||
168 | } |
||
169 | 312 | fernando | |
170 | 649 | vcaballero | /**
|
171 | * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
||
172 | * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
||
173 | * de dibujar.
|
||
174 | *
|
||
175 | * @param g Graphics
|
||
176 | * @param at Transformada afin.
|
||
177 | * @param rv rect?ngulo sobre el que hacer un clip.
|
||
178 | * @param imgBase DOCUMENT ME!
|
||
179 | */
|
||
180 | public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
||
181 | BufferedImage imgBase) {
|
||
182 | Rectangle2D.Double rect = getBoundingBox(at);
|
||
183 | 312 | fernando | |
184 | 649 | vcaballero | if (intersects(rv, rect)) {
|
185 | g.setColor(Color.black);
|
||
186 | 312 | fernando | |
187 | 1073 | vcaballero | FShape m_shape = null;
|
188 | |||
189 | switch (m_type) {
|
||
190 | case (Layout.POINT):
|
||
191 | |||
192 | Point2D.Double p = new Point2D.Double((int) rect.getCenterX(), |
||
193 | (int) rect.getCenterY());
|
||
194 | m_shape = new FPoint2D(p.x, p.y);
|
||
195 | |||
196 | if (rect.width < rect.height) {
|
||
197 | m_symbol.setSize((int) rect.width - 10); |
||
198 | } else {
|
||
199 | m_symbol.setSize((int) rect.height - 10); |
||
200 | } |
||
201 | |||
202 | ///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
|
||
203 | FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
||
204 | |||
205 | break;
|
||
206 | |||
207 | case (Layout.RECTANGLESIMPLE):
|
||
208 | |||
209 | GeneralPathX rectAux = new GeneralPathX(rect);
|
||
210 | rectAux.transform(mT); |
||
211 | m_shape = new FPolygon2D(rectAux); //FConstant.SHAPE_TYPE_POLYLINE, rectAux); |
||
212 | |||
213 | ///m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
|
||
214 | FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
||
215 | |||
216 | break;
|
||
217 | |||
218 | case (Layout.LINE):
|
||
219 | |||
220 | Line2D line = new Line2D.Double(); |
||
221 | line.setLine(new Point2D.Double(rect.x, rect.y), |
||
222 | new Point2D.Double(rect.getMaxX(), rect.getMaxY())); |
||
223 | |||
224 | GeneralPathX rectA = new GeneralPathX(line);
|
||
225 | rectA.transform(mT); |
||
226 | m_shape = new FPolyline2D(rectA);
|
||
227 | |||
228 | ///m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
|
||
229 | FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
||
230 | |||
231 | //g.drawString("POLYLINE",(float)rect.getCenterX(),(float)rect.getCenterY());
|
||
232 | break;
|
||
233 | |||
234 | case (Layout.POLYLINE):
|
||
235 | g.drawString("POLYLINE", (float) rect.getCenterX(), |
||
236 | (float) rect.getCenterY());
|
||
237 | |||
238 | break;
|
||
239 | |||
240 | case (Layout.POLYGON):
|
||
241 | g.drawString("POLYGON", (float) rect.getCenterX(), |
||
242 | (float) rect.getCenterY());
|
||
243 | |||
244 | break;
|
||
245 | |||
246 | case (Layout.CIRCLE):
|
||
247 | |||
248 | Point2D.Double pc = new Point2D.Double((int) rect.getCenterX(), |
||
249 | (int) rect.getCenterY());
|
||
250 | m_shape = new FPoint2D(pc.x, pc.y);
|
||
251 | |||
252 | if (rect.width < rect.height) {
|
||
253 | m_symbol.setSize((int) rect.width - 10); |
||
254 | } else {
|
||
255 | m_symbol.setSize((int) rect.height - 10); |
||
256 | } |
||
257 | |||
258 | ///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
|
||
259 | FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
||
260 | |||
261 | break;
|
||
262 | } |
||
263 | 649 | vcaballero | } |
264 | } |
||
265 | 312 | fernando | |
266 | 649 | vcaballero | /**
|
267 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
||
268 | */
|
||
269 | public XMLEntity getXMLEntity() {
|
||
270 | XMLEntity xml = new XMLEntity();
|
||
271 | 1094 | vcaballero | xml.putProperty("className",this.getClass().getName()); |
272 | 649 | vcaballero | xml.putProperty("m_name", m_name);
|
273 | xml.putProperty("x", getBoundBox().x);
|
||
274 | xml.putProperty("y", getBoundBox().y);
|
||
275 | xml.putProperty("w", getBoundBox().width);
|
||
276 | xml.putProperty("h", getBoundBox().height);
|
||
277 | xml.putProperty("m_Selected", m_Selected);
|
||
278 | xml.putProperty("type", Layout.GRAPHICS);
|
||
279 | 1420 | vcaballero | xml.putProperty("m_type", m_type);
|
280 | 649 | vcaballero | xml.putProperty("tag", getTag());
|
281 | 1420 | vcaballero | xml.addChild(m_symbol.getXMLEntity()); |
282 | 649 | vcaballero | return xml;
|
283 | } |
||
284 | 312 | fernando | |
285 | 649 | vcaballero | /**
|
286 | * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
|
||
287 | *
|
||
288 | * @param xml XMLEntity
|
||
289 | *
|
||
290 | * @return Objeto de esta clase.
|
||
291 | */
|
||
292 | public static FFrameGraphics createFFrameGraphics(XMLEntity xml) { |
||
293 | FFrameGraphics fframe = new FFrameGraphics();
|
||
294 | 312 | fernando | |
295 | 649 | vcaballero | if (xml.getIntProperty("m_Selected") != 0) { |
296 | fframe.setSelected(true);
|
||
297 | } else {
|
||
298 | fframe.setSelected(false);
|
||
299 | } |
||
300 | 312 | fernando | |
301 | 649 | vcaballero | /// fframe.m_type = xml.getIntProperty("m_type");
|
302 | /// fframe.m_symbol = FSymbol.createFSymbol(xml.getChild(0));
|
||
303 | return fframe;
|
||
304 | } |
||
305 | 312 | fernando | |
306 | /**
|
||
307 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#updateNum()
|
||
308 | */
|
||
309 | public void updateNum() { |
||
310 | } |
||
311 | |||
312 | /**
|
||
313 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNum()
|
||
314 | */
|
||
315 | public int getNum() { |
||
316 | return 0; |
||
317 | } |
||
318 | 398 | vcaballero | |
319 | /**
|
||
320 | 649 | vcaballero | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
321 | * com.iver.cit.gvsig.project.Project)
|
||
322 | 398 | vcaballero | */
|
323 | 686 | vcaballero | public void setXMLEntity(XMLEntity xml, Layout p) { |
324 | 1420 | vcaballero | m_Selected=xml.getIntProperty("m_Selected");
|
325 | m_type=xml.getIntProperty("m_type");
|
||
326 | m_symbol=FSymbol.createFromXML(xml.getChild(0));
|
||
327 | 398 | vcaballero | } |
328 | |||
329 | /**
|
||
330 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
|
||
331 | */
|
||
332 | public String getNameFFrame() { |
||
333 | 1073 | vcaballero | return PluginServices.getText(this, "Gr?ficos") + num; |
334 | 398 | vcaballero | } |
335 | 649 | vcaballero | |
336 | /**
|
||
337 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
||
338 | * java.awt.geom.AffineTransform)
|
||
339 | */
|
||
340 | public void print(Graphics2D g, AffineTransform at) |
||
341 | 654 | fernando | throws DriverException {
|
342 | 649 | vcaballero | draw(g, at, null, null); |
343 | } |
||
344 | 312 | fernando | } |