001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/graphics/sld/PolygonSymbolizer.java $
002    /*----------------------------------------------------------------------------
003     This file is part of deegree, http://deegree.org/
004     Copyright (C) 2001-2009 by:
005       Department of Geography, University of Bonn
006     and
007       lat/lon GmbH
008    
009     This library is free software; you can redistribute it and/or modify it under
010     the terms of the GNU Lesser General Public License as published by the Free
011     Software Foundation; either version 2.1 of the License, or (at your option)
012     any later version.
013     This library is distributed in the hope that it will be useful, but WITHOUT
014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016     details.
017     You should have received a copy of the GNU Lesser General Public License
018     along with this library; if not, write to the Free Software Foundation, Inc.,
019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020    
021     Contact information:
022    
023     lat/lon GmbH
024     Aennchenstr. 19, 53177 Bonn
025     Germany
026     http://lat-lon.de/
027    
028     Department of Geography, University of Bonn
029     Prof. Dr. Klaus Greve
030     Postfach 1147, 53001 Bonn
031     Germany
032     http://www.geographie.uni-bonn.de/deegree/
033    
034     e-mail: info@deegree.org
035    ----------------------------------------------------------------------------*/
036    package org.deegree.graphics.sld;
037    
038    import org.deegree.framework.xml.Marshallable;
039    
040    /**
041     * Used to render an interior "fill" and an outlining "stroke" for a polygon or other 2D-area geometry. If a point or
042     * line are used, the fill is ignored and the stroke is used as described in the LineSymbol. A missing Geometry element
043     * selects the default geometry. A missing Fill or Stroke element means that there will be no fill or stroke plotted,
044     * respectively. The contained elements are in the conceptual order of their being used and plotted using the
045     * "painters model", where the Fill will be rendered first, and then the Stroke will be rendered on top of the Fill.
046     * <p>
047     * ----------------------------------------------------------------------
048     * </p>
049     *
050     * @author <a href="mailto:k.lupp@web.de">Katharina Lupp</a>
051     * @version $Revision: 18195 $ $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
052     */
053    
054    public class PolygonSymbolizer extends AbstractSymbolizer implements Marshallable {
055    
056        private Fill fill = null;
057    
058        private Stroke stroke = null;
059    
060        /**
061         * Creates a new PolygonSymbolizer object.
062         */
063        public PolygonSymbolizer() {
064            super( null, "org.deegree.graphics.displayelements.PolygonDisplayElement" );
065            setFill( new Fill() );
066    
067            Stroke stroke = new Stroke();
068            setStroke( stroke );
069        }
070    
071        /**
072         * constructor initializing the class with the <PolygonSymbolizer>
073         *
074         * @param fill
075         * @param stroke
076         * @param geometry
077         * @param min
078         * @param max
079         */
080        public PolygonSymbolizer( Fill fill, Stroke stroke, Geometry geometry, double min, double max ) {
081            super( geometry, "org.deegree.graphics.displayelements.PolygonDisplayElement" );
082            setFill( fill );
083            setStroke( stroke );
084            setMinScaleDenominator( min );
085            setMaxScaleDenominator( max );
086        }
087    
088        /**
089         * constructor initializing the class with the <PolygonSymbolizer>
090         *
091         * @param fill
092         * @param stroke
093         * @param geometry
094         * @param responsibleClass
095         * @param min
096         * @param max
097         */
098        PolygonSymbolizer( Fill fill, Stroke stroke, Geometry geometry, String responsibleClass, double min, double max ) {
099            super( geometry, responsibleClass );
100            setFill( fill );
101            setStroke( stroke );
102            setMinScaleDenominator( min );
103            setMaxScaleDenominator( max );
104        }
105    
106        /**
107         * A Fill allows area geometries to be filled. There are two types of fills: solid-color and repeated GraphicFill.
108         * In general, if a Fill element is omitted in its containing element, no fill will be rendered. The default is a
109         * solid 50%-gray (color "#808080") opaque fill.
110         *
111         * @return the fill of the polygon
112         */
113        public Fill getFill() {
114            return fill;
115        }
116    
117        /**
118         * sets the <Fill>
119         *
120         * @param fill
121         *            the fill of the polygon
122         */
123        public void setFill( Fill fill ) {
124            this.fill = fill;
125        }
126    
127        /**
128         * A Stroke allows a string of line segments (or any linear geometry) to be rendered. There are three basic types of
129         * strokes: solid Color, GraphicFill (stipple), and repeated GraphicStroke. A repeated graphic is plotted linearly
130         * and has its graphic symbol bended around the curves of the line string. The default is a solid black line (Color
131         * "#000000").
132         *
133         * @return the stroke of the polygon
134         */
135        public Stroke getStroke() {
136            return stroke;
137        }
138    
139        /**
140         * sets the <Stroke>
141         *
142         * @param stroke
143         *            the stroke of the polygon
144         */
145        public void setStroke( Stroke stroke ) {
146            this.stroke = stroke;
147        }
148    
149        @Override
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    }