de.erichseifert.gral.plots
Class Label

java.lang.Object
  extended by de.erichseifert.gral.AbstractDrawable
      extended by de.erichseifert.gral.plots.Label
All Implemented Interfaces:
Drawable, SettingsListener, SettingsStorage

public class Label
extends AbstractDrawable
implements SettingsStorage, SettingsListener

Class that draws a label to a specific location. A Label is able to manage its settings and to set and get the displayed text, as well as calculating its bounds.


Field Summary
static Settings.Key ALIGNMENT_X
          Key for specifying the horizontal alignment within the bounding rectangle. 0 means left, 1 means right.
static Settings.Key ALIGNMENT_Y
          Key for specifying the vertical alignment within the bounding rectangle. 0 means top, 1 means bottom.
static Settings.Key ANCHOR
          Key for specifying the DrawableConstants value where the label will be aligned at.
static Settings.Key COLOR
          Key for specifying the Paint instance to be used to paint the label shape.
static Settings.Key FONT
          Key for specifying the font of this label.
static Settings.Key ROTATION
          Key for specifying the rotation of this label,
 
Constructor Summary
Label(String text)
          Creates a new Label object with the specified text.
 
Method Summary
 void draw(DrawingContext context)
          Draws the Drawable with the specified Graphics2D object.
 Dimension2D getPreferredSize()
          Returns the preferred size of the Drawable.
<T> T
getSetting(Settings.Key key)
          Returns the setting with the specified key.
 String getText()
          Returns the text of this label.
 Rectangle2D getTextRectangle()
          Returns the bounding rectangle of the text.
<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 setText(String text)
          Sets the displayed text to the specified value.
 void settingChanged(SettingChangeEvent event)
          Invoked if a setting has changed.
 
Methods inherited from class de.erichseifert.gral.AbstractDrawable
getBounds, getHeight, getWidth, getX, getY, setBounds, setBounds
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALIGNMENT_X

public static final Settings.Key ALIGNMENT_X
Key for specifying the horizontal alignment within the bounding rectangle. 0 means left, 1 means right.


ALIGNMENT_Y

public static final Settings.Key ALIGNMENT_Y
Key for specifying the vertical alignment within the bounding rectangle. 0 means top, 1 means bottom.


ANCHOR

public static final Settings.Key ANCHOR
Key for specifying the DrawableConstants value where the label will be aligned at.


FONT

public static final Settings.Key FONT
Key for specifying the font of this label.


ROTATION

public static final Settings.Key ROTATION
Key for specifying the rotation of this label,


COLOR

public static final Settings.Key COLOR
Key for specifying the Paint instance to be used to paint the label shape.

Constructor Detail

Label

public Label(String text)
Creates a new Label object with the specified text.

Parameters:
text - Text to be displayed.
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
Parameters:
context - Environment used for drawing

getPreferredSize

public Dimension2D getPreferredSize()
Description copied from interface: Drawable
Returns the preferred size of the Drawable.

Specified by:
getPreferredSize in interface Drawable
Overrides:
getPreferredSize in class AbstractDrawable
Returns:
horizontal and vertical extent that wants to be reached

getTextRectangle

public Rectangle2D getTextRectangle()
Returns the bounding rectangle of the text.

Returns:
Bounds.

getText

public String getText()
Returns the text of this label.

Returns:
Text.

setText

public void setText(String text)
Sets the displayed text to the specified value.

Parameters:
text - Text to be displayed.

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.

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.

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.

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.

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.

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.