Class OscilloscopeDispatcher
java.lang.Object
org.eclipse.nebula.widgets.oscilloscope.multichannel.OscilloscopeDispatcher
public class OscilloscopeDispatcher
extends java.lang.Object
This class keeps the oscilloscope animation running and is used to set
various attributes of the scope.
You need to provide an
Oscilloscope
widget by overriding the
getOscilloscope()
method. The Control.redraw()
method
will be called every getDelayLoop()
milliseconds. The higher the
value, the slower the animation will run.
Just before the redraw and just after the redraw the hook..Draw
methods are called. Don't do any expensive calculations there because this
will slow down the animation.
Then a counter is incremented and if the counter reaches the
getPulse()
value, then the hookSetValues(int)
method is
called. This is you opportunity to provide a value to the scope by calling
its setValue or setValues method. The hookSetValues method is only called if
the getPulse()
value is greater than NO_PULSE
You can also be called back by the widget if it runs out of values by setting
a listener in the
Oscilloscope#addStackListener(OscilloscopeStackAdapter)
method.
If you want to speed up the scope, try overriding the
getProgression()
method. This will draw the scope this number of
times before actually painting.-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
OscilloscopeDispatcher.SoundClip
Plays a sound clip. -
Field Summary
Fields Modifier and Type Field Description static int[]
BACKGROUND_MONITOR
Contains a small image that can serve as the background of the scope.static int[]
BACKGROUND_MONITOR_SMALL
Contains a small image that can serve as the background of the scope.static int
NO_PULSE
This is a special value indicating there is no pulse which means thathookPulse(Oscilloscope, int)
will never be called. -
Constructor Summary
Constructors Constructor Description OscilloscopeDispatcher()
The default constructor.OscilloscopeDispatcher(int channel)
OscilloscopeDispatcher(int channel, Oscilloscope oscilloscope)
OscilloscopeDispatcher(Oscilloscope oscilloscope)
-
Method Summary
Modifier and Type Method Description void
dispatch()
This method will get the animation going.protected void
finalize()
org.eclipse.swt.graphics.Color
getActiveForegoundColor()
Is used to get the color of the foreground when the thing that the scope is measuring is still alive.java.io.File
getActiveSoundfile()
Override this to return a soundfile that will be played by the dispatcher in thehookPulse(Oscilloscope, int)
method if theisSoundRequired()
method returns true.org.eclipse.swt.graphics.Image
getBackgroundImage()
Override this to return the background image for the scope.int
getBaseOffset()
Override this to set the offset of the scope line in percentages where 100 is the top of the widget and 0 is the bottom.int
getChannel()
Returns the channel that this scope is the dispatcher for.int
getDelayLoop()
Override this to return a draw delay in milliseconds.boolean
getFade()
Tests if the tail must fade.org.eclipse.swt.graphics.Color
getInactiveForegoundColor()
Is used to get the color of the foreground when the thing that the scope is measuring is not active.java.io.File
getInactiveSoundfile()
int
getLineWidth()
Oscilloscope
getOscilloscope()
This method returns theOscilloscope
.int
getProgression()
Override this to set the number of steps that is calculated before it is actually drawn on the display.int
getPulse()
Returns the heart beat of the scope.OscilloscopeDispatcher.SoundClip
getSoundClip()
Override this to return the Clip player.int
getSteadyPosition()
If the scope value must be drawn on a steady position then this method can supply a value.int
getTailFade()
int
getTailSize()
void
hookAfterDraw(Oscilloscope oscilloscope, int counter)
Is called just after the widget is redrawn everygetDelayLoop()
milliseconds.void
hookBeforeDraw(Oscilloscope oscilloscope, int counter)
Is called just before the widget is redrawn everygetDelayLoop()
milliseconds.void
hookChangeAttributes()
This method sets the values in the scope by calling the individual value methods in the dispatcher.void
hookPulse(Oscilloscope oscilloscope, int pulse)
This method is called every time the dispatcher reaches the getPulse() counter.void
hookSetValues(int pulse)
This method will be called everygetPulse()
times the scope is redrawn which will occur everygetDelayLoop()
milliseconds (if your hardware is capable of doing so).void
init()
Will be called only once.boolean
isPercentage()
Indicates if the value that comes in from the scope is a percentage rather than an absolute value.boolean
isRunning()
boolean
isServiceActive()
A helper method to indicate if something that you are measuring is active.boolean
isSoundRequired()
The dispatcher is able to beep and pling and this method helps in indicating if this is required.boolean
isSteady()
boolean
isTailSizeMax()
boolean
mustConnect()
void
setActiveForegoundColor(org.eclipse.swt.graphics.Color color)
Is used to get the color of the foreground when the thing that the scope is measuring is still alive.void
setInactiveForegoundColor(org.eclipse.swt.graphics.Color color)
Is used to get the color of the foreground when the thing that the scope is measuring is still alive.void
setOscilloscope(Oscilloscope scope)
This method sets theOscilloscope
.void
stop()
Will stop the animation.(package private) void
updateBackgroundImage()
-
Field Details
-
BACKGROUND_MONITOR
public static final int[] BACKGROUND_MONITORContains a small image that can serve as the background of the scope. -
BACKGROUND_MONITOR_SMALL
public static final int[] BACKGROUND_MONITOR_SMALLContains a small image that can serve as the background of the scope. -
NO_PULSE
public static final int NO_PULSEThis is a special value indicating there is no pulse which means thathookPulse(Oscilloscope, int)
will never be called.- See Also:
getPulse()
, Constant Field Values
-
-
Constructor Details
-
OscilloscopeDispatcher
public OscilloscopeDispatcher(int channel)- Parameters:
channel
-- See Also:
getChannel()
-
OscilloscopeDispatcher
public OscilloscopeDispatcher()The default constructor. -
OscilloscopeDispatcher
- Parameters:
channel
-oscilloscope
-- See Also:
getChannel()
,getOscilloscope()
-
OscilloscopeDispatcher
- Parameters:
oscilloscope
-- See Also:
getOscilloscope()
-
-
Method Details
-
dispatch
public void dispatch()This method will get the animation going. It will create a runnable that will be dispatched to the user interface thread. The runnable increments a counter that leads to thegetPulse()
value and if this is reached then the counter is reset. The counter is passed to the hook methods so that they can prepare for the next pulse. After the hook methods are called, the runnable is placed in the user interface thread with a timer ofgetDelayLoop()
milliseconds. However, if the delay loop is set to 1, it will dispatch usingDisplay.asyncExec(Runnable)
for maximum speed. This method is not meant to be overridden, overrideinit()
hookBeforeDraw(Oscilloscope, int)
,hookAfterDraw(Oscilloscope, int)
andhookPulse(Oscilloscope, int)
. -
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
getActiveForegoundColor
public org.eclipse.swt.graphics.Color getActiveForegoundColor()Is used to get the color of the foreground when the thing that the scope is measuring is still alive. The aliveness of the thing that is being measured is returned by theisServiceActive()
method. The result of this method will be used in theControl.setForeground(Color)
method.- Returns:
- the system color green.
- See Also:
getInactiveForegoundColor()
,getActiveForegoundColor()
,setActiveForegoundColor(Color)
,Control.setForeground(Color)
-
setActiveForegoundColor
public void setActiveForegoundColor(org.eclipse.swt.graphics.Color color)Is used to get the color of the foreground when the thing that the scope is measuring is still alive. The aliveness of the thing that is being measured is returned by theisServiceActive()
method. The result of this method will be used in theControl.setForeground(Color)
method.- Parameters:
color
- the new color.- See Also:
getInactiveForegoundColor()
,getActiveForegoundColor()
,getActiveForegoundColor()
-
getActiveSoundfile
public java.io.File getActiveSoundfile()Override this to return a soundfile that will be played by the dispatcher in thehookPulse(Oscilloscope, int)
method if theisSoundRequired()
method returns true.- Returns:
null
. Override to return a file that can be played by your sound hardware.
-
getBackgroundImage
public org.eclipse.swt.graphics.Image getBackgroundImage()Override this to return the background image for the scope.- Returns:
- the image stored in
BACKGROUND_MONITOR
. Override to supply your own Image.
-
getBaseOffset
public int getBaseOffset()Override this to set the offset of the scope line in percentages where 100 is the top of the widget and 0 is the bottom.- Returns:
Oscilloscope.BASE_CENTER
which positions in the center. Override for other values.
-
stop
public void stop()Will stop the animation. -
getSoundClip
Override this to return the Clip player. Overriding this method is not expected.- Returns:
- the PlayClip object
-
getDelayLoop
public int getDelayLoop()Override this to return a draw delay in milliseconds. The scope will progressgetProgression()
steps.- Returns:
- 30 milliseconds. Override with a smaller value for more speed.
-
getFade
public boolean getFade()Tests if the tail must fade.- Returns:
- this default implementation returns true
- See Also:
Oscilloscope.setTailFade(int, int)
,getTailSize()
-
getInactiveForegoundColor
public org.eclipse.swt.graphics.Color getInactiveForegoundColor()Is used to get the color of the foreground when the thing that the scope is measuring is not active. The aliveness of the thing that is being measured is returned by theisServiceActive()
method. The result of this method will be used in theControl.setForeground(Color)
method.- Returns:
- the system color red, override if you want to control the inactive foreground color
- See Also:
setInactiveForegoundColor(Color)
,getActiveForegoundColor()
,setActiveForegoundColor(Color)
,Control.setForeground(Color)
-
setInactiveForegoundColor
public void setInactiveForegoundColor(org.eclipse.swt.graphics.Color color)Is used to get the color of the foreground when the thing that the scope is measuring is still alive. The aliveness of the thing that is being measured is returned by theisServiceActive()
method. The result of this method will be used in theControl.setForeground(Color)
method.- Parameters:
color
- the new color.- See Also:
getInactiveForegoundColor()
,getActiveForegoundColor()
,setActiveForegoundColor(Color)
,Control.setForeground(Color)
-
getInactiveSoundfile
public java.io.File getInactiveSoundfile()- Returns:
- this default implementation returns null
-
getLineWidth
public int getLineWidth()- Returns:
- this default implementation returns 1
-
getOscilloscope
This method returns theOscilloscope
.- Returns:
- the oscilloscope
-
isRunning
public boolean isRunning()- Returns:
- true if the dispatcher is running.
- See Also:
dispatch()
,stop()
-
setOscilloscope
This method sets theOscilloscope
.- Parameters:
scope
-
-
getProgression
public int getProgression()Override this to set the number of steps that is calculated before it is actually drawn on the display. This will make the graphic look more jumpy for slower/higher delay rates but you can win speed at faster/lower delay rates. There will begetProgression()
values consumed so make sure that the value stack contains enough entries. If thegetDelayLoop()
is 10 and thegetPulse()
is 1 and thegetProgression()
is 5 then every 10 milliseconds the graph will have progressed 5 pixels. If you want to avoid gaps in your graph, you need to input 5 values every time you reachhookSetValues(int)
. If thegetPulse()
is 3, you need to input 15 values for a gapless graph. Alternatively, you can implement a stack listener in the scope to let it call you in case it runs out of values.- Returns:
- 1. Override and increment for more speed. Must be higher then zero.
-
getPulse
public int getPulse()Returns the heart beat of the scope.- Returns:
- this default implementation returns 1
- See Also:
dispatch()
,getDelayLoop()
,getProgression()
-
getSteadyPosition
public int getSteadyPosition()If the scope value must be drawn on a steady position then this method can supply a value.- Returns:
- the default implementation returns 200
- See Also:
Oscilloscope.setSteady(int, boolean, int)
-
getTailFade
public int getTailFade()- Returns:
- the percentage of the tail that must fade.
- See Also:
Oscilloscope.setTailFade(int, int)
-
getTailSize
public int getTailSize()- Returns:
- the tail size
- See Also:
Oscilloscope.setTailSize(int, int)
-
getChannel
public int getChannel()Returns the channel that this scope is the dispatcher for. Please note that you do not really need one dispatcher per channel.- Returns:
- the channel for this dispatcher. Can be -1 if not set.
-
hookAfterDraw
Is called just after the widget is redrawn everygetDelayLoop()
milliseconds. The pulse counter will be set to zero when it reachesgetPulse()
.- Parameters:
oscilloscope
-counter
-
-
hookBeforeDraw
Is called just before the widget is redrawn everygetDelayLoop()
milliseconds. It will also call thehookChangeAttributes()
method if the number of times this method is called matches thegetPulse()
value. The pulse counter will be set to zero when it reachesgetPulse()
. If you override this method, don't forget to callhookChangeAttributes()
every now and then.- Parameters:
oscilloscope
-counter
-
-
hookChangeAttributes
public void hookChangeAttributes()This method sets the values in the scope by calling the individual value methods in the dispatcher. Be aware that this method actually calls some candy so you might want to call super. -
hookPulse
This method is called every time the dispatcher reaches the getPulse() counter. This method plays the active or inactive sound if so required. If you do not want the sounds to play, either disable sounds by not overriding theisSoundRequired()
method or override this method.- Parameters:
oscilloscope
-pulse
-
-
hookSetValues
public void hookSetValues(int pulse)This method will be called everygetPulse()
times the scope is redrawn which will occur everygetDelayLoop()
milliseconds (if your hardware is capable of doing so). The scope will progress one pixel everygetDelayLoop()
milliseconds and will draw the next value from the queue of the scope. If the scope is out of values it will progress one pixel without a value (draw a pixel at his center). If the delay loop is 10 and the pulse is 20, you have an opportunity to set a value in the scope every 200 milliseconds. In this time the scope will have progressed 20 pixels. If you supply 10 values by calling the setValue(int) 10 times or if you call the setValues(int[]) with 10 ints then you will see 10 pixels of movement and a straight line of 10 pixels. If the setPulse method is not overridden or if you supplyNO_PULSE
then this method will not be called unless you override the dispatch method (not recommended). To still set values in the scope you can set a stack listener in the widget that will be called when there are no more values in the stack. Alternatively you can set the return value ofgetPulse()
to 1 so you have the opportunity to provide a value every cycle.- Parameters:
pulse
-- See Also:
Oscilloscope#setValue(int)
,Oscilloscope#setValues(int[])
,Oscilloscope#addStackListener(OscilloscopeStackAdapter)
-
init
public void init()Will be called only once. -
isPercentage
public boolean isPercentage()Indicates if the value that comes in from the scope is a percentage rather than an absolute value.- Returns:
- the default implementation returns true
- See Also:
Oscilloscope.setPercentage(int, boolean)
-
isServiceActive
public boolean isServiceActive()A helper method to indicate if something that you are measuring is active. Based on the output of this method things can be done, like playing a flat-line sound, changing the foreground color and such.- Returns:
- the default implementation returns true
-
isSoundRequired
public boolean isSoundRequired()The dispatcher is able to beep and pling and this method helps in indicating if this is required.- Returns:
- this default implementation returns false
- See Also:
Oscilloscope.setSteady(int, boolean, int)
-
isSteady
public boolean isSteady()- Returns:
- this default implementation returns false
- See Also:
Oscilloscope.setSteady(int, boolean, int)
-
isTailSizeMax
public boolean isTailSizeMax()- Returns:
- this default implementation returns false.
- See Also:
Oscilloscope.setTailSize(int, int)
-
mustConnect
public boolean mustConnect()- Returns:
- this default implementation returns false
- See Also:
Oscilloscope.setConnect(int, boolean)
-
updateBackgroundImage
void updateBackgroundImage()
-