001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/graphics/sld/TextSymbolizer.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.sld; 045 046 import org.deegree.framework.xml.Marshallable; 047 048 /** 049 * Used to render a text label, according to the parameters. A missing Geometry, Label, Font, or 050 * LabelPlacement element selects the default value or behavior for the element. The default Label, 051 * Font, and LabelPlacement are system- dependent. Multiple Font elements may be used to specify 052 * alternate fonts in order of preference in case a map server does not support the first 053 * preference. A missing Halo or Fill element means that no halo or fill will be plotted, 054 * respectively. The Fill is rendered over top of the Halo, and the Halo includes the interiors of 055 * the font glyphs. 056 * <p> 057 * 058 * @author <a href="mailto:k.lupp@web.de">Katharina Lupp</a> 059 * @author <a href="mailto:mschneider@lat-lon.de">Markus Schneider</a> 060 * @version $Revision: 9340 $ $Date: 2007-12-27 13:32:12 +0100 (Do, 27 Dez 2007) $ 061 */ 062 063 public class TextSymbolizer extends AbstractSymbolizer implements Marshallable { 064 065 private Fill fill = null; 066 067 private Font font = null; 068 069 private Halo halo = null; 070 071 private LabelPlacement labelPlacement = null; 072 073 private ParameterValueType label = null; 074 075 /** 076 * constructor initializing the class with the <TextSymbolizer> 077 */ 078 TextSymbolizer( Geometry geometry, ParameterValueType label, Font font, LabelPlacement labelPlacement, Halo halo, 079 Fill fill, double min, double max ) { 080 super( geometry, "org.deegree.graphics.displayelements.LabelDisplayElement" ); 081 setLabel( label ); 082 setFont( font ); 083 setLabelPlacement( labelPlacement ); 084 setHalo( halo ); 085 setFill( fill ); 086 setMinScaleDenominator( min ); 087 setMaxScaleDenominator( max ); 088 } 089 090 /** 091 * constructor initializing the class with the <TextSymbolizer> 092 */ 093 TextSymbolizer( Geometry geometry, String responsibleClass, ParameterValueType label, Font font, 094 LabelPlacement labelPlacement, Halo halo, Fill fill, double min, double max ) { 095 super( geometry, responsibleClass ); 096 setLabel( label ); 097 setFont( font ); 098 setLabelPlacement( labelPlacement ); 099 setHalo( halo ); 100 setFill( fill ); 101 setMinScaleDenominator( min ); 102 setMaxScaleDenominator( max ); 103 } 104 105 /** 106 * returns the Label as a <tt>ParameterValueType</tt> to be renderd 107 * 108 * @return the label 109 * 110 */ 111 public ParameterValueType getLabel() { 112 return label; 113 } 114 115 /** 116 * sets the <Label> 117 * 118 * @param label 119 * the label 120 * 121 */ 122 public void setLabel( ParameterValueType label ) { 123 this.label = label; 124 } 125 126 /** 127 * Identifies a Font of a certain family, style, and size. 128 * 129 * @return the font 130 * 131 */ 132 public Font getFont() { 133 return font; 134 } 135 136 /** 137 * Sets a Font of a certain family, style, and size. 138 * 139 * @param font 140 * the font 141 * 142 */ 143 public void setFont( Font font ) { 144 this.font = font; 145 } 146 147 /** 148 * Used to position a label relative to a point or a line string. For a point, you can specify 149 * the anchor point of the label and a linear displacement from the point (so that you can also 150 * plot a graphic symbol at the point). For a line-string placement, you can specify a 151 * perpendicular offset (so you can draw a stroke on the line). 152 * <p> 153 * </p> 154 * MORE PARAMETERS ARE PROBABLY NEEDED HERE. 155 * 156 * @return the labelPlacement 157 * 158 */ 159 public LabelPlacement getLabelPlacement() { 160 return labelPlacement; 161 } 162 163 /** 164 * sets the <LabelPlacement> 165 * 166 * @param labelPlacement 167 * the labelPlacement 168 * 169 */ 170 public void setLabelPlacement( LabelPlacement labelPlacement ) { 171 this.labelPlacement = labelPlacement; 172 } 173 174 /** 175 * A Halo is an extension (sub-type) of a Fill and is applied to the backgrounds of font glyphs. 176 * Either a Radius or a Block halo type can be used. The radius is computed from the outside 177 * edge of the font glyph (or inside of "holes"). The default is a Radius of 1.0 (pixels) but if 178 * no Halo is selected in a containing structure, no halo will be rendered. The default is a 179 * solid white (Color "#FFFFFF") opaque halo. 180 * 181 * @return the halo 182 * 183 */ 184 public Halo getHalo() { 185 return halo; 186 } 187 188 /** 189 * sets <Halo> 190 * 191 * @param halo 192 * the halo 193 * 194 */ 195 public void setHalo( Halo halo ) { 196 this.halo = halo; 197 } 198 199 /** 200 * A Fill allows area geometries to be filled. There are two types of fills: solid-color and 201 * repeated GraphicFill. In general, if a Fill element is omitted in its containing element, no 202 * fill will be rendered. The default is a solid 50%-gray (color "#808080") opaque fill. 203 * 204 * @return the fill 205 * 206 */ 207 public Fill getFill() { 208 return fill; 209 } 210 211 /** 212 * sets the <Fill> 213 * 214 * @param fill 215 * the fill 216 * 217 */ 218 public void setFill( Fill fill ) { 219 this.fill = fill; 220 } 221 222 /** 223 * exports the content of the TextSymbolizer as XML formated String 224 * 225 * @return xml representation of the TextSymbolizer 226 */ 227 public String exportAsXML() { 228 229 StringBuffer sb = new StringBuffer( 1000 ); 230 sb.append( "<TextSymbolizer>" ); 231 if ( geometry != null ) { 232 sb.append( ( (Marshallable) geometry ).exportAsXML() ); 233 } 234 if ( label != null ) { 235 sb.append( "<Label>" ); 236 sb.append( ( (Marshallable) label ).exportAsXML() ); 237 sb.append( "</Label>" ); 238 } 239 if ( font != null ) { 240 sb.append( ( (Marshallable) font ).exportAsXML() ); 241 } 242 if ( labelPlacement != null ) { 243 sb.append( ( (Marshallable) labelPlacement ).exportAsXML() ); 244 } 245 if ( halo != null ) { 246 sb.append( ( (Marshallable) halo ).exportAsXML() ); 247 } 248 if ( fill != null ) { 249 sb.append( ( (Marshallable) fill ).exportAsXML() ); 250 } 251 sb.append( "</TextSymbolizer>" ); 252 253 return sb.toString(); 254 } 255 }