Revision 21144 branches/v2_0_0_prep/libraries/libFMap/src/org/gvsig/fmap/mapcontext/rendering/symbols/FSymbolFactory.java
FSymbolFactory.java | ||
---|---|---|
56 | 56 |
import java.awt.image.BufferedImage; |
57 | 57 |
|
58 | 58 |
import org.gvsig.fmap.core.geometries.utils.FConstant; |
59 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.FStyle2D; |
|
60 | 59 |
|
61 | 60 |
|
62 | 61 |
|
... | ... | |
74 | 73 |
*/ |
75 | 74 |
public class FSymbolFactory { |
76 | 75 |
static int w, h; |
77 |
|
|
76 |
|
|
78 | 77 |
// Podr?amos pasarle tambi?n un color de fondo, y usarlo como background del |
79 |
// graphics2D.
|
|
78 |
// graphics2D. |
|
80 | 79 |
static private Graphics2D createG2(Color cRef, BufferedImage bi) |
81 |
{
|
|
80 |
{ |
|
82 | 81 |
Graphics2D big = bi.createGraphics(); |
83 | 82 |
Color color=new Color(0,0,0,0); |
84 | 83 |
big.setBackground(color); |
85 | 84 |
big.clearRect(0, 0, w, h); |
86 | 85 |
big.setColor(new Color(cRef.getRed(),cRef.getGreen(), cRef.getBlue(),cRef.getAlpha())); |
87 | 86 |
big.setStroke(new BasicStroke()); |
88 |
|
|
87 |
|
|
89 | 88 |
return big; |
90 |
|
|
89 |
|
|
91 | 90 |
} |
92 |
|
|
93 |
|
|
91 |
|
|
92 |
|
|
94 | 93 |
static public Paint createPatternFill(int style, Color cRef) |
95 | 94 |
{ |
96 | 95 |
/* public final static int SYMBOL_STYLE_FILL_SOLID = 1; |
... | ... | |
105 | 104 |
public final static int SYMBOL_STYLE_FILL_LIGHTGRAYFILL = 10; |
106 | 105 |
public final static int SYMBOL_STYLE_FILL_DARKGRAYFILL = 11; */ |
107 | 106 |
|
108 |
|
|
107 |
|
|
109 | 108 |
w=7; h=7; |
110 |
|
|
109 |
|
|
111 | 110 |
BufferedImage bi = null; |
112 |
Graphics2D big = null;
|
|
113 |
|
|
111 |
Graphics2D big = null; |
|
112 |
|
|
114 | 113 |
Rectangle2D rProv = new Rectangle(); |
115 | 114 |
rProv.setFrame(0, 0,w,h); |
116 |
|
|
115 |
|
|
117 | 116 |
Paint resulPatternFill = null; |
118 | 117 |
bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
119 | 118 |
big = createG2(cRef, bi); |
120 |
|
|
119 |
|
|
121 | 120 |
switch (style) |
122 | 121 |
{ |
123 | 122 |
case FConstant.SYMBOL_STYLE_FILL_SOLID: |
... | ... | |
131 | 130 |
big.drawLine(w/2,0,w/2,h); |
132 | 131 |
big.drawLine(0,h/2,w,h/2); |
133 | 132 |
break; |
134 |
case FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL:
|
|
133 |
case FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL: |
|
135 | 134 |
big.drawLine(0,0,w,h); |
136 | 135 |
big.drawLine(0,h,w,0); |
137 | 136 |
break; |
138 |
case FConstant.SYMBOL_STYLE_FILL_VERTICAL:
|
|
137 |
case FConstant.SYMBOL_STYLE_FILL_VERTICAL: |
|
139 | 138 |
big.drawLine(w/2,0,w/2,h); |
140 | 139 |
break; |
141 |
case FConstant.SYMBOL_STYLE_FILL_HORIZONTAL:
|
|
140 |
case FConstant.SYMBOL_STYLE_FILL_HORIZONTAL: |
|
142 | 141 |
big.drawLine(0,h/2,w,h/2); |
143 | 142 |
break; |
144 |
case FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL:
|
|
143 |
case FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL: |
|
145 | 144 |
// DOWNWARD_DIAGONAL m?s ancho |
146 | 145 |
w=15;h=15; |
147 | 146 |
rProv.setFrame(0, 0,w,h); |
... | ... | |
149 | 148 |
big = createG2(cRef, bi); |
150 | 149 |
big.drawLine(-1,h,w,-1); |
151 | 150 |
break; |
152 |
|
|
151 |
|
|
153 | 152 |
} |
154 |
|
|
153 |
|
|
155 | 154 |
resulPatternFill = new TexturePaint(bi,rProv); |
156 |
|
|
155 |
|
|
157 | 156 |
return resulPatternFill; |
158 |
|
|
157 |
|
|
159 | 158 |
} |
160 |
|
|
159 |
|
|
161 | 160 |
/** |
162 | 161 |
* Al crear esto lo mejor ser?a mirar en un directorio y cargar todas las |
163 |
* imagenes que tengamos predise?adas.
|
|
164 |
*
|
|
162 |
* imagenes que tengamos predise?adas. |
|
163 |
* |
|
165 | 164 |
* @param cRef |
166 | 165 |
* @return |
167 | 166 |
*/ |
168 |
static public Paint[] createPatternFills(Color cRef) |
|
169 |
{ |
|
170 |
|
|
171 |
int aux = 3; |
|
172 |
|
|
173 |
w=7; h=7; |
|
174 |
|
|
175 |
BufferedImage bi = null; |
|
176 |
Graphics2D big = null; |
|
177 |
|
|
178 |
Rectangle2D rProv = new Rectangle(); |
|
179 |
rProv.setFrame(0, 0,w,h); |
|
180 |
|
|
181 |
Paint[] patternFills = new Paint[8]; |
|
182 |
|
|
183 |
// UPWARD_DIAGONAL |
|
184 |
bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
|
185 |
big = createG2(cRef, bi); |
|
186 |
big.drawLine(0,0,w,h); |
|
187 |
patternFills[FStyle2D.SYMBOL_STYLE_FILL_UPWARD_DIAGONAL-aux] = |
|
188 |
new TexturePaint(bi,rProv); |
|
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 |
// } |
|
189 | 235 |
|
190 |
// CROSS |
|
191 |
bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
|
192 |
big = createG2(cRef, bi); |
|
193 |
big.drawLine(w/2,0,w/2,h); |
|
194 |
big.drawLine(0,h/2,w,h/2); |
|
195 |
patternFills[FConstant.SYMBOL_STYLE_FILL_CROSS-aux] = |
|
196 |
new TexturePaint(bi,rProv); |
|
197 |
|
|
198 |
// CROSS |
|
199 |
bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
|
200 |
big = createG2(cRef, bi); |
|
201 |
big.drawLine(0,0,w,h); |
|
202 |
big.drawLine(0,h,w,0); |
|
203 |
patternFills[FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL-aux] = |
|
204 |
new TexturePaint(bi,rProv); |
|
205 |
|
|
206 |
|
|
207 |
// VERTICAL |
|
208 |
bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
|
209 |
big = createG2(cRef, bi); |
|
210 |
big.drawLine(w/2,0,w/2,h); |
|
211 |
patternFills[FConstant.SYMBOL_STYLE_FILL_VERTICAL-aux] = |
|
212 |
new TexturePaint(bi,rProv); |
|
213 |
|
|
214 |
// HORIZONTAL |
|
215 |
bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
|
216 |
big = createG2(cRef, bi); |
|
217 |
big.drawLine(0,h/2,w,h/2); |
|
218 |
patternFills[FConstant.SYMBOL_STYLE_FILL_HORIZONTAL-aux] = |
|
219 |
new TexturePaint(bi,rProv); |
|
220 |
|
|
221 |
// DOWNWARD_DIAGONAL m?s ancho |
|
222 |
w=15;h=15; |
|
223 |
rProv.setFrame(0, 0,w,h); |
|
224 |
bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
|
225 |
big = createG2(cRef, bi); |
|
226 |
// big.setColor(Color.BLUE); |
|
227 |
big.drawLine(-1,h,w,-1); |
|
228 |
// big.setColor(Color.RED); |
|
229 |
// big.drawLine(0,0,w,h); |
|
230 |
patternFills[FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL-aux] = |
|
231 |
new TexturePaint(bi,rProv); |
|
232 |
int trans=((TexturePaint)patternFills[FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL-aux]).getTransparency(); |
|
233 |
|
|
234 |
return patternFills; |
|
235 |
} |
|
236 |
|
|
237 | 236 |
} |
Also available in: Unified diff