Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGraphics.java @ 686

History | View | Annotate | Download (8.09 KB)

1
/*
2
 * Created on 22-jun-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
package com.iver.cit.gvsig.gui.layout.fframes;
8

    
9
import java.awt.Color;
10
import java.awt.Graphics2D;
11
import java.awt.geom.AffineTransform;
12
import java.awt.geom.Rectangle2D;
13
import java.awt.image.BufferedImage;
14

    
15
import com.iver.cit.gvsig.fmap.DriverException;
16
import com.iver.cit.gvsig.gui.layout.Layout;
17
import com.iver.utiles.XMLEntity;
18

    
19

    
20
/**
21
 * FFrame para contener un gr?fico.
22
 *
23
 * @author Vicente Caballero Navarro
24
 */
25
public class FFrameGraphics extends FFrame {
26
        ///private int m_type = FConstant.SHAPE_TYPE_POINT;
27
        ///private FSymbol m_symbol = null;
28
        private Color m_color = null;
29
        private AffineTransform mT = null;
30
        private AffineTransform aT = null;
31

    
32
        /**
33
         * Crea un nuevo FFrameGraphics.
34
         */
35
        public FFrameGraphics() {
36
                mT = new AffineTransform();
37
                mT.setToIdentity();
38
        }
39

    
40
        /**
41
         * Rellena el color que se utlizara para dibujar el s?mbolo.
42
         *
43
         * @param color
44
         */
45
        public void setColor(Color color) {
46
                m_color = color;
47
        }
48

    
49
        /**
50
         * Actualiza el Fsymbol a partir del tipo de Gr?fico que se pase como
51
         * par?metro.
52
         *
53
         * @param type tipo de gr?fico.
54
         * @param at Transformada.
55
         */
56
        public void update(int type, AffineTransform at) {
57
                ///   m_type = type;
58
                aT = at;
59

    
60
                if (m_color == null) {
61
                        m_color = Color.red;
62
                }
63

    
64
                /*switch (m_type) {
65
                   case (Layout.POINT):
66
                       m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, m_color);
67
                       break;
68
                   case (Layout.RECTANGLESIMPLE):
69
                       m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_DEFAULT, m_color);
70
                       m_symbol.m_Color = null;
71
                       break;
72
                   case (Layout.LINE):
73
                       m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, m_color);
74
                       break;
75
                   case (Layout.POLYLINE):
76
                               m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
77
                       break;
78
                   case (Layout.POLYGON):
79
                               m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
80
                       break;
81
                   case (Layout.CIRCLE):
82
                               m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
83
                          m_symbol.m_Style=FConstant.SYMBOL_STYLE_MARKER_CIRCLE;
84
                          m_symbol.m_useOutline=true;
85
                          m_symbol.m_outlineColor=Color.red;
86
                               m_symbol.m_Color=null;
87
                       break;
88
                   }*/
89
        }
90

    
91
        /**
92
         * Devuelve el FSymbol que se representa.
93
         *
94
         * @param g DOCUMENT ME!
95
         * @param at DOCUMENT ME!
96
         * @param rv DOCUMENT ME!
97
         * @param imgBase DOCUMENT ME!
98
         */
99

    
100
        /* public FSymbol getFSymbol() {
101
           return m_symbol;
102
           }
103
         */
104

    
105
        /**
106
         * Rellena el FSymbol que se representara al dibujar.
107
         *
108
         * @param g
109
         * @param at DOCUMENT ME!
110
         * @param rv DOCUMENT ME!
111
         * @param imgBase DOCUMENT ME!
112
         */
113

    
114
        /*  public void setFSymbol(FSymbol symbol) {
115
           m_symbol = symbol;
116
           }
117
         */
118

    
119
        /**
120
         * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
121
         * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
122
         * de dibujar.
123
         *
124
         * @param g Graphics
125
         * @param at Transformada afin.
126
         * @param rv rect?ngulo sobre el que hacer un clip.
127
         * @param imgBase DOCUMENT ME!
128
         */
129
        public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
130
                BufferedImage imgBase) {
131
                Rectangle2D.Double rect = getBoundingBox(at);
132

    
133
                if (intersects(rv, rect)) {
134
                        g.setColor(Color.black);
135

    
136
                        /*
137
                           FShape m_shape = null;
138
                           switch (m_type) {
139
                               case (Layout.POINT):
140
                                   Point2D.Double p = new Point2D.Double((int) rect.getCenterX(),
141
                                           (int) rect.getCenterY());
142
                                   m_shape = new FShape(new FPoint(p.x,p.y,0),FConstant.SHAPE_TYPE_POINT);
143
                                   if (rect.width < rect.height) {
144
                                       m_symbol.m_Size = (int) rect.width - 10;
145
                                   } else {
146
                                       m_symbol.m_Size = (int) rect.height - 10;
147
                                   }
148
                                   ///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
149
                                   FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
150
                                   break;
151
                               case (Layout.RECTANGLESIMPLE):
152
                                   GeneralPathX rectAux = new GeneralPathX(rect);
153
                                   rectAux.transform(mT);
154
                                   m_shape = new FShape(FConstant.SHAPE_TYPE_POLYLINE, rectAux);
155
                                   ///m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
156
                                   FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
157
                                   break;
158
                               case (Layout.LINE):
159
                                   Line2D line = new Line2D.Double();
160
                                   line.setLine(new Point2D.Double(rect.x, rect.y),
161
                                       new Point2D.Double(rect.getMaxX(), rect.getMaxY()));
162
                                   GeneralPathX rectA = new GeneralPathX(line);
163
                                   rectA.transform(mT);
164
                                   m_shape = new FShape(FConstant.SHAPE_TYPE_POLYLINE, rectA);
165
                                   ///m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
166
                                   FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
167
                                   //g.drawString("POLYLINE",(float)rect.getCenterX(),(float)rect.getCenterY());
168
                                   break;
169
                               case (Layout.POLYLINE):
170
                                   g.drawString("POLYLINE", (float) rect.getCenterX(),
171
                                       (float) rect.getCenterY());
172
                                   break;
173
                               case (Layout.POLYGON):
174
                                   g.drawString("POLYGON", (float) rect.getCenterX(),
175
                                       (float) rect.getCenterY());
176
                                   break;
177
                               case (Layout.CIRCLE):
178
                                                       Point2D.Double pc = new Point2D.Double((int) rect.getCenterX(),
179
                                                                        (int) rect.getCenterY());
180
                                                       m_shape = new FShape(new FPoint(pc.x,pc.y,0),FConstant.SHAPE_TYPE_POINT);
181
                                                        if (rect.width < rect.height) {
182
                                                                m_symbol.m_Size = (int) rect.width - 10;
183
                                                        } else {
184
                                                                m_symbol.m_Size = (int) rect.height - 10;
185
                                                        }
186
                                                        ///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
187
                                                        FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol);
188
                                   break;
189
                           }
190
                         */
191
                }
192
        }
