org.pzgui
Class PZManager

java.lang.Object
  extended by java.lang.Thread
      extended by org.pzgui.PZManager
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
PZLayoutManager

public class PZManager
extends java.lang.Thread

Manages a GUI consisting of multiple windows which each may each view the scene from a different perspective.

Author:
David Underhill

Nested Class Summary
static class PZManager.LayoutableInfo
          Information used to describe a Layoutable when it is serialized.
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  java.util.concurrent.ConcurrentHashMap<java.lang.Long,PZManager.LayoutableInfo> layoutablePositions
          where layout positions from a file is saved
protected  java.util.Vector<PZWindow> windows
          windows which are displaying the scene
static org.ho.yaml.YamlConfig YAML
          the Yaml configuration
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
PZManager()
           
 
Method Summary
 void addClosingListener(PZClosing c)
          adds a listener to be notified when the manager is terminating
 void addDrawable(Drawable d)
          Add a new entity to draw on the GUI.
 void addDrawableEventListener(DrawableEventListener del)
          adds a listener to be notified when the traffic matrix has changed
 void addWindow(int screenX, int screenY, int width, int height, int drawOffsetX, int drawOffsetY, float zoom)
          adds a new display window in a thread-safe way
 void attachWindow(PZWindow w)
          Calls attchWindow(w, true).
 void attachWindow(PZWindow w, boolean addDefaultEventListener)
          Attach an existing window to this manager.
 void closeWindow(PZWindow w)
          Cleans up after a window which is closing.
 void dehover()
          Clears any hovered state
 void deselect()
          Clears any selection
 void displayIcon(Icon icon, int duration_msec, float scale)
          Display icon for duration_msec scaled by scale at the curret mouse location.
 void displayIcon(Icon icon, int duration_msec, float scale, int x, int y)
          Display icon for duration_msec scaled by scale at the specified location.
 void displayIcon(java.lang.String s, int duration_msec)
          Display text for duration_msec at the default size and the curret mouse location.
 void displayIcon(java.lang.String s, int duration_msec, int sz)
          Display text for duration_msec at the specified size and the curret mouse location.
 void displayIcon(java.lang.String s, int duration_msec, int sz, int x, int y)
          Display text for duration_msec scaled by scale at the specified location.
protected  void drawBeforeObject(java.awt.Graphics2D gfx, Drawable d)
          Calls the drawBeforeObject(gfx) method on d.
protected  void drawObject(java.awt.Graphics2D gfx, Drawable d)
          Calls the drawObject(gfx) method on d.
 void fireDrawableEvent(Drawable d, java.awt.AWTEvent e, java.lang.String event)
          Updates the slider labels and notify those listening for traffic matrix changes.
 Drawable getHovered()
          Returns the currently hovered object, if any
 java.lang.String getLastConfigFilename()
          returns the last configuration file loaded or saved
 long getMouseDownTime()
          Gets how long the mouse has been down
 Vector2i getMousePos()
          Gets the current position of the mouse
 Vector2i getMouseStartPos()
          Gets the position of the mouse when mouse down was depressed
 Drawable getSelected()
          Returns the currently selected object, if any
 double getTargetFPS()
          Returns the target FPS
 int getWindowIndex(PZWindow frame)
          Returns the internal index of the frame specified.
 void hover(Drawable d)
          Sets that the specified object is being hovered over
 void loadDrawablePositionsFromFile(java.lang.String file)
          Loads positions for Layoutable objects from a file.
 void noteMouseUp()
          Account for a mouse up event
protected  void postRedraw()
          This method is called after each redraw.
