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