001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/graphics/sld/RasterSymbolizer.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003     
004     This file is part of deegree.
005     Copyright (C) 2001-2006 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.log.ILogger;
047    import org.deegree.framework.log.LoggerFactory;
048    import org.deegree.model.filterencoding.FilterEvaluationException;
049    
050    /**
051     * <code>RasterSymbolizer</code> encapsulates the Symbology Encoding values that may have been
052     * set. Note that everything is optional, so all values may be null.
053     * 
054     * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
055     * @author last edited by: $Author: aschmitz $
056     * 
057     * @version $Revision: 7824 $, $Date: 2007-07-24 11:02:18 +0200 (Di, 24 Jul 2007) $
058     */
059    public class RasterSymbolizer extends AbstractSymbolizer {
060    
061        private static final ILogger LOG = LoggerFactory.getLogger( RasterSymbolizer.class );
062    
063        private double opacity;
064    
065        private boolean opacitySet;
066    
067        private Categorize categorize;
068    
069        private Interpolate interpolate;
070    
071        private double min;
072    
073        private double max;
074    
075        private boolean scaleSet;
076    
077        /**
078         * Initializes nothing.
079         */
080        public RasterSymbolizer() {
081            // initialize nothing
082        }
083    
084        /**
085         * @param min
086         * @param max
087         */
088        public RasterSymbolizer( double min, double max ) {
089            if ( min > 0 && max > 0 ) {
090                scaleSet = true;
091                this.min = min;
092                this.max = max;
093            }
094        }
095    
096        /**
097         * @param opac
098         */
099        public void setOpacity( ParameterValueType opac ) {
100            try {
101                opacity = Double.parseDouble( opac.evaluate( null ) );
102                opacitySet = true;
103            } catch ( NumberFormatException e ) {
104                LOG.logError( "The opacity value of a RasterSymbolizer could not be parsed.", e );
105            } catch ( FilterEvaluationException e ) {
106                LOG.logError( "The opacity value of a RasterSymbolizer could not be parsed.", e );
107            }
108        }
109    
110        /**
111         * @return the opacity or 1, if none was set
112         */
113        public double getOpacity() {
114            return opacitySet ? opacity : 1;
115        }
116    
117        /**
118         * @param categorize
119         */
120        public void setCategorize( Categorize categorize ) {
121            this.categorize = categorize;
122        }
123    
124        /**
125         * @param interpolate
126         */
127        public void setInterpolate( Interpolate interpolate ) {
128            this.interpolate = interpolate;
129        }
130    
131        /**
132         * @return the categorize
133         */
134        public Categorize getCategorize() {
135            return categorize;
136        }
137    
138        /**
139         * @return the interpolate
140         */
141        public Interpolate getInterpolate() {
142            return interpolate;
143        }
144    
145        /**
146         * @return true, if none of the options has been set (scale is ignored)
147         */
148        public boolean isDefault() {
149            return ( !opacitySet ) && categorize == null && interpolate == null;
150        }
151    
152        /**
153         * @param scale
154         * @return true, if no scale hints have been set or if the given scale is valid
155         */
156        public boolean scaleValid( double scale ) {
157            return ( scaleSet && min <= scale && max >= scale ) || !scaleSet;
158        }
159    
160        @Override
161        public String toString() {
162            return opacity + ", " + categorize + ", " + interpolate;
163        }
164    
165        /**
166         * @return the max
167         */
168        public double getMax() {
169            return max;
170        }
171    
172        /**
173         * @return the min
174         */
175        public double getMin() {
176            return min;
177        }
178    
179    }