Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGraphics.java @ 2391

History | View | Annotate | Download (9.38 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.gui.layout.fframes;
46

    
47
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
import java.awt.Color;
62
import java.awt.Graphics2D;
63
import java.awt.geom.AffineTransform;
64
import java.awt.geom.Line2D;
65
import java.awt.geom.Point2D;
66
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
        private int m_type = FConstant.SHAPE_TYPE_POINT;
77
        private FSymbol m_symbol = null;
78
        private Color m_color = null;
79
        private AffineTransform mT = null;
80
        private AffineTransform aT = null;
81

    
82
        /**
83
         * Crea un nuevo FFrameGraphics.
84
         */
85
        public FFrameGraphics() {
86
                mT = new AffineTransform();
87
                mT.setToIdentity();
88
        }
89

    
90
        /**
91
         * Rellena el color que se utlizar? para dibujar el s?mbolo.
92
         *
93
         * @param color
94
         */
95
        public void setColor(Color color) {
96
                m_color = color;
97
        }
98

    
99
        /**
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
                m_type = type;
108
                aT = at;
109

    
110
                if (m_color == null) {
111
                        m_color = Color.red;
112
                }
113

    
114
                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
                                m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
122
                                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
        }
151

    
152
        /**
153
         * Devuelve el FSymbol que se representa.
154
         *
155
         * @return DOCUMENT ME!
156
         */
157
        public FSymbol getFSymbol() {
158
                return m_symbol;
159
        }
160

    
161
        /**
162
         * Rellena el FSymbol que se representara al dibujar.
163
         *
164
         * @param symbol
165
         */
166
        public void setFSymbol(FSymbol symbol) {
167
                m_symbol = symbol;
168
        }
169

    
170
        /**
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
                g.rotate(Math.toRadians(getRotation()), rect.x + (rect.width / 2),
184
                                rect.y + (rect.height / 2));
185
                if (intersects(rv, rect)) {
186
                        g.setColor(Color.black);
187

    
188
                        FShape m_shape = null;
189

    
190
                        switch (m_type) {
191
                                case (Layout.POINT):
192

    
193
                                        Point2D.Double p = new Point2D.Double((int) rect.getCenterX(),
194
                                                        (int) rect.getCenterY());
195
                                        m_shape = new FPoint2D(p.x, p.y);
196

    
197
                                        if (rect.width < rect.height) {
198
                                                m_symbol.setSize((int) rect.width - 10);
199
                                        } else {
200
                                                m_symbol.setSize((int) rect.height - 10);
201
                                        }
202

    
203
                                        ///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
204
                                        FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
205

    
206
                                        break;
207

    
208
                                case (Layout.RECTANGLESIMPLE):
209

    
210
                                        GeneralPathX rectAux = new GeneralPathX(rect);
211
                                        rectAux.transform(mT);
212
                                        m_shape = new FPolygon2D(rectAux); //FConstant.SHAPE_TYPE_POLYLINE, rectAux);
213

    
214
                                        ///m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
215
                                        FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
216

    
217
                                        break;
218

    
219
                                case (Layout.LINE):
220

    
221
                                        Line2D line = new Line2D.Double();
222
                                        line.setLine(new Point2D.Double(rect.x, rect.y),
223
                                                new Point2D.Double(rect.getMaxX(), rect.getMaxY()));
224

    
225
                                        GeneralPathX rectA = new GeneralPathX(line);
226
                                        rectA.transform(mT);
227
                                        m_shape = new FPolyline2D(rectA);
228

    
229
                                        ///m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
230
                                        FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
231

    
232
                                        //g.drawString("POLYLINE",(float)rect.getCenterX(),(float)rect.getCenterY());
233
                                        break;
234

    
235
                                case (Layout.POLYLINE):
236
                                        g.drawString("POLYLINE", (float) rect.getCenterX(),
237
                                                (float) rect.getCenterY());
238

    
239
                                        break;
240

    
241
                                case (Layout.POLYGON):
242
                                        g.drawString("POLYGON", (float) rect.getCenterX(),
243
                                                (float) rect.getCenterY());
244

    
245
                                        break;
246

    
247
                                case (Layout.CIRCLE):
248

    
249
                                        Point2D.Double pc = new Point2D.Double((int) rect.getCenterX(),
250
                                                        (int) rect.getCenterY());
251
                                        m_shape = new FPoint2D(pc.x, pc.y);
252

    
253
                                        if (rect.width < rect.height) {
254
                                                m_symbol.setSize((int) rect.width - 10);
255
                                        } else {
256
                                                m_symbol.setSize((int) rect.height - 10);
257
                                        }
258

    
259
                                        ///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
260
                                        FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
261

    
262
                                        break;
263
                        }
264
                }
265
                g.rotate(Math.toRadians(-getRotation()),
266
                                rect.x + (rect.width / 2), rect.y + (rect.height / 2));
267
        }
268

    
269
        /**
270
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
271
         */
272
        public XMLEntity getXMLEntity() {
273
                XMLEntity xml = new XMLEntity();
274
                xml.putProperty("className",this.getClass().getName());
275
                xml.putProperty("m_name", m_name);
276
                xml.putProperty("x", getBoundBox().x);
277
                xml.putProperty("y", getBoundBox().y);
278
                xml.putProperty("w", getBoundBox().width);
279
                xml.putProperty("h", getBoundBox().height);
280
                xml.putProperty("m_Selected", m_Selected);
281
                xml.putProperty("type", Layout.GRAPHICS);
282
                xml.putProperty("m_type", m_type);
283
                xml.putProperty("tag", getTag());
284
                xml.putProperty("m_rotation",getRotation());
285
                xml.addChild(m_symbol.getXMLEntity());
286
                return xml;
287
        }
288

    
289
        /**
290
         * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
291
         *
292
         * @param xml XMLEntity
293
         *
294
         * @return Objeto de esta clase.
295
         */
296
        public static FFrameGraphics createFFrameGraphics(XMLEntity xml) {
297
                FFrameGraphics fframe = new FFrameGraphics();
298

    
299
                if (xml.getIntProperty("m_Selected") != 0) {
300
                        fframe.setSelected(true);
301
                } else {
302
                        fframe.setSelected(false);
303
                }
304

    
305
                /// fframe.m_type = xml.getIntProperty("m_type");
306
                /// fframe.m_symbol = FSymbol.createFSymbol(xml.getChild(0));
307
                return fframe;
308
        }
309

    
310
        /**
311
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#updateNum()
312
         */
313
        public void updateNum() {
314
        }
315

    
316
        /**
317
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNum()
318
         */
319
        public int getNum() {
320
                return 0;
321
        }
322

    
323
        /**
324
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
325
         *                 com.iver.cit.gvsig.project.Project)
326
         */
327
        public void setXMLEntity(XMLEntity xml, Layout p) {
328
                m_Selected=xml.getIntProperty("m_Selected");
329
                m_type=xml.getIntProperty("m_type");
330
                if (xml.contains("m_rotation"))
331
                setRotation(xml.getDoubleProperty("m_rotation"));
332
                m_symbol=FSymbol.createFromXML(xml.getChild(0));
333
        }
334

    
335
        /**
336
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
337
         *                 com.iver.cit.gvsig.project.Project)
338
         */
339
        public void setXMLEntity03(XMLEntity xml, Layout p) {
340
                m_Selected=xml.getIntProperty("m_Selected");
341
                m_type=xml.getIntProperty("m_type");
342
                m_symbol=FSymbol.createFromXML03(xml.getChild(0));
343
        }
344

    
345
        /**
346
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
347
         */
348
        public String getNameFFrame() {
349
                return PluginServices.getText(this, "Gr?ficos") + num;
350
        }
351

    
352
        /**
353
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
354
         *                 java.awt.geom.AffineTransform)
355
         */
356
        public void print(Graphics2D g, AffineTransform at)
357
                throws DriverException {
358
                draw(g, at, null, null);
359
        }
360
}