JClass 4.5.0 API
Documentation

com.klg.jclass.util.legend
Class JCLegend

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--com.klg.jclass.util.legend.JCLegend
Direct Known Subclasses:
JCGridLegend

public abstract class JCLegend
extends JComponent
implements com.klg.jclass.util.Changeable, Serializable

JCLegend manages and renders a legend for a component. It is an abstract class that require a subclass to provide a specific layout. It requires a JCLegendPopulator instance to populate it with legend items and a JCLegendRenderer instance to help in rendering the items. Each legend item is represented by a JCLegendItem instance.

See Also:
JCGridLegend, JCMultiColLegend, JCLegendPopulator, JCLegendRenderer, JCLegendItem, Serialized Form

Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Field Summary
protected  int anchor
           
protected  int ascent
           
static int BOX
           
protected  Font cachedFont
           
protected  boolean cachedVertical
           
protected  CellRendererPane cellRendererPane
          CellRendererPane object used in rendering HTML text.
protected  boolean changed
          Boolean representing the value of the Changed property.
protected  int changedFlag
           
static int CUSTOM_ALL
           
static int CUSTOM_SYMBOL
           
protected  int descent
           
static int EAST
           
static int EASTWEST_MASK
           
static int HORIZONTAL
           
static int IMAGE
           
static int IMAGE_OUTLINED
           
protected  List legendItems
           
protected  JCLegendPopulator legendPopulator
          JCLegendPopulator instance used to populate the legend
protected  JCLegendRenderer legendRenderer
          JCLegendRenderer instance used to help draw the legend
static int NONE
           
static int NORTH
           
static int NORTHEAST
           
static int NORTHSOUTH_MASK
           
static int NORTHWEST
           
protected  int orientation
           
protected  Dimension preferredSize
          The preferred size of the legend.
protected  Dimension ps
           
static int SOUTH
           
static int SOUTHEAST
           
static int SOUTHWEST
           
protected  int symbolSize
           
protected static com.klg.jclass.util.swing.TextRenderer textRend
           
protected  boolean updateParent
          Used to turn off updates to the parent in certain cases.
static int VERTICAL
           
static int WEST
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface com.klg.jclass.util.Changeable
BASIC_CHANGE_MASK, LAYOUT, NO_CHANGE, NOTIFY_PARENT_LAYOUT, RECALC, REDRAW
 
Constructor Summary
JCLegend()
          Internal constructor for legend
 
Method Summary
 void drawLegendItem(Graphics gc, Font useFont, JCLegendItem thisItem)
          Draws one legend item based on the size and position given in it's JCLegendItem instance.
 int getAnchor()
          Gets the Anchor property, which determines the position of the legend relative to the parent components primary draw area.
 CellRendererPane getCellRendererPane()
          Gets the cell renderer pane used by this component.
 boolean getChanged()
          Gets the value of the Changed property.
 boolean getChanged(int mask)
          Checks the value of the ChangedFlag property for the specified mask (see Changeable for a list of valid masks).
 Rectangle getDrawingArea()
          Gets the bounding rectangle of the component's drawing area, (its area minus the shadows and insets).
 void getDrawingArea(Rectangle rect)
          Gets the bounding rectangle of the component's drawing area, (its area minus the insets).
 Graphics getGraphics()
          Override parent getGraphics().
 JCLegendPopulator getLegendPopulator()
          Gets the JCLegendPopulator instance used to populate this legend.
 JCLegendRenderer getLegendRenderer()
          Gets the legend renderer class which is used to help draw the legend.
 int getOrientation()
          Gets the Orientation property, which determines how the legend information is laid out.
 Dimension getPreferredSize()
          Calculates and returns the preferred size for the legend or the manually set preferred size if it has been manually set.
 int getSymbolSize()
          Gets the default symbol size being used for legend item.
 com.klg.jclass.util.swing.TextRenderer getTextRenderer()
          Gets the TextRenderer class used to draw HTML text.
 boolean isBatched()
          This method is not used by this implementation of Changeable, so it always returns false.
 boolean isChanged()
          Gets the value of the Changed property.
 boolean isChanged(int mask)
          Checks the value of the ChangedFlag property for the specified mask (see Changeable for a list of valid masks).
 boolean isTitleItem(JCLegendItem item)
          Defers the decision on whether an item is a title item or not to the populator class.
abstract  Dimension layoutLegend(List itemList, boolean vertical, Font useFont)
          To be overridden by a legend implementation.
 void paintComponent(Graphics gc)
          Paint method for the legend.
 JCLegendItem pick(Point p)
          Internal pick method.
 void recalc()
          Recalculates extents of the legend.
 void setAnchor(int a)
          Sets the Anchor property, which determines the position of the legend relative to the parent components primary draw area.
 void setChanged(boolean c, int cf)
          Sets the value of the Changed property and updates the parent object.
 void setChanged(boolean n, int cf, boolean updateParent)
          Sets the value of the Changed property.
 void setGraphics(Graphics g)
          Provides a way for the legend to draw to a custom Graphics object.
 void setLegendPopulator(JCLegendPopulator legPop)
          Sets the legend populator class which will populate the legend.
 void setLegendRenderer(JCLegendRenderer legRend)
          Sets the legend renderer class which will help draw the legend.
 void setOrientation(int orient)
          Sets the Orientation property, which determines how the legend information is laid out.
 void setPreferredSize(Dimension dim)
          Sets the preferred size manually.
 void updateParent(int cf)
           
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setCursor, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

