Sun SPOT Telemetry Demo -- Host side
v1.1

org.sunspotworld.demo
Class GraphView

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.sunspotworld.demo.GraphView
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class GraphView
extends javax.swing.JPanel

A simple class to store up to 10 minutes of telemetry data, display it on the screen, do some simple filtering of the data and read/write it to a file.

Author:
Ron Goldman
Date: May 2, 2006
Revised: August 3, 2007
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int AXIS_WIDTH
          Specifies the width of the y-axis display.
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
GraphView()
          Creates a new instance of GraphPanel.
 
Method Summary
 void clearGraph()
          Flush any current data and clear the display.
 int getMaxWidth()
          Return the width that the current telemetry data occupies.
 boolean is2G()
          Returns whether the accelerometer data using the 2G or 6G scales.
 void paintComponent(java.awt.Graphics g)
          Paint the X-axis & the G forces recorded.
 void paintYaxis(java.awt.Graphics g)
          Draw the tick marks on the acceleration axis (= y-axis).
 boolean readTelemetryFile(java.io.File file)
          Read in acceleration telemetry data from a file.
 void repaint()
          Cause the display to be repainted.
 void setAxisPanel(javax.swing.JPanel ax)
          Specify the panel displaying the Y-axis.
 void setFiltertype(boolean b)
          Select which filter to use when smoothing the data.
 void setFilterWidth(int w)
          Specify the filter's window size.
 void setGOffset(double gx, double gy, double gz)
          Set the rest offsets used by the accelerometer.
 void setIncludeGravity(boolean includeGravity)
          Specify whether the forces displayed should include gravity or not.
 void setMaxGLabel(javax.swing.JLabel lab)
          Label to use to display maximum G force recorded.
 void setShowG(boolean b)
          Enable/disable the display of the combined G forces.
 void setShowX(boolean b)
          Enable/disable the display of the x-axis G forces.
 void setShowY(boolean b)
          Enable/disable the display of the y-axis G forces.
 void setShowZ(boolean b)
          Enable/disable the display of the z-axis G forces.
 void setSmooth(boolean b)
          Enable/disable the smoothing of the data with a filter.
 void setViewport(javax.swing.JViewport viewport)
          Connect us with the view port that is displaying us.
 void setZoomX(int s)
          Set the scale factor for the x-axis.
 void setZoomY(int s)
          Set the scale factor for the y-axis.
 void takeData(java.lang.String id, long tMS, int index, double x, double y, double z, double g, boolean twoG)
          Add new telemetry data from remote SPOT.
 boolean writeData(java.io.File file)
          Write the current acceleration telemetry data out to a file.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

AXIS_WIDTH

public static final int AXIS_WIDTH
Specifies the width of the y-axis display.

See Also:
Constant Field Values
Constructor Detail

GraphView

public GraphView()
Creates a new instance of GraphPanel. Set up our data structures (= simple arrays) and define some constants.

Method Detail

setAxisPanel

public void setAxisPanel(javax.swing.JPanel ax)
Specify the panel displaying the Y-axis.

Parameters:
ax - the panel to be used to display the y-axis

is2G

public boolean is2G()
Returns whether the accelerometer data using the 2G or 6G scales.

Returns:
true if using the 2G scale, false if using the 6G scale

getMaxWidth

public int getMaxWidth()
Return the width that the current telemetry data occupies. Used by printing to determine number of pages needed.

Returns:
the width (in pixels) that the current telemetry data occupies

writeData

public boolean writeData(java.io.File file)
Write the current acceleration telemetry data out to a file.

Parameters:
file - the file to write the data into
Returns:
true if successful, false otherwise

readTelemetryFile

public boolean readTelemetryFile(java.io.File file)
Read in acceleration telemetry data from a file.

Parameters:
file - the file to read the data from
Returns:
true if successful, false otherwise

takeData

public void takeData(java.lang.String id,
                     long tMS,
                     int index,
                     double x,
                     double y,
                     double z,
                     double g,
                     boolean twoG)
Add new telemetry data from remote SPOT.

Parameters:
id - IEEE address of SPOT sending the data
tMS - time in milliseconds when the data was recorded
index - index of this reading
g - the combined accelerations of all three dimensions (in gravities)
x - the x-axis acceleration (in gravities)
y - the y-axis acceleration (in gravities)
z - the z-axis acceleration (in gravities)
twoG - true if measured using the 2 G accelerometer scale

setViewport

public void setViewport(javax.swing.JViewport viewport)
Connect us with the view port that is displaying us. Needed so we can auto scroll as data is entered.

Parameters:
viewport - the JViewport to scroll to control what data is displayed

setMaxGLabel

public void setMaxGLabel(javax.swing.JLabel lab)
Label to use to display maximum G force recorded.

Parameters:
lab - the label to use to display the maximum G force encountered

clearGraph

public void clearGraph()
Flush any current data and clear the display.


setShowG

public void setShowG(boolean b)
Enable/disable the display of the combined G forces.

Parameters:
b - true if the combined G forces should be displayed

setShowX

public void setShowX(boolean b)
Enable/disable the display of the x-axis G forces.

Parameters:
b - true if the x-axis G forces should be displayed

setShowY

public void setShowY(boolean b)
Enable/disable the display of the y-axis G forces.

Parameters:
b - true if the y-axis G forces should be displayed

setShowZ

public void setShowZ(boolean b)
Enable/disable the display of the z-axis G forces.

Parameters:
b - true if the z-axis G forces should be displayed

setSmooth

public void setSmooth(boolean b)
Enable/disable the smoothing of the data with a filter.

Parameters:
b - true if the data displayed should be smoothed.

setFiltertype

public void setFiltertype(boolean b)
Select which filter to use when smoothing the data.

Parameters:
b - true for the boxcar filter, false for the triangle filter

setFilterWidth

public void setFilterWidth(int w)
Specify the filter's window size.

Parameters:
w - the number of samples to use when filtering

setZoomX

public void setZoomX(int s)
Set the scale factor for the x-axis.

Parameters:
s - the scale / 2, so s = 1, means 1/2 size, s = 4 means double size

setZoomY

public void setZoomY(int s)
Set the scale factor for the y-axis.

Parameters:
s - the scale, so s = 1, means normal size, s = 2 means double size

setGOffset

public void setGOffset(double gx,
                       double gy,
                       double gz)
Set the rest offsets used by the accelerometer. Used when we need the display to include the force of gravity.

Parameters:
gx - the X-axis rest offset
gy - the Y-axis rest offset
gz - the Z-axis rest offset

setIncludeGravity

public void setIncludeGravity(boolean includeGravity)
Specify whether the forces displayed should include gravity or not.

Parameters:
includeGravity - true if gravity should be shown

repaint

public void repaint()
Cause the display to be repainted. Also repaints the y-axis panel.

Overrides:
repaint in class java.awt.Component

paintComponent

public void paintComponent(java.awt.Graphics g)
Paint the X-axis & the G forces recorded. The Y-axis is now drawn in a separate panel.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - the graphics component to use to paint things

paintYaxis

public void paintYaxis(java.awt.Graphics g)
Draw the tick marks on the acceleration axis (= y-axis). The y-axis is drawn in a separate display panel.

Parameters:
g - the graphics component to use

Sun SPOT Telemetry Demo -- Host side
v1.1

Copyright © 2006, 2007 Sun Microsystems, Inc. All Rights Reserved.