net.sourceforge.webcompmath.draw.beans
Class WCMAxisTickBean

java.lang.Object
  extended by java.awt.Component
      extended by net.sourceforge.webcompmath.draw.Drawable
          extended by net.sourceforge.webcompmath.draw.beans.WCMAxisTickBean
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, Computable

public class WCMAxisTickBean
extends Drawable
implements Computable

This class provides a convenient way to create a labeled tick mark for one of the axes. The label is optional. The location of the tick mark is specified by a Value, and hence can be tied to various other WCM components.

Author:
Tom Downey
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int ABOVE_RIGHT
          Indicates that the preferred label position is above (for x axis) or to the right (for y axis) of the axis.
static int BELOW_LEFT
          Indicates that the preferred label position is below (for x axis) or to the left (for y axis) of the axis.
 
Fields inherited from class net.sourceforge.webcompmath.draw.Drawable
canvas, coords
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
WCMAxisTickBean()
          Default constructor.
WCMAxisTickBean(boolean xAxis, Value coord, java.lang.String labelText)
          Constructor for a new WCMAxisTickBean.
 
Method Summary
 void compute()
          Normally only called by a controller
 void draw(java.awt.Graphics g, boolean coordsChanged)
          Draw the tick and label.
 Value getCoord()
          Get the value that defines the coordinate location of the tick mark.
 java.awt.Color getLabelColor()
          Get the label color.
 java.awt.Font getLabelFont()
          Get the font.
 java.lang.String getLabelText()
          Get the label text.
 int getLineWidth()
          Get the line width.
 int getPosition()
          Get the label position, one of BELOW_LEFT or ABOVE_RIGHT
 java.awt.Color getTickColor()
          Get the tick color.
 boolean getVisible()
          Return true if this WCMAxisTickBean is visible, false if it is hidden.
 boolean isXAxis()
          Get whether tick is on the x axis
 void needsRedraw()
          This routine should be called if the appearance of the WCMAxisTickBean changes so that the rectangular area that it occupies has to be redrawn.
 void setCoord(Value coord)
          Set the value that defines the coordinate location of the tick mark.
 void setLabelColor(java.awt.Color labelColor)
          Set the label color.
 void setLabelFont(java.awt.Font labelFont)
          Set the font that is used for drawing the label.
 void setLabelText(java.lang.String labelText)
          Set the label text.
 void setLineWidth(int lineWidth)
          Set the line width.
protected  void setOwnerData(DisplayCanvas canvas, CoordinateRect coords)
          Override to set the owner data for the embedded drawables and add them to a coordinate rect.
 void setPosition(int position)
          Set the label position, one of BELOW_LEFT or ABOVE_RIGHT
 void setTickColor(java.awt.Color tickColor)
          Set the tick color.
 void setVisible(boolean show)
          Set the visibility of this WCMAxisTickBean.
 void setXAxis(boolean axis)
          Set whether the tick is on the x axis
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ABOVE_RIGHT

public static final int ABOVE_RIGHT
Indicates that the preferred label position is above (for x axis) or to the right (for y axis) of the axis.

See Also:
Constant Field Values

BELOW_LEFT

public static final int BELOW_LEFT
Indicates that the preferred label position is below (for x axis) or to the left (for y axis) of the axis.

See Also:
Constant Field Values
Constructor Detail

WCMAxisTickBean

public WCMAxisTickBean()
Default constructor. Creates a tick with no label, at 0.0 on the x axis.


WCMAxisTickBean

public WCMAxisTickBean(boolean xAxis,
                       Value coord,
                       java.lang.String labelText)
Constructor for a new WCMAxisTickBean. The colors default to black, the line width to 1, and the position to BELOW_LEFT.

Parameters:
xAxis - true if tick is on x axis, false for y axis
coord - the coordinate of the tick
labelText - the label for the tick
Method Detail

draw

public void draw(java.awt.Graphics g,
                 boolean coordsChanged)