protected  void preRedraw(PZWindow window)
          This method is called before each redraw.
 void redraw(PZWindow window)
          Redraw the scene on the specified display.
 void removeClosingListener(PZClosing c)
          removes the specified closing listener
 void removeDrawable(Drawable d)
          Stop drawing the specified entity.
 void removeDrawableEventListener(DrawableEventListener del)
          removes the specified traffic matrix change listener
 void run()
          Continuously redraws the windows at the desired interval.
 void saveDrawablePositionsToFile(java.lang.String file)
          Saves positions for Layoutable objects to a file.
 void select(Drawable d)
          Selects the specified object
 void select(int x, int y)
          Selects the object at the specified coordinates, if any
 Drawable selectFrom(int x, int y)
          Returns the Drawable which contains the location x, y.
 Drawable selectFrom(int x, int y, DrawableFilter filter)
          Returns the object of type C which contains the location x, y.
 void setDrawOrder(java.util.Collection<java.lang.Class> newOrder)
          Sets the default ordering of entity objects.
 void setMousePos(int x, int y, boolean dragging)
          Sets the current position of the mouse and whether dragging is going on.
 void setTargetFPS(double fps)
          Sets the target FPS
 boolean wasDoubleClick()
          Get whether the last click was of a double-click
 void windowResized(PZWindow window)
          This is called when a window is resized.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

windows

protected final java.util.Vector<PZWindow> windows
windows which are displaying the scene


YAML

public static final org.ho.yaml.YamlConfig YAML
the Yaml configuration


layoutablePositions

protected java.util.concurrent.ConcurrentHashMap<java.lang.Long,PZManager.LayoutableInfo> layoutablePositions
where layout positions from a file is saved

Constructor Detail

PZManager

public PZManager()
Method Detail

addWindow

public void addWindow(int screenX,
                      int screenY,
                      int width,
                      int height,
                      int drawOffsetX,
                      int drawOffsetY,
                      float zoom)
adds a new display window in a thread-safe way


attachWindow

public void attachWindow(PZWindow w)
Calls attchWindow(w, true).


attachWindow

public void attachWindow(PZWindow w,
                         boolean addDefaultEventListener)
Attach an existing window to this manager. This registers event callbacks with the window to notify the manager of relevant events. If addDefaultEventListener is true, then a new PZWindowEventListener is setup for w.


closeWindow

public void closeWindow(PZWindow w)
Cleans up after a window which is closing. Terminates the application if no windows are left.


getWindowIndex

public int getWindowIndex(PZWindow frame)
Returns the internal index of the frame specified.

Parameters:
frame - the frame to get the index of (may change over time)

windowResized

public void windowResized(PZWindow window)
This is called when a window is resized. This implementation does nothing but is here for subclasses to override.


addClosingListener

public void addClosingListener(PZClosing c)
adds a listener to be notified when the manager is terminating


removeClosingListener

public void removeClosingListener(PZClosing c)
removes the specified closing listener


addDrawable

public void addDrawable(Drawable d)
Add a new entity to draw on the GUI.

Parameters:
d - the entity to start drawing

removeDrawable

public void removeDrawable(Drawable d)
Stop drawing the specified entity.

Parameters:
d - the entity to stop drawing

setDrawOrder

public void setDrawOrder(java.util.Collection<java.lang.Class> newOrder)
Sets the default ordering of entity objects. The existing entities will be resorted into the new ordering.

Parameters:
newOrder - The new order, with the first class specified being the class of objects drawn on top (e.g. drawn last).

getLastConfigFilename

public java.lang.String getLastConfigFilename()
returns the last configuration file loaded or saved


loadDrawablePositionsFromFile

public void loadDrawablePositionsFromFile(java.lang.String file)
Loads positions for Layoutable objects from a file.

Parameters:
file - the filename to load from

saveDrawablePositionsToFile

public void saveDrawablePositionsToFile(java.lang.String file)
Saves positions for Layoutable objects to a file.

Parameters:
file - the filename to save to

displayIcon

public void displayIcon(Icon icon,
                        int duration_msec,
                        float scale)
Display icon for duration_msec scaled by scale at the curret mouse location.

Parameters:
icon - the icon to draw
duration_msec - how long to display it
scale - scaling factor

displayIcon

public void displayIcon(Icon icon,
                        int duration_msec,
                        float scale,
                        int x,
                        int y)
Display icon for duration_msec scaled by scale at the specified location.

Parameters:
icon - the icon to draw
duration_msec - how long to display it
scale - scaling factor
x - x location of the icon
y - y location of the icon

