JClass 4.5.0 API
Documentation

com.klg.jclass.swing.gauge
Class JCNeedle

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--com.klg.jclass.swing.gauge.JCNeedle

public class JCNeedle
extends JComponent

A needle points to values on its scale. There may be multiple needles associated with a scale.

See Also:
JCNeedleStyle, Serialized Form

Inner Class Summary
static class JCNeedle.InteractionType
          Needle interaction types.
 
Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Field Summary
protected  ChangeEvent changeEvent
          Reuse the same event for notifications.
protected  com.klg.jclass.util.JCListenerList changeListeners
          List of listeners interested in knowing when a needle's value has changed.
protected  JCCircularGauge gauge
          The associated gauge.
protected  JCNeedle.InteractionType interactionType
          The type of interaction, one of InteractionType.NONE InteractionType.DRAG InteractionType.CLICK InteractionType CLICK_DRAG
protected  double length
          The length of the needle as a ratio of the scale's radius.
protected  JCNeedleStyle needleStyle
          The needle style, one of, JCNeedleStyle.ARROW JCNeedleStyle.POINTER JCNeedleStyle.TRIANGLE or a user-defined instance of the JCNeedleStyle class
protected  double needleWidth
          The needle width in pixels.
protected  boolean sendEvents
          Controls whether to send change events or not.
protected  double value
          The scale value at which this needle should point.
 
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
JCNeedle(Color foreground, double needleWidth, JCCircularGauge gauge, JCNeedle.InteractionType interactionType, boolean visible, double length, JCNeedleStyle needleStyle, double value)
          Create a needle.
JCNeedle(JCCircularGauge gauge)
          Creates a needle.
 
Method Summary
 void addChangeListener(ChangeListener l)
          Adds listener interested in needle movements.
 JCCircularGauge getGauge()
          Returns the gauge associated with this scale.
 JCNeedle.InteractionType getInteractionType()
          Returns the interation type for this needle.
 double getLength()
          Returns the length of this needle as a ratio of the scale's radius.
 JCNeedleStyle getNeedleStyle()
          Returns the JCNeedleStyle for this needle.
 double getNeedleWidth()
          Returns the needle width in pixels.
 Dimension getPreferredSize()
          Returns the preferred size for this component.
 boolean getSendEvents()
          Returns a sendEvents flag; true means events will be sent when the needle's value changes, false means don't send the events.
 double getValue()
          Returns the scale value at which this needle is currently pointing.
 void paint(Graphics g)
          This routine actually draws the needle object on the screen.
 void redraw()
          Call this instead of paint so that the repaintEnabled flag can be checked.
 void removeChangeListener(ChangeListener l)
          Removes listener interested in needle movements.
 void sendChangeEvent(ChangeEvent ev)
          Broadcasts the move event to interested listeners.
 void setGauge(JCCircularGauge gauge)
          Sets the gauge associated with this scale.
 void setInteractionType(JCNeedle.InteractionType interactionType)
          Sets the interation type for this needle.
 void setLength(double length)
          Sets the length of this needle as a ratio of the scale's radius.
 void setNeedleStyle(JCNeedleStyle needleStyle)
          Sets the JCNeedleStyle for this needle.
 void setNeedleWidth(double needleWidth)
          Sets the needle width in pixels.
 void setSendEvents(boolean sendEvents)
          Sets the sendEvents flag; true means events will be sent when the needle's value changes, false means don't send the events.
 void setValue(double value)
          Sets the scale value to which this needle should point.
 
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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, 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

needleWidth

protected double needleWidth
The needle width in pixels.

gauge

protected JCCircularGauge gauge
The associated gauge.

changeListeners

protected com.klg.jclass.util.JCListenerList changeListeners
List of listeners interested in knowing when a needle's value has changed.

changeEvent

protected ChangeEvent changeEvent
Reuse the same event for notifications. The source will be this needle.

sendEvents

protected boolean sendEvents
Controls whether to send change events or not.

interactionType

protected JCNeedle.InteractionType interactionType
The type of interaction, one of

length

protected double length
The length of the needle as a ratio of the scale's radius.

needleStyle

protected JCNeedleStyle needleStyle
The needle style, one of, or a user-defined instance of the JCNeedleStyle class