Draw the tick and label. Does nothing, as the actual embedded Drawables handle the work.

Specified by:
draw in class Drawable
Parameters:
g - The graphics context in which the Drawble is to be drawn. (The drawing can change the color in g, but should not permanently change font, painting mode, etc. Thus, every drawable is responsible for setting the color it wants to use.)
coordsChanged - Indicates whether the CoordinateRect has changed.
See Also:
Drawable.draw(java.awt.Graphics, boolean)

compute

public void compute()
Normally only called by a controller

Specified by:
compute in interface Computable
See Also:
Computable.compute()

setOwnerData

protected void setOwnerData(DisplayCanvas canvas,
                            CoordinateRect coords)
Override to set the owner data for the embedded drawables and add them to a coordinate rect.

Overrides:
setOwnerData in class Drawable
Parameters:
canvas - DisplayCanvas to use
coords - CoordinateRect to use
See Also:
Drawable.setOwnerData(net.sourceforge.webcompmath.draw.DisplayCanvas, net.sourceforge.webcompmath.draw.CoordinateRect)

getVisible

public boolean getVisible()
Return true if this WCMAxisTickBean is visible, false if it is hidden.

Overrides:
getVisible in class Drawable
Returns:
true or false
See Also:
Drawable.getVisible()

needsRedraw

public void needsRedraw()
This routine should be called if the appearance of the WCMAxisTickBean changes so that the rectangular area that it occupies has to be redrawn. The routine is generally meant to be called by the WCMAxisTickBean itself.

Overrides:
needsRedraw in class Drawable
See Also:
Drawable.needsRedraw()

setVisible

public void setVisible(boolean show)
Set the visibility of this WCMAxisTickBean. If show is false, then it is hidden. If it is true, it is shown.

Overrides:
setVisible in class Drawable
Parameters:
show - true or false
See Also:
Drawable.setVisible(boolean)

getCoord

public Value getCoord()
Get the value that defines the coordinate location of the tick mark.

Returns:
the coord

setCoord

public void setCoord(Value coord)
Set the value that defines the coordinate location of the tick mark.

Parameters:
coord - the coord to set

getLabelFont

public java.awt.Font getLabelFont()
Get the font.

Returns:
the font

setLabelFont

public void setLabelFont(java.awt.Font labelFont)
Set the font that is used for drawing the label. If f is null, then the font is obtained from the Graphics context in which the tick/label is drawn.

Parameters:
labelFont - the font to set

getLabelText

public java.lang.String getLabelText()
Get the label text.

Returns:
the label

setLabelText

public void setLabelText(java.lang.String labelText)
Set the label text.

Parameters:
labelText - the label to set

getLabelColor

public java.awt.Color getLabelColor()
Get the label color.

Returns:
the labelColor

setLabelColor

public void setLabelColor(java.awt.Color labelColor)
Set the label color.

Parameters:
labelColor - the labelColor to set

getPosition

public int getPosition()
Get the label position, one of BELOW_LEFT or ABOVE_RIGHT

Returns:
the position

setPosition

public void setPosition(int position)
Set the label position, one of BELOW_LEFT or ABOVE_RIGHT

Parameters:
position - the position to set

getLineWidth

public int getLineWidth()
Get the line width.

Returns:
the line width

setLineWidth

public void setLineWidth(int lineWidth)
Set the line width. If set to 0, the thinnest possible line is drawn.

Parameters:
lineWidth - the lineWidth to set

getTickColor

public java.awt.Color getTickColor()
Get the tick color.

Returns:
the tickColor

setTickColor

public void setTickColor(java.awt.Color tickColor)
Set the tick color.

Parameters:
tickColor - the tickColor to set

isXAxis

public boolean isXAxis()
Get whether tick is on the x axis

Returns:
true for x axis, false for y axis.

setXAxis

public void setXAxis(boolean axis)
Set whether the tick is on the x axis

Parameters:
axis - true for x axis, false for y axis.