lt.monarch.chart.legend
Class Legend

java.lang.Object
  extended by lt.monarch.chart.AbstractView<LegendPaintTags>
      extended by lt.monarch.chart.engine.AbstractLegend
          extended by lt.monarch.chart.legend.Legend
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, StyleEditorEntity, View, ExpandableDecoration

public class Legend
extends AbstractLegend

Legend view. Maintains a list of legend entries and renders a legend.

Here is an example of legend, when the labels are centered into the box:

Here is an example of legend, when the labels are below boxes:

Here is an example of legend when the labels are in several columns:

You can set background color ant border paint style using PaintStyle object. Text properties can be set using TextStyle object.

See Also:
Serialized Form

Nested Class Summary
Modifier and Type Class and Description
static class Legend.RangeRepresentation
          Inner range representation class used for representing ranges, such as: 1..6 or 1-6 or [1-6]
 
Nested classes/interfaces inherited from class lt.monarch.chart.engine.AbstractLegend
AbstractLegend.LegendEntryEntity
 
Field Summary
Modifier and Type Field and Description
protected  lt.monarch.chart.legend.Legend.MouseEvents mouseEvents
          Mouse event listener
 
Fields inherited from class lt.monarch.chart.engine.AbstractLegend
actualSize, currentSelection, cursorChanged, dimension, drawBounds, entries, horizontalLabelAlignment, labelSorting, lastPt, layout, margin, mouseClick, moveCursor, orientation, scrollRange, style, tempCursor, textPainter, textStyle, verticalLabelAlignment, wordWrappingEnabled
 
Fields inherited from class lt.monarch.chart.AbstractView
layoutInvalid, paintStyle
 
Constructor Summary
Constructor and Description
Legend()
          Creates an empty legend object
Legend(Chart chart)
          Creates a legend object and initializes it with data from the chart object
Legend(LegendEntry[] entries)
          Creates a legend object and initializes it with the entry list
 
Method Summary
Modifier and Type Method and Description
protected  void activate()
          Activates the legend.
 void addEntries(LegendEntry[] ll)
          Adds a list of entries the the legend at once.
 void addEntries(LegendEntry[] ll, boolean skipDuplicates)
          Adds a list of entries the the legend at once.
 void addEntry(LegendEntry entry)
          Adds a new entry to the legend.
 void addEntry(LegendEntry entry, boolean skipDuplicates)
          Adds a new entry to the legend.
 void addEntry(java.lang.String text, LegendSymbol symbol)
          Constructs and adds a new entry to the legend.
 void addSeparator()
          Adds a separator to the legend.
 void addSeparator(java.lang.String label)
          Adds a separator to the legend.
protected  void deactivate()
          Deactivates the legend.
protected  java.awt.Dimension[] getEntryDimensions(AbstractGraphics g)
          Computes and returns dimensions of legend entries.
 int getMaxColumns()
          Returns number of columns allowed in the legend layout.
protected  int getMaxKeyWidth(AbstractGraphics g)
          Returns the width of the widest legend symbol.
 java.awt.Dimension getPreferredSize(AbstractGraphics g)
          Gets the preferred size of this legend.
 Legend.RangeRepresentation getRangeRepresentation()
          Gets range representation for the labels
protected  void layout(AbstractGraphics g)
          Layouts the legend.
protected  void paint(AbstractGraphics g)
          Paints the legend in the specified Graphics context.
 void setMaxColumns(int maxColumns)
          Sets number of columns allowed in the legend.
 
Methods inherited from class lt.monarch.chart.engine.AbstractLegend
dispose, getContainingObjects, getEntries, getEntry, getLabelHAlignment, getLabelSorting, getLabelVAlignment, getLayout, getOrientation, getStyle, getTextStyle, getWordWrappingEnabled, initCursor, isHorizontallyExpandable, isVerticallyExpandable, readObject, removeAllEntries, removeEntry, setCurrentSelection, setHorizontalAlignment, setLabelAlignment, setLabelSorting, setLayout, setOrientation, setPreferredSize, setPreferredSize, setVerticalAlignment, setWordWrappingEnabled, sortLabels
 
Methods inherited from class lt.monarch.chart.AbstractView
addViewListener, clone, container, finalize, getAlignmentX, getAlignmentY, getBounds, getChartObjectBounds, getContainer, getGraphicsType, getHeight, getMaximumSize, getMinimumSize, getPaintMode, getPaintStyle, getParent, getSize, getSize, getStyle, getWidth, getX, getY, invalidate, isLayoutValid, removeViewListener, render, repaint, repaint, setAlignmentX, setAlignmentY, setBounds, setBounds, setContainer, setLocation, setMaximumSize, setMinimumSize, setPaintMode, setSize, validate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mouseEvents

protected lt.monarch.chart.legend.Legend.MouseEvents mouseEvents
Mouse event listener

Constructor Detail

Legend

public Legend()
Creates an empty legend object


Legend

public Legend(Chart chart)
Creates a legend object and initializes it with data from the chart object

Parameters:
chart - chart object to be used

Legend

public Legend(LegendEntry[] entries)
Creates a legend object and initializes it with the entry list

Parameters:
entries - legend entries
Method Detail

setMaxColumns

public void setMaxColumns(int maxColumns)
Sets number of columns allowed in the legend. Default is 1. Setting column number to more than 1 allows to wrap the legend if there is more available horizontal space than required by a single column.

Parameters:
maxColumns - maximum allowed columns

getMaxColumns

public int getMaxColumns()
Returns number of columns allowed in the legend layout.

Returns:
maximum allowed columns

addEntry

public void addEntry(LegendEntry entry)
Description copied from class: AbstractLegend
Adds a new entry to the legend.

Specified by:
addEntry in class AbstractLegend
Parameters:
entry - new legend entry

addEntry

public void addEntry(java.lang.String text,
                     LegendSymbol symbol)
Description copied from class: AbstractLegend
Constructs and adds a new entry to the legend.

Specified by:
addEntry in class AbstractLegend
Parameters:
text - legend entry label
symbol - legend entry symbol

addEntries

public void addEntries(LegendEntry[] ll)
Description copied from class: AbstractLegend
Adds a list of entries the the legend at once.

Specified by:
addEntries in class AbstractLegend
Parameters:
ll - array of legend entries

addEntry

public void addEntry(LegendEntry entry,
                     boolean skipDuplicates)
Adds a new entry to the legend.

Parameters:
entry - new legend entry
skipDuplicates - true if duplicated entries must be skipped, false otherwise.

addEntries

public void addEntries(LegendEntry[] ll,
                       boolean skipDuplicates)
Adds a list of entries the the legend at once.

Parameters:
ll - array of legend entries
skipDuplicates - true if duplicated entries must be skipped, false otherwise.

addSeparator

public void addSeparator()
Description copied from class: AbstractLegend
Adds a separator to the legend.

Specified by:
addSeparator in class AbstractLegend

addSeparator

public void addSeparator(java.lang.String label)
Description copied from class: AbstractLegend
Adds a separator to the legend.

Specified by:
addSeparator in class AbstractLegend
Parameters:
label - Separator label

getMaxKeyWidth

protected int getMaxKeyWidth(AbstractGraphics g)
Returns the width of the widest legend symbol.

Parameters:
g - the Graphics context in which legend will be painted
Returns:
the width of the widest legend entry

getEntryDimensions

protected java.awt.Dimension[] getEntryDimensions(AbstractGraphics g)
Computes and returns dimensions of legend entries.

Parameters:
g - the Graphics context in which legend will be painted
Returns:
an array of Dimension objects, representing dimensions of the legend entries

getPreferredSize

public java.awt.Dimension getPreferredSize(AbstractGraphics g)
Description copied from class: AbstractLegend
Gets the preferred size of this legend.

Specified by:
getPreferredSize in interface View
Specified by:
getPreferredSize in class AbstractLegend
Parameters:
g - the Graphics context in which legend will be painted
Returns:
A dimension object indicating this legend's preferred size.

layout

protected void layout(AbstractGraphics g)
Layouts the legend.

Overrides:
layout in class AbstractView<LegendPaintTags>
Parameters:
g - the Graphics context in which legend will be painted

paint

protected void paint(AbstractGraphics g)
Paints the legend in the specified Graphics context.

Specified by:
paint in class AbstractView<LegendPaintTags>
Parameters:
g - the Graphics context in which to paint legend

activate

protected void activate()
Activates the legend.

Overrides:
activate in class AbstractView<LegendPaintTags>

deactivate

protected void deactivate()
Deactivates the legend.

Overrides:
deactivate in class AbstractView<LegendPaintTags>

getRangeRepresentation

public Legend.RangeRepresentation getRangeRepresentation()
Gets range representation for the labels

Returns:
the range representation for the labels object. This is used when each entry contain two values.