Statistics
| Revision:

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

History | View | Annotate | Download (9.68 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 java.awt.Color;
48
import java.awt.Graphics2D;
49
import java.awt.Shape;
50
import java.awt.geom.AffineTransform;
51
import java.awt.geom.Ellipse2D;
52
import java.awt.geom.Line2D;
53
import java.awt.geom.Point2D;
54
import java.awt.geom.Rectangle2D;
55
import java.awt.image.BufferedImage;
56

    
57
import com.iver.andami.PluginServices;
58
import com.iver.cit.gvsig.fmap.DriverException;
59
import com.iver.cit.gvsig.fmap.core.FPoint2D;
60
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
61
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
62
import com.iver.cit.gvsig.fmap.core.FShape;
63
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
64
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
65
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
66
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
67
import com.iver.cit.gvsig.gui.layout.Layout;
68
import com.iver.utiles.XMLEntity;
69

    
70

    
71
/**
72
 * FFrame para contener un gr?fico.
73
 *
74
 * @author Vicente Caballero Navarro
75
 */
76
public class FFrameGraphics extends FFrame {
77
        private int m_type = FConstant.SHAPE_TYPE_POINT;
78
        private FSymbol m_symbol = null;
79
        private Color m_color = null;
80
        private AffineTransform mT = null;
81
        //private AffineTransform aT = null;
82

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

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

    
100
        /**
101
         * Actualiza el Fsymbol a partir del tipo de Gr?fico que se pase como
102
         * par?metro.
103
         *
104
         * @param type tipo de gr?fico.
105
         * @param at Transformada.
106
         */
107
        public void update(int type, AffineTransform at) {
108
                m_type = type;
109
                //aT = at;
110

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

    
115
                switch (m_type) {
116
                        case (Layout.POINT):
117
                                m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, m_color);
118

    
119
                                break;
120

    
121
                        case (Layout.RECTANGLESIMPLE):
122
                                m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
123
                                m_symbol.setColor(null);
124

    
125
                                break;
126

    
127
                        case (Layout.LINE):
128
                                m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, m_color);
129

    
130
                                break;
131

    
132
                        case (Layout.POLYLINE):
133
                                m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
134

    
135
                                break;
136

    
137
                        case (Layout.POLYGON):
138
                                m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
139

    
140
                                break;
141

    
142
                        case (Layout.CIRCLE):
143
                                m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
144
                                m_symbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE);
145
                                m_symbol.setOutlined(true);
146
                                m_symbol.setOutlineColor(Color.red);
147
                                m_symbol.setColor(null);
148

    
149
                                break;
150
                }
151
        }
152

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

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

    
171
        /**
172
         * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
173
         * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
174
         * de dibujar.
175
         *
176
         * @param g Graphics
177
         * @param at Transformada afin.
178
         * @param rv rect?ngulo sobre el que hacer un clip.
179
         * @param imgBase DOCUMENT ME!
180
         */
181
        public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
182
                BufferedImage imgBase) {
183
                Rectangle2D.Double rect = getBoundingBox(at);
184
                g.rotate(Math.toRadians(getRotation()), rect.x + (rect.width / 2),
185
                                rect.y + (rect.height / 2));
186
                if (intersects(rv, rect)) {
187
                        g.setColor(Color.black);
188

    
189
                        FShape m_shape = null;
190

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

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

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

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

    
207
                                        break;
208

    
209
                                case (Layout.RECTANGLESIMPLE):
210

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

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

    
218
                                        break;
219

    
220
                                case (Layout.LINE):
221

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

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

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

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

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

    
240
                                        break;
241

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

    
246
                                        break;
247

    
248
                                case (Layout.CIRCLE):
249
                        
250
                                        Point2D.Double pc = new Point2D.Double((int) rect.getCenterX(),
251
                                                        (int) rect.getCenterY());
252
                                        m_shape = new FPoint2D(pc.x, pc.y);
253
                                        double x=rect.getX();
254
                                        double y=rect.getY();
255
                                        double w=rect.getWidth();
256
                                        double h=rect.getHeight();
257
                                        if (w < h) {
258
                                                y=rect.getCenterY()-w/2;
259
                                                h=w;
260
                                                m_symbol.setSize((int) rect.width - 10);
261
                                        } else {
262
                                                x=rect.getCenterX()-h/2;
263
                                                w=h;
264
                                                m_symbol.setSize((int) rect.height - 10);
265
                                        }
266
                                        Shape circle=new Ellipse2D.Double(x,y,w,h);
267
                                        m_shape =new FPolygon2D(new GeneralPathX(circle));
268
                                        ///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
269
                                        FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
270

    
271
                                        break;
272
                        }
273
                }
274
                g.rotate(Math.toRadians(-getRotation()),
275
                                rect.x + (rect.width / 2), rect.y + (rect.height / 2));
276
        }
277

    
278
        /**
279
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
280
         */
281
        public XMLEntity getXMLEntity() {
282
                XMLEntity xml = new XMLEntity();
283
                xml.putProperty("className",this.getClass().getName());
284
                xml.putProperty("m_name", m_name);
285
                xml.putProperty("x", getBoundBox().x);
286
                xml.putProperty("y", getBoundBox().y);
287
                xml.putProperty("w", getBoundBox().width);
288
                xml.putProperty("h", getBoundBox().height);
289
                xml.putProperty("m_Selected", m_Selected);
290
                xml.putProperty("type", Layout.GRAPHICS);
291
                xml.putProperty("m_type", m_type);
292
                xml.putProperty("tag", getTag());
293
                xml.putProperty("m_rotation",getRotation());
294
                xml.addChild(m_symbol.getXMLEntity());
295
                return xml;
296
        }
297

    
298
        /**
299
         * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
300
         *
301
         * @param xml XMLEntity
302
         *
303
         * @return Objeto de esta clase.
304
         */
305
        public static FFrameGraphics createFFrameGraphics(XMLEntity xml) {
306
                FFrameGraphics fframe = new FFrameGraphics();
307

    
308
                if (xml.getIntProperty("m_Selected") != 0) {
309
                        fframe.setSelected(true);
310
                } else {
311
                        fframe.setSelected(false);
312
                }
313

    
314
                /// fframe.m_type = xml.getIntProperty("m_type");
315
                /// fframe.m_symbol = FSymbol.createFSymbol(xml.getChild(0));
316
                return fframe;
317
        }
318

    
319
        /**
320
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#updateNum()
321
         */
322
        public void updateNum() {
323
        }
324

    
325
        /**
326
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNum()
327
         */
328
        public int getNum() {
329
                return 0;
330
        }
331

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

    
343
        /**
344
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
345
         *                 com.iver.cit.gvsig.project.Project)
346
         */
347
        public void setXMLEntity03(XMLEntity xml, Layout p) {
348
                m_Selected=xml.getIntProperty("m_Selected");
349
                m_type=xml.getIntProperty("m_type");
350
                m_symbol=FSymbol.createFromXML03(xml.getChild(0));
351
        }
352

    
353
        /**
354
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
355
         */
356
        public String getNameFFrame() {
357
                return PluginServices.getText(this, "Gr?ficos") + num;
358
        }
359

    
360
        /**
361
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
362
         *                 java.awt.geom.AffineTransform)
363
         */
364
        public void print(Graphics2D g, AffineTransform at)
365
                throws DriverException {
366
                draw(g, at, null, null);
367
        }
368
}