Statistics
| Revision:

svn-gvsig-desktop / tags / Root_Fmap_GisPlanet / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / styling / FStyle2D.java @ 1826

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

    
101
        //        Para s?mbolos de tipo Punto
102
        public final static int SYMBOL_STYLE_MARKER_CIRCLE = 30;
103
        public final static int SYMBOL_STYLE_MARKER_SQUARE = 31;
104
        public final static int SYMBOL_STYLE_MARKER_TRIANGLE = 32;
105
        public final static int SYMBOL_STYLE_MARKER_CROSS = 33;
106
        public final static int SYMBOL_STYLE_MARKER_TRUETYPE = 34;
107
        public final static int SYMBOL_STYLE_MARKER_IMAGEN = 35;                      
108

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