JClass 4.5.0 API
Documentation

com.klg.jclass.swing.gauge
Class JCTick

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--com.klg.jclass.swing.gauge.JCTick
Direct Known Subclasses:
JCCircularTick

public abstract class JCTick
extends JComponent
implements Serializable

A graduated scale marker object. It comprises a set of uniformly spaced tick marks.

See Also:
JCCircularTick, Serialized Form

Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Field Summary
protected  boolean automatic
          The automatic boolean determines whether tick increments are calculated automatically or set by the incrementValue property.
protected  boolean drawLabels
          If true, draw tick labels, otherwise don't.
protected  boolean drawTicks
          If true, draw tick marks, otherwise don't.
protected  Color fontColor
          The color of the font labeling ticks.
protected  double incrementValue
          If not automatic, the scale values at which tick marks are to be placed.
protected  double innerExtent
          The percentage of the scale's radius (as a decimal) at at which to begin drawing ticks radially outward.
protected  double labelExtent
          The percentage, expressed as a decimal fraction of the scale's radius, at which to place tick labels.
protected  JCLabelGenerator labelGenerator
          A custom label generator.
protected  double outerExtent
          The percentage of the scale's radius (as a decimal) at which to stop drawing the ticks.
protected  int precision
          If precisionUseDefault is false, use this precision.
protected  boolean precisionUseDefault
          If true, use gauge-determined precision.
protected  JCCircularScale scale
          The scale associated with this tick.
protected  double startValue
          The startValue is the scale value at which to begin this set oftick marks.
protected  double stopValue
          The stopValue is the scale value at which this set of tick marks ends.
protected  Color tickColor
          The color in which to draw ticks.
protected  JCTickStyle tickStyle
          The JCTickStyle controlling the shape of the tick.
protected  double tickWidth
          The width of a tick in pixels.
 
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
 
Constructor Summary
JCTick(JCCircularScale scale, boolean automatic, double startValue, double stopValue, double incrementValue, boolean precisionUseDefault, int precision, double tickWidth, boolean drawLabels, boolean drawTicks, double labelExtent, double innerExtent, double outerExtent, Color tickColor, JCTickStyle tickStyle, Font font, Color fontColor)
          Create a tick object and set its properties.
JCTick(JCCircularScale scale, double startValue, double stopValue)
          Create ticks.
 
Method Summary
protected  void calcPrecision(double min, double max)
          Determine and set a "nice" precision to use if useDefaultPrecision is set to true.
protected  void calcTicks(Graphics g)
          If "automatic," this method is called to determine and set the start/stop and increment values for laying out ticks.
 boolean getAutomatic()
          Returns the automatic Boolean for this tick object.
 boolean getDrawLabels()
          Returns the Boolean controlling the drawing of labels.
 boolean getDrawTicks()
          Returns the Boolean controlling the drawing of ticks.
 Color getFontColor()
          Returns the color of the font labeling ticks.
 double getIncrementValue()
          In non-automatic mode, uses this value as the increment value, that is, places ticks at every incrementValue along the scale.
 double getInnerExtent()
          Returns the percentage of the scale's radius (as a decimal) at at which to begin drawing ticks radially outward.
 double getLabelExtent()
          Returns the position, expressed as a decimal fraction of the scale's radius, where tick labels are placed.
 JCLabelGenerator getLabelGenerator()
          Returns the label generator associated with this tick.
 double getOuterExtent()
          Returns the percentage of the scale's radius (as a decimal) at which to stop drawing the ticks.
 int getPrecision()
          Returns the format for numbers in a tick label: positive values denote the number of places after the decimal point (for example, 3 means multiples of 0.001); negative values indicate the positive number of zeros are used before the decimal place (for example, -3 means numbering will be in multiples of 1000).
 boolean getPrecisionUseDefault()
          If true, uses gauge-determined precision for tick labels, otherwise uses setPrecision to label tick marks.
 JCCircularScale getScale()
          Returns the scale associated with this tick object.
 double getStartValue()
          In non-automatic mode, uses this value as the start value.
 double getStopValue()
          In non-automatic mode, uses this value as the stop value.
 Color getTickColor()
          Returns the color in which to draw ticks.
 JCTickStyle getTickStyle()
          Returns the JCTickStyle controlling the shape of the tick.
 double getTickWidth()
          Returns the width in pixels of the tick mark.
