org.deegree_impl.graphics.legend
Class LegendElement_Impl

java.lang.Object
  extended byorg.deegree_impl.graphics.legend.LegendElement_Impl
All Implemented Interfaces:
LegendElement
Direct Known Subclasses:
LegendElementCollection_Impl

public class LegendElement_Impl
extends java.lang.Object
implements LegendElement

The implements the basic legend element. a legend element may has a label that can be set to eight positions relative to the legend graphic. A LegendElement can be activated or deactivated. It depends on the using application what effect this behavior will have.

LegendElements can be collected in a LegendElementCollection which also is a LegendElement to group elements or to create more complex elements.

Each LegendElement is able to paint itself as BufferedImage

Version:
$Revision: 1.11 $ $Date: 2004/06/01 15:55:05 $
Author:
Andreas Poth

Field Summary
protected  boolean active
           
protected  java.awt.image.BufferedImage bi
           
protected  int bufferBetweenLegendAndLabel
           
protected  int height
           
protected  java.lang.String label
           
protected  int labelPosition
           
protected  double orientation
           
protected  java.util.ArrayList ruleslist
           
protected  int width
           
 
Fields inherited from interface org.deegree.graphics.legend.LegendElement
LP_BOTTOMCENTER, LP_BOTTOMLEFT, LP_BOTTOMRIGHT, LP_LEFT, LP_NOLABEL, LP_RIGHT, LP_TOPCENTER, LP_TOPLEFT, LP_TOPRIGHT
 
Constructor Summary
(package private) LegendElement_Impl()
          empty constructor
(package private) LegendElement_Impl(java.awt.image.BufferedImage legendImage)
           
(package private) LegendElement_Impl(Rule[] rules, java.lang.String label, double orientation, int labelPosition, boolean active, int width, int height)
          constructor
 
Method Summary
 void addRule(Rule rule)
          adds a rule to the ArrayList ruleslist
protected  int[] calculateFontMetrics(java.lang.String label)
          calculates the FontMetrics of the LegendLabel in pixels.
private  java.awt.image.BufferedImage calculateImage(int labelposition, int labelwidth, int ascent, int descent, int legendwidth, int legendheight, int buffer)
          calculates the width and height of the resulting LegendSymbol depending on the LabelPlacement
protected  void drawLineStringLegend(java.awt.Graphics2D g, LineSymbolizer ls, int width, int height)
          draws a legendsymbol, if the SLD defines a line
protected  void drawPointLegend(java.awt.Graphics g, PointSymbolizer c, int width, int height)
          draws a legendsymbol, if the SLD defines a point
protected  void drawPolygonLegend(java.awt.Graphics2D g, PolygonSymbolizer ps, int width, int height)
          draws a legendsymbol, if the SLD defines a polygon
 java.awt.image.BufferedImage exportAsImage()
          exports the LegendElement as BufferedImage
private  java.awt.BasicStroke getBasicStroke(Stroke sldstroke)
          constructs a java.awt.BasicStroke for painting a LineString legend symbol.
 int getBufferBetweenLegendAndLabel()
          returns the buffer place between the legend symbol and the legend label in pixels
 int getHeight()
          gets the height of the LegendSymbol (in pixels)
 java.lang.String getLabel()
          returns the label set to LegendElement.
 double getLabelOrientation()
          returns the current orientation of the label of the LegendElement in radians.
 int getLabelPlacement()
          returns the placement of the label relative to the legend symbol.
 Rule[] getRules()
          gets the Rules as an array
 int getWidth()
          gets the width of the LegendSymbol (in pixels)
 boolean isActive()
          gets the activtion-status of the label
 void setActive(boolean active)
          activates or deactivates the label
 void setBufferBetweenLegendAndLabel(int i)
           
private  java.awt.Graphics2D setColor(java.awt.Graphics2D g2, java.awt.Color color, double opacity)
          sets the color including an opacity
 void setHeight(int height)
          sets the height of the LegendSymbol (in pixels)
 void setLabel(java.lang.String label)
          sets the label of the LegendElement
 void setLabelOrientation(double orientation)
          sets the orientation of the label of the LegendElement.
 void setLabelPlacement(int labelPosition)
          sets the placement of the label relative to the legend symbol.
 void setRules(Rule[] rules)
          sets the rules
 void setWidth(int width)
          sets the width of the LegendSymbol (in pixels)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ruleslist

protected java.util.ArrayList ruleslist

label

protected java.lang.String label

orientation

protected double orientation

labelPosition

protected int labelPosition

active

protected boolean active

width

protected int width

height

protected int height

bufferBetweenLegendAndLabel

protected int bufferBetweenLegendAndLabel

bi

protected java.awt.image.BufferedImage bi
Constructor Detail

LegendElement_Impl

LegendElement_Impl()
empty constructor


LegendElement_Impl

LegendElement_Impl(java.awt.image.BufferedImage legendImage)

LegendElement_Impl

LegendElement_Impl(Rule[] rules,
                   java.lang.String label,
                   double orientation,
                   int labelPosition,
                   boolean active,
                   int width,
                   int height)
constructor

Parameters:
rules - the different rules from the SLD
label - the label beneath the legend symbol
orientation - the rotation of the text in the legend
labelPosition - the position of the text according to the symbol
active - whether the legendsymbol is active or not
width - the requested width of the legend symbol
height - the requested height of the legend symbol
Method Detail

getRules

public Rule[] getRules()
gets the Rules as an array

Returns:
array of sld rules

addRule

public void addRule(Rule rule)
adds a rule to the ArrayList ruleslist

Parameters:
rule - a sld rule

setRules

public void setRules(Rule[] rules)
sets the rules

Parameters:
rules - an array of sld rules

setLabel

public void setLabel(java.lang.String label)
sets the label of the LegendElement

Specified by:
setLabel in interface LegendElement
Parameters:
label - label of the LegendElement

getLabel

public java.lang.String getLabel()
returns the label set to LegendElement. If no label is set, the method returns null

Specified by:
getLabel in interface LegendElement
Returns:
label of the LegendElement or null

setLabelOrientation

public void setLabelOrientation(double orientation)
sets the orientation of the label of the LegendElement. A label can have an orientation from -90° to 90° expressed in radians, where 0° is horizontal

Specified by:
setLabelOrientation in interface LegendElement
Parameters:
orientation -

getLabelOrientation

public double getLabelOrientation()
returns the current orientation of the label of the LegendElement in radians. If the element hasn't a label Double.NEGATIVE_INFINITY will be returned.

Specified by:
getLabelOrientation in interface LegendElement
Returns:
orientation of the label of the LegendElement in radians

setLabelPlacement

public void setLabelPlacement(int labelPosition)
sets the placement of the label relative to the legend symbol. Possible values are:
 +---+---+---+
 | 1 | 0 | 2 |
 +---+---+---+
 | 4 |LEG| 3 |
 +---+---+---+
 | 7 | 5 | 6 |
 +---+---+---+
 
An implementation of the interface may not supoort all positions.

Specified by:
setLabelPlacement in interface LegendElement
Parameters:
labelPosition -

getLabelPlacement

public int getLabelPlacement()
returns the placement of the label relative to the legend symbol. If the element hasn't a label LegendElement.LP_NOLABEL will be returned. Otherwise possible values are:

Specified by:
getLabelPlacement in interface LegendElement
Returns:
coded placement of the label relative to the legend symbol

setActive

public void setActive(boolean active)
activates or deactivates the label

Specified by:
setActive in interface LegendElement
Parameters:
active -

isActive

public boolean isActive()
gets the activtion-status of the label


setWidth

public void setWidth(int width)
sets the width of the LegendSymbol (in pixels)


getWidth

public int getWidth()
gets the width of the LegendSymbol (in pixels)


setHeight

public void setHeight(int height)
sets the height of the LegendSymbol (in pixels)


getHeight

public int getHeight()
gets the height of the LegendSymbol (in pixels)


getBufferBetweenLegendAndLabel

public int getBufferBetweenLegendAndLabel()
returns the buffer place between the legend symbol and the legend label in pixels

Returns:
the buffer as integer in pixels

setBufferBetweenLegendAndLabel

public void setBufferBetweenLegendAndLabel(int i)
Parameters:
i - the buffer as integer in pixels
See Also:
getBufferBetweenLegendAndLabel()

drawPointLegend

protected void drawPointLegend(java.awt.Graphics g,
                               PointSymbolizer c,
                               int width,
                               int height)
                        throws LegendException
draws a legendsymbol, if the SLD defines a point

Parameters:
g - the graphics context
c - the PointSymbolizer representing the drawable point
width - the requested width of the symbol
height - the requested height of the symbol
Throws:
LegendException - is thrown, if the parsing of the sld failes.

drawLineStringLegend

protected void drawLineStringLegend(java.awt.Graphics2D g,
                                    LineSymbolizer ls,
                                    int width,
                                    int height)
                             throws LegendException
draws a legendsymbol, if the SLD defines a line

Parameters:
g - the graphics context
ls - the LineSymbolizer representing the drawable line
width - the requested width of the symbol
height - the requested height of the symbol
Throws:
LegendException - is thrown, if the parsing of the sld failes.

drawPolygonLegend

protected void drawPolygonLegend(java.awt.Graphics2D g,
                                 PolygonSymbolizer ps,
                                 int width,
                                 int height)
                          throws LegendException
draws a legendsymbol, if the SLD defines a polygon

Parameters:
g - the graphics context
ps - the PolygonSymbolizer representing the drawable polygon
width - the requested width of the symbol
height - the requested height of the symbol
Throws:
LegendException - if the parsing of the sld failes.

setColor

private java.awt.Graphics2D setColor(java.awt.Graphics2D g2,
                                     java.awt.Color color,
                                     double opacity)
sets the color including an opacity

Parameters:
g2 - the graphics contect as Graphics2D
color - the requested color of the legend symbol
opacity - the requested opacity of the legend symbol
Returns:
the Graphics2D object containing color and opacity

getBasicStroke

private java.awt.BasicStroke getBasicStroke(Stroke sldstroke)
                                     throws LegendException
constructs a java.awt.BasicStroke for painting a LineString legend symbol.

Parameters:
sldstroke - the deegree sld stroke
Returns:
a java.awt.BasicStroke
Throws:
LegendException - if the sld cannot be processed

calculateFontMetrics

protected int[] calculateFontMetrics(java.lang.String label)
calculates the FontMetrics of the LegendLabel in pixels. It returns an 3-dimensional array containing [0] the width, [1] the ascent and [2] the descent.

Parameters:
label - the label of the LegendElement
Returns:
the 3-dimensional INT-Array contains [0] the width of the string, [1] the ascent and [2] the descent.

calculateImage

private java.awt.image.BufferedImage calculateImage(int labelposition,
                                                    int labelwidth,
                                                    int ascent,
                                                    int descent,
                                                    int legendwidth,
                                                    int legendheight,
                                                    int buffer)
calculates the width and height of the resulting LegendSymbol depending on the LabelPlacement


exportAsImage

public java.awt.image.BufferedImage exportAsImage()
                                           throws LegendException
exports the LegendElement as BufferedImage

Specified by:
exportAsImage in interface LegendElement
Returns:
Throws:
LegendException