displayIcon

public void displayIcon(java.lang.String s,
                        int duration_msec)
Display text for duration_msec at the default size and the curret mouse location.

Parameters:
s - the string to draw
duration_msec - how long to display it

displayIcon

public void displayIcon(java.lang.String s,
                        int duration_msec,
                        int sz)
Display text for duration_msec at the specified size and the curret mouse location.

Parameters:
s - the string to draw
duration_msec - how long to display it
sz - font size

displayIcon

public void displayIcon(java.lang.String s,
                        int duration_msec,
                        int sz,
                        int x,
                        int y)
Display text for duration_msec scaled by scale at the specified location.

Parameters:
s - the string to draw
duration_msec - how long to display it
sz - font size

run

public void run()
Continuously redraws the windows at the desired interval.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

preRedraw

protected void preRedraw(PZWindow window)
This method is called before each redraw.


postRedraw

protected void postRedraw()
This method is called after each redraw. This implementation is a no-op but derived classes may override it to do something after each redraw.


redraw

public void redraw(PZWindow window)
Redraw the scene on the specified display.

Parameters:
window - the display which is to be redrawn

drawBeforeObject

protected void drawBeforeObject(java.awt.Graphics2D gfx,
                                Drawable d)
Calls the drawBeforeObject(gfx) method on d. This method is simply present so it can be overriden to extend how the drawing of individual Drawables is done.


drawObject

protected void drawObject(java.awt.Graphics2D gfx,
                          Drawable d)
Calls the drawObject(gfx) method on d. This method is simply present so it can be overriden to extend how the drawing of individual Drawables is done.


getTargetFPS

public double getTargetFPS()
Returns the target FPS


setTargetFPS

public void setTargetFPS(double fps)
Sets the target FPS


getMouseStartPos

public Vector2i getMouseStartPos()
Gets the position of the mouse when mouse down was depressed


getMousePos

public Vector2i getMousePos()
Gets the current position of the mouse


getMouseDownTime

public long getMouseDownTime()
Gets how long the mouse has been down


noteMouseUp

public void noteMouseUp()
Account for a mouse up event


setMousePos

public void setMousePos(int x,
                        int y,
                        boolean dragging)
Sets the current position of the mouse and whether dragging is going on. Also track which object is being hovered over.


wasDoubleClick

public boolean wasDoubleClick()
Get whether the last click was of a double-click


getSelected

public Drawable getSelected()
Returns the currently selected object, if any


deselect

public void deselect()
Clears any selection


select

public void select(Drawable d)
Selects the specified object


select

public void select(int x,
                   int y)
Selects the object at the specified coordinates, if any


selectFrom

public Drawable selectFrom(int x,
                           int y)
Returns the Drawable which contains the location x, y. If no such object exists, then null is returned.

Parameters:
x - x position the drawable must contain
y - y position the drawable must contain
Returns:
the drawable at the specified position

selectFrom

public Drawable selectFrom(int x,
                           int y,
                           DrawableFilter filter)
Returns the object of type C which contains the location x, y. If no such object exists, then null is returned.

Parameters:
x - x position the Drawable must contain
y - y position the Drawable must contain
filter - a Drawable filter; only nodes for which filter.consider() returns true will be considered for selection. If this filter is null, then all nodes will be considered.
Returns:
the Drawable at the specified position

getHovered

public Drawable getHovered()
Returns the currently hovered object, if any


dehover

public void dehover()
Clears any hovered state


hover

public void hover(Drawable d)
Sets that the specified object is being hovered over


addDrawableEventListener

public void addDrawableEventListener(DrawableEventListener del)
adds a listener to be notified when the traffic matrix has changed


removeDrawableEventListener

public void removeDrawableEventListener(DrawableEventListener del)
removes the specified traffic matrix change listener


fireDrawableEvent

public void fireDrawableEvent(Drawable d,
                              java.awt.AWTEvent e,
                              java.lang.String event)
Updates the slider labels and notify those listening for traffic matrix changes.