PamguardMVC
Class PamObservable

java.lang.Object
  extended by PamguardMVC.PamObservable
All Implemented Interfaces:
PanelOverlayDraw
Direct Known Subclasses:
PamDataBlock

public class PamObservable
extends java.lang.Object
implements PanelOverlayDraw

Author:
Doug Gillespie

Similar functionality to the Observable Class, but works with the PamObserver interface which has a bitmore functionality.

e.g. The PamDataBlock, which is the most common class of PamObservable asks the observers what the first required sample is for each observing process or view.


Field Summary
private  double[] cpuPercent
           
private  long[] cpuUsage
           
private static long LARGEST_SAMPLE
           
private  long lastCPUCheckTime
           
private  PamObserver longestObserver
           
protected  long masterClockSample
          Sample numbers are now passed around to all observers.
protected  boolean objectChanged
           
protected  PanelOverlayDraw overlayDraw
          Reference to a class that knows how to draw these things on any of the standard displays in the view, e.g.
protected  java.util.ArrayList<PamObserver> pamObservers
          List of PamObservers
protected  PamProfiler pamProfiler
           
(package private)  javax.swing.Timer t
           
(package private)  long totalCalls
           
 
Constructor Summary
PamObservable()
           
 
Method Summary
 void addObserver(PamObserver o)
          Adds a PamObserver, which will then receive notifications when data is added.
 void addObserver(PamObserver o, boolean reThread)
           
 boolean canDraw(GeneralProjector projectorInfo)
           
 void clearchanged()
          Set flag to say the data have changed
 int countObservers()
           
 PamKeyItem createKeyItem(GeneralProjector generalProjector, int keyType)
          provide a graphics component (probably a JPanel) that can be incorporated into a key panel for maps, and anything else that uses overlay graphics.
 void deleteObserver(PamObserver o)
          Removes an observer from the list
 void deleteObservers()
          Removes all observers from the list
 java.awt.Rectangle drawDataUnit(java.awt.Graphics g, PamDataUnit pamDataUnit, GeneralProjector projectorInfo)
           
 ThreadedObserver findThreadedObserver(PamObserver o)
          Go through the observer list and check inside any that are wrapped in threaded observers,
 double getCPUPercent(int objectIndex)
           
 double getCPUPercent(PamObserver pamObserver)
           
 java.lang.String getHoverText(GeneralProjector generalProjector, PamDataUnit dataUnit, int iSide)
          Provides text for popup hover windows on displays.
 PamObserver getLongestObserver()
           
 java.util.ArrayList<PamObserver> getPamObservers()
           
 long getRequiredHistory()
          Goes through all observers and works out which requires data the longest.
 void notifyObservers()
          Instruction to notify observers that data have changed, but not to send them any information about the new data.
 void notifyObservers(PamDataUnit o)
          Notify observers that data have changed and send them a reference to the new Data
 void setChanged()
          Set flag to say the data have changed
 void setOverlayDraw(PanelOverlayDraw overlayDraw)
           
 boolean waitForThreadedObservers(long timeOutms)
          Go through all the threaded observers and wait for them to finish processing any data remaining in their lists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LARGEST_SAMPLE

private static final long LARGEST_SAMPLE
See Also:
Constant Field Values

pamObservers

protected java.util.ArrayList<PamObserver> pamObservers
List of PamObservers


cpuUsage

private long[] cpuUsage

lastCPUCheckTime

private long lastCPUCheckTime

cpuPercent

private double[] cpuPercent

objectChanged

protected boolean objectChanged

totalCalls

long totalCalls

longestObserver

private PamObserver longestObserver

overlayDraw

protected PanelOverlayDraw overlayDraw
Reference to a class that knows how to draw these things on any of the standard displays in the view, e.g. whistle contours, particular shapes on the map, etc.


pamProfiler

protected PamProfiler pamProfiler

masterClockSample

protected long masterClockSample
Sample numbers are now passed around to all observers.


t

javax.swing.Timer t
Constructor Detail

PamObservable

PamObservable()
Method Detail

addObserver

public void addObserver(PamObserver o)
Adds a PamObserver, which will then receive notifications when data is added. This is for single thread ops only

Parameters:
o - Reference to the observer

addObserver

public void addObserver(PamObserver o,
                        boolean reThread)

findThreadedObserver

public ThreadedObserver findThreadedObserver(PamObserver o)
Go through the observer list and check inside any that are wrapped in threaded observers,