static double niceNum(double x, int exp, boolean round)
          Given x, nudge it towards a "nice" number.
 void paintChildren(Graphics g)
          Controls whether labels should be drawn according to the drawLabels boolean.
 void redraw()
          Call this instead of paint so that the repaintEnabled flag can be checked.
 void redraw(boolean redrawLabels)
          Does nothing.
 void redrawLabels()
          Does nothing.
 void setAutomatic(boolean automatic)
          Sets the automatic Boolean for this tick object.
 void setDrawLabels(boolean drawLabels)
          Sets the Boolean controlling the drawing of labels.True means draw the labels, false means hide the labels.
 void setDrawTicks(boolean drawTicks)
          Sets the Boolean controlling the drawing of ticks.True means draw the ticks, false means hide the ticks.
 void setFontColor(Color fontColor)
          Sets the color of the font labeling ticks.
 void setIncrementValue(double incrementValue)
          In non-automatic mode, uses this value as the increment value, that is, places ticks at every incrementValue along the scale.
 void setInnerExtent(double innerExtent)
          Sets the percentage of the scale's radius (as a decimal) at at which to begin drawing ticks radially outward.
 void setLabelExtent(double labelExtent)
          Sets the percentage, expressed as a decimal fraction of the scale's radius, at which to place the center of the tick label objects.
 void setLabelGenerator(JCLabelGenerator labelGenerator)
          Sets the label generator associated with this tick.
 void setOuterExtent(double outerExtent)
          Sets the percentage of the scale's radius (as a decimal) at which to stop drawing the ticks.
 void setPrecision(int precision)
          Sets the format for numbers in a tick label: positive values denote the number of places after the decimal point (for example, 3 means multiples of 0.001); negative values indicate the positive number of zeros are used before the decimal place (for example, -3 means numbering will be in multiples of 1000).
 void setPrecisionUseDefault(boolean precisionUseDefault)
          If true, uses gauge-determined precision for tick labels, otherwise uses setPrecision to label tick marks.
 void setStartValue(double startValue)
          In non-automatic mode, uses this value as the start value.
 void setStopValue(double stopValue)
          In non-automatic mode, uses this value as the stop value.
 void setTickColor(Color tickColor)
          Sets the color in which to draw ticks.
 void setTickStyle(JCTickStyle tickStyle)
          Sets the JCTickStyle controlling the shape of the tick.
 void setTickWidth(double tickWidth)
          Sets the width in pixels of the tick mark.
 
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, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, 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, paintComponent, 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, setPreferredSize, 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

scale

protected JCCircularScale scale
The scale associated with this tick.

automatic

protected boolean automatic
The automatic boolean determines whether tick increments are calculated automatically or set by the incrementValue property. If true, tick increments are calculated by the gauge. If false, the incrementValue property is used to set the tick spacing.

startValue

protected double startValue
The startValue is the scale value at which to begin this set oftick marks.

stopValue

protected double stopValue
The stopValue is the scale value at which this set of tick marks ends.

incrementValue

protected double incrementValue
If not automatic, the scale values at which tick marks are to be placed.

precisionUseDefault

protected boolean precisionUseDefault
If true, use gauge-determined precision. If false, use the precision property to determine the number of decimal places on tick labels.

precision

protected int precision
If precisionUseDefault is false, use this precision.

tickWidth

protected double tickWidth
The width of a tick in pixels.

drawLabels

protected boolean drawLabels
If true, draw tick labels, otherwise don't.

drawTicks

protected boolean drawTicks
If true, draw tick marks, otherwise don't.

labelExtent

protected double labelExtent
The percentage, expressed as a decimal fraction of the scale's radius, at which to place tick labels.

innerExtent

protected double innerExtent
The percentage of the scale's radius (as a decimal) at at which to begin drawing ticks radially outward.

outerExtent

protected double outerExtent
The percentage of the scale's radius (as a decimal) at which to stop drawing the ticks.

tickColor

protected Color tickColor
The color in which to draw ticks.

tickStyle

protected JCTickStyle tickStyle
The JCTickStyle controlling the shape of the tick.

fontColor

protected Color fontColor
The color of the font labeling ticks.

labelGenerator

protected JCLabelGenerator labelGenerator
A custom label generator.
Constructor Detail

JCTick

public JCTick(JCCircularScale scale,
              double startValue,
              double stopValue)
Create ticks.
Parameters:
scale - The associated circular scale
startValue - Where the tick marks are to begin
stopValue - Where the tick marks are to end

JCTick

