ControlBeans
Class CPlotter

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--ControlBeans.CPlotter

public class CPlotter
extends javax.swing.JPanel
implements ComponentInterface, java.lang.Runnable

This class implements a simple plotter. Its purpose it to provide the user with a visual graph indicator. This is a passive component, meaning that it will never itself send any values to the communicator. It can contain several curves with varying colors being drawn over a user defined range.
It has been implemented as a Javabean, meaning that it is well suited to use within visual programming tools such as NetBeans or JBuilder.

See Also:
AbstractCommunicator, Serialized Form

Inner classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
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 ControlBeans.ComponentInterface
DEFAULT_ID
 
Constructor Summary
CPlotter()
          Constructs a new CPlotter.
 
Method Summary
 void addComponentListener(ComponentListener l)
          Registers a ComponentListener.
 void drawCurves(java.awt.Graphics g)
          This methods draws the curves, axis and ticks.
 int getCapacity()
          Gets how many values each curve in this plotter will store.
 java.awt.Color[] getColors()
          Gets the color for each of the plottable curves in this plotter.
 boolean getDrawAxis()
          Gets whether or not the x-axis and y-axis will be drawn.
 boolean getDrawTicks()
          Gets whether or not the ticks will be drawn on the x-axis and y-axis.
 boolean getIsReceiver()
          Gets whether or not this component will receive values.
 boolean getIsSender()
          Gets whether or not this component will send values.
 double getMajorXTickSpacing()
          Gets the number of units between each of the larger lines (ticks) on the scale on the x-axis.
 double getMajorYTickSpacing()
          Gets the number of units between each of the larger lines (ticks) on the scale on the y-axis.
 double getMinorXTickSpacing()
          Gets the number of units between each of the smaller lines (ticks) on the scale on the x-axis.
 double getMinorYTickSpacing()
          Gets the number of units between each of the smaller lines (ticks) on the scale on the y-axis.
 int getRefreshrate()
          Gets how often this plotter will refresh itself.
 int[] getTags()
          Returns an array of integers containing all tags for which this plotter will draw curves.
 double getXRange()
          Gets the range of the x-axis for this plotter.
 double getYOffset()
          Gets the minimum plottable value on the y-axis for this plotter.
 double getYRange()
          Gets the range of the y-axis for this plotter.
 void paint(java.awt.Graphics g)
          This methods draws the curves, axis and ticks.
 void putValue(double value, int aTag, double time, int ID)
          Sets the value of this component.
 void putValue(int value, int aTag, double time, int ID)
          Sets the value of this component.
 void putValue(java.lang.String value, int aTag, double time, int ID)
          Sets the value for this component.
 void registerCommunicator(AbstractCommunicator c, int ID)
          The communicator uses this method to alert this component of its presence.
 void removeComponentListener(ComponentListener l)
          Deregisters the ComponentListener.
 void requestValues()
          Called by the communicator to make this component send its value(s).
 void run()
          Starts the automatic refreshing of this plotter.
 void setCapacity(int value)
          Sets how many values each curve will store.
 void setColors(java.awt.Color[] value)
          Sets the color for each of the plottable curves in this plotter.
 void setDrawAxis(boolean value)
          Sets whether or not the x-axis and y-axis will be drawn.
 void setDrawTicks(boolean value)
          Sets whether or not the ticks will be drawn on the x-axis and y-axis.
 void setIsReceiver(boolean value)
          Sets whether or not this component should receive values.
 void setIsSender(boolean value)
          Sets whether or not this component should send values.
 void setMajorXTickSpacing(double value)
          Sets the number of units between each of the larger lines (ticks) on the scale on the x-axis.
 void setMajorYTickSpacing(double value)
          Sets the number of units between each of the larger lines (ticks) on the scale on the y-axis.
 void setMinorXTickSpacing(double value)
          Sets the number of units between each of the smaller lines (ticks) on the scale on the x-axis.
 void setMinorYTickSpacing(double value)
          Sets the number of units between each of the smaller lines (ticks) on the scale on the y-axis.
 void setRefreshrate(int value)
          Sets how often this plotter will refresh itself.
 void setTags(int[] value)
          Sets the tags for which this plotter will draw curves.
 void setXRange(double value)
          Sets the range of the x-axis for this plotter.
 void setYOffset(double value)
          Sets the minimum plottable value on the y-axis for this plotter.
 void setYRange(double value)
          Sets the range of the y-axis for this plotter.
 void update(java.awt.Graphics g)
          This methods draws the curves, axis and ticks.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, updateUI
 
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, 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, getWidth, getVisibleRect, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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
 
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
 

Constructor Detail

CPlotter

public CPlotter()
Constructs a new CPlotter.
Method Detail

run

public void run()
Starts the automatic refreshing of this plotter. This method is invoked in the registerCommunicator method and should therefore not be called directly by the user.
Specified by:
run in interface java.lang.Runnable
See Also:
registerCommunicator(ControlBeans.AbstractCommunicator, int)

getDrawAxis

