001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/graphics/displayelements/GeometryDisplayElement.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.displayelements;
037    
038    import java.io.Serializable;
039    
040    import org.deegree.graphics.sld.Symbolizer;
041    import org.deegree.model.feature.Feature;
042    import org.deegree.model.spatialschema.Envelope;
043    import org.deegree.model.spatialschema.Geometry;
044    import org.deegree.model.spatialschema.Position;
045    
046    /**
047     * Basic interface of all display elements that are related to a geometry (this is the common case).
048     *
049     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
050     * @author last edited by: $Author: mschneider $
051     *
052     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
053     */
054    abstract class GeometryDisplayElement extends AbstractDisplayElement implements Serializable {
055    
056        /** Use serialVersionUID for interoperability. */
057        private final static long serialVersionUID = 465725117946501686L;
058    
059        /**
060         * the geometry
061         */
062        protected Geometry geometry;
063    
064        /**
065         * the symbolizer
066         */
067        protected Symbolizer symbolizer;
068    
069        /**
070         * the highlighted Symbolizer
071         */
072        protected Symbolizer highlightSymbolizer;
073    
074        /**
075         * the selected Symbolizer
076         */
077        protected Symbolizer selectedSymbolizer;
078    
079        /**
080         * The placement?
081         */
082        protected Object placement;
083    
084        /**
085         * Creates a new GeometryDisplayElement object.
086         *
087         * @param feature
088         * @param geometry
089         */
090        GeometryDisplayElement( Feature feature, Geometry geometry ) {
091            super( feature );
092            setGeometry( geometry );
093        }
094    
095        /**
096         * Creates a new GeometryDisplayElement object.
097         *
098         * @param feature
099         * @param geometry
100         * @param symbolizer
101         */
102        GeometryDisplayElement( Feature feature, Geometry geometry, Symbolizer symbolizer ) {
103            super( feature );
104            setGeometry( geometry );
105            setSymbolizer( symbolizer );
106            setHighlightSymbolizer( symbolizer );
107            setSelectedSymbolizer( symbolizer );
108        }
109    
110        /**
111         * Creates a new GeometryDisplayElement object.
112         *
113         * @param feature
114         * @param geometry
115         * @param symbolizer
116         * @param selectedSymbolizer
117         * @param highlightSymbolizer
118         */
119        GeometryDisplayElement( Feature feature, Geometry geometry, Symbolizer symbolizer, Symbolizer highlightSymbolizer,
120                                Symbolizer selectedSymbolizer ) {
121            super( feature );
122            setGeometry( geometry );
123            setSymbolizer( symbolizer );
124            setSelectedSymbolizer( selectedSymbolizer );
125            setHighlightSymbolizer( highlightSymbolizer );
126        }
127    
128        /**
129         * Returns a new {@link Envelope} for the given envelope that has a border of percent * (with |
130         * height) on all sides around it (the longer side is used to determine the border size).
131         *
132         * @param env
133         * @param percent
134         * @return envelope with border around it
135         */
136        protected Envelope growEnvelope( Envelope env, float percent ) {
137            Position minPos = env.getMin();
138            Position maxPos = env.getMax();
139            double h = maxPos.getX() - minPos.getX();
140            double w = maxPos.getY() - minPos.getY();
141            h = Math.abs( h );
142            w = Math.abs( w );
143            double maxSide = Math.max( w, h );
144            return env.getBuffer( maxSide * percent );
145        }
146    
147        /**
148         * Overwrites the default placement of the <tt>DisplayElement</tt>. This method is used by
149         * the <tt>PlacementOptimizer</tt> to minimize the overlapping of labels, for example.
150         * <p>
151         *
152         * @param o
153         *            the placement to be used
154         */
155        public void setPlacement( Object o ) {
156            placement = o;
157        }
158    
159        /**
160         * sets the geometry that determines the position the DisplayElement will be rendered to
161         * @param geometry to set
162         */
163        public void setGeometry( Geometry geometry ) {
164            this.geometry = geometry;
165        }
166    
167        /**
168         * returns the geometry that determines the position the DisplayElement will be rendered to
169         * @return the geometry that determines the position the DisplayElement will be rendered to
170         */
171        public Geometry getGeometry() {
172            return geometry;
173        }
174    
175        /**
176         * sets the rules that determines how the geometry will be rendered
177         * @param symbolizer
178         */
179        public void setSymbolizer( Symbolizer symbolizer ) {
180            this.symbolizer = symbolizer;
181        }
182    
183        /**
184         * Returns the symbolizer that determines how the geometry will be rendered.
185         * @return the symbolizer that determines how the geometry will be rendered.
186         */
187        public Symbolizer getSymbolizer() {
188            return symbolizer;
189        }
190    
191        /**
192         * sets the rule that determines how the geometry will be rendered when it's highlighted
193         *
194         * @param rule
195         *            symbolizer defining rendering style
196         */
197        public void setHighlightSymbolizer( Symbolizer rule ) {
198            this.highlightSymbolizer = rule;
199        }
200    
201        /**
202         * returns the symbolizer that determines how the geometry will be rendered if it's highlighted
203         * @return the symbolizer that determines how the geometry will be rendered if it's highlighted
204         */
205        public Symbolizer getHighlightSymbolizer() {
206            return highlightSymbolizer;
207        }
208    
209        /**
210         * sets the rule that determines how the geometry will be rendered when it's selected
211         *
212         * @param rule
213         *            symbolizer defining rendering style
214         */
215        public void setSelectedSymbolizer( Symbolizer rule ) {
216            selectedSymbolizer = rule;
217        }
218    
219        /**
220         * returns the symbolizer that determines how the geometry will be rendered if it's selected
221         * @return the symbolizer that determines how the geometry will be rendered if it's selected
222         */
223        public Symbolizer getSelectedSymbolizer() {
224            return selectedSymbolizer;
225        }
226    
227        /**
228         * Returns if the <tt>DisplayElement</tt> should be painted at the current scale or not.
229         */
230        @Override
231        public boolean doesScaleConstraintApply( double scale ) {
232            return symbolizer.getMinScaleDenominator() <= scale && symbolizer.getMaxScaleDenominator() > scale;
233        }
234    }