public class IlvLegend extends JComponent
An IlvLegend
object is associated with a unique chart (you
cannot share a legend among several charts). Each time a change occurs
on the chart, the legend is automatically notified and updates itself
accordingly. Usually, items are automatically added to the legend that invokes
the IlvChartRenderer.createLegendItems()
method of each renderer of
the chart. In this case, items are by default instances of
.
IlvRendererLegendItem
You may also wish to add items that are not associated with any renderer
(for example for information purpose or when an annotation has been added to
the chart). In this case, you should create
objects and add them explicitly to the legend.
IlvIconLegendItem
Since legend items inherit from JComponent
, they are added to the legend
using the Container.add()
method and can be retrieved
using the standard AWT Container methods (get()
, getAll()
).
The IlvLegend
class inherits from JComponent
,
it can thus be added to any Container
, in particular to an
IlvChart
instance (Note that this is the only component that can
be added directly to the chart. See IlvChart
for more information.)
When added to a chart, a legend can either be placed around the chart
area or within it, depending on its constraints (see
IlvChartLayout
.) It can also have a dockable
behavior (click on its border and drag it around) if its movable property
is set to true
.
By default, an IlvLegend
uses a custom layout manager (instance
of IlvLegendLayout
) to dynamically lay out the items
depending on the current legend position. You can change this default layout
by using the layout manager of your choice invoking the setLayout()
method.
A legend may also generate an event to all the registered listeners
each time an item is clicked. This behavior is associated with the
interactive
property.
Note: So that the auto-transparency capability of the IlvLegend
class works properly with the Swing RepaintManager, the IlvLegend
class does
not use the opaque
property to know whether it should fill its
background or not. Instead, a new property paintingBackground
(see setPaintingBackground(boolean)
) with the same purpose has been added in
JViews 5.0. The default value is true
, which means that the legend paints its
background by default. Note that this behavior is different from the
IlvChart
behavior that is not filled by default.
Here is a picture showing the different parameters and components of a legend :
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
IlvLegend()
Creates a new
IlvLegend object. |
Modifier and Type | Method and Description |
---|---|
void |
addImageMapAreas(IlvIMapDefinition mapdef,
List<? super IlvIMapArea> areaList)
Generates image map areas for the legend items.
|
void |
addLegendDockingListener(LegendDockingListener l)
Adds a new
LegendDockingListener . |
void |
addLegendItem(IlvLegendItem item)
Adds a new legend item to this legend.
|
void |
addLegendListener(LegendListener l)
Adds a new
LegendListener |
protected void |
baseTextDirectionChanged()
This method is invoked when the effective base text direction has changed.
|
protected void |
chartConnected(IlvChart oldChart,
IlvChart newChart)
Called when the chart referenced by the legend has changed.
|
void |
clear()
Removes all the legend items.
|
protected void |
componentOrientationChanged(ComponentOrientation oldOrientation,
ComponentOrientation newOrientation)
This method is invoked when the component orientation of this legend has
changed.
|
protected Color |
computeBackgroundColor()
Returns the background color to use, depending on the
floating property value. |
protected LayoutManager |
createLegendLayout()
Creates the layout used by the legend.
|
void |
drawIntoHitmap(IlvChartHitmapDefinition definition,
IlvChartHitmapAccumulator accumulator)
Draws the rendering into a hitmap.
|
protected void |
fireLegendDockingEvent(LegendDockingEvent event)
Fires the given event to all the registered listeners.
|
protected void |
fireLegendEvent(LegendEvent event)
Fires the given event to all the registered listeners.
|
int |
getBaseTextDirection()
Returns the base text direction for this legend.
|
IlvChart |
getChart()
Returns the chart whose
this is attached to. |
int |
getFloatingLayoutDirection()
Returns the flow direction of the floating layout.
|
int |
getHorizontalOrientation()
Returns the orientation used by a horizontal layout.
|
Object |
getLock()
Returns an object identifying this legend.
|
String |
getPosition()
Returns the legend position in a chart.
|
Dimension |
getPreferredSize()
Returns the legend preferred size.
|
int |
getResolvedBaseTextDirection()
Returns the resolved base text direction.
|
Dimension |
getSymbolSize()
Returns the size of the items symbols.
|
int |
getSymbolTextSpacing()
Returns the space (in pixels) between
the symbol and the text of an item.
|
String |
getTitle()
Returns the legend title.
|
String |
getToolTipText(MouseEvent event)
Overridden to take into account the base text direction (see
getResolvedBaseTextDirection() ). |
int |
getTransparency()
Returns the alpha value of the background color.
|
int |
getVerticalOrientation()
Returns the orientation used by a vertical layout.
|
boolean |
isAntiAliasing()
Returns the value of the
antiAliasing property. |
boolean |
isAntiAliasingText()
Returns the value of the
antiAliasingText property. |
boolean |
isFloating()
Returns whether the legend is placed using an
absolute layout.
|
boolean |
isFollowChartResize()
Returns whether the legend location is updated on a chart resize event.
|
boolean |
isInteractive()
Returns whether the legend is in interactive mode.
|
boolean |
isMovable()
Returns whether the legend is movable.
|
boolean |
isPaintingBackground()
Returns whether the legend fills it background
with its background color.
|
protected void |
itemClicked(IlvLegendItem item)
Called when a legend item has been clicked.
|
protected boolean |
itemClickMayMoveLegend(IlvLegendItem item)
Called when a mouse button has been pressed on a legend item.
|
protected void |
paintChildren(Graphics g)
Paints the legend items.
|
protected void |
paintComponent(Graphics g)
Paints the legend.
|
void |
removeLegendDockingListener(LegendDockingListener l)
Removes a new
LegendDockingListener . |
void |
removeLegendItem(IlvLegendItem item)
Removes the specified legend item from this legend.
|
void |
removeLegendListener(LegendListener l)
Removes a
LegendListener . |
void |
repaint()
Overridden to do nothing if not executing in the AWT/Swing event thread.
|
void |
revalidate()
Overridden to do nothing if not executing in the AWT/Swing event thread.
|
void |
setAntiAliasing(boolean b)
Sets the
antiAliasing property. |
void |
setAntiAliasingText(boolean b)
Sets the
antiAliasingText property. |
void |
setBackground(Color color)
Sets the background color.
|
void |
setBaseTextDirection(int btd)
Sets the base text direction for this legend.
|
void |
setBounds(int x,
int y,
int width,
int height) |
void |
setComponentOrientation(ComponentOrientation o)
Sets the component orientation of this legend.
|
void |
setDynamicSize(Dimension size)
This method is designed for internal use only.
|
void |
setFloating(boolean floating)
Sets the floating property.
|
void |
setFloatingLayoutDirection(int direction)
Sets the flow direction of the floating layout.
|
void |
setFollowChartResize(boolean followResize)
Sets whether the legend location is updated on a chart resize event.
|
void |
setFont(Font font)
Sets the font of the legend.
|
void |
setForeground(Color color)
Sets the foreground color of the legend.
|
void |
setHorizontalOrientation(int orientation)
Sets the orientation used by a horizontal layout.
|
void |
setInteractive(boolean mode)
Sets the interactive mode property.
|
void |
setLocation(Point p)
Moves the legend to a new location.
|
void |
setMovable(boolean movable)
Sets the legend movable property.
|
void |
setPaintingBackground(boolean paint)
Sets the
paintingBackground property. |
void |
setSymbolSize(Dimension d)
Sets the size of the items symbols.
|
void |
setSymbolTextSpacing(int space)
Sets the space (in pixels) between the
symbol and the text of a legend item.
|
void |
setTitle(String title)
Sets the legend title.
|
void |
setTransparency(int value)
Sets the alpha value of the background color.
|
void |
setVerticalOrientation(int orientation)
Sets the orientation used by a vertical layout.
|
BufferedImage |
toImage(BufferedImage image,
boolean erase)
Paints the legend in a
BufferedImage object. |
BufferedImage |
toImage(Graphics2D graphics,
int width,
int height,
Color bgColor)
Paints the legend in a
BufferedImage object. |
void |
updateUI()
Resets the UI property to a value from the current look and feel.
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, resize, resize, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public IlvLegend()
IlvLegend
object.
By default, a legend is movable and uses a TitledBorder
.public Object getLock()
When used in server side situation, the returned object must be serializable.
protected LayoutManager createLegendLayout()
IlvLegendLayout
.public void updateUI()
updateUI
in class JComponent
public void setComponentOrientation(ComponentOrientation o)
setComponentOrientation
in class Component
protected void componentOrientationChanged(ComponentOrientation oldOrientation, ComponentOrientation newOrientation)
oldOrientation
- The component orientation before the change.newOrientation
- The component orientation after the change.Component.getComponentOrientation()
,
setComponentOrientation(ComponentOrientation)
public final boolean isAntiAliasing()
antiAliasing
property.setAntiAliasing(boolean)
public void setAntiAliasing(boolean b)
antiAliasing
property.
When this property is set
to true
, all drawings in the legend component and subcomponents are
antialiased. This property does not affect text. To toggle the
anti-aliasing of text, use the setAntiAliasingText(boolean)
method.
The default value of this property is false
.isAntiAliasing()
public final boolean isAntiAliasingText()
antiAliasingText
property.setAntiAliasingText(boolean)
public void setAntiAliasingText(boolean b)
antiAliasingText
property.
When this property is set to true
, all text drawings in the legend
component and subcomponents are antialiased.
This property only affects text. To toggle the anti-aliasing of other
drawings, use the setAntiAliasing(boolean)
method.
The default value of this property is false
.setAntiAliasing(boolean)
,
isAntiAliasingText()
public final int getBaseTextDirection()
The base text direction influences the display of text strings that are composed of segments that are read from left to right as well as of segments that are read from right to left. It determines the order of these segments.
IlvBidiUtil.COMPONENT_DIRECTION
,
IlvBidiUtil.CONTEXTUAL_DIRECTION
,
IlvBidiUtil.LEFT_TO_RIGHT
,
IlvBidiUtil.RIGHT_TO_LEFT
,
IlvBidiUtil.INHERITED_DIRECTION
.setBaseTextDirection(int)
,
getResolvedBaseTextDirection()
public void setBaseTextDirection(int btd)
The base text direction influences the display of text strings that are composed of segments that are read from left to right as well as of segments that are read from right to left. It determines the order of these segments.
Possible values are:
IlvBidiUtil.COMPONENT_DIRECTION
,
IlvBidiUtil.CONTEXTUAL_DIRECTION
,
IlvBidiUtil.LEFT_TO_RIGHT
, IlvBidiUtil.RIGHT_TO_LEFT
,
and IlvBidiUtil.INHERITED_DIRECTION
, which in this case is
equivalent to the chart's base text direction.
btd
- The base text direction.getBaseTextDirection()
public int getResolvedBaseTextDirection()
The base text direction influences the display of text strings that are composed of segments that are read from left to right as well as of segments that are read from right to left. It determines the order of these segments.
This method is based on getBaseTextDirection()
but determines
the value when it is inherited from a parent component
(IlvBidiUtil.INHERITED_DIRECTION
) or dependent on
the component orientation (IlvBidiUtil.COMPONENT_DIRECTION
).
IlvBidiUtil.CONTEXTUAL_DIRECTION
,
IlvBidiUtil.LEFT_TO_RIGHT
,
IlvBidiUtil.RIGHT_TO_LEFT
.protected void baseTextDirectionChanged()
getResolvedBaseTextDirection()
has
changed, orgetComponentOrientation()
has changed
and the value of getResolvedBaseTextDirection()
is
IlvBidiUtil.CONTEXTUAL_DIRECTION
.public final int getTransparency()
public void setTransparency(int value)
public void setBackground(Color color)
setBackground
in class JComponent
public void setForeground(Color color)
IlvLegendItem.setForeground(java.awt.Color)
.setForeground
in class JComponent
public void setLocation(Point p)
IlvChartLayout.ABSOLUTE
.setLocation
in class Component
getPosition()
public void setFont(Font font)
IlvLegendItem.setFont(java.awt.Font)
.setFont
in class JComponent
public Dimension getPreferredSize()
getPreferredSize
in class JComponent
public final String getTitle()
public void setTitle(String title)
public final Dimension getSymbolSize()
public void setSymbolSize(Dimension d)
public final int getSymbolTextSpacing()
public void setSymbolTextSpacing(int space)
public final boolean isPaintingBackground()
public final void setPaintingBackground(boolean paint)
paintingBackground
property. If paint
is true
, the legend fills its background before
drawing its items.public final boolean isFloating()
public final void setFloating(boolean floating)
public final boolean isInteractive()
setInteractive(boolean)
public final void setInteractive(boolean mode)
mode
is true
, an event is fired each time the user clicks
on an item.public final boolean isMovable()
setMovable(boolean)
public void setMovable(boolean movable)
movable
is true
, the legend can be moved by dragging it
anywhere within the chart bounds. If false
, the
legend is set unmovable.public final boolean isFollowChartResize()
public void setFollowChartResize(boolean followResize)
true
, the legend position is updated when its
chart is resized so that its position relative to the chart does not change.
When set to false
, the legend position does not change.
The default value is false
.public final int getFloatingLayoutDirection()
IlvLegendLayout
instance.setFloatingLayoutDirection(int)
public void setFloatingLayoutDirection(int direction)
IlvLegendLayout
instance.direction
- The direction of the flow. One of the SwingConstants.HORIZONTAL
or SwingConstants.VERTICAL
constants.getFloatingLayoutDirection()
public final int getHorizontalOrientation()
setHorizontalOrientation(int)
public void setHorizontalOrientation(int orientation)
orientation
- The direction in which the items are layed out.
One of the constants
SwingConstants.TRAILING
(meaning the usual writing direction)
and SwingConstants.LEADING
(meaning the opposite direction).getHorizontalOrientation()
public final int getVerticalOrientation()
setVerticalOrientation(int)
public void setVerticalOrientation(int orientation)
orientation
- The direction in which the items are layed out.
One of the constants
SwingConstants.BOTTOM
(meaning down from top to bottom)
and SwingConstants.TOP
(meaning up from bottom to top).getVerticalOrientation()
protected void chartConnected(IlvChart oldChart, IlvChart newChart)
oldChart
- The previous associated chart. May be null
if no chart has been attached before.newChart
- The new associated chart. May be null
if
no new chart has been attached.IlvChart.setLegend(ilog.views.chart.IlvLegend)
public final IlvChart getChart()
this
is attached to.public final void setDynamicSize(Dimension size)
public void addLegendItem(IlvLegendItem item)
item
- The legend item to add.public void removeLegendItem(IlvLegendItem item)
item
- The legend item to remove.public void clear()
protected Color computeBackgroundColor()
floating
property value. By default, the
color used to paint the background is the one returned
by getBackground()
if floating
is false
or if the legend parent is not the
chart. In other cases, the color returned matches the
background color RGB values plus an alpha value.protected void paintComponent(Graphics g)
paintComponent
in class JComponent
protected void paintChildren(Graphics g)
Graphics
is first
initialized according to the anti-aliasing attributes and clip
to the legend bounds.paintChildren
in class JComponent
setAntiAliasing(boolean)
,
setAntiAliasingText(boolean)
public BufferedImage toImage(Graphics2D graphics, int width, int height, Color bgColor)
BufferedImage
object.
The operation is performed in the caller thread.graphics
- A Graphics2D
to write in. If null
,
an image is created.width
- The width of the image. Must be > 0.height
- The height of the image. Must be > 0.bgColor
- The background color of the image.public BufferedImage toImage(BufferedImage image, boolean erase)
BufferedImage
object.
The operation is performed in the AWT-Event thread.image
- The destination image. If null
, a new image is created.erase
- Indicates whether the specified image should be erased. This
parameter is only taken into account if the image is not null
.public void addLegendListener(LegendListener l)
LegendListener
l
- The listener.LegendListener
public void removeLegendListener(LegendListener l)
LegendListener
.l
- The listener.LegendListener
protected void itemClicked(IlvLegendItem item)
LegendEvent
event to all the registered
listeners calling their itemClicked
method.
If you override this method, you should also override the
itemClickMayMoveLegend(IlvLegendItem)
method.
item
- The clicked item.protected final void fireLegendEvent(LegendEvent event)
protected boolean itemClickMayMoveLegend(IlvLegendItem item)
itemClicked(ilog.views.chart.IlvLegendItem)
method and the interactor that allows the user to
move the legend. It should be implemented consistently with the
itemClicked(IlvLegendItem)
method.item
- The item on which the mouse button has been pressed.false
if the interaction shall be processed by the
itemClicked(IlvLegendItem)
method. true
if
it may be the start of an interaction that moves the legend.public void addLegendDockingListener(LegendDockingListener l)
LegendDockingListener
.l
- The listener.LegendDockingListener
public void removeLegendDockingListener(LegendDockingListener l)
LegendDockingListener
.l
- The listener.LegendListener
protected final void fireLegendDockingEvent(LegendDockingEvent event)
public String getPosition()
IlvChartLayout
constraint,
or null
if the legend has not been added to an
IlvChart
.IlvChartLayout
public void addImageMapAreas(IlvIMapDefinition mapdef, List<? super IlvIMapArea> areaList)
mapdef
- The map definition.areaList
- The list of map areas. The method must add instances of
IlvIMapArea
to this list.public void drawIntoHitmap(IlvChartHitmapDefinition definition, IlvChartHitmapAccumulator accumulator)
definition
- The specification how to construct the hitmap.accumulator
- The object that accumulates objects in the hitmap.IlvChartHitmapDefinition.drawIntoHitmap(IlvLegend, IlvChartHitmapAccumulator)
public void revalidate()
revalidate
in class JComponent
public void repaint()
public String getToolTipText(MouseEvent event)
getResolvedBaseTextDirection()
).getToolTipText
in class JComponent
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.