Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / styling / FStyle2D.java @ 38563

History | View | Annotate | Download (13.4 KB)

1
/*
2
 * Created on 22-nov-2004
3
 *
4
 * TODO To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Generation - Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package com.iver.cit.gvsig.fmap.rendering.styling;
48

    
49
import java.awt.Color;
50
import java.awt.GradientPaint;
51
import java.awt.Graphics2D;
52
import java.awt.Rectangle;
53
import java.awt.TexturePaint;
54
import java.awt.image.BufferedImage;
55

    
56
import org.geotools.renderer.style.LineStyle2D;
57
import org.geotools.renderer.style.PolygonStyle2D;
58
import org.geotools.renderer.style.Style2D;
59

    
60
import com.iver.cit.gvsig.fmap.rendering.FStyledShapePainter;
61
import com.iver.utiles.StringUtilities;
62
import com.iver.utiles.XMLEntity;
63

    
64
/**
65
 * @author   FJP  TODO To change the template for this generated type comment go to  Window - Preferences - Java - Code Generation - Code and Comments
66
 */
67
public class FStyle2D {
68
        public static final int POINT = 1;
69
    public static final int LINE = 2;
70
    public static final int POLYGON = 4;
71
    public static final int TEXT = 8;
72
        
73
        public final static int SYMBOL_TYPE_POINT = 1;
74
        public final static int SYMBOL_TYPE_LINE = 3;
75
        public final static int SYMBOL_TYPE_FILL = 5;
76
        public final static int SYMBOL_TYPE_TEXT = 7;
77
        public final static int SYMBOL_TYPE_ICON = 9;
78
                
79
        public final static int SYMBOL_TYPE_POINTZ = 11;
80
        public final static int SYMBOL_TYPE_MULTIPOINT = 8;
81
        public final static int SYMBOL_STYLE_POINTZ = 0;
82
        public final static int SYMBOL_TYPE_POLYLINEZ = 13;
83
        public final static int SYMBOL_TYPE_POLYGONZ = 15;
84
        // Para s?mbolos de tipo pol?gono.
85
        public final static int SYMBOL_STYLE_FILL_SOLID = 1;
86
        public final static int SYMBOL_STYLE_FILL_TRANSPARENT = 2;
87
        public final static int SYMBOL_STYLE_FILL_HORIZONTAL = 3;
88
        public final static int SYMBOL_STYLE_FILL_VERTICAL = 4;
89
        public final static int SYMBOL_STYLE_FILL_CROSS = 5;
90
        public final static int SYMBOL_STYLE_FILL_UPWARD_DIAGONAL = 6;
91
        public final static int SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL = 7;
92
        public final static int SYMBOL_STYLE_FILL_CROSS_DIAGONAL = 8;
93
        public final static int SYMBOL_STYLE_FILL_GRAYFILL = 9;
94
        public final static int SYMBOL_STYLE_FILL_LIGHTGRAYFILL = 10;
95
        public final static int SYMBOL_STYLE_FILL_DARKGRAYFILL = 11;
96

    
97
        //        Para s?mbolos de tipo Punto
98
        public final static int SYMBOL_STYLE_MARKER_CIRCLE = 30;
99
        public final static int SYMBOL_STYLE_MARKER_SQUARE = 31;
100
        public final static int SYMBOL_STYLE_MARKER_TRIANGLE = 32;
101
        public final static int SYMBOL_STYLE_MARKER_CROSS = 33;
102
        public final static int SYMBOL_STYLE_MARKER_TRUETYPE = 34;
103
        public final static int SYMBOL_STYLE_MARKER_IMAGEN = 35;                      
104

    
105
        // Para s?mbolos de l?neas
106
        public final static int SYMBOL_STYLE_LINE_SOLID = 60;
107
        public final static int SYMBOL_STYLE_LINE_DASH = 61;
108
        public final static int SYMBOL_STYLE_LINE_DOT = 62;
109
        public final static int SYMBOL_STYLE_LINE_DASHDOT = 63;
110
        public final static int SYMBOL_STYLE_LINE_DASHDOTDOT = 64;
111
        public final static int SYMBOL_STYLE_LINE_RAIL = 65;
112
        public final static int SYMBOL_STYLE_LINE_ARROW = 66;
113
    
114
        // Para s?mbolos de tipo texto
115
        public final static int SYMBOL_STYLE_TEXT_NORMAL = 90;
116
        public final static int SYMBOL_STYLE_TEXT_CURSIVE = 91;
117
        public final static int SYMBOL_STYLE_TEXT_BOLD = 92;
118
        public final static int SYMBOL_STYLE_TEXT_BOLDCURSIVE = 93;
119
    
120
    /**
121
         * RGB (incluye transparencia) que se utilizar? para la aceleraci?n gr?fica
122
         * @uml.property  name="rgbPoint"
123
         */
124
        private int rgbPoint;
125
        /**
126
         * @uml.property  name="rgbLine"
127
         */
128
        private int rgbLine;
129
        /**
130
         * @uml.property  name="rgbPolygon"
131
         */
132
        private int rgbPolygon;
133
        /**
134
         * @uml.property  name="rgbText"
135
         */
136
        private int rgbText;
137
        /**
138
         * @uml.property  name="pointStyle2D"
139
         */
140
        private Style2D pointStyle2D;
141
        /**
142
         * @uml.property  name="lineStyle2D"
143
         */
144
        private LineStyle2D lineStyle2D;
145
        /**
146
         * @uml.property  name="polygonStyle2D"
147
         */
148
        private PolygonStyle2D polygonStyle2D;
149
        /**
150
         * @uml.property  name="textStyle2D"
151
         */
152
        private Style2D textStyle2D;
153
        private static BufferedImage img = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB);
