deegree 2.3 (2010/04/09 10:10 build-4-official)

org.deegree.graphics.legend
Class LegendElement

java.lang.Object
  extended by org.deegree.graphics.legend.LegendElement
Direct Known Subclasses:
LegendElementCollection

public class LegendElement
extends Object

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: 7363 $ $Date: 2007-05-29 20:47:55 +0200 (Di, 29 Mai 2007) $
Author:
Andreas Poth

Field Summary
protected  boolean active
          A flag signaling if the legend is active initialized with false.
protected  BufferedImage bi
          The icon of the legend
protected  int bufferBetweenLegendAndLabel
          The width in pixels between the legend and it's label initialized with 10;
protected  int height
          The height of the legend element initialized with 0;
protected  String label
          The initial empty label.
protected  int labelPosition
          The label position initialized with -1.
protected  double orientation
          The orientation initialized with 0.
protected  ArrayList<Rule> ruleslist
          the list of rules
protected  int width
          The width of the legend element initialized with 0;
 
Constructor Summary
protected LegendElement()
          empty constructor
(package private) LegendElement(BufferedImage legendImage)
           
(package private) LegendElement(Rule[] rules, 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(String label)
          calculates the FontMetrics of the LegendLabel in pixels.
protected  void drawLineStringLegend(Graphics2D g, LineSymbolizer ls, int width, int height)
          draws a legendsymbol, if the SLD defines a line
protected  void drawPointLegend(Graphics g, PointSymbolizer c, int width, int height)
          draws a legendsymbol, if the SLD defines a point
protected  void drawPolygonLegend(Graphics2D g, PolygonSymbolizer ps, int width, int height)
          draws a legendsymbol, if the SLD defines a polygon
 BufferedImage exportAsImage(String mime)
          exports the LegendElement as BufferedImage
 int getBufferBetweenLegendAndLabel()
          returns the buffer place between the legend symbol and the legend label in pixels
 int getHeight()
           
 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()
           
 boolean isActive()
           
 void setActive(boolean active)
          activates or deactivates the label
 void setBufferBetweenLegendAndLabel(int i)
           
 void setHeight(int height)
          sets the height of the LegendSymbol (in pixels)
 void setLabel(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 ArrayList<Rule> ruleslist
the list of rules


label

protected String label
The initial empty label.


orientation

protected double orientation
The orientation initialized with 0.


labelPosition

protected int labelPosition
The label position initialized with -1.


active

protected boolean active
A flag signaling if the legend is active initialized with false.


width

protected int width
The width of the legend element initialized with 0;


height

protected int height
The height of the legend element initialized with 0;


bufferBetweenLegendAndLabel

protected int bufferBetweenLegendAndLabel
The width in pixels between the legend and it's label initialized with 10;


bi

protected BufferedImage bi
The icon of the legend

Constructor Detail

LegendElement

protected LegendElement()
empty constructor


LegendElement

LegendElement(BufferedImage legendImage)
Parameters:
legendImage - the icon of the legend.

LegendElement

LegendElement(Rule[] rules,
              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(String label)
sets the label of the LegendElement

Parameters:
label - label of the LegendElement

getLabel

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

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

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.

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.

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:

Returns:
coded placement of the label relative to the legend symbol

setActive

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

Parameters:
active -

isActive

public boolean isActive()
Returns:
the activtion-status of the label

setWidth

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

Parameters:
width -

getWidth

public int getWidth()
Returns:
the width of the LegendSymbol (in pixels)

setHeight

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

Parameters:
height -

getHeight

public int getHeight()
Returns:
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(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(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(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.

calculateFontMetrics

protected int[] calculateFontMetrics(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.

exportAsImage

public BufferedImage exportAsImage(String mime)
                            throws LegendException
exports the LegendElement as BufferedImage

Parameters:
mime -
Returns:
the image
Throws:
LegendException

deegree 2.3 (2010/04/09 10:10 build-4-official)

an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://www.deegree.org