public abstract class AbstractLegend extends DrawableContainer 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.
|
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.
|
double |
getAlignmentX()
Returns the horizontal alignment of the legend relative to the plot area.
|
double |
getAlignmentY()
Returns the vertical alignment of the legend relative to the plot area.
|
java.awt.Paint |
getBackground()
Returns the paint used to draw the background.
|
java.awt.Paint |
getBorderColor()
Returns the paint used to fill the border of the legend.
|
java.awt.Stroke |
getBorderStroke()
Returns the stroke used to draw the border of the legend.
|
protected abstract java.lang.Iterable<Row> |
getEntries(DataSource source)
Returns a sequence of items for the specified data source that should be
added to the legend.
|
java.awt.Font |
getFont()
Returns the font used to display the labels.
|
java.awt.geom.Dimension2D |
getGap()
Returns the horizontal and vertical gap between items.
|
protected abstract java.lang.String |
getLabel(Row row)
Returns the label text for the specified row.
|
Orientation |
getOrientation()
Returns the direction of the legend's items.
|
java.awt.geom.Dimension2D |
getSymbolSize()
Returns the size of the legend's symbols.
|
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.
|
protected void |
refreshLayout()
Refreshes the layout of the legend.
|
void |
remove(DataSource source)
Removes the specified data source.
|
void |
setAlignmentX(double alignmentX)
Sets the horizontal alignment of the legend relative to the plot area.
|
void |
setAlignmentY(double alignmentY)
Sets the vertical alignment of the legend relative to the plot area.
|
void |
setBackground(java.awt.Paint background)
Sets the paint used to draw the background.
|
void |
setBorderColor(java.awt.Paint borderColor)
Sets the paint used to fill the border of the legend.
|
void |
setBorderStroke(java.awt.Stroke borderStroke)
Sets the stroke used to draw the border of the legend.
|
void |
setBounds(double x,
double y,
double width,
double height)
Sets the bounds to the specified coordinates, width and height.
|
protected void |
setDrawableFonts(java.awt.Font font)
Sets the font of the contained drawables.
|
void |
setFont(java.awt.Font font)
Sets the font used to display the labels.
|
void |
setGap(java.awt.geom.Dimension2D gap)
Sets the horizontal and vertical gap between items.
|
void |
setOrientation(Orientation orientation)
Sets the direction of the legend's items.
|
void |
setSymbolSize(java.awt.geom.Dimension2D symbolSize)
Sets the size of the legend's symbols.
|
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
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 java.lang.Iterable<Row> getEntries(DataSource source)
source
- Data source.protected abstract java.lang.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()
protected final void refreshLayout()
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()
protected final void setDrawableFonts(java.awt.Font font)
font
- Font to be set.public java.awt.Paint getBackground()
Legend
getBackground
in interface Legend
public void setBackground(java.awt.Paint background)
Legend
setBackground
in interface Legend
background
- Paint used for background drawing.public java.awt.Stroke getBorderStroke()
Legend
getBorderStroke
in interface Legend
public void setBorderStroke(java.awt.Stroke borderStroke)
Legend
setBorderStroke
in interface Legend
borderStroke
- Stroke used for border drawing.public java.awt.Font getFont()
Legend
public void setFont(java.awt.Font font)
Legend
public java.awt.Paint getBorderColor()
Legend
getBorderColor
in interface Legend
public void setBorderColor(java.awt.Paint borderColor)
Legend
setBorderColor
in interface Legend
borderColor
- Paint used for border drawing.public Orientation getOrientation()
Legend
getOrientation
in interface Legend
public void setOrientation(Orientation orientation)
Legend
setOrientation
in interface Legend
orientation
- Item orientation.public double getAlignmentX()
Legend
0.0
means left, 0.5
means centered, and 1.0
means right.getAlignmentX
in interface Legend
public void setAlignmentX(double alignmentX)
Legend
0.0
means left, 0.5
means centered, and 1.0
means right.setAlignmentX
in interface Legend
alignmentX
- Relative horizontal alignment.public double getAlignmentY()
Legend
0.0
means top, 0.5
means centered, and 1.0
means bottom.getAlignmentY
in interface Legend
public void setAlignmentY(double alignmentY)
Legend
0.0
means top, 0.5
means centered, and 1.0
means bottom.setAlignmentY
in interface Legend
alignmentY
- Relative vertical alignment.public java.awt.geom.Dimension2D getGap()
Legend
public void setGap(java.awt.geom.Dimension2D gap)
Legend
public java.awt.geom.Dimension2D getSymbolSize()
Legend
getSymbolSize
in interface Legend
public void setSymbolSize(java.awt.geom.Dimension2D symbolSize)
Legend
setSymbolSize
in interface Legend
symbolSize
- Symbol size relative to the font height.