value

protected double value
The scale value at which this needle should point.
Constructor Detail

JCNeedle

public JCNeedle(JCCircularGauge gauge)
Creates a needle.
Parameters:
gauge - The parent circular gauge

JCNeedle

public JCNeedle(Color foreground,
                double needleWidth,
                JCCircularGauge gauge,
                JCNeedle.InteractionType interactionType,
                boolean visible,
                double length,
                JCNeedleStyle needleStyle,
                double value)
Create a needle.
Parameters:
foreground - The needle's color
needleWidth - The needle's width in pixels
gauge - The associated circular gauge
interactionType - The interaction type, CLICK, CLICK_DRAG, or NONE
visible - A Boolean that controls the visibility of the needle
length - The needle's length, expressed as a ratio of its length to the radius of the associated circular scale
needleStyle - Needle styles are kept in JCNeedleStyle. User-defined needle styles may be passed to JCNeedleStyle's constructor.
value - The needles value. The needle points to this value on its associated scale
Method Detail

getPreferredSize

public Dimension getPreferredSize()
Returns the preferred size for this component.
Overrides:
getPreferredSize in class JComponent
Returns:
the preferred size

paint

public void paint(Graphics g)
This routine actually draws the needle object on the screen.
Overrides:
paint in class JComponent
Parameters:
g -  

addChangeListener

public void addChangeListener(ChangeListener l)
Adds listener interested in needle movements.
Parameters:
l -  

removeChangeListener

public void removeChangeListener(ChangeListener l)
Removes listener interested in needle movements.
Parameters:
l -  

sendChangeEvent

public void sendChangeEvent(ChangeEvent ev)
Broadcasts the move event to interested listeners.
Parameters:
ev - The ChangeEvent of interest

getValue

public double getValue()
Returns the scale value at which this needle is currently pointing.
Returns:
The current value pointed to by this needle

setValue

public void setValue(double value)
Sets the scale value to which this needle should point.
Parameters:
value - The value at which to point

getLength

public double getLength()
Returns the length of this needle as a ratio of the scale's radius.
Returns:
The length of this needle as a ratio of the scale's radius

setLength

public void setLength(double length)
Sets the length of this needle as a ratio of the scale's radius. For example, 0.75 means draw out to 75% of the scale's radius.
Parameters:
length - The length of this needle as a ratio of the scale's radius

getGauge

public JCCircularGauge getGauge()
Returns the gauge associated with this scale.
Returns:
the gauge

setGauge

public void setGauge(JCCircularGauge gauge)
Sets the gauge associated with this scale.
Parameters:
gauge - The gauge

getNeedleStyle

public JCNeedleStyle getNeedleStyle()
Returns the JCNeedleStyle for this needle.
Returns:
the JCNeedleStyle of this needle

setNeedleStyle

public void setNeedleStyle(JCNeedleStyle needleStyle)
Sets the JCNeedleStyle for this needle.
Parameters:
needleStyle - The JCNeedleStyle for this needle

getInteractionType

public JCNeedle.InteractionType getInteractionType()
Returns the interation type for this needle.
Returns:
the JCNeedle.InteractionType for this needle

setInteractionType

public void setInteractionType(JCNeedle.InteractionType interactionType)
Sets the interation type for this needle.
Parameters:
interactionType - The JCNeedle.InteractionType for this needle, one of
  • InteractionType NONE
  • InteractionType DRAG
  • InteractionType.CLICK
  • InteractionType CLICK_DRAG

getNeedleWidth

public double getNeedleWidth()
Returns the needle width in pixels.
Returns:
The needle width in pixels

setNeedleWidth

public void setNeedleWidth(double needleWidth)
Sets the needle width in pixels.
Parameters:
needleWidth - The needle width in pixels

getSendEvents

public boolean getSendEvents()
Returns a sendEvents flag; true means events will be sent when the needle's value changes, false means don't send the events.
Returns:
the sendEvents boolean

setSendEvents

public void setSendEvents(boolean sendEvents)
Sets the sendEvents flag; true means events will be sent when the needle's value changes, false means don't send the events.
Parameters:
sendEvents - true means send needle's value change events to listeners, false means don't.

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.

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