01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.renderer.style;
17:
18: import java.awt.AlphaComposite;
19: import java.awt.Color;
20: import java.awt.Composite;
21: import java.awt.Paint;
22:
23: import org.geotools.feature.Feature;
24: import org.geotools.styling.Fill;
25: import org.geotools.styling.PolygonSymbolizer;
26:
27: /**
28: * A dynamic polygon style, that will compute its parameters each time they are requested instead
29: * of caching them
30: *
31: * @author jamesm
32: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/render/src/main/java/org/geotools/renderer/style/DynamicPolygonStyle2D.java $
33: */
34: public class DynamicPolygonStyle2D extends
35: org.geotools.renderer.style.PolygonStyle2D {
36: Feature feature;
37: PolygonSymbolizer ps;
38:
39: /**
40: * Creates a new instance of DynamicPolygonStyle2D
41: */
42: public DynamicPolygonStyle2D(Feature f, PolygonSymbolizer sym) {
43: feature = f;
44: ps = sym;
45: }
46:
47: /**
48: * Computes and returns the fill based on the feature and the symbolizer
49: */
50: public java.awt.Paint getFill() {
51: Fill fill = ps.getFill();
52:
53: if (fill == null) {
54: return null;
55: }
56:
57: Paint fillPaint = (Color) fill.getColor().evaluate(feature,
58: Color.class);
59:
60: // if a graphic fill is to be used, prepare the paint accordingly....
61: org.geotools.styling.Graphic gr = fill.getGraphicFill();
62:
63: if (gr != null) {
64: SLDStyleFactory fac = new SLDStyleFactory();
65: fillPaint = fac.getTexturePaint(gr, feature);
66: }
67:
68: return fillPaint;
69: }
70:
71: /**
72: * Computes and returns the fill composite based on the feature and the symbolizer
73: */
74: public Composite getFillComposite() {
75: Fill fill = ps.getFill();
76:
77: if (fill == null) {
78: return null;
79: }
80:
81: // get the opacity and prepare the composite
82: float opacity = ((Float) fill.getOpacity().evaluate(feature,
83: Float.class)).floatValue();
84:
85: if (opacity == 1) {
86: return null;
87: }
88:
89: return AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
90: opacity);
91: }
92: }
|