154
        private static FStyledShapePainter shpPainter = new FStyledShapePainter();
155
        private static Rectangle rect = new Rectangle(0,0,1,1);
156
                
157
        /**
158
         * @return  Returns the rgb (incluye transparencia) que se utilizar? para la aceleraci?n gr?fica.
159
         * @uml.property  name="rgbPoint"
160
         */
161
        public int getRgbPoint() {
162
                return rgbPoint;
163
        }
164
        /**
165
         * @return  Returns the rgbLine.
166
         * @uml.property  name="rgbLine"
167
         */
168
        public int getRgbLine() {
169
                return rgbLine;
170
        }
171
        /**
172
         * @return  Returns the rgbPolygon.
173
         * @uml.property  name="rgbPolygon"
174
         */
175
        public int getRgbPolygon() {
176
                return rgbPolygon;
177
        }
178
        /**
179
         * @return  Returns the rgbText.
180
         * @uml.property  name="rgbText"
181
         */
182
        public int getRgbText() {
183
                return rgbText;
184
        }
185
        
186
        /**
187
         * @return  Returns the style2D.
188
         * @uml.property  name="lineStyle2D"
189
         */
190
        public synchronized LineStyle2D getLineStyle2D() {
191
                return lineStyle2D;
192
        }
193
        /**
194
         * @param style2D  The style2D to set.
195
         * @uml.property  name="lineStyle2D"
196
         */
197
        public synchronized void setLineStyle2D(LineStyle2D style2D) {
198
                lineStyle2D = style2D;
199
                // Recalculamos el RGB
200
                Graphics2D g2 = img.createGraphics();
201
                
202
                shpPainter.paint(g2,rect,style2D,0);                
203
                rgbLine = img.getRGB(0,0);
204
                
205
        }
206
        
207
        /**
208
         * @return  Returns the style2D.
209
         * @uml.property  name="polygonStyle2D"
210
         */
211
        public synchronized PolygonStyle2D getPolygonStyle2D() {
212
                return polygonStyle2D;
213
        }
214
        /**
215
         * @param style2D  The style2D to set.
216
         * @uml.property  name="polygonStyle2D"
217
         */
218
        public synchronized void setPolygonStyle2D(PolygonStyle2D style2D) {
219
                polygonStyle2D = style2D;
220
                // Recalculamos el RGB
221
                Graphics2D g2 = img.createGraphics();
222
                
223
                shpPainter.paint(g2,rect,style2D,0);                
224
                rgbPolygon = img.getRGB(0,0);
225
                
226
        }
227
        
228
        /**
229
         * @return  Returns the style2D.
230
         * @uml.property  name="pointStyle2D"
231
         */
232
        public synchronized Style2D getPointStyle2D() {
233
                return pointStyle2D;
234
        }
235
        /**
236
         * @param style2D  The style2D to set.
237
         * @uml.property  name="pointStyle2D"
238
         */