public JCTick(JCCircularScale scale,
              boolean automatic,
              double startValue,
              double stopValue,
              double incrementValue,
              boolean precisionUseDefault,
              int precision,
              double tickWidth,
              boolean drawLabels,
              boolean drawTicks,
              double labelExtent,
              double innerExtent,
              double outerExtent,
              Color tickColor,
              JCTickStyle tickStyle,
              Font font,
              Color fontColor)
Create a tick object and set its properties.
Parameters:
scale - The associated circular scale
automatic - Whether to use automatic tick spacing or use incrementValue as the tick spacing
startValue - Where the tick marks are to begin
stopValue - Where the tick marks are to end
incrementValue - I automatic is false, this sets the tick interval.
precisionUseDefault - Sets whether tick labels use a default precision, or use precision.
precision - If precisionUseDefault is false, use this value to determine the precision of tick labels.
tickWidth - The width of a tick mark
drawLabels - Whether tick labels are to be drawn
drawTicks - Whether tick marks are to be drawn
labelExtent - The radial distance to the center of a tick label, expressed as a decimal fraction of the scale's radius
innerExtent -  
outerExtent - The place where the tick mark ends
tickColor - The color of the tick mark
tickStyle - A JCTickStyle enum
font - The font for tick labels
fontColor - The tick label's color
Method Detail

paintChildren

public void paintChildren(Graphics g)
Controls whether labels should be drawn according to the drawLabels boolean.
Overrides:
paintChildren in class JComponent
Parameters:
g -  

calcTicks

protected void calcTicks(Graphics g)
If "automatic," this method is called to determine and set the start/stop and increment values for laying out ticks. The goal is to have as many ticks/labels as will fit without the ticks or labels overlapping.
Parameters:
g - The graphics used to get font metric information.

calcPrecision

protected void calcPrecision(double min,
                             double max)
Determine and set a "nice" precision to use if useDefaultPrecision is set to true.
Parameters:
min -  
max -  

niceNum

public static double niceNum(double x,
                             int exp,
                             boolean round)
Given x, nudge it towards a "nice" number. Here nice means that the least significant digit is a 0, 1, 2 or 5. The desired exponent to use is provided, so that there is a consistency with default_precision.
Parameters:
x -  
exp -  
round -  

getLabelGenerator

public JCLabelGenerator getLabelGenerator()
Returns the label generator associated with this tick. If non-null, it will be called, and expected to return a JComponent which will be the label for a tick mark.
Returns:
The labelGenerator

setLabelGenerator

public void setLabelGenerator(JCLabelGenerator labelGenerator)
Sets the label generator associated with this tick. If non-null, it will be called, and expected to return a JComponent which will be the label for a tick mark. See the code in StopWatchExample.java for an example.
Parameters:
labelGenerator - The labelGenerator which implements the JCLabelGeneratorInterface

getScale

public JCCircularScale getScale()
Returns the scale associated with this tick object.
Returns:
The associated circular scale

getAutomatic

public boolean getAutomatic()
Returns the automatic Boolean for this tick object.
Returns:
The automatic setting for this tick, true means ticks and increments are dynamically determined by the gauge. Otherwise, startValue, stopValue and incrementValue are used to lay out ticks.

setAutomatic

public void setAutomatic(boolean automatic)
Sets the automatic Boolean for this tick object.
Parameters:
automatic - The automatic setting for this tick, true means ticks and increments are dynamically determined by the gauge. Otherwise, startValue, stopValue and incrementValue are used to lay out ticks.

getStartValue

public double getStartValue()
In non-automatic mode, uses this value as the start value.
Returns:
the startValue

setStartValue

public void setStartValue(double startValue)
In non-automatic mode, uses this value as the start value.
Parameters:
startValue - The startValue

getStopValue

public double getStopValue()
In non-automatic mode, uses this value as the stop value.
Returns:
the stopValue

setStopValue

public void setStopValue(double stopValue)
In non-automatic mode, uses this value as the stop value.
Parameters:
stopValue - The stopValue

getIncrementValue

public double getIncrementValue()
In non-automatic mode, uses this value as the increment value, that is, places ticks at every incrementValue along the scale.
Returns:
The spacing between adjacent tick marks

setIncrementValue

public void setIncrementValue(double incrementValue)
In non-automatic mode, uses this value as the increment value, that is, places ticks at every incrementValue along the scale.
Parameters:
incrementValue - The spacing between adjacent tick marks

getPrecisionUseDefault

public boolean getPrecisionUseDefault()
If true, uses gauge-determined precision for tick labels, otherwise uses setPrecision to label tick marks.
Returns:
A Boolean indicating whether or not a label's precision is calculated by the gauge or set using setPrecision.

