Class Oscilloscope

java.lang.Object
org.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
org.eclipse.swt.widgets.Canvas
org.eclipse.nebula.widgets.oscilloscope.multichannel.Oscilloscope
All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable
Direct Known Subclasses:
Oscilloscope

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

  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    class  Oscilloscope.IntegerFiFoCircularStack
    The stack can hold a limited number of values but will never overflow.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int BASE_CENTER
    The base of the line is positioned at the center of the widget.
    static int CURSOR_START_DEFAULT
    The default cursor starting position.
    static int DEFAULT_HEIGHT
    The default comfortable widget height.
    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 LINE_WIDTH_DEFAULT
    The default line width.
    static int PROGRESSION_DEFAULT
    The default tail fade percentage
    static int STEADYPOSITION_75PERCENT
    Steady position @ 75% of graph.
    static int TAILFADE_DEFAULT
    The default amount of tail fading in percentages (25).
    static int TAILFADE_NONE
    No tailfade.
    static int TAILFADE_PERCENTAGE
    The default tail fade percentage
    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

    Constructors 
    Constructor Description
    Oscilloscope​(int channels, OscilloscopeDispatcher dispatcher, org.eclipse.swt.widgets.Composite parent, int style)
    Creates a new scope with channels channels and adds attaches it to the supplied dispatcher.
    Oscilloscope​(int channels, org.eclipse.swt.widgets.Composite parent, int style)
    Creates a scope with channels channels.
    Oscilloscope​(org.eclipse.swt.widgets.Composite parent, int style)
    Creates a scope with one channel.
  • Method Summary

    Modifier and Type Method Description
    void addStackListener​(int channel, 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)  
    protected void controlMoved​(org.eclipse.swt.widgets.Event e)  
    protected void controlResized​(org.eclipse.swt.widgets.Event e)  
    int getBase​(int channel)
    This method can be called outside of the UI thread.
    int getBaseOffset​(int channel)
    Gets the relative location where the line is drawn in the widget.
    int getChannels()
    This method can be called outside of the UI thread.
    OscilloscopeDispatcher getDispatcher​(int channel)
    This method can be called outside of the UI thread.
    org.eclipse.swt.graphics.Color getForeground​(int channel)
    This method can be called outside of the UI thread.
    org.eclipse.swt.graphics.Color getGridBackground()
    Returns the background color of the oscilloscope.
    org.eclipse.swt.graphics.Color getGridForeground()
    Returns the color of the grid.
    int getGridLineWidth()  
    int getGridSquareSize()  
    int getLineWidth​(int channel)
    This method can be called outside of the UI thread.
    int getProgression​(int channel)
    This method can be called outside of the UI thread.
    int getTailFade​(int channel)
    Gets the percentage of tail that must be faded out.
    int getTailSize​(int channel)
    Returns the size of the tail.
    boolean isAntiAlias​(int channel)
    This method can be called outside of the UI thread.
    boolean isConnect​(int channel)
    This method can be called outside of the UI thread.
    boolean isFade​(int channel)
    This method can be called outside of the UI thread.
    boolean isPercentage​(int channel)
    This method can be called outside of the UI thread.
    boolean isSteady​(int channel)
    This method can be called outside of the UI thread.
    boolean needsRedraw()  
    protected void paintControl​(org.eclipse.swt.widgets.Event e)  
    void removeStackListener​(int channel, OscilloscopeStackAdapter listener)
    Removes a stack listener from the collection of stack listeners.
    void setAntialias​(int channel, boolean antialias)
    Sets if the line must be anti-aliased which uses more processing power in return of a smoother image.
    void setBaseOffset​(int channel, 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​(int channel, boolean connectHeadAndTail)
    Connects head and tail only if tail size is TAILSIZE_MAX and no fading.
    void setDispatcher​(int channel, OscilloscopeDispatcher dispatcher)
    Sets the dispatcher that is associated with the supplied channel.
    void setFade​(int channel, 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 setForeground​(int channel, org.eclipse.swt.graphics.Color color)
    Sets the foreground color for the supplied channel.
    void setGridBackground​(org.eclipse.swt.graphics.Color gridBackground)
    Sets the oscilloscope's background color to the color specified by the argument, or to the default system color for the control if the argument is null.
    void setGridForeground​(org.eclipse.swt.graphics.Color gridForeground)
    Sets the color of the grid to the color specified by the argument, or to the default system color for the control if the argument is null.
    void setGridLineWidth​(int gridLineWidth)
    Set the with of the lines size of the square displayed in the grid
    void setGridSquareSize​(int size)
    Set the size of the square displayed in the grid
    void setLineWidth​(int channel, int lineWidth)
    Sets the line width.
    void setPercentage​(int channel, boolean percentage)
    If set to true then the values are treated as percentages of the available space rather than absolute values.
    void setProgression​(int channel, int progression)
    The number of internal steps that must be made before drawing.
    void setSteady​(int channel, boolean steady, int steadyPosition)
    If steady is true the graph will draw on a steady position instead of advancing.
    void setTailFade​(int channel, int tailFade)
    Sets the percentage of tail that must be faded out.
    void setTailSize​(int channel, int size)
    The tail size defaults to TAILSIZE_DEFAULT which is 75% of the width.
    void setValue​(int channel, int value)
    Sets a value to be drawn relative to the center of the channel.
    void setValues​(int channel, int[] values)
    Sets a bunch of values that will be drawn.
    protected void widgetDisposed​(org.eclipse.swt.widgets.Event e)  

    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, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList, toString

    Methods inherited from class org.eclipse.swt.widgets.Scrollable

    computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar

    Methods inherited from class org.eclipse.swt.widgets.Control

    addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update

    Methods inherited from class org.eclipse.swt.widgets.Widget

    addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.eclipse.swt.graphics.Drawable

    isAutoScalable
  • Field Details

  • Constructor Details

    • Oscilloscope

      public Oscilloscope​(org.eclipse.swt.widgets.Composite parent, int style)
      Creates a scope with one channel.
      Parameters:
      parent -
      style -
    • Oscilloscope

      public Oscilloscope​(int channels, org.eclipse.swt.widgets.Composite parent, int style)
      Creates a scope with channels channels.
      Parameters:
      channels -
      parent -
      style -
    • Oscilloscope

      public Oscilloscope​(int channels, OscilloscopeDispatcher dispatcher, org.eclipse.swt.widgets.Composite parent, int style)
      Creates a new scope with channels channels and adds attaches it to the supplied dispatcher.
      Parameters:
      channels -
      dispatcher - may be null
      parent -
      style -
  • Method Details

    • addStackListener

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

      This method can be called outside of the UI thread.

      Parameters:
      listener -
    • computeSize

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

      protected void controlMoved​(org.eclipse.swt.widgets.Event e)
    • controlResized

      protected void controlResized​(org.eclipse.swt.widgets.Event e)
    • getBase

      public int getBase​(int channel)
      This method can be called outside of the UI thread.
      Returns:
      the base of the line.
    • getBaseOffset

      public int getBaseOffset​(int channel)
      Gets the relative location where the line is drawn in the widget. This method can be called outside of the UI thread.
      Returns:
      baseOffset
    • getChannels

      public int getChannels()
      This method can be called outside of the UI thread.
      Returns:
      int, number of channels.
    • getDispatcher

      public OscilloscopeDispatcher getDispatcher​(int channel)
      This method can be called outside of the UI thread.
      Parameters:
      channel -
      Returns:
      the dispatcher associated with this channel.
    • getForeground

      public org.eclipse.swt.graphics.Color getForeground​(int channel)
      This method can be called outside of the UI thread.
      Parameters:
      channel -
      Returns:
      the foreground color associated with the supplied channel.
    • getLineWidth

      public int getLineWidth​(int channel)
      This method can be called outside of the UI thread.
      Returns:
      int, the width of the line.
      See Also:
      #setLineWidth(int)
    • getProgression

      public int getProgression​(int channel)
      This method can be called outside of the UI thread.
      Returns:
      the number of internal calculation steps at each draw request.
      See Also:
      #setProgression(int)
    • getTailFade

      public int getTailFade​(int channel)
      Gets the percentage of tail that must be faded out. This method can be called outside of the UI thread.
      Returns:
      int percentage
      See Also:
      #setFade(boolean)
    • getTailSize

      public int getTailSize​(int channel)
      Returns the size of the tail. This method can be called outside of the UI thread.
      Returns:
      int
      See Also:
      #setTailSize(int), TAILSIZE_DEFAULT, TAILSIZE_FILL, TAILSIZE_MAX
    • isConnect

      public boolean isConnect​(int channel)
      This method can be called outside of the UI thread.
      Returns:
      boolean, true if the tail and the head of the graph must be connected if tail size is TAILSIZE_MAX no fading graph.
    • isFade

      public boolean isFade​(int channel)
      This method can be called outside of the UI thread.
      Returns:
      boolean fade
      See Also:
      #setFade(boolean)
    • isPercentage

      public boolean isPercentage​(int channel)
      This method can be called outside of the UI thread.
      Returns:
      boolean
      See Also:
      #setPercentage(boolean)
    • isSteady

      public boolean isSteady​(int channel)
      This method can be called outside of the UI thread.
      Returns:
      boolean steady indicator
      See Also:
      Oscilloscope#setSteady(boolean, int)
    • isAntiAlias

      public boolean isAntiAlias​(int channel)
      This method can be called outside of the UI thread.
      Returns:
      boolean anti-alias indicator
      See Also:
      setAntialias(int, boolean)
    • needsRedraw

      public boolean needsRedraw()
    • paintControl

      protected void paintControl​(org.eclipse.swt.widgets.Event e)
    • removeStackListener

      public void removeStackListener​(int channel, OscilloscopeStackAdapter listener)
      Removes a stack listener from the collection of stack listeners. This method can be called outside of the UI thread.
      Parameters:
      listener -
    • setBaseOffset

      public void setBaseOffset​(int channel, 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. This method can be called outside of the UI thread.
      Parameters:
      baseOffset - must be between 100 and -100, exceeding values are rounded to the closest allowable value.
    • setConnect

      public void setConnect​(int channel, boolean connectHeadAndTail)
      Connects head and tail only if tail size is TAILSIZE_MAX and no fading. This method can be called outside of the UI thread.
      Parameters:
      connectHeadAndTail -
    • setAntialias

      public void setAntialias​(int channel, boolean antialias)
      Sets if the line must be anti-aliased which uses more processing power in return of a smoother image. The default value is false. This method can be called outside of the UI thread.
      Parameters:
      channel -
      antialias -
    • setDispatcher

      public void setDispatcher​(int channel, OscilloscopeDispatcher dispatcher)
      Sets the dispatcher that is associated with the supplied channel. This method can be called outside of the UI thread.
      Parameters:
      channel -
      dispatcher -
    • setFade

      public void setFade​(int channel, 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).

      This method can be called outside of the UI thread.

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

      public void setForeground​(int channel, org.eclipse.swt.graphics.Color color)
      Sets the foreground color for the supplied channel.

      This method can be called outside of the UI thread.

      Parameters:
      channel -
      color -
    • setLineWidth

      public void setLineWidth​(int channel, int lineWidth)
      Sets the line width. A value equal or below zero is ignored. The default width is 1. This method can be called outside of the UI thread.
      Parameters:
      lineWidth -
    • setPercentage

      public void setPercentage​(int channel, 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.

      This method can be called outside of the UI thread.

      Parameters:
      percentage - true if percentages
    • setProgression

      public void setProgression​(int channel, 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.

      This method can be called outside of the UI thread.

      Parameters:
      progression -
    • setSteady

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

      This method can be called outside of the UI thread.

      Parameters:
      steady -
      steadyPosition -
    • setTailFade

      public void setTailFade​(int channel, 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.

      This method can be called outside of the UI thread.

      Parameters:
      tailFade -
    • setTailSize

      public void setTailSize​(int channel, 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
    • setValue

      public void setValue​(int channel, int value)
      Sets a value to be drawn relative to the center of the channel. Supply a positive or negative value. This method will only accept values if the width of the scope > 0. 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.

      This method can be called outside of the UI thread.

      Parameters:
      channel -
      value - which is an absolute value or a percentage
      See Also:
      isPercentage(int), setBaseOffset(int, int)
    • setValues

      public void setValues​(int channel, int[] values)
      Sets a bunch of values that will be drawn. See setValue(int, int) for details.

      This method can be called outside of the UI thread.

      Parameters:
      channel -
      values -
      See Also:
      setValue(int, int)
    • widgetDisposed

      protected void widgetDisposed​(org.eclipse.swt.widgets.Event e)
    • getGridSquareSize

      public int getGridSquareSize()
      Returns:
      the width of the square displayed in the grid
      Throws:
      org.eclipse.swt.SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setGridSquareSize

      public void setGridSquareSize​(int size)
      Set the size of the square displayed in the grid
      Parameters:
      size - the new size
      Throws:
      org.eclipse.swt.SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • ERROR_INVALID_ARGUMENT - if size is lower than 1
    • getGridLineWidth

      public int getGridLineWidth()
      Returns:
      the width of the lines of the grid
      Throws:
      org.eclipse.swt.SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setGridLineWidth

      public void setGridLineWidth​(int gridLineWidth)
      Set the with of the lines size of the square displayed in the grid
      Parameters:
      gridLineWidth - the new size
      Throws:
      org.eclipse.swt.SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • ERROR_INVALID_ARGUMENT - if gridLineWidth is lower than 1
    • getGridBackground

      public org.eclipse.swt.graphics.Color getGridBackground()
      Returns the background color of the oscilloscope.
      Returns:
      the oscilloscope background color
      Throws:
      org.eclipse.swt.SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setGridBackground

      public void setGridBackground​(org.eclipse.swt.graphics.Color gridBackground)
      Sets the oscilloscope's background color to the color specified by the argument, or to the default system color for the control if the argument is null.
      Parameters:
      color - the new color (or null)
      Throws:
      java.lang.IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the argument has been disposed
      org.eclipse.swt.SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • getGridForeground

      public org.eclipse.swt.graphics.Color getGridForeground()
      Returns the color of the grid.
      Returns:
      the color or the grid
      Throws:
      org.eclipse.swt.SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setGridForeground

      public void setGridForeground​(org.eclipse.swt.graphics.Color gridForeground)
      Sets the color of the grid to the color specified by the argument, or to the default system color for the control if the argument is null.
      Parameters:
      color - the new color (or null)
      Throws:
      java.lang.IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the argument has been disposed
      org.eclipse.swt.SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver