de.erichseifert.gral
Class Legend

java.lang.Object
  extended by de.erichseifert.gral.AbstractDrawable
      extended by de.erichseifert.gral.DrawableContainer
          extended by de.erichseifert.gral.Legend
All Implemented Interfaces:
Container, Drawable, SettingsListener, SettingsStorage, Iterable<Drawable>
Direct Known Subclasses:
XYPlot.XYLegend

public abstract class Legend
extends DrawableContainer
implements SettingsStorage, SettingsListener

Abstract class that serves as a basic for any legend in a plot. It provides an inner Item class which is responsible for displaying a specific DataSource.

The functionality includes:


Field Summary
static Settings.Key BACKGROUND
          Key for specifying the Paint instance to be used to paint the background.
static Settings.Key BORDER
          Key for specifying the Stroke instance to be used to paint the border of the legend.
static Settings.Key COLOR
          Key for specifying the Paint instance to be used to fill the border of the legend.
static Settings.Key GAP
          Key for specifying the gap between items.
static Settings.Key ORIENTATION
          Key for specifying the orientation of the legend using a DrawableConstants.Orientation value.
static Settings.Key SYMBOL_SIZE
          Key for specifying the gap between items.
 
Constructor Summary
Legend()
          Creates a new Legend object with default background color, border, orientation and gap between the Items.
 
Method Summary
 void add(DataSource source)
          Adds the specified DataSource in order to display it.
 boolean contains(DataSource source)
          Returns whether the specified DataSource was added to the legend.
 void draw(DrawingContext context)
          Draws the Drawable with the specified Graphics2D object.
<T> T
getSetting(Settings.Key key)
          Returns the setting with the specified key.
 void remove(DataSource source)
          Removes the specified DataSource.
<T> void
removeSetting(Settings.Key key)
          Removes the setting with the specified key.
<T> void
removeSettingDefault(Settings.Key key)
          Removes the default setting with the specified key.
<T> void
setSetting(Settings.Key key, T value)
          Sets the setting with the specified key to the specified value.
<T> void
setSettingDefault(Settings.Key key, T value)
          Sets a default value for the setting with the specified key.
 void settingChanged(SettingChangeEvent event)
          Invoked if a setting has changed.
 
Methods inherited from class de.erichseifert.gral.DrawableContainer
add, add, getConstraints, getInsets, getLayout, getPreferredSize, iterator, remove, setBounds, setBounds, setInsets, setLayout, size
 
Methods inherited from class de.erichseifert.gral.AbstractDrawable
getBounds, getHeight, getWidth, getX, getY
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.erichseifert.gral.Container
getBounds
 

Field Detail

BACKGROUND

public static final Settings.Key BACKGROUND
Key for specifying the Paint instance to be used to paint the background.


BORDER

public static final Settings.Key BORDER
Key for specifying the Stroke instance to be used to paint the border of the legend.


COLOR

public static final Settings.Key COLOR
Key for specifying the Paint instance to be used to fill the border of the legend.


ORIENTATION

public static final Settings.Key ORIENTATION
Key for specifying the orientation of the legend using a DrawableConstants.Orientation value.


GAP

public static final Settings.Key GAP
Key for specifying the gap between items.


SYMBOL_SIZE

public static final Settings.Key SYMBOL_SIZE
Key for specifying the gap between items.

Constructor Detail

Legend

public Legend()
Creates a new Legend object with default background color, border, orientation and gap between the Items.

Method Detail

draw

public void draw(DrawingContext context)
Description copied from interface: Drawable
Draws the Drawable with the specified Graphics2D object.

Specified by:
draw in interface Drawable
Overrides:
draw in class DrawableContainer
Parameters:
context - Environment used for drawing

add

public void add(DataSource source)
Adds the specified DataSource in order to display it.

Parameters:
source - DataSource to be added.

contains

public boolean contains(DataSource source)
Returns whether the specified DataSource was added to the legend.

Parameters:
source - Data source
Returns:
true if legend contains the data source, otherwise false

remove

public void remove(DataSource source)
Removes the specified DataSource.

Parameters:
source - DataSource to be removed.

getSetting

public <T> T getSetting(Settings.Key key)
Description copied from interface: SettingsStorage
Returns the setting with the specified key. If no setting is available, the default setting will be returned.

Specified by:
getSetting in interface SettingsStorage
Type Parameters:
T - Type of setting.
Parameters:
key - Key.
Returns:
Setting.

removeSetting

public <T> void removeSetting(Settings.Key key)
Description copied from interface: SettingsStorage
Removes the setting with the specified key.

Specified by:
removeSetting in interface SettingsStorage
Type Parameters:
T - Type of setting.
Parameters:
key - Key.

removeSettingDefault

public <T> void removeSettingDefault(Settings.Key key)
Description copied from interface: SettingsStorage
Removes the default setting with the specified key.

Specified by:
removeSettingDefault in interface SettingsStorage
Type Parameters:
T - Type of setting.
Parameters:
key - Key.

setSetting

public <T> void setSetting(Settings.Key key,
                           T value)
Description copied from interface: SettingsStorage
Sets the setting with the specified key to the specified value.

Specified by:
setSetting in interface SettingsStorage
Type Parameters:
T - Type of setting.
Parameters:
key - Key.
value - Value to be set.

setSettingDefault

public <T> void setSettingDefault(Settings.Key key,
                                  T value)
Description copied from interface: SettingsStorage
Sets a default value for the setting with the specified key.

Specified by:
setSettingDefault in interface SettingsStorage
Type Parameters:
T - Type of setting.
Parameters:
key - Key.
value - Value to be set.

settingChanged

public void settingChanged(SettingChangeEvent event)
Description copied from interface: SettingsListener
Invoked if a setting has changed.

Specified by:
settingChanged in interface SettingsListener
Parameters:
event - Event containing information about the changed setting.


Copyright © 2009-2010. All Rights Reserved.