anchor

protected int anchor

orientation

protected int orientation

NORTH

public static final int NORTH

SOUTH

public static final int SOUTH

EAST

public static final int EAST

WEST

public static final int WEST

NORTHEAST

public static final int NORTHEAST

NORTHWEST

public static final int NORTHWEST

SOUTHEAST

public static final int SOUTHEAST

SOUTHWEST

public static final int SOUTHWEST

NORTHSOUTH_MASK

public static final int NORTHSOUTH_MASK

EASTWEST_MASK

public static final int EASTWEST_MASK

HORIZONTAL

public static final int HORIZONTAL

VERTICAL

public static final int VERTICAL

NONE

public static final int NONE

BOX

public static final int BOX

IMAGE

public static final int IMAGE

IMAGE_OUTLINED

public static final int IMAGE_OUTLINED

CUSTOM_SYMBOL

public static final int CUSTOM_SYMBOL

CUSTOM_ALL

public static final int CUSTOM_ALL

textRend

protected static com.klg.jclass.util.swing.TextRenderer textRend

legendItems

protected List legendItems

ps

protected Dimension ps

symbolSize

protected int symbolSize

ascent

protected int ascent

descent

protected int descent

cachedVertical

protected boolean cachedVertical

cachedFont

protected transient Font cachedFont

updateParent

protected boolean updateParent
Used to turn off updates to the parent in certain cases.

changed

protected boolean changed
Boolean representing the value of the Changed property.

changedFlag

protected int changedFlag

preferredSize

protected Dimension preferredSize
The preferred size of the legend.

cellRendererPane

protected CellRendererPane cellRendererPane
CellRendererPane object used in rendering HTML text.

legendPopulator

protected JCLegendPopulator legendPopulator
JCLegendPopulator instance used to populate the legend

legendRenderer

protected JCLegendRenderer legendRenderer
JCLegendRenderer instance used to help draw the legend
Constructor Detail

JCLegend

public JCLegend()
Internal constructor for legend
Method Detail

setLegendPopulator

public void setLegendPopulator(JCLegendPopulator legPop)
Sets the legend populator class which will populate the legend.
Parameters:
legPop - the JCLegendPopulator instance used to populate this legend.

getLegendPopulator

public JCLegendPopulator getLegendPopulator()
Gets the JCLegendPopulator instance used to populate this legend.
Returns:
the JCLegendPopulator instance used to populate this legend.

setLegendRenderer

public void setLegendRenderer(JCLegendRenderer legRend)
Sets the legend renderer class which will help draw the legend.
Parameters:
legRend - the JCLegendRenderer instance used to help draw this legend.

getLegendRenderer

public JCLegendRenderer getLegendRenderer()
Gets the legend renderer class which is used to help draw the legend.
Returns:
the JCLegendRenderer instance used to help draw this legend.

getAnchor

public int getAnchor()
Gets the Anchor property, which determines the position of the legend relative to the parent components primary draw area.
Returns:
one of NORTH, SOUTH, EAST, WEST, NORTHWEST, SOUTHWEST, NORTHEAST, or SOUTHEAST

getOrientation

public int getOrientation()
Gets the Orientation property, which determines how the legend information is laid out.
Returns:
one of VERTICAL or HORIZONTAL

setAnchor

public void setAnchor(int a)
Sets the Anchor property, which determines the position of the legend relative to the parent components primary draw area.
Parameters:
a -  

setOrientation

public void setOrientation(int orient)
Sets the Orientation property, which determines how the legend information is laid out.
Parameters:
orient - one of VERTICAL or HORIZONTAL

getSymbolSize

public int getSymbolSize()
Gets the default symbol size being used for legend item. The default value is the ascent of the font (set in recalc()). It is overridable by users who want to provide a different symbolSize.
Returns:
the default symbol size.

recalc

public void recalc()
Recalculates extents of the legend.

layoutLegend

public abstract Dimension layoutLegend(List itemList,
                                       boolean vertical,
                                       Font useFont)
To be overridden by a legend implementation. This method is used to layout the items within the legend by filling in the dim, pos, textPos, and symPos members of each JCLegendItem insance, returning the size of the layed out legend.
Parameters:
itemList - the legend vector. It contains a vector for each group (data view). Each group vector contains a number of JCLegendItem instances, each reflecting one item within the legend group. The first JCLegendItem within each group is the title of the group.
vertical - true for vertical legend, false for horizontal legend.
useFont - font used for legend.
Returns:
the size of the legend.
Since:
JClass 4.0K for Java 2. If you are using JClass 4.0J, which is based on JDK 1.1, this method's parameter must be a com.sun.java.util.collections.List.

paintComponent

