de.erichseifert.gral.plots.legends
Class AbstractLegend
- java.lang.Object
-
- de.erichseifert.gral.graphics.AbstractDrawable
-
- de.erichseifert.gral.graphics.DrawableContainer
-
- de.erichseifert.gral.plots.legends.AbstractLegend
-
- All Implemented Interfaces:
- Container, Drawable, Legend, java.io.Serializable, java.lang.Iterable<Drawable>
- Direct Known Subclasses:
- SeriesLegend, ValueLegend
public abstract class AbstractLegend extends DrawableContainer implements Legend
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.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classAbstractLegend.AbstractSymbolAn abstract base class for drawable symbols.static classAbstractLegend.ItemClass that displays a specific data source as an item of a legend.
-
Constructor Summary
Constructors Constructor and Description AbstractLegend()Initializes a new instance with a default background color, a border, vertical orientation and a gap between the items.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(DataSource source)Adds the specified data source in order to display it.voidclear()Removes all data sources from the legend.booleancontains(DataSource source)Returns whether the specified data source was added to the legend.voiddraw(DrawingContext context)Draws theDrawablewith the specified drawing context.doublegetAlignmentX()Returns the horizontal alignment of the legend relative to the plot area.doublegetAlignmentY()Returns the vertical alignment of the legend relative to the plot area.java.awt.PaintgetBackground()Returns the paint used to draw the background.java.awt.FontgetBaseFont()Returns the current font used as a default for sub-components ans for calculation of relative sizes.java.awt.PaintgetBorderColor()Returns the paint used to fill the border of the legend.java.awt.StrokegetBorderStroke()Returns the stroke used to draw the border of the legend.java.awt.FontgetFont()Returns the font used to display the labels.java.awt.geom.Dimension2DgetGap()Returns the horizontal and vertical gap between items.OrientationgetOrientation()Returns the direction of the legend's items.java.util.Set<DataSource>getSources()Returns all data sources displayed in this legend.java.awt.geom.Dimension2DgetSymbolSize()Returns the size of the legend's symbols.voidremove(DataSource source)Removes the specified data source.voidsetAlignmentX(double alignmentX)Sets the horizontal alignment of the legend relative to the plot area.voidsetAlignmentY(double alignmentY)Sets the vertical alignment of the legend relative to the plot area.voidsetBackground(java.awt.Paint background)Sets the paint used to draw the background.voidsetBaseFont(java.awt.Font baseFont)Sets the new font that will be used as a default for sub-components and for calculation of relative sizes.voidsetBorderColor(java.awt.Paint borderColor)Sets the paint used to fill the border of the legend.voidsetBorderStroke(java.awt.Stroke borderStroke)Sets the stroke used to draw the border of the legend.voidsetBounds(double x, double y, double width, double height)Sets the bounds to the specified coordinates, width and height.voidsetFont(java.awt.Font font)Sets the font used to display the labels.voidsetGap(java.awt.geom.Dimension2D gap)Sets the horizontal and vertical gap between items.voidsetOrientation(Orientation orientation)Sets the direction of the legend's items.voidsetSymbolSize(java.awt.geom.Dimension2D symbolSize)Sets the size of the legend's symbols.-
Methods inherited from class de.erichseifert.gral.graphics.DrawableContainer
add, add, contains, getConstraints, getDrawables, getDrawablesAt, getInsets, getLayout, getPreferredSize, iterator, layout, remove, setBounds, setInsets, setLayout, size
-
Methods inherited from class de.erichseifert.gral.graphics.AbstractDrawable
getBounds, getHeight, getWidth, getX, getY, setPosition
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.erichseifert.gral.graphics.Container
add, add, contains, getBounds, getConstraints, getDrawables, getDrawablesAt, getInsets, getLayout, layout, remove, setBounds, setInsets, setLayout, size
-
Methods inherited from interface de.erichseifert.gral.graphics.Drawable
getBounds, getHeight, getPreferredSize, getWidth, getX, getY, setBounds, setPosition
-
-
-
-
Constructor Detail
-
AbstractLegend
public AbstractLegend()
Initializes a new instance with a default background color, a border, vertical orientation and a gap between the items. The default alignment is set to top-left.
-
-
Method Detail
-
draw
public void draw(DrawingContext context)
Draws theDrawablewith the specified drawing context.- Specified by:
drawin interfaceDrawable- Overrides:
drawin classDrawableContainer- Parameters:
context- Environment used for drawing.
-
add
public void add(DataSource source)
Adds the specified data source in order to display it.
-
contains
public boolean contains(DataSource source)
Returns whether the specified data source was added to the legend.
-
remove
public void remove(DataSource source)
Removes the specified data source.
-
getSources
public java.util.Set<DataSource> getSources()
Returns all data sources displayed in this legend.- Returns:
- Displayed data sources.
-
clear
public void clear()
Removes all data sources from the legend.
-
setBounds
public void setBounds(double x, double y, double width, double height)Description copied from class:AbstractDrawableSets the bounds to the specified coordinates, width and height. This method should be used when overriding functionality.- Specified by:
setBoundsin interfaceDrawable- Overrides:
setBoundsin classDrawableContainer- Parameters:
x- horizontal position of the upper-left cornery- vertical position of the upper-left cornerwidth- horizontal extentheight- vertical extent
-
getBaseFont
public java.awt.Font getBaseFont()
Description copied from interface:LegendReturns the current font used as a default for sub-components ans for calculation of relative sizes.- Specified by:
getBaseFontin interfaceLegend- Returns:
- Current base font.
-
setBaseFont
public void setBaseFont(java.awt.Font baseFont)
Description copied from interface:LegendSets the new font that will be used as a default for sub-components and for calculation of relative sizes. This method is only used internally to propagate the base font and shouldn't be used manually.- Specified by:
setBaseFontin interfaceLegend- Parameters:
baseFont- New base font.
-
getBackground
public java.awt.Paint getBackground()
Description copied from interface:LegendReturns the paint used to draw the background.- Specified by:
getBackgroundin interfaceLegend- Returns:
- Paint used for background drawing.
-
setBackground
public void setBackground(java.awt.Paint background)
Description copied from interface:LegendSets the paint used to draw the background.- Specified by:
setBackgroundin interfaceLegend- Parameters:
background- Paint used for background drawing.
-
getBorderStroke
public java.awt.Stroke getBorderStroke()
Description copied from interface:LegendReturns the stroke used to draw the border of the legend.- Specified by:
getBorderStrokein interfaceLegend- Returns:
- Stroke used for border drawing.
-
setBorderStroke
public void setBorderStroke(java.awt.Stroke borderStroke)
Description copied from interface:LegendSets the stroke used to draw the border of the legend.- Specified by:
setBorderStrokein interfaceLegend- Parameters:
borderStroke- Stroke used for border drawing.
-
getFont
public java.awt.Font getFont()
Description copied from interface:LegendReturns the font used to display the labels.
-
setFont
public void setFont(java.awt.Font font)
Description copied from interface:LegendSets the font used to display the labels.
-
getBorderColor
public java.awt.Paint getBorderColor()
Description copied from interface:LegendReturns the paint used to fill the border of the legend.- Specified by:
getBorderColorin interfaceLegend- Returns:
- Paint used for border drawing.
-
setBorderColor
public void setBorderColor(java.awt.Paint borderColor)
Description copied from interface:LegendSets the paint used to fill the border of the legend.- Specified by:
setBorderColorin interfaceLegend- Parameters:
borderColor- Paint used for border drawing.
-
getOrientation
public Orientation getOrientation()
Description copied from interface:LegendReturns the direction of the legend's items.- Specified by:
getOrientationin interfaceLegend- Returns:
- Item orientation.
-
setOrientation
public void setOrientation(Orientation orientation)
Description copied from interface:LegendSets the direction of the legend's items.- Specified by:
setOrientationin interfaceLegend- Parameters:
orientation- Item orientation.
-
getAlignmentX
public double getAlignmentX()
Description copied from interface:LegendReturns the horizontal alignment of the legend relative to the plot area.0.0means left,0.5means centered, and1.0means right.- Specified by:
getAlignmentXin interfaceLegend- Returns:
- Relative horizontal alignment.
-
setAlignmentX
public void setAlignmentX(double alignmentX)
Description copied from interface:LegendSets the horizontal alignment of the legend relative to the plot area.0.0means left,0.5means centered, and1.0means right.- Specified by:
setAlignmentXin interfaceLegend- Parameters:
alignmentX- Relative horizontal alignment.
-
getAlignmentY
public double getAlignmentY()
Description copied from interface:LegendReturns the vertical alignment of the legend relative to the plot area.0.0means top,0.5means centered, and1.0means bottom.- Specified by:
getAlignmentYin interfaceLegend- Returns:
- Relative vertical alignment.
-
setAlignmentY
public void setAlignmentY(double alignmentY)
Description copied from interface:LegendSets the vertical alignment of the legend relative to the plot area.0.0means top,0.5means centered, and1.0means bottom.- Specified by:
setAlignmentYin interfaceLegend- Parameters:
alignmentY- Relative vertical alignment.
-
getGap
public java.awt.geom.Dimension2D getGap()
Description copied from interface:LegendReturns the horizontal and vertical gap between items.
-
setGap
public void setGap(java.awt.geom.Dimension2D gap)
Description copied from interface:LegendSets the horizontal and vertical gap between items.
-
getSymbolSize
public java.awt.geom.Dimension2D getSymbolSize()
Description copied from interface:LegendReturns the size of the legend's symbols.- Specified by:
getSymbolSizein interfaceLegend- Returns:
- Symbol size relative to the font height.
-
setSymbolSize
public void setSymbolSize(java.awt.geom.Dimension2D symbolSize)
Description copied from interface:LegendSets the size of the legend's symbols.- Specified by:
setSymbolSizein interfaceLegend- Parameters:
symbolSize- Symbol size relative to the font height.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG