001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/graphics/displayelements/PointDisplayElement.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.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 * DisplayElement that encapsulates a point geometry (<tt>GM_Point</tt>) and a 066 * <tt>PointSymbolizer</tt>. 067 * <p> 068 * 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: 9340 $ $Date: 2007-12-27 13:32:12 +0100 (Do, 27 Dez 2007) $ 072 */ 073 class PointDisplayElement extends GeometryDisplayElement implements DisplayElement, Serializable { 074 075 private static ILogger LOG = LoggerFactory.getLogger( PointDisplayElement.class ); 076 077 /** Use serialVersionUID for interoperability. */ 078 private final static long serialVersionUID = -2979559276151855757L; 079 080 private transient static Image defaultImg = new BufferedImage( 7, 7, BufferedImage.TYPE_INT_ARGB ); 081 082 static { 083 Graphics g = defaultImg.getGraphics(); 084 g.setColor( Color.LIGHT_GRAY ); 085 g.fillRect( 0, 0, 9, 9 ); 086 g.dispose(); 087 } 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, PointSymbolizer symbolizer ) { 134 super( feature, geometry, symbolizer ); 135 } 136 137 /** 138 * renders the DisplayElement to the submitted graphic context 139 */ 140 public void paint( Graphics g, GeoTransform projection, double scale ) { 141 synchronized ( symbolizer ) { 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 /** 167 * renders one point to the submitted graphic context considering 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 }