001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2002, Center for Computational Geography
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation;
010: * version 2.1 of the License.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * Contacts:
018: * UNITED KINGDOM: James Macgill. j.macgill@geog.leeds.ac.uk
019: */
020: package org.geotools.styling;
021:
022: import java.awt.Color;
023: import org.opengis.filter.expression.Expression;
024: import org.geotools.event.GTComponent;
025: import org.geotools.event.GTConstant;
026: import org.geotools.filter.ConstantExpression;
027:
028: /**
029: * The Fill object encapsulates the graphical-symbolization parameters for
030: * areas of geometries.
031: *
032: * <p>
033: * There are two types of fill: solid-color and repeated graphic fill.
034: * </p>
035: *
036: * <p>
037: * The details of this object are taken from the <a
038: * href="https://portal.opengeospatial.org/files/?artifact_id=1188"> OGC
039: * Styled-Layer Descriptor Report (OGC 02-070) version 1.0.0.</a>:
040: * <pre><code>
041: * <xsd:element name="Fill">
042: * <xsd:annotation>
043: * <xsd:documentation>
044: * A "Fill" specifies the pattern for filling an area geometry.
045: * The allowed CssParameters are: "fill" (color) and "fill-opacity".
046: * </xsd:documentation>
047: * </xsd:annotation>
048: * <xsd:complexType>
049: * <xsd:sequence>
050: * <xsd:element ref="sld:GraphicFill" minOccurs="0"/>
051: * <xsd:element ref="sld:CssParameter" minOccurs="0"
052: * maxOccurs="unbounded"/>
053: * </xsd:sequence>
054: * </xsd:complexType>
055: * </xsd:element>
056: * </code></pre>
057: * </p>
058: *
059: * <p>
060: * Renderers can use this information when displaying styled features, though
061: * it must be remembered that not all renderers will be able to fully
062: * represent strokes as set out by this interface. For example, opacity may
063: * not be supported.
064: * </p>
065: *
066: * <p>
067: * Notes:
068: *
069: * <ul>
070: * <li>
071: * The graphical parameters and their values are derived from SVG/CSS2
072: * standards with names and semantics which are as close as possible.
073: * </li>
074: * </ul>
075: * </p>
076: *
077: * @author James Macgill, CCG
078: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/api/src/main/java/org/geotools/styling/Fill.java $
079: * @version $Id: Fill.java 25459 2007-05-08 05:19:25Z jgarnett $
080: */
081: public interface Fill extends GTComponent {
082: static final Fill DEFAULT = new ConstantFill() {
083: final Expression COLOR = ConstantExpression.constant(new Color(
084: 128, 128, 128));
085: final Expression BGCOLOR = ConstantExpression
086: .constant(new Color(255, 255, 255, 0));
087: final Expression OPACITY = ConstantExpression.ONE;
088:
089: public Expression getColor() {
090: return COLOR;
091: }
092:
093: public Expression getBackgroundColor() {
094: return BGCOLOR;
095: }
096:
097: public Expression getOpacity() {
098: return OPACITY;
099: }
100:
101: public Graphic getGraphicFill() {
102: return Graphic.NULL;
103: }
104: };
105:
106: static final Fill NULL = new ConstantFill() {
107: public Expression getColor() {
108: return ConstantExpression.NULL;
109: }
110:
111: public Expression getBackgroundColor() {
112: return ConstantExpression.NULL;
113: }
114:
115: public Expression getOpacity() {
116: return ConstantExpression.NULL;
117: }
118:
119: public Graphic getGraphicFill() {
120: return Graphic.NULL;
121: }
122: };
123:
124: /**
125: * This parameter gives the solid color that will be used for a Fill.<br>
126: * The color value is RGB-encoded using two hexidecimal digits per
127: * primary-color component, in the order Red, Green, Blue, prefixed with
128: * the hash (#) sign. The hexidecimal digits beetween A and F may be in
129: * either upper or lower case. For example, full red is encoded as
130: * "#ff0000" (with no quotation marks). The default color is defined to
131: * be 50% gray ("#808080"). Note: in CSS this parameter is just called
132: * Fill and not Color.
133: *
134: * @return The color of the Fill encoded as a hexidecimal RGB value.
135: */
136: Expression getColor();
137:
138: /**
139: * This parameter gives the solid color that will be used for a Fill.<br>
140: * The color value is RGB-encoded using two hexidecimal digits per
141: * primary-color component, in the order Red, Green, Blue, prefixed with
142: * the hash (#) sign. The hexidecimal digits beetween A and F may be in
143: * either upper or lower case. For example, full red is encoded as
144: * "#ff0000" (with no quotation marks).
145: *
146: * @param color solid color that will be used for a Fill
147: */
148: void setColor(Expression color);
149:
150: /**
151: * This parameter gives the solid color that will be used as a background
152: * for a Fill.<br>
153: * The color value is RGB-encoded using two hexidecimal digits per
154: * primary-color component, in the order Red, Green, Blue, prefixed with
155: * the hash (#) sign. The hexidecimal digits beetween A and F may be in
156: * either upper or lower case. For example, full red is encoded as
157: * "#ff0000" (with no quotation marks). The default color is defined to
158: * be transparent.
159: *
160: * @return The background color of the Fill encoded as a hexidecimal RGB
161: * value.
162: */
163: Expression getBackgroundColor();
164:
165: /**
166: * This parameter gives the solid color that will be used as a background
167: * for a Fill.<br>
168: * The color value is RGB-encoded using two hexidecimal digits per
169: * primary-color component, in the order Red, Green, Blue, prefixed with
170: * the hash (#) sign. The hexidecimal digits beetween A and F may be in
171: * either upper or lower case. For example, full red is encoded as
172: * "#ff0000" (with no quotation marks).
173: *
174: * @param backgroundColor solid color that will be used as a background
175: */
176: void setBackgroundColor(Expression backgroundColor);
177:
178: /**
179: * This specifies the level of translucency to use when rendering the fill. <br>
180: * The value is encoded as a floating-point value between 0.0 and 1.0 with
181: * 0.0 representing totally transparent and 1.0 representing totally
182: * opaque, with a linear scale of translucency for intermediate values.<br>
183: * For example, "0.65" would represent 65% opacity. The default value is
184: * 1.0 (opaque).
185: *
186: * @return The opacity of the fill, where 0.0 is completely transparent and
187: * 1.0 is completely opaque.
188: */
189: Expression getOpacity();
190:
191: /**
192: * This specifies the level of translucency to use when rendering the fill. <br>
193: * The value is encoded as a floating-point value between 0.0 and 1.0 with
194: * 0.0 representing totally transparent and 1.0 representing totally
195: * opaque, with a linear scale of translucency for intermediate values.<br>
196: * For example, "0.65" would represent 65% opacity.
197: *
198: * @param opacity DOCUMENT ME!
199: */
200: void setOpacity(Expression opacity);
201:
202: /**
203: * This parameter indicates that a stipple-fill repeated graphic will be
204: * used and specifies the fill graphic to use.
205: *
206: * @return The graphic to use as a stipple fill. If null then no stipple
207: * fill should be used.
208: */
209: Graphic getGraphicFill();
210:
211: /**
212: * This parameter indicates that a stipple-fill repeated graphic will be
213: * used and specifies the fill graphic to use.
214: *
215: * @param graphicFill DOCUMENT ME!
216: */
217: void setGraphicFill(Graphic graphicFill);
218:
219: void accept(StyleVisitor visitor);
220: }
221:
222: abstract class ConstantFill extends GTConstant implements Fill {
223: private void cannotModifyConstant() {
224: throw new UnsupportedOperationException(
225: "Constant Fill may not be modified");
226: }
227:
228: public void setColor(Expression color) {
229: cannotModifyConstant();
230: }
231:
232: public void setBackgroundColor(Expression backgroundColor) {
233: cannotModifyConstant();
234: }
235:
236: public void setOpacity(Expression opacity) {
237: cannotModifyConstant();
238: }
239:
240: public void setGraphicFill(Graphic graphicFill) {
241: cannotModifyConstant();
242: }
243:
244: public void accept(StyleVisitor visitor) {
245: cannotModifyConstant();
246: }
247: };
|