edu.uci.ics.jung.visualization
Class DefaultVisualizationModel

java.lang.Object
  extended by edu.uci.ics.jung.visualization.DefaultVisualizationModel
All Implemented Interfaces:
ChangeEventSupport, VisualizationModel

public class DefaultVisualizationModel
extends Object
implements VisualizationModel, ChangeEventSupport

The model containing state values for visualizations of graphs. Refactored and extracted from the 1.6.0 version of VisualizationViewer

Author:
Tom Nelson

Nested Class Summary
protected  class DefaultVisualizationModel.VisRunner
          the relaxer thread that applies the Layout algorithm to the graph
 
Field Summary
protected  ChangeListener changeListener
           
protected  Layout layout
          the layout algorithm currently in use
 Object pauseObject
           
protected  long relaxerThreadSleepTime
          how long the relaxer thread pauses between iteration loops.
protected  StatusCallback statusCallback
          a callback called during relaxer iteration
 
Constructor Summary
DefaultVisualizationModel(Layout layout)
           
DefaultVisualizationModel(Layout layout, Dimension d)
           
 
Method Summary
 void addChangeListener(ChangeListener l)
          Adds a ChangeListener.
protected  double average(long[] paintTimes)
          Returns the double average of a number of long values.
 void fireStateChanged()
          Notifies all listeners that have registered interest for notification on this event type.
 ChangeListener[] getChangeListeners()
          Returns an array of all the ChangeListeners added with addChangeListener().
 Layout getGraphLayout()
          Returns the current graph layout.
 long getRelaxerThreadSleepTime()
          Returns the time between iterations of the Relaxer thread.
 void init()
          Pre-relaxes and starts a visRunner thread
 boolean isVisRunnerRunning()
          Returns a flag that says whether the visRunner thread is running.
 void prerelax()
          Runs the visualization forward a few hundred iterations (for half a second)
 void removeChangeListener(ChangeListener l)
          Removes a ChangeListener.
 void restart()
          Restarts layout, then calls init();
 void restartThreadOnly()
          starts a visRunner thread without prerelaxing
 void setGraphLayout(Layout layout)
          set the graph Layout and if it is not already initialized, initialize it to the default VisualizationViewer preferred size of 600x600
 void setGraphLayout(Layout layout, Dimension viewSize)
          Removes the current graph layout, and adds a new one.
 void setRelaxerThreadSleepTime(long relaxerThreadSleepTime)
          Sets the relaxerThreadSleepTime.
 void setTextCallback(StatusCallback scb)
          set a callback to be called during the relaxer iteration
 void start()
          If the visualization runner is not yet running, kick it off.
 void stop()
          set a flag to stop the VisRunner relaxer thread
 void suspend()
          set a flag to suspend the relaxer thread
 void unsuspend()
          un-set the suspend flag for the relaxer thead
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

statusCallback

protected StatusCallback statusCallback
a callback called during relaxer iteration


layout

protected Layout layout
the layout algorithm currently in use


relaxerThreadSleepTime

protected long relaxerThreadSleepTime
how long the relaxer thread pauses between iteration loops.


changeListener

protected ChangeListener changeListener

pauseObject

public Object pauseObject
Constructor Detail

DefaultVisualizationModel

public DefaultVisualizationModel(Layout layout)
Parameters:
layout - The Layout to apply, with its associated Graph

DefaultVisualizationModel

public DefaultVisualizationModel(Layout layout,
                                 Dimension d)
Parameters:
layout -
d - The preferred size of the View that will display this graph
Method Detail

getRelaxerThreadSleepTime

public long getRelaxerThreadSleepTime()
Returns the time between iterations of the Relaxer thread. The Relaxer thread sleeps for a moment before calling the Layout to update again. This tells how long the current delay is. The default, 20 milliseconds, essentially causes the system to run the next iteration with virtually no pause.

Specified by:
getRelaxerThreadSleepTime in interface VisualizationModel
Returns:
Returns the relaxerThreadSleepTime.

setRelaxerThreadSleepTime

public void setRelaxerThreadSleepTime(long relaxerThreadSleepTime)
Sets the relaxerThreadSleepTime.

Specified by:
setRelaxerThreadSleepTime in interface VisualizationModel
Parameters:
relaxerThreadSleepTime - The relaxerThreadSleepTime to set.
See Also:
getRelaxerThreadSleepTime()

setGraphLayout

public void setGraphLayout(Layout layout,
                           Dimension viewSize)
Removes the current graph layout, and adds a new one.

Specified by:
setGraphLayout in interface VisualizationModel
Parameters:
layout - the new layout to use
viewSize - the size of the View that will display this layout

setGraphLayout

public void setGraphLayout(Layout layout)
set the graph Layout and if it is not already initialized, initialize it to the default VisualizationViewer preferred size of 600x600

Specified by:
setGraphLayout in interface VisualizationModel

getGraphLayout

public Layout getGraphLayout()
Returns the current graph layout.

Specified by:
getGraphLayout in interface VisualizationModel

restartThreadOnly

public void restartThreadOnly()
starts a visRunner thread without prerelaxing

Specified by:
restartThreadOnly in interface VisualizationModel

init

public void init()
Pre-relaxes and starts a visRunner thread

Specified by:
init in interface VisualizationModel

restart

public void restart()
Restarts layout, then calls init();

Specified by:
restart in interface VisualizationModel

prerelax

public void prerelax()
Runs the visualization forward a few hundred iterations (for half a second)

Specified by:
prerelax in interface VisualizationModel

start

public void start()
If the visualization runner is not yet running, kick it off.

Specified by:
start in interface VisualizationModel

suspend

public void suspend()
set a flag to suspend the relaxer thread

Specified by:
suspend in interface VisualizationModel

unsuspend

public void unsuspend()
un-set the suspend flag for the relaxer thead

Specified by:
unsuspend in interface VisualizationModel

isVisRunnerRunning

public boolean isVisRunnerRunning()
Returns a flag that says whether the visRunner thread is running. If it is not, then you may need to restart the thread.

Specified by:
isVisRunnerRunning in interface VisualizationModel

average

protected double average(long[] paintTimes)
Returns the double average of a number of long values.

Parameters:
paintTimes - an array of longs
Returns:
the average of the doubles

setTextCallback

public void setTextCallback(StatusCallback scb)
Description copied from interface: VisualizationModel
set a callback to be called during the relaxer iteration

Specified by:
setTextCallback in interface VisualizationModel
Parameters:
scb -

stop

public void stop()
set a flag to stop the VisRunner relaxer thread

Specified by:
stop in interface VisualizationModel

addChangeListener

public void addChangeListener(ChangeListener l)
Adds a ChangeListener.

Specified by:
addChangeListener in interface ChangeEventSupport
Specified by:
addChangeListener in interface VisualizationModel
Parameters:
l - the listener to be added

removeChangeListener

public void removeChangeListener(ChangeListener l)
Removes a ChangeListener.

Specified by:
removeChangeListener in interface ChangeEventSupport
Specified by:
removeChangeListener in interface VisualizationModel
Parameters:
l - the listener to be removed

getChangeListeners

public ChangeListener[] getChangeListeners()
Returns an array of all the ChangeListeners added with addChangeListener().

Specified by:
getChangeListeners in interface ChangeEventSupport
Specified by:
getChangeListeners in interface VisualizationModel
Returns:
all of the ChangeListeners added or an empty array if no listeners have been added

fireStateChanged

public void fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created. The primary listeners will be views that need to be repainted because of changes in this model instance

Specified by:
fireStateChanged in interface ChangeEventSupport
See Also:
EventListenerList