root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / v02 / FSymbolFactory.java @ 3609
History | View | Annotate | Download (6.63 KB)
1 | 1261 | fjp | /*
|
---|---|---|---|
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 com.iver.cit.gvsig.fmap.core.v02; |
||
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 com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
||
59 | |||
60 | |||
61 | /**
|
||
62 | * @author fjp
|
||
63 | *
|
||
64 | * To change the template for this generated type comment go to
|
||
65 | * Window>Preferences>Java>Code Generation>Code and Comments
|
||
66 | */
|
||
67 | /**
|
||
68 | * @author fjp
|
||
69 | *
|
||
70 | * To change the template for this generated type comment go to
|
||
71 | * Window>Preferences>Java>Code Generation>Code and Comments
|
||
72 | */
|
||
73 | public class FSymbolFactory { |
||
74 | static int w, h; |
||
75 | |||
76 | // Podr?amos pasarle tambi?n un color de fondo, y usarlo como background del
|
||
77 | // graphics2D.
|
||
78 | static private Graphics2D createG2(Color cRef, BufferedImage bi) |
||
79 | { |
||
80 | Graphics2D big = bi.createGraphics();
|
||
81 | Color color=new Color(0,0,0,0); |
||
82 | big.setBackground(color); |
||
83 | big.clearRect(0, 0, w, h); |
||
84 | big.setColor(new Color(cRef.getRed(),cRef.getGreen(), cRef.getBlue(),cRef.getAlpha())); |
||
85 | big.setStroke(new BasicStroke()); |
||
86 | |||
87 | return big;
|
||
88 | |||
89 | } |
||
90 | |||
91 | |||
92 | static public Paint createPatternFill(int style, Color cRef) |
||
93 | { |
||
94 | /* public final static int SYMBOL_STYLE_FILL_SOLID = 1;
|
||
95 | public final static int SYMBOL_STYLE_FILL_TRANSPARENT = 2;
|
||
96 | public final static int SYMBOL_STYLE_FILL_HORIZONTAL = 3;
|
||
97 | public final static int SYMBOL_STYLE_FILL_VERTICAL = 4;
|
||
98 | public final static int SYMBOL_STYLE_FILL_CROSS = 5;
|
||
99 | public final static int SYMBOL_STYLE_FILL_UPWARD_DIAGONAL = 6;
|
||
100 | public final static int SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL = 7;
|
||
101 | public final static int SYMBOL_STYLE_FILL_CROSS_DIAGONAL = 8;
|
||
102 | public final static int SYMBOL_STYLE_FILL_GRAYFILL = 9;
|
||
103 | public final static int SYMBOL_STYLE_FILL_LIGHTGRAYFILL = 10;
|
||
104 | public final static int SYMBOL_STYLE_FILL_DARKGRAYFILL = 11; */
|
||
105 | |||
106 | |||
107 | w=7; h=7; |
||
108 | |||
109 | BufferedImage bi = null; |
||
110 | Graphics2D big = null; |
||
111 | |||
112 | Rectangle2D rProv = new Rectangle(); |
||
113 | rProv.setFrame(0, 0,w,h); |
||
114 | |||
115 | Paint resulPatternFill = null; |
||
116 | bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
||
117 | big = createG2(cRef, bi); |
||
118 | |||
119 | switch (style)
|
||
120 | { |
||
121 | case FConstant.SYMBOL_STYLE_FILL_SOLID:
|
||
122 | return null; |
||
123 | case FConstant.SYMBOL_STYLE_FILL_TRANSPARENT:
|
||
124 | return null; |
||
125 | case FConstant.SYMBOL_STYLE_FILL_UPWARD_DIAGONAL:
|
||
126 | big.drawLine(0,0,w,h); |
||
127 | break;
|
||
128 | case FConstant.SYMBOL_STYLE_FILL_CROSS:
|
||
129 | big.drawLine(w/2,0,w/2,h); |
||
130 | big.drawLine(0,h/2,w,h/2); |
||
131 | break;
|
||
132 | case FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL:
|
||
133 | big.drawLine(0,0,w,h); |
||
134 | big.drawLine(0,h,w,0); |
||
135 | break;
|
||
136 | case FConstant.SYMBOL_STYLE_FILL_VERTICAL:
|
||
137 | big.drawLine(w/2,0,w/2,h); |
||
138 | break;
|
||
139 | case FConstant.SYMBOL_STYLE_FILL_HORIZONTAL:
|
||
140 | big.drawLine(0,h/2,w,h/2); |
||
141 | break;
|
||
142 | case FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL:
|
||
143 | // DOWNWARD_DIAGONAL m?s ancho
|
||
144 | w=15;h=15; |
||
145 | rProv.setFrame(0, 0,w,h); |
||
146 | bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
||
147 | big = createG2(cRef, bi); |
||
148 | big.drawLine(-1,h,w,-1); |
||
149 | break;
|
||
150 | |||
151 | } |
||
152 | |||
153 | resulPatternFill = new TexturePaint(bi,rProv); |
||
154 | |||
155 | return resulPatternFill;
|
||
156 | |||
157 | } |
||
158 | |||
159 | /**
|
||
160 | * Al crear esto lo mejor ser?a mirar en un directorio y cargar todas las
|
||
161 | * imagenes que tengamos predise?adas.
|
||
162 | *
|
||
163 | * @param cRef
|
||
164 | * @return
|
||
165 | */
|
||
166 | static public Paint[] createPatternFills(Color cRef) |
||
167 | { |
||
168 | |||
169 | int aux = 3; |
||
170 | |||
171 | w=7; h=7; |
||
172 | |||
173 | BufferedImage bi = null; |
||
174 | Graphics2D big = null; |
||
175 | |||
176 | Rectangle2D rProv = new Rectangle(); |
||
177 | rProv.setFrame(0, 0,w,h); |
||
178 | |||
179 | Paint[] patternFills = new Paint[8]; |
||
180 | |||
181 | // UPWARD_DIAGONAL
|
||
182 | bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
||
183 | big = createG2(cRef, bi); |
||
184 | big.drawLine(0,0,w,h); |
||
185 | patternFills[FStyle2D.SYMBOL_STYLE_FILL_UPWARD_DIAGONAL-aux] = |
||
186 | new TexturePaint(bi,rProv); |
||
187 | |||
188 | // CROSS
|
||
189 | bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
||
190 | big = createG2(cRef, bi); |
||
191 | big.drawLine(w/2,0,w/2,h); |
||
192 | big.drawLine(0,h/2,w,h/2); |
||
193 | patternFills[FConstant.SYMBOL_STYLE_FILL_CROSS-aux] = |
||
194 | new TexturePaint(bi,rProv); |
||
195 | |||
196 | // CROSS
|
||
197 | bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
||
198 | big = createG2(cRef, bi); |
||
199 | big.drawLine(0,0,w,h); |
||
200 | big.drawLine(0,h,w,0); |
||
201 | patternFills[FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL-aux] = |
||
202 | new TexturePaint(bi,rProv); |
||
203 | |||
204 | |||
205 | // VERTICAL
|
||
206 | bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
||
207 | big = createG2(cRef, bi); |
||
208 | big.drawLine(w/2,0,w/2,h); |
||
209 | patternFills[FConstant.SYMBOL_STYLE_FILL_VERTICAL-aux] = |
||
210 | new TexturePaint(bi,rProv); |
||
211 | |||
212 | // HORIZONTAL
|
||
213 | bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
||
214 | big = createG2(cRef, bi); |
||
215 | big.drawLine(0,h/2,w,h/2); |
||
216 | patternFills[FConstant.SYMBOL_STYLE_FILL_HORIZONTAL-aux] = |
||
217 | new TexturePaint(bi,rProv); |
||
218 | |||
219 | // DOWNWARD_DIAGONAL m?s ancho
|
||
220 | w=15;h=15; |
||
221 | rProv.setFrame(0, 0,w,h); |
||
222 | bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
||
223 | big = createG2(cRef, bi); |
||
224 | // big.setColor(Color.BLUE);
|
||
225 | big.drawLine(-1,h,w,-1); |
||
226 | // big.setColor(Color.RED);
|
||
227 | // big.drawLine(0,0,w,h);
|
||
228 | patternFills[FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL-aux] = |
||
229 | new TexturePaint(bi,rProv); |
||
230 | int trans=((TexturePaint)patternFills[FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL-aux]).getTransparency(); |
||
231 | |||
232 | return patternFills;
|
||
233 | } |
||
234 | |||
235 | } |