org.eclipse.nebula.widgets.oscilloscope
Class Oscilloscope

java.lang.Object
  extended by org.eclipse.swt.widgets.Widget
      extended by org.eclipse.swt.widgets.Control
          extended by org.eclipse.swt.widgets.Scrollable
              extended by org.eclipse.swt.widgets.Composite
                  extended by org.eclipse.swt.widgets.Canvas
                      extended by org.eclipse.nebula.widgets.oscilloscope.Oscilloscope
All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable

public class Oscilloscope
extends org.eclipse.swt.widgets.Canvas

Animated widget that tries to mimic an Oscilloscope. An oscilloscope (also known as a scope, CRO or, an O-scope) is a type of electronic test instrument that allows observation of constantly varying signal voltages, usually as a two-dimensional graph of one or more electrical potential differences using the vertical or 'Y' axis, plotted as a function of time, (horizontal or 'x' axis).

http://en.wikipedia.org/ wiki/Oscilloscope

Author:
Wim.Jongman (@remainsoftware.com)

Nested Class Summary
 class Oscilloscope.IntegerFiFoCircularStack
          The stack will not overflow if you push too many values into it but it will rotate and overwrite the older values.
 
Field Summary
static int BASE_CENTER
          The base of the line is positioned at the center of the widget.
static int DEFAULT_HEIGHT
          The default comfortable widget height.
static int DEFAULT_TAILFADE
          The default amount of tail fading in percentages.
static int DEFAULT_WIDTH
          The default comfortable widget width.
static int[] HEARTBEAT
          This set of values will draw a figure that is similar to the heart beat that you see on hospital monitors.
static int STEADYPOSITION_75PERCENT
          Steady position @ 75% of graph.
static int TAILSIZE_DEFAULT
          The default tail size is 75% of the width.
static int TAILSIZE_FILL
          Will draw a tail from the left border but is only valid if the boolean in setSteady(boolean, int) was set to true, will default to TAILSIZE_MAX otherwise.
static int TAILSIZE_MAX
          Will draw a maximum tail.
 
Fields inherited from class org.eclipse.swt.widgets.Control
handle
 
Constructor Summary
Oscilloscope(org.eclipse.swt.widgets.Composite parent, int style)
          Creates a new Oscilloscope.
 
Method Summary
 void addStackListener(OscilloscopeStackAdapter listener)
          Adds a new stack listener to the collection of stack listeners.
 org.eclipse.swt.graphics.Point computeSize(int wHint, int hHint, boolean changed)
           
 int getBase()
           
 int getBaseOffset()
          Gets the relative location where the line is drawn in the widget.
 int getLineWidth()
           
 int getProgression()
           
 int getTailFade()
          gets the percentage of tail that must be faded out.
 int getTailSize()
          Returns the size of the tail.
 boolean isConnect()
           
 boolean isFade()
           
 boolean isPercentage()
           
 boolean isSteady()
           
 boolean needsRedraw()
           
 void removeStackListener(OscilloscopeStackAdapter listener)
          Removes a stack listener from the collection of stack listeners.
 void setBaseOffset(int baseOffset)
          Gets the relative location where the line is drawn in the widget, the default is BASE_CENTER which is in the middle of the scope.
 void setConnect(boolean connectHeadAndTail)
          Connects head and tail only if tail size is TAILSIZE_MAX and no fading.
 void setFade(boolean fade)
          Sets fade mode so that a percentage of the tail will be faded out at the costs of extra CPU utilization (no beauty without pain or as the Dutch say: "Wie mooi wil gaan moet pijn doorstaan").
 void setLineWidth(int lineWidth)
          Sets the line width.
 void setPercentage(boolean percentage)
          If set to true then the values are treated as percentages of the available space rather than absolute values.
 void setProgression(int progression)
          The number of internal steps that must be made before drawing.
 void setSteady(boolean steady, int steadyPosition)
          If steady is true the graph will draw on a steady position instead of advancing.
 void setTailFade(int tailFade)
          Sets the percentage of tail that must be faded out.
 void setTailSize(int size)
          The tail size defaults to TAILSIZE_DEFAULT which is 75% of the width.
 void setValue(int value)
          Sets a value to be drawn relative to the middle of the widget.
 void setValues(int[] values)
          Set a bunch of values that will be drawn.
 
Methods inherited from class org.eclipse.swt.widgets.Canvas
drawBackground, getCaret, getIME, scroll, setCaret, setFont, setIME
 
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getRegion, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTraverseListener, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setRegion, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, dispose, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, reskin, setData, setData, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_WIDTH

public static final int DEFAULT_WIDTH
The default comfortable widget width.

See Also:
Constant Field Values

DEFAULT_HEIGHT

public static final int DEFAULT_HEIGHT
The default comfortable widget height.

See Also:
Constant Field Values

DEFAULT_TAILFADE

public static final int DEFAULT_TAILFADE
The default amount of tail fading in percentages.

See Also:
Constant Field Values

HEARTBEAT

public static final int[] HEARTBEAT
This set of values will draw a figure that is similar to the heart beat that you see on hospital monitors.


TAILSIZE_MAX

public static final int TAILSIZE_MAX
Will draw a maximum tail.

See Also:
Constant Field Values

TAILSIZE_FILL

public static final int TAILSIZE_FILL
Will draw a tail from the left border but is only valid if the boolean in setSteady(boolean, int) was set to true, will default to TAILSIZE_MAX otherwise.

