Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap / src / org / gvsig / fmap / mapcontext / rendering / symbols / FSymbolFactory.java @ 21144

History | View | Annotate | Download (6.65 KB)

1
/*
2
 * Created on 04-may-2004
3
 *
4
 * 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 org.gvsig.fmap.mapcontext.rendering.symbols;
48

    
49
import java.awt.BasicStroke;
50
import java.awt.Color;
51
import java.awt.Graphics2D;
52
import java.awt.Paint;
53
import java.awt.Rectangle;
54
import java.awt.TexturePaint;
55
import java.awt.geom.Rectangle2D;
56
import java.awt.image.BufferedImage;
57

    
58
import org.gvsig.fmap.core.geometries.utils.FConstant;
59

    
60

    
61

    
62
/**
63
 * @author fjp
64
 *
65
 * To change the template for this generated type comment go to
66
 * Window>Preferences>Java>Code Generation>Code and Comments
67
 */
68
/**
69
 * @author fjp
70
 *
71
 * To change the template for this generated type comment go to
72
 * Window>Preferences>Java>Code Generation>Code and Comments
73
 */
74
public class FSymbolFactory {
75
        static int w, h;
76

    
77
        // Podr?amos pasarle tambi?n un color de fondo, y usarlo como background del
78
        // graphics2D.
79
        static private Graphics2D createG2(Color cRef, BufferedImage bi)
80
        {
81
                   Graphics2D big = bi.createGraphics();
82
                   Color color=new Color(0,0,0,0);
83
                   big.setBackground(color);
84
                   big.clearRect(0, 0, w, h);
85
                   big.setColor(new Color(cRef.getRed(),cRef.getGreen(), cRef.getBlue(),cRef.getAlpha()));
86
                   big.setStroke(new BasicStroke());
87

    
88
                   return big;
89

    
90
        }
91

    
92

    
93
        static public Paint createPatternFill(int style, Color cRef)
94
        {
95
                /* public final static int SYMBOL_STYLE_FILL_SOLID = 1;
96
                public final static int SYMBOL_STYLE_FILL_TRANSPARENT = 2;
97
                public final static int SYMBOL_STYLE_FILL_HORIZONTAL = 3;
98
                public final static int SYMBOL_STYLE_FILL_VERTICAL = 4;
99
                public final static int SYMBOL_STYLE_FILL_CROSS = 5;
100
                public final static int SYMBOL_STYLE_FILL_UPWARD_DIAGONAL = 6;
101
                public final static int SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL = 7;
102
                public final static int SYMBOL_STYLE_FILL_CROSS_DIAGONAL = 8;
103
                public final static int SYMBOL_STYLE_FILL_GRAYFILL = 9;
104
                public final static int SYMBOL_STYLE_FILL_LIGHTGRAYFILL = 10;
105
                public final static int SYMBOL_STYLE_FILL_DARKGRAYFILL = 11; */
106

    
107

    
108
                w=7; h=7;
109

    
110
                BufferedImage bi = null;
111
                Graphics2D big = null;
112

    
113
                Rectangle2D rProv = new Rectangle();
114
                rProv.setFrame(0, 0,w,h);
115

    
116
                Paint resulPatternFill = null;
117
                bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
118
                big = createG2(cRef, bi);
119

    
120
                switch (style)
121
                {
122
                        case FConstant.SYMBOL_STYLE_FILL_SOLID:
123
                            return null;
124
                        case FConstant.SYMBOL_STYLE_FILL_TRANSPARENT:
125
                            return null;
126
                        case FConstant.SYMBOL_STYLE_FILL_UPWARD_DIAGONAL:
127
                            big.drawLine(0,0,w,h);
128
                                break;
129
                        case FConstant.SYMBOL_STYLE_FILL_CROSS:
130
                                big.drawLine(w/2,0,w/2,h);
131
                                big.drawLine(0,h/2,w,h/2);
132
                                break;
133
                        case FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL:
134
                                big.drawLine(0,0,w,h);
135
                                big.drawLine(0,h,w,0);
136
                                break;
137
                        case FConstant.SYMBOL_STYLE_FILL_VERTICAL:
138
                                big.drawLine(w/2,0,w/2,h);
139
                                break;
140
                        case FConstant.SYMBOL_STYLE_FILL_HORIZONTAL:
141
                                big.drawLine(0,h/2,w,h/2);
142
                                break;
143
                        case FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL:
144
                                // DOWNWARD_DIAGONAL m?s ancho
145
                                w=15;h=15;
146
                                rProv.setFrame(0, 0,w,h);
147
                                bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
148
                                big = createG2(cRef, bi);
149
                                big.drawLine(-1,h,w,-1);
150
                                break;
151

    
152
                }
153

    
154
                resulPatternFill = new TexturePaint(bi,rProv);
155

    
156
                return resulPatternFill;
157

    
158
        }
159

    
160
        /**
161
         * Al crear esto lo mejor ser?a mirar en un directorio y cargar todas las
162
         * imagenes que tengamos predise?adas.
163
         *
164
         * @param cRef
165
         * @return
166
         */
167
//        static public Paint[] createPatternFills(Color cRef)
168
//        {
169
//
170
//                int aux = 3;
171
//
172
//                w=7; h=7;
173
//
174
//                BufferedImage bi = null;
175
//                Graphics2D big = null;
176
//
177
//                Rectangle2D rProv = new Rectangle();
178
//                rProv.setFrame(0, 0,w,h);
179
//
180
//                Paint[] patternFills = new Paint[8];
181
//
182
//                // UPWARD_DIAGONAL
183
//                bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
184
//                big = createG2(cRef, bi);
185
//                big.drawLine(0,0,w,h);
186
//                patternFills[FStyle2D.SYMBOL_STYLE_FILL_UPWARD_DIAGONAL-aux] =
187
//                                new TexturePaint(bi,rProv);
188
//
189
//                // CROSS
190
//                bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
191
//                big = createG2(cRef, bi);
192
//                big.drawLine(w/2,0,w/2,h);
193
//                big.drawLine(0,h/2,w,h/2);
194
//                patternFills[FConstant.SYMBOL_STYLE_FILL_CROSS-aux] =
195
//                                new TexturePaint(bi,rProv);
196
//
197
//                // CROSS
198
//                bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
199
//                big = createG2(cRef, bi);
200
//                big.drawLine(0,0,w,h);
201
//                big.drawLine(0,h,w,0);
202
//                patternFills[FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL-aux] =
203
//                                new TexturePaint(bi,rProv);
204
//
205
//
206
//                // VERTICAL
207
//                bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
208
//                big = createG2(cRef, bi);
209
//                big.drawLine(w/2,0,w/2,h);
210
//                patternFills[FConstant.SYMBOL_STYLE_FILL_VERTICAL-aux] =
211
//                                new TexturePaint(bi,rProv);
212
//
213
//                // HORIZONTAL
214
//                bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
215
//                big = createG2(cRef, bi);
216
//                big.drawLine(0,h/2,w,h/2);
217
//                patternFills[FConstant.SYMBOL_STYLE_FILL_HORIZONTAL-aux] =
218
//                                new TexturePaint(bi,rProv);
219
//
220
//                // DOWNWARD_DIAGONAL m?s ancho
221
//                w=15;h=15;
222
//                rProv.setFrame(0, 0,w,h);
223
//                bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
224
//                big = createG2(cRef, bi);
225
//                // big.setColor(Color.BLUE);
226
//                big.drawLine(-1,h,w,-1);
227
//                // big.setColor(Color.RED);
228
//                // big.drawLine(0,0,w,h);
229
//                patternFills[FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL-aux] =
230
//                                new TexturePaint(bi,rProv);
231
//                int trans=((TexturePaint)patternFills[FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL-aux]).getTransparency();
232
//
233
//                return patternFills;
234
//        }
235

    
236
}