Parameters:
o -
Returns:
reference to threadedobserver.

waitForThreadedObservers

public boolean waitForThreadedObservers(long timeOutms)
Go through all the threaded observers and wait for them to finish processing any data remaining in their lists.

Parameters:
timeOutms - timeout in milliseconds
Returns:
false if the timeout time was reached before all threaded observers had emptied their ques. true if all ques had been emptied successfully.

deleteObserver

public void deleteObserver(PamObserver o)
Removes an observer from the list

Parameters:
o - Observer to remove

deleteObservers

public void deleteObservers()
Removes all observers from the list


countObservers

public int countObservers()
Returns:
Count of PamObservers subscribing to this observable

getPamObservers

public java.util.ArrayList<PamObserver> getPamObservers()

notifyObservers

public void notifyObservers()
Instruction to notify observers that data have changed, but not to send them any information about the new data.


setChanged

public void setChanged()
Set flag to say the data have changed


clearchanged

public void clearchanged()
Set flag to say the data have changed


notifyObservers

public void notifyObservers(PamDataUnit o)
Notify observers that data have changed and send them a reference to the new Data

Parameters:
o - Reference to the new PamDataUnit

getCPUPercent

public double getCPUPercent(int objectIndex)

getCPUPercent

public double getCPUPercent(PamObserver pamObserver)

getRequiredHistory

public long getRequiredHistory()
Goes through all observers and works out which requires data the longest.

Returns:
Required data storage time in milliseconds.

getLongestObserver

public PamObserver getLongestObserver()

setOverlayDraw

public void setOverlayDraw(PanelOverlayDraw overlayDraw)
Parameters:
overlayDraw - Instance of a concrete class implementing the PanelIverlayDraw interface.

Called to set the class which can draw overlays of the PamDataUnits held in this data block.


drawDataUnit

public java.awt.Rectangle drawDataUnit(java.awt.Graphics g,
                                       PamDataUnit pamDataUnit,
                                       GeneralProjector projectorInfo)
Specified by:
drawDataUnit in interface PanelOverlayDraw
Parameters:
g - An awt Graphics object

projectorInfo - Class implementing GeneralProjector which can convert data to screen coordinates.

pamDataUnit - PamDataUnit to draw
Returns:
a rectangle containing the pixels which will need to be invalidated or redrawn by the calling process

Any PamObserver which has been notified by a PamObservable that a new PamDatUnit has been created can call this function to draw some arbitrary shape on the image, e.g. a whistle contour, a picture of a whale, etc.

This should be overridden in the concrete class if it is to do anything.


canDraw

public boolean canDraw(GeneralProjector projectorInfo)
Specified by:
canDraw in interface PanelOverlayDraw
Returns:
Returns whether or not the object can be drawn using the given projector. The implementation of CanDraw should examine the parameter types in GeneralProjector and check that it will know how to prvide those parameters before returning true, or false otherwise.

getHoverText

public java.lang.String getHoverText(GeneralProjector generalProjector,
                                     PamDataUnit dataUnit,
                                     int iSide)
Description copied from interface: PanelOverlayDraw
Provides text for popup hover windows on displays.

Specified by:
getHoverText in interface PanelOverlayDraw
Parameters:
generalProjector - Projector associated with the display requiring the text
dataUnit - Data unit the mouse hovered over
Returns:
Text to display

createKeyItem

public PamKeyItem createKeyItem(GeneralProjector generalProjector,
                                int keyType)
Description copied from interface: PanelOverlayDraw
provide a graphics component (probably a JPanel) that can be incorporated into a key panel for maps, and anything else that uses overlay graphics.

Since multiple keys may be created in various displays, new ones should normally be created each time this is called.

The GeneralProjector reference is passed as a parameter since the type of symbol or shape drawn on a particular plot may depend on the type of coordinate system. For example, whistles are drawn as a contour on the spectrogram display, but as a point (PamSymbol) on the map.

It is possible that some PanelOverlayDraw implementations will be rather complicated and the keys consequently quite large. The extendedKey parameter may therefore be used to draw a full or a cut down version of the key. It is expected that most implementations will ignore this parameter !

Specified by:
createKeyItem in interface PanelOverlayDraw
Parameters:
generalProjector - Reference to a GeneralProjector responsible for drawing with the PAnelOverlayDraw implementation
keyType - Draw a more complicated key, giving more detail
Returns:
java.awt compnent (usually a JPanel).
See Also:
WhistleGraphics, PamSymbol