See Also:
Constant Field Values

TAILSIZE_DEFAULT

public static final int TAILSIZE_DEFAULT
The default tail size is 75% of the width.

See Also:
Constant Field Values

STEADYPOSITION_75PERCENT

public static final int STEADYPOSITION_75PERCENT
Steady position @ 75% of graph.

See Also:
Constant Field Values

BASE_CENTER

public static final int BASE_CENTER
The base of the line is positioned at the center of the widget.

See Also:
setBaseOffset(int), Constant Field Values
Constructor Detail

Oscilloscope

public Oscilloscope(org.eclipse.swt.widgets.Composite parent,
                    int style)
Creates a new Oscilloscope.

Parameters:
parent -
style -
Method Detail

getTailSize

public int getTailSize()
Returns the size of the tail.

Returns:
int
See Also:
setTailSize(int), TAILSIZE_DEFAULT, TAILSIZE_FILL, TAILSIZE_MAX

getBaseOffset

public int getBaseOffset()
Gets the relative location where the line is drawn in the widget.

Returns:
baseOffset

setBaseOffset

public void setBaseOffset(int baseOffset)
Gets the relative location where the line is drawn in the widget, the default is BASE_CENTER which is in the middle of the scope.

Parameters:
baseOffset - must be between 0 and 0, exceeding values are rounded to the closest allowable value.

getBase

public int getBase()
Returns:
the base of the line

getProgression

public int getProgression()
Returns:
the number of internal calculation steps at each draw request.
See Also:
setProgression(int)

setProgression

public void setProgression(int progression)
The number of internal steps that must be made before drawing. Normally this will slide the graph one pixel. Setting this to a higher value will speed up the animation at the cost of a more jerky motion.

Parameters:
progression -

isConnect

public boolean isConnect()
Returns:
boolean, true if the tail and the head of the graph must be connected if tail size is TAILSIZE_MAX no fading graph.

setConnect

public void setConnect(boolean connectHeadAndTail)
Connects head and tail only if tail size is TAILSIZE_MAX and no fading.

Parameters:
connectHeadAndTail -

isFade

public boolean isFade()
Returns:
boolean fade
See Also:
setFade(boolean)

setFade

public void setFade(boolean fade)
Sets fade mode so that a percentage of the tail will be faded out at the costs of extra CPU utilization (no beauty without pain or as the Dutch say: "Wie mooi wil gaan moet pijn doorstaan"). The reason for this is that each pixel must be drawn separately with alpha faded in instead of the elegant GC.drawPolygon(int[]) routine which does not support alpha blending.

In addition to this, set the percentage of tail that must be faded out setTailFade(int).

Parameters:
fade - true or false
See Also:
setTailFade(int)

getTailFade

public int getTailFade()
gets the percentage of tail that must be faded out.

Returns:
int percentage
See Also:
setFade(boolean)

isSteady

public boolean isSteady()
Returns:
boolean steady indicator
See Also:
setSteady(boolean, int)

setValues

public void setValues(int[] values)
Set a bunch of values that will be drawn. The values will be stored in a stack and popped once a value is needed. The size of the stack is the width of the widget. If you resize the widget, the old stack will be copied into a new stack with the new capacity.

Parameters:
values -

setValue

public void setValue(int value)
Sets a value to be drawn relative to the middle of the widget. Supply a positive or negative value.

Parameters:
value -

setTailSize

public void setTailSize(int size)
The tail size defaults to TAILSIZE_DEFAULT which is 75% of the width. Setting it with TAILSIZE_MAX will leave one pixel between the tail and the head. All values are absolute except TAILSIZE*. If the width is smaller then the tail size then the tail size will behave like TAILSIZE_MAX.

Parameters:
size - the size of the tail
See Also:
getTailSize(), TAILSIZE_DEFAULT, TAILSIZE_FILL, TAILSIZE_MAX

computeSize

public org.eclipse.swt.graphics.Point computeSize(int wHint,
                                                  int hHint,
                                                  boolean changed)
Overrides:
computeSize in class org.eclipse.swt.widgets.Composite

needsRedraw

public boolean needsRedraw()

setLineWidth

public void setLineWidth(int lineWidth)
Sets the line width. A value equal or below zero is ignored. The default width is 1.

Parameters:
lineWidth -

getLineWidth

public int getLineWidth()
Returns:
int, the width of the line.
See Also:
setLineWidth(int)

setPercentage

public void setPercentage(boolean percentage)
If set to true then the values are treated as percentages of the available space rather than absolute values. This will scale the amplitudes if the control is resized. Default is false.

Parameters:
percentage - true if percentages

isPercentage

public boolean isPercentage()
Returns:
boolean
See Also:
setPercentage(boolean)

setSteady

public void setSteady(boolean steady,
                      int steadyPosition)
If steady is true the graph will draw on a steady position instead of advancing.

Parameters:
steady -
steadyPosition -

setTailFade

public void setTailFade(int tailFade)
Sets the percentage of tail that must be faded out. If you supply 100 then the tail is faded out all the way to the top. The effect will become increasingly less obvious.

Parameters:
tailFade -

addStackListener

public void addStackListener(OscilloscopeStackAdapter listener)
Adds a new stack listener to the collection of stack listeners. Adding the same listener twice will have no effect.

Parameters:
listener -

removeStackListener

public void removeStackListener(OscilloscopeStackAdapter listener)
Removes a stack listener from the collection of stack listeners.

Parameters:
listener -