193

    
194
        /**
195
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
196
         */
197
        public XMLEntity getXMLEntity() {
198
                XMLEntity xml = new XMLEntity();
199
                xml.putProperty("nameClass", this.getClass().getName());
200
                xml.putProperty("m_name", m_name);
201
                xml.putProperty("x", getBoundBox().x);
202
                xml.putProperty("y", getBoundBox().y);
203
                xml.putProperty("w", getBoundBox().width);
204
                xml.putProperty("h", getBoundBox().height);
205
                xml.putProperty("m_Selected", m_Selected);
206
                xml.putProperty("type", Layout.GRAPHICS);
207

    
208
                /// xml.putProperty("m_type", m_type);
209
                xml.putProperty("tag", getTag());
210

    
211
                /// xml.addChild(m_symbol.getXMLEntity());
212
                return xml;
213
        }
214

    
215
        /**
216
         * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
217
         *
218
         * @param xml XMLEntity
219
         *
220
         * @return Objeto de esta clase.
221
         */
222
        public static FFrameGraphics createFFrameGraphics(XMLEntity xml) {
223
                FFrameGraphics fframe = new FFrameGraphics();
224

    
225
                if (xml.getIntProperty("m_Selected") != 0) {
226
                        fframe.setSelected(true);
227
                } else {
228
                        fframe.setSelected(false);
229
                }
230

    
231
                /// fframe.m_type = xml.getIntProperty("m_type");
232
                /// fframe.m_symbol = FSymbol.createFSymbol(xml.getChild(0));
233
                return fframe;
234
        }
235

    
236
        /**
237
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#updateNum()
238
         */
239
        public void updateNum() {
240
        }
241

    
242
        /**
243
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNum()
244
         */
245
        public int getNum() {
246
                return 0;
247
        }
248

    
249
        /**
250
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
251
         *                 com.iver.cit.gvsig.project.Project)
252
         */
253
        public void setXMLEntity(XMLEntity xml, Layout p) {
254
        }
255

    
256
        /**
257
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
258
         */
259
        public String getNameFFrame() {
260
                return null;
261
        }
262

    
263
        /**
264
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
265
         *                 java.awt.geom.AffineTransform)
266
         */
267
        public void print(Graphics2D g, AffineTransform at)
268
                throws DriverException {
269
                draw(g, at, null, null);
270
        }
271
}