239
        public synchronized void setPointStyle2D(Style2D style2D) {
240
                pointStyle2D = style2D;
241
                // Recalculamos el RGB
242
                Graphics2D g2 = img.createGraphics();
243
                
244
                shpPainter.paint(g2,rect,style2D,0);                
245
                rgbPoint = img.getRGB(0,0);
246
                
247
        }
248
        
249
        /**
250
         * @return  Returns the style2D.
251
         * @uml.property  name="textStyle2D"
252
         */
253
        public synchronized Style2D getTextStyle2D() {
254
                return textStyle2D;
255
        }
256
        /**
257
         * @param style2D  The style2D to set.
258
         * @uml.property  name="textStyle2D"
259
         */
260
        public synchronized void setTextStyle2D(Style2D style2D) {
261
                textStyle2D = style2D;
262
                // Recalculamos el RGB
263
                Graphics2D g2 = img.createGraphics();
264
                
265
                shpPainter.paint(g2,rect,style2D,0);                
266
                rgbText = img.getRGB(0,0);
267
                
268
        }
269
public XMLEntity getXMLEntity(){
270
        XMLEntity xml = new XMLEntity();
271
        xml.putProperty("className",this.getClass().getName());
272
        xml.putProperty("rgbLine",rgbLine);
273
        xml.putProperty("rgbPolygon",rgbPolygon);
274
        xml.putProperty("rbgText",rgbText);
275
        
276
        ///////////////LINE
277
        xml.putProperty("lMaxScale",lineStyle2D.getMaxScale());
278
        xml.putProperty("lMinScale",lineStyle2D.getMinScale());
279
        if (lineStyle2D.getContour() instanceof Color){
280
                xml.putProperty("lContour",StringUtilities.color2String((Color)lineStyle2D.getContour()));
281
        }else if (lineStyle2D.getContour() instanceof GradientPaint){
282
                xml.putProperty("lTransparency",((GradientPaint)lineStyle2D.getContour()).getTransparency());
283
                xml.putProperty("lColor1",StringUtilities.color2String(((GradientPaint)lineStyle2D.getContour()).getColor1()));
284
                xml.putProperty("lColor2",StringUtilities.color2String(((GradientPaint)lineStyle2D.getContour()).getColor2()));
285
                xml.putProperty("lPoint1X",((GradientPaint)lineStyle2D.getContour()).getPoint1().getX());
286
                xml.putProperty("lPoint1Y",((GradientPaint)lineStyle2D.getContour()).getPoint1().getY());
287
                xml.putProperty("lPoint2X",((GradientPaint)lineStyle2D.getContour()).getPoint2().getX());
288
                xml.putProperty("lPoint2Y",((GradientPaint)lineStyle2D.getContour()).getPoint2().getY());
289
        }else if (lineStyle2D.getContour() instanceof TexturePaint){
290
                xml.putProperty("lTransparency",((TexturePaint)lineStyle2D.getContour()).getTransparency());
291
                xml.putProperty("lAnchorRectX",((TexturePaint)lineStyle2D.getContour()).getAnchorRect().getX());
292
                xml.putProperty("lAnchorRectY",((TexturePaint)lineStyle2D.getContour()).getAnchorRect().getY());
293
                xml.putProperty("lAnchorRectW",((TexturePaint)lineStyle2D.getContour()).getAnchorRect().getWidth());
294
                xml.putProperty("lAnchorRectH",((TexturePaint)lineStyle2D.getContour()).getAnchorRect().getHeight());
295
                //TODO falta que guardar la imagen
296
        }
297
        //TODO xml.putProperty("",lineStyle2D.getContourComposite());
298
        //TODO xml.putProperty("",lineStyle2D.getGraphicStroke());
299
        //TODO xml.putProperty("",lineStyle2D.getStroke());
300
        
301
        
302
        //////POINT
303
        xml.putProperty("pointMaxScale",pointStyle2D.getMaxScale());
304
        xml.putProperty("pointMinScale",pointStyle2D.getMinScale());
305
        
306
        ////////////POLYGON
307
        xml.putProperty("pMaxScale",polygonStyle2D.getMaxScale());
308
        xml.putProperty("pMinScale",polygonStyle2D.getMinScale());
309
        if (polygonStyle2D.getContour() instanceof Color){
310
                xml.putProperty("pContour",StringUtilities.color2String((Color)polygonStyle2D.getContour()));
311
        }else if (polygonStyle2D.getContour() instanceof GradientPaint){
312
                xml.putProperty("pContourTransparency",((GradientPaint)polygonStyle2D.getContour()).getTransparency());
313
                xml.putProperty("pContourColor1",StringUtilities.color2String(((GradientPaint)polygonStyle2D.getContour()).getColor1()));
314
                xml.putProperty("pContourColor2",StringUtilities.color2String(((GradientPaint)polygonStyle2D.getContour()).getColor2()));
315
                xml.putProperty("pContourPoint1X",((GradientPaint)polygonStyle2D.getContour()).getPoint1().getX());
316
                xml.putProperty("pContourPoint1Y",((GradientPaint)polygonStyle2D.getContour()).getPoint1().getY());
317
                xml.putProperty("pContourPoint2X",((GradientPaint)polygonStyle2D.getContour()).getPoint2().getX());
318
                xml.putProperty("pContourPoint2Y",((GradientPaint)polygonStyle2D.getContour()).getPoint2().getY());
319
        }else if (polygonStyle2D.getContour() instanceof TexturePaint){
320
                xml.putProperty("pContourTransparency",((TexturePaint)polygonStyle2D.getContour()).getTransparency());
321
                xml.putProperty("pContourAnchorRectX",((TexturePaint)polygonStyle2D.getContour()).getAnchorRect().getX());
322
                xml.putProperty("pContourAnchorRectY",((TexturePaint)polygonStyle2D.getContour()).getAnchorRect().getY());
323
                xml.putProperty("pContourAnchorRectW",((TexturePaint)polygonStyle2D.getContour()).getAnchorRect().getWidth());
324
                xml.putProperty("pContourAnchorRectH",((TexturePaint)polygonStyle2D.getContour()).getAnchorRect().getHeight());
325
                //TODO falta que guardar la imagen
326
        }
327
        if (polygonStyle2D.getFill() instanceof Color){
328
                xml.putProperty("pFill",StringUtilities.color2String((Color)polygonStyle2D.getContour()));
329
        }else if (polygonStyle2D.getContour() instanceof GradientPaint){
330
                xml.putProperty("pFillTransparency",((GradientPaint)polygonStyle2D.getContour()).getTransparency());
331
                xml.putProperty("pFillColor1",StringUtilities.color2String(((GradientPaint)polygonStyle2D.getContour()).getColor1()));
332
                xml.putProperty("pFillColor2",StringUtilities.color2String(((GradientPaint)polygonStyle2D.getContour()).getColor2()));
333
                xml.putProperty("pFillPoint1X",((GradientPaint)polygonStyle2D.getContour()).getPoint1().getX());
334
                xml.putProperty("pFillPoint1Y",((GradientPaint)polygonStyle2D.getContour()).getPoint1().getY());
335
                xml.putProperty("pFillPoint2X",((GradientPaint)polygonStyle2D.getContour()).getPoint2().getX());
336
                xml.putProperty("pFillPoint2Y",((GradientPaint)polygonStyle2D.getContour()).getPoint2().getY());
337
        }else if (polygonStyle2D.getContour() instanceof TexturePaint){
338
                xml.putProperty("pFillTransparency",((TexturePaint)polygonStyle2D.getContour()).getTransparency());
339
                xml.putProperty("pFillAnchorRectX",((TexturePaint)polygonStyle2D.getContour()).getAnchorRect().getX());
340
                xml.putProperty("pFillAnchorRectY",((TexturePaint)polygonStyle2D.getContour()).getAnchorRect().getY());
341
                xml.putProperty("pFillAnchorRectW",((TexturePaint)polygonStyle2D.getContour()).getAnchorRect().getWidth());
342
                xml.putProperty("pFillAnchorRectH",((TexturePaint)polygonStyle2D.getContour()).getAnchorRect().getHeight());
343
                //TODO falta que guardar la imagen
344
        }
345
        //TODO xml.putProperty("",polygonStyle2D.getContourComposite());
346
        //TODO xml.putProperty("",polygonStyle2D.getGraphicStroke());
347
        //TODO xml.putProperty("",polygonStyle2D.getStroke());
348
        
349
        
350
        
351
                return xml;
352
}
353
}