001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/graphics/sld/PolygonSymbolizer.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2008 by:
006     EXSE, Department of Geography, University of Bonn
007     http://www.giub.uni-bonn.de/deegree/
008     lat/lon GmbH
009     http://www.lat-lon.de
010    
011     This library is free software; you can redistribute it and/or
012     modify it under the terms of the GNU Lesser General Public
013     License as published by the Free Software Foundation; either
014     version 2.1 of the License, or (at your option) any later version.
015    
016     This library is distributed in the hope that it will be useful,
017     but WITHOUT ANY WARRANTY; without even the implied warranty of
018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019     Lesser General Public License for more details.
020    
021     You should have received a copy of the GNU Lesser General Public
022     License along with this library; if not, write to the Free Software
023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
024    
025     Contact:
026    
027     Andreas Poth
028     lat/lon GmbH
029     Aennchenstr. 19
030     53115 Bonn
031     Germany
032     E-Mail: poth@lat-lon.de
033    
034     Prof. Dr. Klaus Greve
035     Department of Geography
036     University of Bonn
037     Meckenheimer Allee 166
038     53115 Bonn
039     Germany
040     E-Mail: greve@giub.uni-bonn.de
041    
042     
043     ---------------------------------------------------------------------------*/
044    package org.deegree.graphics.sld;
045    
046    import org.deegree.framework.xml.Marshallable;
047    
048    /**
049     * Used to render an interior "fill" and an outlining "stroke" for a polygon or other 2D-area
050     * geometry. If a point or line are used, the fill is ignored and the stroke is used as described in
051     * the LineSymbol. A missing Geometry element selects the default geometry. A missing Fill or Stroke
052     * element means that there will be no fill or stroke plotted, respectively. The contained elements
053     * are in the conceptual order of their being used and plotted using the "painters model", where the
054     * Fill will be rendered first, and then the Stroke will be rendered on top of the Fill.
055     * <p>
056     * ----------------------------------------------------------------------
057     * </p>
058     * 
059     * @author <a href="mailto:k.lupp@web.de">Katharina Lupp</a>
060     * @version $Revision: 9340 $ $Date: 2007-12-27 13:32:12 +0100 (Do, 27 Dez 2007) $
061     */
062    
063    public class PolygonSymbolizer extends AbstractSymbolizer implements Marshallable {
064    
065        private Fill fill = null;
066    
067        private Stroke stroke = null;
068    
069        /**
070         * Creates a new PolygonSymbolizer object.
071         */
072        public PolygonSymbolizer() {
073            super( null, "org.deegree.graphics.displayelements.PolygonDisplayElement" );
074            setFill( new Fill() );
075    
076            Stroke stroke = new Stroke();
077            setStroke( stroke );
078        }
079    
080        /**
081         * constructor initializing the class with the <PolygonSymbolizer>
082         */
083        PolygonSymbolizer( Fill fill, Stroke stroke, Geometry geometry, double min, double max ) {
084            super( geometry, "org.deegree.graphics.displayelements.PolygonDisplayElement" );
085            setFill( fill );
086            setStroke( stroke );
087            setMinScaleDenominator( min );
088            setMaxScaleDenominator( max );
089        }
090    
091        /**
092         * constructor initializing the class with the <PolygonSymbolizer>
093         */
094        PolygonSymbolizer( Fill fill, Stroke stroke, Geometry geometry, String responsibleClass, double min, double max ) {
095            super( geometry, responsibleClass );
096            setFill( fill );
097            setStroke( stroke );
098            setMinScaleDenominator( min );
099            setMaxScaleDenominator( max );
100        }
101    
102        /**
103         * A Fill allows area geometries to be filled. There are two types of fills: solid-color and
104         * repeated GraphicFill. In general, if a Fill element is omitted in its containing element, no
105         * fill will be rendered. The default is a solid 50%-gray (color "#808080") opaque fill.
106         * 
107         * @return the fill of the polygon
108         */
109        public Fill getFill() {
110            return fill;
111        }
112    
113        /**
114         * sets the <Fill>
115         * 
116         * @param fill
117         *            the fill of the polygon
118         */
119        public void setFill( Fill fill ) {
120            this.fill = fill;
121        }
122    
123        /**
124         * A Stroke allows a string of line segments (or any linear geometry) to be rendered. There are
125         * three basic types of strokes: solid Color, GraphicFill (stipple), and repeated GraphicStroke.
126         * A repeated graphic is plotted linearly and has its graphic symbol bended around the curves of
127         * the line string. The default is a solid black line (Color "#000000").
128         * 
129         * @return the stroke of the polygon
130         */
131        public Stroke getStroke() {
132            return stroke;
133        }
134    
135        /**
136         * sets the <Stroke>
137         * 
138         * @param stroke
139         *            the stroke of the polygon
140         */
141        public void setStroke( Stroke stroke ) {
142            this.stroke = stroke;
143        }
144    
145        /**
146         * Produces a textual representation of this object.
147         * 
148         * @return the textual representation
149         */
150        public String toString() {
151            StringBuffer sb = new StringBuffer();
152            sb.append( "scale constraint:  >=" + minDenominator + " AND <" + maxDenominator + "\n" );
153            sb.append( "<PolygonSymbolizer>\n" );
154    
155            if ( getGeometry() != null ) {
156                sb.append( getGeometry() ).append( "\n" );
157            }
158    
159            if ( getFill() != null ) {
160                sb.append( getFill() ).append( "\n" );
161            }
162    
163            if ( getStroke() != null ) {
164                sb.append( getStroke() ).append( "\n" );
165            }
166    
167            sb.append( "</PolygonSymbolizer>\n" );
168    
169            return sb.toString();
170        }
171    
172        /**
173         * exports the content of the PolygonSymbolizer as XML formated String
174         * 
175         * @return xml representation of the PolygonSymbolizer
176         */
177        public String exportAsXML() {
178    
179            StringBuffer sb = new StringBuffer( 1000 );
180            sb.append( "<PolygonSymbolizer>" );
181            if ( geometry != null ) {
182                sb.append( ( (Marshallable) geometry ).exportAsXML() );
183            }
184            if ( fill != null ) {
185                sb.append( ( (Marshallable) fill ).exportAsXML() );
186            }
187            if ( stroke != null ) {
188                sb.append( ( (Marshallable) stroke ).exportAsXML() );
189            }
190            sb.append( "</PolygonSymbolizer>" );
191    
192            return sb.toString();
193        }
194    }