public abstract class AbstractLegend extends StylableContainer implements Legend, LegendSymbolRenderer
Abstract class that serves as a base for legends in plots. It stores a list of of items that are used to display a symbol and label for each (visible) data source.
Like other elements legends can be styled using various settings. The settings are used to control to control how the legend, and its items are displayed. The actual rendering of symbols has to be implemented by derived classes.
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractLegend.AbstractSymbol
An abstract base class for drawable symbols.
|
protected static class |
AbstractLegend.Item
Class that displays a specific data source as an item of a legend.
|
ALIGNMENT_X, ALIGNMENT_Y, BACKGROUND, BORDER, COLOR, FONT, GAP, ORIENTATION, SYMBOL_SIZE
Constructor and Description |
---|
AbstractLegend()
Initializes a new instance with a default background color, a border,
vertical orientation and a gap between the items.
|
Modifier and Type | Method and Description |
---|---|
void |
add(DataSource source)
Adds the specified data source in order to display it.
|
void |
clear()
Removes all data sources from the legend.
|
boolean |
contains(DataSource source)
Returns whether the specified data source was added to the legend.
|
void |
draw(DrawingContext context)
Draws the
Drawable with the specified drawing context. |
protected void |
drawBackground(DrawingContext context)
Draws the background of this legend with the specified drawing context.
|
protected void |
drawBorder(DrawingContext context)
Draws the border of this legend with the specified drawing context.
|
protected abstract Iterable<Row> |
getEntries(DataSource source)
Returns a sequence of items for the specified data source that should be
added to the legend.
|
protected abstract String |
getLabel(Row row)
Returns the label text for the specified row.
|
protected void |
invalidate()
Marks this legend's values and layout as invalid.
|
protected boolean |
isValid()
Returns whether this legend's values and layout are valid.
|
void |
refresh()
Updates the items for all data sources stored in this legend.
|
void |
remove(DataSource source)
Removes the specified data source.
|
void |
setBounds(double x,
double y,
double width,
double height)
Sets the bounds to the specified coordinates, width and height.
|
void |
settingChanged(SettingChangeEvent event)
Invoked if a setting has changed.
|
getSetting, removeSetting, removeSettingDefault, setSetting, setSettingDefault
add, add, drawComponents, getConstraints, getDrawableAt, getInsets, getLayout, getPreferredSize, iterator, layout, remove, setBounds, setInsets, setLayout, size
getBounds, getHeight, getWidth, getX, getY
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
add, add, getBounds, getConstraints, getDrawableAt, getInsets, getLayout, layout, remove, setBounds, setInsets, setLayout, size
getBounds, getHeight, getPreferredSize, getWidth, getX, getY, setBounds
getSetting, removeSetting, removeSettingDefault, setSetting, setSettingDefault
getSymbol
public AbstractLegend()
public void draw(DrawingContext context)
Drawable
with the specified drawing context.draw
in interface Drawable
draw
in class DrawableContainer
context
- Environment used for drawing.protected void drawBackground(DrawingContext context)
context
- Environment used for drawing.protected void drawBorder(DrawingContext context)
context
- Environment used for drawing.protected abstract Iterable<Row> getEntries(DataSource source)
source
- Data source.protected abstract String getLabel(Row row)
row
- Data row.public void add(DataSource source)
public boolean contains(DataSource source)
public void remove(DataSource source)
public void clear()
public void refresh()
refresh
in interface Legend
invalidate()
public void settingChanged(SettingChangeEvent event)
settingChanged
in interface SettingsListener
settingChanged
in class StylableContainer
event
- Event containing information about the changed setting.public void setBounds(double x, double y, double width, double height)
AbstractDrawable
setBounds
in interface Drawable
setBounds
in class DrawableContainer
x
- horizontal position of the upper-left cornery
- vertical position of the upper-left cornerwidth
- horizontal extentheight
- vertical extentprotected boolean isValid()
true
if the values and the layout are valid,
otherwise false
.invalidate()
protected void invalidate()
refresh()
Copyright © 2009-2013. All Rights Reserved.