public boolean getDrawAxis()
Gets whether or not the x-axis and y-axis will be drawn.
Returns:
true if the two axis will be drawn, false otherwise.

setDrawAxis

public void setDrawAxis(boolean value)
Sets whether or not the x-axis and y-axis will be drawn.
Parameters:
value - true if this component should draw the two axis, false otherwise.

getDrawTicks

public boolean getDrawTicks()
Gets whether or not the ticks will be drawn on the x-axis and y-axis.
Returns:
true if the ticks will be drawn, false otherwise.
See Also:
getMajorXTickSpacing(), getMajorYTickSpacing(), getMinorXTickSpacing(), getMinorYTickSpacing()

setDrawTicks

public void setDrawTicks(boolean value)
Sets whether or not the ticks will be drawn on the x-axis and y-axis.
Parameters:
value - true if the ticks should be drawn, false otherwise.

getIsReceiver

public boolean getIsReceiver()
Gets whether or not this component will receive values.
Specified by:
getIsReceiver in interface ComponentInterface
Returns:
true if this component will receive values from the communicator; false otherwise.

setIsReceiver

public void setIsReceiver(boolean value)
Sets whether or not this component should receive values.
Specified by:
setIsReceiver in interface ComponentInterface
Parameters:
value - true if this component should receive values from the communicator; false otherwise.

getIsSender

public boolean getIsSender()
Gets whether or not this component will send values.
NOTE: Implemented for compatibility reasons only. This component cannot send values, hence this method will always return false.
Specified by:
getIsSender in interface ComponentInterface
Returns:
true if this component will send values to the communicator; false otherwise.

setIsSender

public void setIsSender(boolean value)
Sets whether or not this component should send values.
NOTE: Implemented for compatibility reasons only. This component cannot send values, hence calling this method will have no effect.
Specified by:
setIsSender in interface ComponentInterface
Parameters:
value - true if this component should send values to the communicator; false otherwise.

getCapacity

public int getCapacity()
Gets how many values each curve in this plotter will store.
Returns:
the capacity of the curves

setCapacity

public void setCapacity(int value)
Sets how many values each curve will store. Larger numbers will make the curves longer or more detailed (depending on how often values are added to the curve). This may affect the time spent on redrawing.
Parameters:
value - the desired capacity of the curves

getRefreshrate

public int getRefreshrate()
Gets how often this plotter will refresh itself.
Returns:
the time between each refresh in milliseconds

setRefreshrate

public void setRefreshrate(int value)
Sets how often this plotter will refresh itself. Please note that even if additions to the curve(s) will not be shown until next refresh, they will not be lost. The plotter will only refresh itself if needed. Too high refreshrate might slow the program.
Parameters:
value - the desired time between each refresh in milliseconds

getTags

public int[] getTags()
Returns an array of integers containing all tags for which this plotter will draw curves.
Specified by:
getTags in interface ComponentInterface
Returns:
all tags used by this component
See Also:
getColors()

setTags

public void setTags(int[] value)
Sets the tags for which this plotter will draw curves.
Parameters:
value - an integer array containing the tags for this component

getMajorXTickSpacing

public double getMajorXTickSpacing()
Gets the number of units between each of the larger lines (ticks) on the scale on the x-axis.
Returns:
the spacing between the larger lines on the x-axis

setMajorXTickSpacing

public void setMajorXTickSpacing(double value)
Sets the number of units between each of the larger lines (ticks) on the scale on the x-axis. These ticks will also have a number by them.
Parameters:
value - the desired spacing between the larger lines on the x-axis

getMajorYTickSpacing

public double getMajorYTickSpacing()
Gets the number of units between each of the larger lines (ticks) on the scale on the y-axis.
Returns:
the spacing between the larger lines on the y-axis

setMajorYTickSpacing

public void setMajorYTickSpacing(double value)
Sets the number of units between each of the larger lines (ticks) on the scale on the y-axis. These ticks will also have a number by them.
Parameters:
value - the desired spacing between the larger lines on the y-axis

getMinorXTickSpacing

public double getMinorXTickSpacing()
Gets the number of units between each of the smaller lines (ticks) on the scale on the x-axis.
Returns:
the spacing between the smaller lines on the x-axis

setMinorXTickSpacing

public void setMinorXTickSpacing(double value)
Sets the number of units between each of the smaller lines (ticks) on the scale on the x-axis.
Parameters:
value - the desired spacing between the smaller lines on the x-axis

getMinorYTickSpacing

public double getMinorYTickSpacing()
Gets the number of units between each of the smaller lines (ticks) on the scale on the y-axis.
Returns:
the spacing between the smaller lines on the y-axis

setMinorYTickSpacing

public void setMinorYTickSpacing(double value)
Sets the number of units between each of the smaller lines (ticks) on the scale on the y-axis.
Parameters:
value - the desired spacing between the smaller lines on the y-axis

getXRange

public double getXRange()
Gets the range of the x-axis for this plotter.
Returns:
the number of units on the x-axis over which this plotter plots values

setXRange