setPrecisionUseDefault

public void setPrecisionUseDefault(boolean precisionUseDefault)
If true, uses gauge-determined precision for tick labels, otherwise uses setPrecision to label tick marks.
Parameters:
precisionUseDefault -  

getPrecision

public int getPrecision()
Returns the format for numbers in a tick label: positive values denote the number of places after the decimal point (for example, 3 means multiples of 0.001); negative values indicate the positive number of zeros are used before the decimal place (for example, -3 means numbering will be in multiples of 1000). Overridden if precisionUseDefault is set to true.

setPrecision

public void setPrecision(int precision)
Sets the format for numbers in a tick label: positive values denote the number of places after the decimal point (for example, 3 means multiples of 0.001); negative values indicate the positive number of zeros are used before the decimal place (for example, -3 means numbering will be in multiples of 1000). Overridden if precisionUseDefault is set to true.
Parameters:
precision - An integer

getTickWidth

public double getTickWidth()
Returns the width in pixels of the tick mark.
Returns:
The width of the tick to be drawn

setTickWidth

public void setTickWidth(double tickWidth)
Sets the width in pixels of the tick mark.
Parameters:
tickWidth - The width of the tick to be drawn in pixels

getDrawLabels

public boolean getDrawLabels()
Returns the Boolean controlling the drawing of labels. True means draw the labels, false means hide the labels.
Returns:
the boolean controlling the drawing of labels.

setDrawLabels

public void setDrawLabels(boolean drawLabels)
Sets the Boolean controlling the drawing of labels.True means draw the labels, false means hide the labels.
Parameters:
drawLabels - the boolean controlling the drawing of labels.

getDrawTicks

public boolean getDrawTicks()
Returns the Boolean controlling the drawing of ticks. True means draw the ticks, false means hide the ticks.
Returns:
the boolean controlling the drawing of ticks.

setDrawTicks

public void setDrawTicks(boolean drawTicks)
Sets the Boolean controlling the drawing of ticks.True means draw the ticks, false means hide the ticks.
Parameters:
drawTicks - the boolean controlling the drawing of ticks.

getLabelExtent

public double getLabelExtent()
Returns the position, expressed as a decimal fraction of the scale's radius, where tick labels are placed.

setLabelExtent

public void setLabelExtent(double labelExtent)
Sets the percentage, expressed as a decimal fraction of the scale's radius, at which to place the center of the tick label objects.
Parameters:
labelExtent -  

getInnerExtent

public double getInnerExtent()
Returns the percentage of the scale's radius (as a decimal) at at which to begin drawing ticks radially outward.
Returns:
The innerExtent of the tick mark

setInnerExtent

public void setInnerExtent(double innerExtent)
Sets the percentage of the scale's radius (as a decimal) at at which to begin drawing ticks radially outward.
Parameters:
innerExtent - The inner extent of the tick mark

getOuterExtent

public double getOuterExtent()
Returns the percentage of the scale's radius (as a decimal) at which to stop drawing the ticks.
Returns:
The outerExtent of the tick mark

setOuterExtent

public void setOuterExtent(double outerExtent)
Sets the percentage of the scale's radius (as a decimal) at which to stop drawing the ticks.
Parameters:
outerExtent - The outerExtent of the tick mark

getTickColor

public Color getTickColor()
Returns the color in which to draw ticks.
Returns:
The color of the tick mark

setTickColor

public void setTickColor(Color tickColor)
Sets the color in which to draw ticks.
Parameters:
tickColor - The color of the tick mark

getTickStyle

public JCTickStyle getTickStyle()
Returns the JCTickStyle controlling the shape of the tick.
Returns:
The tick style
See Also:
JCTickStyle

setTickStyle

public void setTickStyle(JCTickStyle tickStyle)
Sets the JCTickStyle controlling the shape of the tick. Users may define their own tick style, if desired.
Parameters:
tickStyle - One of the built-in tick styles, or a user-supplied style
See Also:
JCTickStyle

getFontColor

public Color getFontColor()
Returns the color of the font labeling ticks.
Returns:
The font color

setFontColor

public void setFontColor(Color fontColor)
Sets the color of the font labeling ticks.
Parameters:
fontColor - The font color

redraw

public void redraw(boolean redrawLabels)
Does nothing. Overridden in JCCircularTick.

redraw

public void redraw()
Call this instead of paint so that the repaintEnabled flag can be checked. No repaint will occur if that flag is false.

redrawLabels

public void redrawLabels()
Does nothing. Overridden in JCCircularTick.

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