root / trunk / libraries / libArcIMS / src / org / gvsig / remoteClient / arcims / styling / symbols / ArcImsFSymbolFactory.java @ 8109
History | View | Annotate | Download (22.3 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL
|
34 |
* Conde Salvatierra de ?lava , 34-10
|
35 |
* 46004 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963 510 612
|
39 |
* +34 963 510 968
|
40 |
* gis@prodevelop.es
|
41 |
* http://www.prodevelop.es
|
42 |
*/
|
43 |
|
44 |
/**
|
45 |
*
|
46 |
*/
|
47 |
package org.gvsig.remoteClient.arcims.styling.symbols; |
48 |
|
49 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
50 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
51 |
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
52 |
|
53 |
import com.iver.utiles.ImageFilter; |
54 |
|
55 |
import org.apache.log4j.Logger; |
56 |
|
57 |
import org.gvsig.remoteClient.arcims.utils.ArcImsDownloadUtils; |
58 |
|
59 |
import java.awt.BasicStroke; |
60 |
import java.awt.Color; |
61 |
import java.awt.Font; |
62 |
import java.awt.Graphics2D; |
63 |
import java.awt.Paint; |
64 |
import java.awt.Rectangle; |
65 |
import java.awt.TexturePaint; |
66 |
import java.awt.geom.Rectangle2D; |
67 |
import java.awt.image.BufferedImage; |
68 |
|
69 |
import java.io.File; |
70 |
import java.io.IOException; |
71 |
|
72 |
import java.net.ConnectException; |
73 |
import java.net.MalformedURLException; |
74 |
import java.net.URI; |
75 |
import java.net.URL; |
76 |
import java.net.UnknownHostException; |
77 |
|
78 |
import java.util.ArrayList; |
79 |
|
80 |
import javax.swing.ImageIcon; |
81 |
|
82 |
|
83 |
/**
|
84 |
* Factory class to produce FSymbol's from ArcIMS Symbol defintions
|
85 |
* @author jsanz
|
86 |
*
|
87 |
*/
|
88 |
public class ArcImsFSymbolFactory { |
89 |
private static Logger logger = Logger.getLogger(ArcImsFSymbolFactory.class.getName()); |
90 |
public static char ds = '.'; |
91 |
private static ArrayList initialColors = new ArrayList(); |
92 |
|
93 |
static {
|
94 |
initialColors.add(new Color(179, 226, 205)); |
95 |
initialColors.add(new Color(253, 205, 172)); |
96 |
initialColors.add(new Color(203, 213, 232)); |
97 |
initialColors.add(new Color(230, 245, 201)); |
98 |
initialColors.add(new Color(141, 211, 199)); |
99 |
initialColors.add(new Color(255, 255, 179)); |
100 |
initialColors.add(new Color(190, 186, 218)); |
101 |
initialColors.add(new Color(251, 128, 114)); |
102 |
initialColors.add(new Color(128, 177, 211)); |
103 |
} |
104 |
|
105 |
//This code is copy&paste from com.iver.cit.gvsig.fmap.core.v02.FSymbolFactory;
|
106 |
static int w; |
107 |
|
108 |
//This code is copy&paste from com.iver.cit.gvsig.fmap.core.v02.FSymbolFactory;
|
109 |
static int h; |
110 |
|
111 |
/**
|
112 |
* Returns a point FSymbol
|
113 |
* @param simb
|
114 |
* @return
|
115 |
*/
|
116 |
protected static FSymbol getFSymbol(SimpleMarkerSymbol simb) { |
117 |
Color mcolor = SymbolUtils.getColor(simb.getColor(), 1); |
118 |
int pointWidth = Integer.parseInt(simb.getWidth()); |
119 |
int pointStyle = getPointType(simb.getType());
|
120 |
|
121 |
FSymbol mSimb = new FSymbol(FConstant.SYMBOL_TYPE_POINT, mcolor);
|
122 |
mSimb.setSizeInPixels(true);
|
123 |
mSimb.setSize(pointWidth); |
124 |
mSimb.setStyle(pointStyle); |
125 |
logger.info("Getting ArcIMS simple point symbol");
|
126 |
|
127 |
return mSimb;
|
128 |
} |
129 |
|
130 |
/**
|
131 |
* Returns a point FSymbol with a remote image
|
132 |
* @param symb
|
133 |
* @return
|
134 |
*/
|
135 |
protected static FSymbol getFSymbol(RasterMarkerSymbol symb) { |
136 |
String surl = symb.getUrl();
|
137 |
|
138 |
// Get the icon size
|
139 |
float size = 0; |
140 |
|
141 |
if (symb.getSize() != null) { |
142 |
String[] tams = symb.getSize().split(","); |
143 |
int ntams = tams.length;
|
144 |
|
145 |
if (ntams != 0) { |
146 |
for (int i = 0; i < ntams; i++) |
147 |
size += Float.parseFloat(tams[i]); // Sums different sizes |
148 |
|
149 |
size = size / ntams; // Get the mean
|
150 |
} |
151 |
} else {
|
152 |
size = 15; // Default size |
153 |
} |
154 |
|
155 |
// Get the icon file
|
156 |
File img = getIconFile(surl);
|
157 |
|
158 |
// If is an image, we build the symbol
|
159 |
ImageFilter filter = new ImageFilter(); |
160 |
|
161 |
if (filter.accept(img)) {
|
162 |
FSymbol mSimb = new FSymbol(FConstant.SYMBOL_TYPE_POINT);
|
163 |
mSimb.setStyle(FStyle2D.SYMBOL_STYLE_MARKER_IMAGEN); |
164 |
|
165 |
URI theUri = img.toURI();
|
166 |
mSimb.setIconURI(theUri); |
167 |
mSimb.setSizeInPixels(true);
|
168 |
mSimb.setSize((int) size);
|
169 |
|
170 |
logger.info("Getting ArcIMS raster marker point symbol");
|
171 |
|
172 |
return mSimb;
|
173 |
} else {
|
174 |
logger.info("Getting random point symbol");
|
175 |
|
176 |
return getDefaultFSymbol(FConstant.SYMBOL_TYPE_POINT);
|
177 |
} |
178 |
} |
179 |
|
180 |
/**
|
181 |
* Returns a line FSymbol
|
182 |
* @param simb
|
183 |
* @return
|
184 |
*/
|
185 |
protected static FSymbol getFSymbol(SimpleLineSymbol simb) { |
186 |
String sTrans = simb.getTransparency();
|
187 |
|
188 |
if (ds != '.') { |
189 |
sTrans = sTrans.replace(ds, '.');
|
190 |
} |
191 |
|
192 |
float trans = Float.parseFloat(sTrans); |
193 |
|
194 |
Color mcolor = SymbolUtils.getColor(simb.getColor(), trans);
|
195 |
int lineWidth = Integer.parseInt(simb.getWidth()); |
196 |
int intCapType = getCapType(simb.getCaptype());
|
197 |
int intJoin = getJoinType(simb.getJointype());
|
198 |
String linePattern = getLinePattern(simb.getType());
|
199 |
|
200 |
BasicStroke bStroke = new BasicStroke(lineWidth, intCapType, intJoin, |
201 |
1.0f, FSymbol.toArray(linePattern, lineWidth), 0); |
202 |
|
203 |
FSymbol theSymbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, mcolor);
|
204 |
theSymbol.setSizeInPixels(true);
|
205 |
theSymbol.setSize(Integer.parseInt(simb.getWidth()));
|
206 |
theSymbol.setSizeInPixels(true);
|
207 |
theSymbol.setStroke(bStroke); |
208 |
|
209 |
logger.info("Getting ArcIMS simple line symbol");
|
210 |
|
211 |
return theSymbol;
|
212 |
} |
213 |
|
214 |
/**
|
215 |
* The hasline symbol seems as a railroad, as gvSIG doesn't supports
|
216 |
* railroad symbols, this method will return a simple line with the
|
217 |
* same color and width
|
218 |
* @param symbol
|
219 |
* @return
|
220 |
*/
|
221 |
protected static FSymbol getFSymbol(HashLineSymbol symbol) { |
222 |
SimpleLineSymbol line = new SimpleLineSymbol();
|
223 |
line.setColor(symbol.getColor()); |
224 |
line.setWidth(symbol.getLinethickness()); |
225 |
line.setType(SymbolUtils.LINE_TYPE_SOLID); |
226 |
|
227 |
logger.info("Getting ArcIMS hashline as a simple line symbol");
|
228 |
|
229 |
return line.getFSymbol();
|
230 |
} |
231 |
|
232 |
/**
|
233 |
* Returns a polygon FSymbol with proper fill
|
234 |
* @param simb
|
235 |
* @return
|
236 |
*/
|
237 |
protected static FSymbol getFSymbol(SimplePolygonSymbol simb) { |
238 |
String sTrans = simb.getFilltransparency();
|
239 |
|
240 |
if (ds != '.') { |
241 |
sTrans = sTrans.replace(ds, '.');
|
242 |
} |
243 |
|
244 |
float trans = Float.parseFloat(sTrans); |
245 |
|
246 |
Color fColor = SymbolUtils.getColor(simb.getFillcolor(), trans);
|
247 |
FSymbol mSimb = new FSymbol(FConstant.SYMBOL_TYPE_FILL, fColor);
|
248 |
|
249 |
//Set the type of fill
|
250 |
int type = getFillStyle(simb.getFilltype());
|
251 |
|
252 |
switch (type) {
|
253 |
case FConstant.SYMBOL_STYLE_FILL_GRAYFILL:
|
254 |
mSimb.setColor(getGray(fColor)); |
255 |
|
256 |
break;
|
257 |
|
258 |
case FConstant.SYMBOL_STYLE_FILL_LIGHTGRAYFILL:
|
259 |
mSimb.setColor(getLightGray(fColor)); |
260 |
|
261 |
break;
|
262 |
|
263 |
case FConstant.SYMBOL_STYLE_FILL_DARKGRAYFILL:
|
264 |
mSimb.setColor(getDarkGray(fColor)); |
265 |
|
266 |
break;
|
267 |
|
268 |
default:
|
269 |
|
270 |
Paint fill = createPatternFill(type, fColor);
|
271 |
mSimb.setFill(fill); |
272 |
} |
273 |
|
274 |
if (simb.isHasBoundary()) {
|
275 |
FSymbol bSimb = simb.getBoundary().getFSymbol(); |
276 |
|
277 |
mSimb.setOutlined(true);
|
278 |
mSimb.setOutlineColor(bSimb.getColor()); |
279 |
mSimb.setStroke(bSimb.getStroke()); |
280 |
|
281 |
int mStyle = getFillStyle(simb.getFilltype());
|
282 |
mSimb.setStyle(mStyle); |
283 |
} |
284 |
|
285 |
logger.info("Getting ArcIMS simple polygon symbol");
|
286 |
|
287 |
return mSimb;
|
288 |
} |
289 |
|
290 |
/**
|
291 |
* A this time, this symbol will be promoted into a genery polygon symbol
|
292 |
* with the intermediate color between start and finish color and an outline
|
293 |
* "darker" color
|
294 |
* @param simb
|
295 |
* @return
|
296 |
*/
|
297 |
protected static FSymbol getFSymbol(GradientFillSymbol simb) { |
298 |
String sTrans = simb.getTransparency();
|
299 |
|
300 |
if (ds != '.') { |
301 |
sTrans = sTrans.replace(ds, '.');
|
302 |
} |
303 |
|
304 |
float trans = Float.parseFloat(sTrans); |
305 |
|
306 |
Color startColor = SymbolUtils.getColor(simb.getStartcolor(), trans);
|
307 |
Color finishColor = SymbolUtils.getColor(simb.getFinishcolor(), trans);
|
308 |
Color avgColor = mixColors(startColor, finishColor);
|
309 |
|
310 |
FSymbol mSimb = new FSymbol(FConstant.SYMBOL_TYPE_FILL, avgColor);
|
311 |
mSimb.setOutlineColor(avgColor.darker()); |
312 |
|
313 |
//Until gvSIG supports gradients, this code is useless
|
314 |
/*
|
315 |
int type = getFillStyle(simb.getType());
|
316 |
|
317 |
Point2D startP2D = null;
|
318 |
Point2D finishP2D = null;
|
319 |
|
320 |
double ratio = 150;
|
321 |
|
322 |
switch (type) {
|
323 |
case FConstant.SYMBOL_STYLE_FILL_UPWARD_DIAGONAL:
|
324 |
startP2D = new Point2D.Double(0.0*ratio,0.0*ratio);
|
325 |
finishP2D = new Point2D.Double(1.0*ratio,1.0*ratio);
|
326 |
break;
|
327 |
case FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL:
|
328 |
startP2D = new Point2D.Double(0.0*ratio,1.0*ratio);
|
329 |
finishP2D = new Point2D.Double(1.0*ratio,0.0*ratio);
|
330 |
break;
|
331 |
case FConstant.SYMBOL_STYLE_FILL_VERTICAL:
|
332 |
startP2D = new Point2D.Double(0.5*ratio,0.0*ratio);
|
333 |
finishP2D = new Point2D.Double(0.5*ratio,1.0*ratio);
|
334 |
break;
|
335 |
case FConstant.SYMBOL_STYLE_FILL_HORIZONTAL:
|
336 |
startP2D = new Point2D.Double(0.0*ratio,0.5*ratio);
|
337 |
finishP2D = new Point2D.Double(1.0*ratio,0.5*ratio);
|
338 |
break;
|
339 |
}
|
340 |
|
341 |
//Set the paint
|
342 |
mSimb.setFill((Paint) new GradientPaint(startP2D,startColor,finishP2D,finishColor));
|
343 |
//Remove the outline
|
344 |
mSimb.setOutlined(false);
|
345 |
*/
|
346 |
logger.info("Getting ArcIMS gradient fill as a simple polygon symbol");
|
347 |
|
348 |
return mSimb;
|
349 |
} |
350 |
|
351 |
protected static FSymbol getFSymbol(RasterFillSymbol simb) { |
352 |
//Get the icon file
|
353 |
String surl = simb.getUrl();
|
354 |
File img = getIconFile(surl);
|
355 |
|
356 |
//Get the transparency
|
357 |
String sTrans = simb.getTransparency();
|
358 |
|
359 |
if (ds != '.') { |
360 |
sTrans = sTrans.replace(ds, '.');
|
361 |
} |
362 |
|
363 |
float trans = Float.parseFloat(sTrans); |
364 |
Color fColor = new Color(1.0f, 1.0f, 1.0f, trans); |
365 |
|
366 |
FSymbol mSimb = new FSymbol(FConstant.SYMBOL_TYPE_FILL, fColor);
|
367 |
|
368 |
// If is an image, we build the paint
|
369 |
ImageFilter filter = new ImageFilter(); |
370 |
|
371 |
if (filter.accept(img)) {
|
372 |
//Creates the BufferedImage object
|
373 |
BufferedImage bi;
|
374 |
ImageIcon icon = new ImageIcon(img.getAbsolutePath()); |
375 |
int w = icon.getIconWidth();
|
376 |
int h = icon.getIconHeight();
|
377 |
bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
378 |
|
379 |
// Draw the image in the BufferedImage object
|
380 |
Graphics2D big = createG2(fColor, bi);
|
381 |
big.drawImage(icon.getImage(), 0, 0, null); |
382 |
|
383 |
Rectangle2D rProv = new Rectangle(); |
384 |
rProv.setFrame(0, 0, w, h); |
385 |
|
386 |
mSimb.setFill(new TexturePaint(bi, rProv)); |
387 |
mSimb.setOutlined(false);
|
388 |
} |
389 |
|
390 |
logger.info("Getting ArcIMS raster fill symbol");
|
391 |
|
392 |
return mSimb;
|
393 |
} |
394 |
|
395 |
/**
|
396 |
* Return a Font Symbol
|
397 |
* @param symbol
|
398 |
* @return
|
399 |
*/
|
400 |
protected static FSymbol getFSymbol(TextSymbol symb) { |
401 |
FSymbol mSimb = new FSymbol(FConstant.SYMBOL_TYPE_POINT);
|
402 |
|
403 |
String font = symb.getFont();
|
404 |
int fontSize = Integer.parseInt(symb.getFontSize()); |
405 |
Color fontColor = SymbolUtils.getColor(symb.getFontColor(), 1); |
406 |
int fontStyle = SymbolUtils.getFontStyle(symb.getFontStyle());
|
407 |
|
408 |
mSimb.setFont(new Font(font, fontStyle, fontSize)); |
409 |
mSimb.setFontColor(fontColor); |
410 |
mSimb.setFontSize(fontSize); |
411 |
|
412 |
logger.info( |
413 |
"Getting ArcIMS TextSymbol as point symbol with Font properties");
|
414 |
|
415 |
return mSimb;
|
416 |
} |
417 |
|
418 |
/**
|
419 |
* @param symbol
|
420 |
* @return
|
421 |
*/
|
422 |
protected static FSymbol getFSymbol(TextMarkerSymbol symbol) { |
423 |
logger.info("Getting ArcIMS TextSymbol as a random point symbol");
|
424 |
|
425 |
return getDefaultFSymbol(FConstant.SYMBOL_TYPE_POINT);
|
426 |
} |
427 |
|
428 |
protected static FSymbol getFSymbol(TrueTypeMarkerSymbol symbol) { |
429 |
logger.info("Getting ArcIMS TextSymbol as a random point symbol");
|
430 |
|
431 |
return getDefaultFSymbol(FConstant.SYMBOL_TYPE_POINT);
|
432 |
} |
433 |
|
434 |
/**
|
435 |
* This method will return a null value as
|
436 |
* this kind of symbol cannot be promoted to other
|
437 |
* supported symbol
|
438 |
* @param symbol
|
439 |
* @return null
|
440 |
*/
|
441 |
protected static FSymbol getFSymbol(ChartSymbol symbol) { |
442 |
return null; |
443 |
} |
444 |
|
445 |
public static FSymbol getDefaultFSymbol(int featType) { |
446 |
FSymbol mSimb = null;
|
447 |
int colorind = (int) (System.currentTimeMillis() % ((long) initialColors.size())); |
448 |
Color randomColor = (Color) initialColors.get(colorind); |
449 |
mSimb = new FSymbol(featType, randomColor);
|
450 |
mSimb.setFont(new Font("Arial", Font.PLAIN, 10)); |
451 |
mSimb.setFontColor(Color.BLACK);
|
452 |
mSimb.setSize(10);
|
453 |
mSimb.setSizeInPixels(true);
|
454 |
|
455 |
return mSimb;
|
456 |
} |
457 |
|
458 |
/*
|
459 |
* Supporting private methods
|
460 |
*/
|
461 |
|
462 |
/**
|
463 |
* Gets the correct constant for a ArcIMS point type
|
464 |
* @param type
|
465 |
* @return
|
466 |
*/
|
467 |
private static int getPointType(String type) { |
468 |
//Default symbol, as gvsig doesn't paints stars
|
469 |
int mtype = FConstant.SYMBOL_STYLE_MARKER_CIRCLE;
|
470 |
|
471 |
if (type.equals(SymbolUtils.POINT_TYPE_CIRCLE)) {
|
472 |
mtype = FConstant.SYMBOL_STYLE_MARKER_CIRCLE; |
473 |
} else if (type.equals(SymbolUtils.POINT_TYPE_CROSS)) { |
474 |
mtype = FConstant.SYMBOL_STYLE_MARKER_CROSS; |
475 |
} else if (type.equals(SymbolUtils.POINT_TYPE_SQUARE)) { |
476 |
mtype = FConstant.SYMBOL_STYLE_MARKER_SQUARE; |
477 |
} else if (type.equals(SymbolUtils.POINT_TYPE_TRIANGLE)) { |
478 |
mtype = FConstant.SYMBOL_STYLE_MARKER_TRIANGLE; |
479 |
} |
480 |
|
481 |
return mtype;
|
482 |
} |
483 |
|
484 |
/**
|
485 |
* Method to translate from ArcIMS type to a string of values that will be parsed
|
486 |
* @return a correct string for the line type definition as "1,3" for dots
|
487 |
*/
|
488 |
private static String getLinePattern(String type) { |
489 |
return (String) SymbolUtils.LINE_TYPES.get(type); |
490 |
} |
491 |
|
492 |
/**
|
493 |
* Translates ArcIMS line end style into BasicStroke line end constants
|
494 |
* @see java.awt.BasicStroke#getEndCap()
|
495 |
* @param captype
|
496 |
* @return
|
497 |
*/
|
498 |
private static int getCapType(String captype) { |
499 |
int resp = BasicStroke.CAP_BUTT; |
500 |
|
501 |
if (captype.equals(SymbolUtils.CAP_TYPE_BUTT)) {
|
502 |
resp = BasicStroke.CAP_BUTT;
|
503 |
} else if (captype.equals(SymbolUtils.CAP_TYPE_ROUND)) { |
504 |
resp = BasicStroke.CAP_ROUND;
|
505 |
} else if (captype.equals(SymbolUtils.CAP_TYPE_SQUARE)) { |
506 |
resp = BasicStroke.CAP_SQUARE;
|
507 |
} |
508 |
|
509 |
return resp;
|
510 |
} |
511 |
|
512 |
/**
|
513 |
* Translate ArcIMS joining line types into BasicStroke join line constants
|
514 |
* @see java.awt.BasicStroke#getLineJoin()
|
515 |
* @param jointype
|
516 |
* @return
|
517 |
*/
|
518 |
private static int getJoinType(String jointype) { |
519 |
int resp = BasicStroke.CAP_BUTT; |
520 |
|
521 |
if (jointype.equals(SymbolUtils.JOIN_TYPE_ROUND)) {
|
522 |
resp = BasicStroke.JOIN_ROUND;
|
523 |
} else if (jointype.equals(SymbolUtils.JOIN_TYPE_MITER)) { |
524 |
resp = BasicStroke.JOIN_MITER;
|
525 |
} else if (jointype.equals(SymbolUtils.JOIN_TYPE_BEVEL)) { |
526 |
resp = BasicStroke.JOIN_BEVEL;
|
527 |
} |
528 |
|
529 |
return resp;
|
530 |
} |
531 |
|
532 |
/**
|
533 |
* Gets a valid FConstant integer to translate an ArcIMS fill style
|
534 |
* @param filltype
|
535 |
* @return
|
536 |
*/
|
537 |
private static int getFillStyle(String filltype) { |
538 |
int style = FConstant.SYMBOL_STYLE_FILL_SOLID;
|
539 |
|
540 |
if (filltype.equals(SymbolUtils.FILL_TYPE_SOLID)) {
|
541 |
style = FConstant.SYMBOL_STYLE_FILL_SOLID; |
542 |
} else if (filltype.equals(SymbolUtils.FILL_TYPE_BDIAG)) { |
543 |
style = FConstant.SYMBOL_STYLE_FILL_UPWARD_DIAGONAL; |
544 |
} else if (filltype.equals(SymbolUtils.FILL_TYPE_FDIAG)) { |
545 |
style = FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL; |
546 |
} else if (filltype.equals(SymbolUtils.FILL_TYPE_CROSS)) { |
547 |
style = FConstant.SYMBOL_STYLE_FILL_CROSS; |
548 |
} else if (filltype.equals(SymbolUtils.FILL_TYPE_DIAGC)) { |
549 |
style = FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL; |
550 |
} else if (filltype.equals(SymbolUtils.FILL_TYPE_HORIZ)) { |
551 |
style = FConstant.SYMBOL_STYLE_FILL_HORIZONTAL; |
552 |
} else if (filltype.equals(SymbolUtils.FILL_TYPE_VERT)) { |
553 |
style = FConstant.SYMBOL_STYLE_FILL_VERTICAL; |
554 |
} else if (filltype.equals(SymbolUtils.FILL_TYPE_GRAYFILL)) { |
555 |
style = FConstant.SYMBOL_STYLE_FILL_GRAYFILL; |
556 |
} else if (filltype.equals(SymbolUtils.FILL_TYPE_LIGHTGRAYFILL)) { |
557 |
style = FConstant.SYMBOL_STYLE_FILL_LIGHTGRAYFILL; |
558 |
} else if (filltype.equals(SymbolUtils.FILL_TYPE_DARKGRAYFILL)) { |
559 |
style = FConstant.SYMBOL_STYLE_FILL_DARKGRAYFILL; |
560 |
} |
561 |
|
562 |
return style;
|
563 |
} |
564 |
|
565 |
/**
|
566 |
* @see com.iver.cit.gvsig.fmap.core.v02.FSymbolFactory
|
567 |
* @param cRef
|
568 |
* @param bi
|
569 |
* @return
|
570 |
*/
|
571 |
static private Graphics2D createG2(Color cRef, BufferedImage bi) { |
572 |
Graphics2D big = bi.createGraphics();
|
573 |
Color color = new Color(0, 0, 0, 0); |
574 |
big.setBackground(color); |
575 |
big.clearRect(0, 0, w, h); |
576 |
big.setColor(new Color(cRef.getRed(), cRef.getGreen(), cRef.getBlue(), |
577 |
cRef.getAlpha())); |
578 |
big.setStroke(new BasicStroke()); |
579 |
|
580 |
return big;
|
581 |
} |
582 |
|
583 |
/**
|
584 |
* @see com.iver.cit.gvsig.fmap.core.v02.FSymbolFactory
|
585 |
* @param style
|
586 |
* @param cRef
|
587 |
* @return
|
588 |
*/
|
589 |
private static Paint createPatternFill(int style, Color cRef) { |
590 |
w = 7;
|
591 |
h = 7;
|
592 |
|
593 |
BufferedImage bi = null; |
594 |
Graphics2D big = null; |
595 |
|
596 |
Rectangle2D rProv = new Rectangle(); |
597 |
rProv.setFrame(0, 0, w, h); |
598 |
|
599 |
Paint resulPatternFill = null; |
600 |
bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
601 |
big = createG2(cRef, bi); |
602 |
|
603 |
switch (style) {
|
604 |
case FConstant.SYMBOL_STYLE_FILL_SOLID:
|
605 |
return null; |
606 |
|
607 |
case FConstant.SYMBOL_STYLE_FILL_TRANSPARENT:
|
608 |
return null; |
609 |
|
610 |
case FConstant.SYMBOL_STYLE_FILL_UPWARD_DIAGONAL:
|
611 |
big.drawLine(0, 0, w, h); |
612 |
|
613 |
break;
|
614 |
|
615 |
case FConstant.SYMBOL_STYLE_FILL_CROSS:
|
616 |
big.drawLine(w / 2, 0, w / 2, h); |
617 |
big.drawLine(0, h / 2, w, h / 2); |
618 |
|
619 |
break;
|
620 |
|
621 |
case FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL:
|
622 |
big.drawLine(0, 0, w, h); |
623 |
big.drawLine(0, h, w, 0); |
624 |
|
625 |
break;
|
626 |
|
627 |
case FConstant.SYMBOL_STYLE_FILL_VERTICAL:
|
628 |
big.drawLine(w / 2, 0, w / 2, h); |
629 |
|
630 |
break;
|
631 |
|
632 |
case FConstant.SYMBOL_STYLE_FILL_HORIZONTAL:
|
633 |
big.drawLine(0, h / 2, w, h / 2); |
634 |
|
635 |
break;
|
636 |
|
637 |
case FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL:
|
638 |
big.drawLine(0, h, w, 0); |
639 |
|
640 |
break;
|
641 |
} |
642 |
|
643 |
resulPatternFill = new TexturePaint(bi, rProv); |
644 |
|
645 |
return resulPatternFill;
|
646 |
} |
647 |
|
648 |
/**
|
649 |
* Gets the hue of a color and returns the color
|
650 |
* with 75% of saturation and 50% of brightness
|
651 |
* @param cRef
|
652 |
* @return
|
653 |
*/
|
654 |
private static Color getGray(Color cRef) { |
655 |
float[] hsbvals = new float[3]; |
656 |
Color.RGBtoHSB(cRef.getRed(), cRef.getGreen(), cRef.getBlue(), hsbvals);
|
657 |
|
658 |
return new Color(Color.HSBtoRGB(hsbvals[0], 0.75f, 0.5f)); |
659 |
} |
660 |
|
661 |
/**
|
662 |
* Gets the hue of a color and returns the color
|
663 |
* with 75% of saturation and 25% of brightness
|
664 |
* @param cRef
|
665 |
* @return
|
666 |
*/
|
667 |
private static Color getLightGray(Color cRef) { |
668 |
float[] hsbvals = new float[3]; |
669 |
Color.RGBtoHSB(cRef.getRed(), cRef.getGreen(), cRef.getBlue(), hsbvals);
|
670 |
|
671 |
return new Color(Color.HSBtoRGB(hsbvals[0], 0.25f, 0.75f)); |
672 |
} |
673 |
|
674 |
/**
|
675 |
* Gets the hue of a color and returns the color
|
676 |
* with 75% of saturation and 75% of brightness
|
677 |
* @param cRef
|
678 |
* @return
|
679 |
*/
|
680 |
private static Color getDarkGray(Color cRef) { |
681 |
float[] hsbvals = new float[3]; |
682 |
Color.RGBtoHSB(cRef.getRed(), cRef.getGreen(), cRef.getBlue(), hsbvals);
|
683 |
|
684 |
return new Color(Color.HSBtoRGB(hsbvals[0], 0.25f, 0.25f)); |
685 |
} |
686 |
|
687 |
/**
|
688 |
* Get the average of two colours
|
689 |
* @param a Color to mix
|
690 |
* @param b Color to mix
|
691 |
* @return (a+b)/2
|
692 |
*/
|
693 |
private static Color mixColors(Color a, Color b) { |
694 |
return new Color((a.getRed() + b.getRed()) / 2, |
695 |
(a.getGreen() + b.getGreen()) / 2, (a.getBlue() + b.getBlue()) / 2); |
696 |
} |
697 |
|
698 |
/**
|
699 |
* Gets from an URL a File with the icon stored in a temporary directory
|
700 |
* @param surl
|
701 |
* @return
|
702 |
*/
|
703 |
private static File getIconFile(String surl) { |
704 |
File img = null; |
705 |
|
706 |
try {
|
707 |
URL url;
|
708 |
url = new URL(surl); |
709 |
|
710 |
String[] partes = surl.split("/"); |
711 |
String realFilename = partes[partes.length - 1]; |
712 |
String[] realsplit = realFilename.split("\\."); |
713 |
|
714 |
String downFileName = realsplit[0] + |
715 |
Long.toString(System.currentTimeMillis()) + "." + realsplit[1]; |
716 |
|
717 |
img = ArcImsDownloadUtils.downloadFile(url, downFileName); |
718 |
} catch (MalformedURLException e) { |
719 |
logger.error(e.getMessage(), e); |
720 |
} catch (ConnectException e) { |
721 |
logger.error(e.getMessage(), e); |
722 |
} catch (UnknownHostException e) { |
723 |
logger.error(e.getMessage(), e); |
724 |
} catch (IOException e) { |
725 |
logger.error(e.getMessage(), e); |
726 |
} |
727 |
|
728 |
return img;
|
729 |
} |
730 |
} |