public void setXRange(double value)
Sets the range of the x-axis for this plotter.
Parameters:
value - the desired number of units on the x-axis over which this plotter should plot values

getYOffset

public double getYOffset()
Gets the minimum plottable value on the y-axis for this plotter.
Returns:
the minimum value of the y-axis for this plotter

setYOffset

public void setYOffset(double value)
Sets the minimum plottable value on the y-axis for this plotter.
Parameters:
value - the desired minimum value of the y-axis for this plotter

getYRange

public double getYRange()
Gets the range of the y-axis for this plotter.
Returns:
the number of units on the y-axis over which this plotter plots values

setYRange

public void setYRange(double value)
Sets the range of the y-axis for this plotter.
Parameters:
value - the desired number of units on the y-axis over which this plotter should plot values

getColors

public java.awt.Color[] getColors()
Gets the color for each of the plottable curves in this plotter. Each color stored on a certain index will correspond to the tag on stored on the same index.
Returns:
an array of Colors
See Also:
getTags()

setColors

public void setColors(java.awt.Color[] value)
Sets the color for each of the plottable curves in this plotter.
Parameters:
value - an array of Colors where value[0] will correspond to the curve whose index is stored in tags[0], value[1] to tags[1], and so on.
See Also:
setTags(int[])

addComponentListener

public void addComponentListener(ComponentListener l)
Registers a ComponentListener. By doing so the ComponentListener can receive component events from this component.
NOTE: This component can only hold one ComponentListener.
Specified by:
addComponentListener in interface ComponentInterface
Parameters:
l - the ComponentListener to register.

removeComponentListener

public void removeComponentListener(ComponentListener l)
Deregisters the ComponentListener.
Specified by:
removeComponentListener in interface ComponentInterface
Parameters:
l - the ComponentListener to remove.

registerCommunicator

public void registerCommunicator(AbstractCommunicator c,
                                 int ID)
The communicator uses this method to alert this component of its presence.
NOTE: This method is invoked by AbstractCommunicator and should therefore never be called directly by the user.
NOTE: This method starts the automatic refreshing of this plotter by calling the run method.
Specified by:
registerCommunicator in interface ComponentInterface
Parameters:
c - the communicator in question
ID - the ID number assigned to this component and is stored in myID
See Also:
run(), putValue(int, int, double, int), putValue(double, int, double, int), putValue(java.lang.String, int, double, int)

putValue

public void putValue(int value,
                     int aTag,
                     double time,
                     int ID)
Sets the value of this component.
Specified by:
putValue in interface ComponentInterface
Parameters:
value - the value to be set
aTag - the tag of the component
time - a time tag for the value
ID - the ID of the component
See Also:
registerCommunicator(ControlBeans.AbstractCommunicator, int)

putValue

public void putValue(double value,
                     int aTag,
                     double time,
                     int ID)
Sets the value of this component.
Specified by:
putValue in interface ComponentInterface
Parameters:
value - the value to be set
aTag - the tag of the component
time - a time tag for the value
ID - the ID of the component
See Also:
registerCommunicator(ControlBeans.AbstractCommunicator, int)

putValue

public void putValue(java.lang.String value,
                     int aTag,
                     double time,
                     int ID)
Sets the value for this component.
NOTE: Implemented for compatibility reasons only. This component cannot receive string values, hence calling this method will have no effect.
Specified by:
putValue in interface ComponentInterface
Parameters:
value - the value to be set
aTag - the tag of the component
time - a time tag for the value
ID - the ID of the component
See Also:
registerCommunicator(ControlBeans.AbstractCommunicator, int)

drawCurves

public void drawCurves(java.awt.Graphics g)
This methods draws the curves, axis and ticks. The drawing of axes and ticks may be supressed by calling drawAxis and drawTicks.
NOTE: The user should never invoke this method directly but instead call paint(Graphics g).
Parameters:
g - the graphics context of this plotter, typically obtained by calling getGraphics()
See Also:
getDrawAxis(), getDrawTicks(), paint(java.awt.Graphics)

paint

public void paint(java.awt.Graphics g)
This methods draws the curves, axis and ticks. The drawing of axes and ticks may be supressed by calling drawAxis and drawTicks.
Overrides:
paint in class javax.swing.JComponent
Parameters:
g - the graphics context of this plotter, typically obtained by calling getGraphics()
See Also:
getDrawAxis(), getDrawTicks()

update

public void update(java.awt.Graphics g)
This methods draws the curves, axis and ticks. The drawing of axes and ticks may be supressed by calling drawAxis and drawTicks.
NOTE: The user should never invoke this method directly but instead call paint(Graphics g).
Overrides:
update in class javax.swing.JComponent
Parameters:
g - the graphics context of this plotter, typically obtained by calling getGraphics()
See Also:
getDrawAxis(), getDrawTicks(), paint(java.awt.Graphics)

requestValues

public void requestValues()
Called by the communicator to make this component send its value(s). This can be used for initialization.
NOTE: Implemented for compatibility reasons only. This component does not send values, hence calling this method will have no effect,
Specified by:
requestValues in interface ComponentInterface