public void paintComponent(Graphics gc)
Paint method for the legend.
Overrides:
paintComponent in class JComponent
Parameters:
gc - graphics context to use for drawing

drawLegendItem

public void drawLegendItem(Graphics gc,
                           Font useFont,
                           JCLegendItem thisItem)
Draws one legend item based on the size and position given in it's JCLegendItem instance. The symbol to be drawn is derived from the legend item's draw type. A user that wants to provide different drawing behaviour should use either the CUSTOM_SYMBOL or CUSTOM_ALL draw types.
Parameters:
gc - the graphics context
useFont - the font used for this legend.
thisItem - the legend item to draw. A JCLegendItem instance.

isTitleItem

public boolean isTitleItem(JCLegendItem item)
Defers the decision on whether an item is a title item or not to the populator class. It knows best.
Parameters:
item - the JCLegendItem in question
Returns:
true if the item is a title in the legend, false otherwise.

getPreferredSize

public Dimension getPreferredSize()
Calculates and returns the preferred size for the legend or the manually set preferred size if it has been manually set.
Overrides:
getPreferredSize in class JComponent
Returns:
preferred size.

setPreferredSize

public void setPreferredSize(Dimension dim)
Sets the preferred size manually.
Overrides:
setPreferredSize in class JComponent
Parameters:
dim - the preferred size

getTextRenderer

public com.klg.jclass.util.swing.TextRenderer getTextRenderer()
Gets the TextRenderer class used to draw HTML text.

pick

public JCLegendItem pick(Point p)
Internal pick method. Chooses the legend item closest to the provided position.
Parameters:
p - pick point relative to legend
Returns:
the JCLegendItem instance representing the picked point.

getDrawingArea

public Rectangle getDrawingArea()
Gets the bounding rectangle of the component's drawing area, (its area minus the shadows and insets).
See Also:
JComponent.setBorder(javax.swing.border.Border)

getDrawingArea

public void getDrawingArea(Rectangle rect)
Gets the bounding rectangle of the component's drawing area, (its area minus the insets).
Parameters:
rect -  
See Also:
JComponent.setBorder(javax.swing.border.Border)

getCellRendererPane

public CellRendererPane getCellRendererPane()
Gets the cell renderer pane used by this component. Used to render HTML encoded text with a JLabel.

getGraphics

public Graphics getGraphics()
Override parent getGraphics(). If another Graphics object has been set to be the current one, return that. Otherwise, call the superclass' getGraphics() method.
Overrides:
getGraphics in class JComponent
Returns:
the Graphics object to use to draw this legend.

setGraphics

public void setGraphics(Graphics g)
Provides a way for the legend to draw to a custom Graphics object. Call with a null to specify use of the default Graphics object used to draw to the screen.
Parameters:
g - Graphics object to use for drawing.

getChanged

public boolean getChanged()
Gets the value of the Changed property. The Changed property determines whether the object needs to be recalculated.
Specified by:
getChanged in interface com.klg.jclass.util.Changeable
Returns:
True if the object has been changed and needs recalculation, false otherwise.

getChanged

public boolean getChanged(int mask)
Checks the value of the ChangedFlag property for the specified mask (see Changeable for a list of valid masks). The ChangedFlag property determines the action the object needs to take in regards to the current change.
Specified by:
getChanged in interface com.klg.jclass.util.Changeable
Parameters:
mask -  
Returns:
True if the specified mask exists in the ChangedFlag property, false otherwise.

isChanged

public final boolean isChanged()
Gets the value of the Changed property. The Changed property determines whether the object needs to be recalculated.
Specified by:
isChanged in interface com.klg.jclass.util.Changeable
Returns:
True if the object has been changed and needs recalculation, false otherwise.

isChanged

public final boolean isChanged(int mask)
Checks the value of the ChangedFlag property for the specified mask (see Changeable for a list of valid masks). The ChangedFlag property determines the action the object needs to take in regards to the current change.
Specified by:
isChanged in interface com.klg.jclass.util.Changeable
Parameters:
mask -  
Returns:
True if the specified mask exists in the ChangedFlag property, false otherwise.

setChanged

public void setChanged(boolean c,
                       int cf)
Sets the value of the Changed property and updates the parent object. The Changed property determines whether the object needs to be recalculated.
Specified by:
setChanged in interface com.klg.jclass.util.Changeable
Parameters:
c -  
cf -  

setChanged

public void setChanged(boolean n,
                       int cf,
                       boolean updateParent)
Sets the value of the Changed property. The Changed property determines whether the object needs to be recalculated.
Specified by:
setChanged in interface com.klg.jclass.util.Changeable
Parameters:
n - New value for Changed.
cf -  
updateParent - If true, the parent is updated. Otherwise, the parent is not updated. The "update" semantics are up to the implementor

updateParent

public void updateParent(int cf)
Parameters:
cf -  

isBatched

public boolean isBatched()
This method is not used by this implementation of Changeable, so it always returns false.
Specified by:
isBatched in interface com.klg.jclass.util.Changeable

Copyright© 1999-2000 KL Group Inc.
All rights reserved.