001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/graphics/displayelements/PointDisplayElement.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.displayelements;
045
046 import java.awt.Color;
047 import java.awt.Graphics;
048 import java.awt.Graphics2D;
049 import java.awt.Image;
050 import java.awt.image.BufferedImage;
051 import java.io.Serializable;
052
053 import org.deegree.framework.log.ILogger;
054 import org.deegree.framework.log.LoggerFactory;
055 import org.deegree.graphics.sld.PointSymbolizer;
056 import org.deegree.graphics.sld.Symbolizer;
057 import org.deegree.graphics.transformation.GeoTransform;
058 import org.deegree.model.feature.Feature;
059 import org.deegree.model.filterencoding.FilterEvaluationException;
060 import org.deegree.model.spatialschema.MultiPoint;
061 import org.deegree.model.spatialschema.Point;
062 import org.deegree.model.spatialschema.Position;
063
064
065 /**
066 * DisplayElement that encapsulates a point geometry (<tt>GM_Point</tt>)
067 * and a <tt>PointSymbolizer</tt>.
068 * <p>
069 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
070 * @author <a href="mailto:mschneider@lat-lon.de">Markus Schneider</a>
071 * @version $Revision: 6259 $ $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $
072 */
073 class PointDisplayElement extends GeometryDisplayElement implements DisplayElement,
074 Serializable {
075
076 private static ILogger LOG = LoggerFactory.getLogger( PointDisplayElement.class );
077
078 /** Use serialVersionUID for interoperability. */
079 private final static long serialVersionUID = -2979559276151855757L;
080 private transient static Image defaultImg =
081 new BufferedImage( 7, 7, BufferedImage.TYPE_INT_ARGB );
082
083 static {
084 Graphics g = defaultImg.getGraphics();
085 g.setColor( Color.LIGHT_GRAY );
086 g.fillRect( 0, 0, 9, 9 );
087 g.dispose();
088 }
089 /**
090 * Creates a new PointDisplayElement_Impl object.
091 *
092 * @param feature
093 * @param geometry
094 */
095 public PointDisplayElement( Feature feature, Point geometry ) {
096 super( feature, geometry, null );
097
098 Symbolizer defaultSymbolizer = new PointSymbolizer();
099 this.setSymbolizer( defaultSymbolizer );
100 }
101
102 /**
103 * Creates a new PointDisplayElement_Impl object.
104 *
105 * @param feature
106 * @param geometry
107 * @param symbolizer
108 */
109 public PointDisplayElement( Feature feature, Point geometry, PointSymbolizer symbolizer ) {
110 super( feature, geometry, symbolizer );
111 }
112
113 /**
114 * Creates a new PointDisplayElement object.
115 *
116 * @param feature
117 * @param geometry
118 */
119 public PointDisplayElement( Feature feature, MultiPoint geometry ) {
120 super( feature, geometry, null );
121
122 Symbolizer defaultSymbolizer = new PointSymbolizer();
123 this.setSymbolizer( defaultSymbolizer );
124 }
125
126 /**
127 * Creates a new PointDisplayElement object.
128 *
129 * @param feature
130 * @param geometry
131 * @param symbolizer
132 */
133 public PointDisplayElement( Feature feature, MultiPoint geometry,
134 PointSymbolizer symbolizer ) {
135 super( feature, geometry, symbolizer );
136 }
137
138 /**
139 * renders the DisplayElement to the submitted graphic context
140 */
141 public void paint( Graphics g, GeoTransform projection, double scale ) {
142 ((ScaledFeature)feature).setScale(scale);
143 try {
144 Image image = defaultImg;
145
146 if ( ( (PointSymbolizer)symbolizer ).getGraphic() != null ) {
147 image = ( (PointSymbolizer)symbolizer ).getGraphic().getAsImage( feature );
148 }
149 Graphics2D g2D = (Graphics2D)g;
150
151 if ( geometry instanceof Point ) {
152 drawPoint( g2D, (Point)geometry, projection, image );
153 } else {
154 MultiPoint mp = (MultiPoint)geometry;
155
156 for ( int i = 0; i < mp.getSize(); i++ ) {
157 drawPoint( g2D, mp.getPointAt( i ), projection, image );
158 }
159 }
160 } catch ( FilterEvaluationException e ) {
161 LOG.logError( "Exception caught evaluating an Expression!", e );
162 }
163 }
164
165 /**
166 * renders one point to the submitted graphic context considering
167 * the also submitted projection
168 */
169 private void drawPoint( Graphics2D g, Point point, GeoTransform projection, Image image ) {
170 Position source = point.getPosition();
171 int x = (int)( projection.getDestX( source.getX() ) + 0.5 );
172 int y = (int)( projection.getDestY( source.getY() ) + 0.5 );
173
174 int x_ = x - ( image.getWidth( null ) >> 1 );
175 int y_ = y - ( image.getHeight( null ) >> 1 );
176 g.drawImage( image, x_, y_, null );
177 }
178 }/* ********************************************************************
179 Changes to this class. What the people have been up to:
180 $Log$
181 Revision 1.8 2006/11/27 13:07:29 poth
182 unnecessary import removed
183
184 Revision 1.7 2006/11/27 09:07:53 poth
185 JNI integration of proj4 has been removed. The CRS functionality now will be done by native deegree code.
186
187 Revision 1.6 2006/07/12 14:46:16 poth
188 comment footer added
189
190 ********************************************************************** */