y.module
Class YModule

java.lang.Object
  |
  +--y.module.YModule
Direct Known Subclasses:
IOHandlerModule, LabelingModule, LayoutModule

public abstract class YModule
extends Object

This abstract class provides a skeleton for algorithms on graphs. It defines an interface for the caller of the the algorithm and provides an mechanism for parameter passing. Modules can be run either in a separate thread or in the actual thread.

Tips how to write your own module:
To write your own graph algorithm you have to overwrite the following methods:

To specify your own options/paramters you have overwrite the createOptionHandler method. Via setExitStatus you can tell the caller how the module succeeded. Via statisticHeaders/statisticInfo statistical information can passed to an evalution autority like an batch processor.


Field Summary
static short FAILED
          Exit state constant.
static short PRECONDITION_VIOLATED
          Exit state constant.
static short SUCCESS
          Exit state constant.
 
Constructor Summary
YModule(String moduleName, String authorName, String description)
          Instantiates a YModule.
 
Method Summary
protected  OptionHandler createOptionHandler()
          Creates an option handler for this class.
protected  void dispose()
          Disposition code performed after the execution of YModule.mainrun() was finished.
protected  void fitGraph2DView()
          Fits the content if the current view is of type Graph2DView.
 String getAuthor()
          Returns the name of this module's author
 String getDescription()
          Returns a short description of what this module does
 short getExitStatus()
          Ask how the the module succeeded.
protected  Graph2D getGraph2D()
          Grants access to the graph2D acted upon.
protected  Graph2DView getGraph2DView()
          Grants access to the current view this module acts upon.
 String getModuleName()
          Returns the name of this module.
 OptionHandler getOptionHandler()
          Returns the option handler of this module.
protected  Timer getTimer()
          Grants access to a timer object associated with this module.
protected  View getView()
          Grants access to the current view this module acts upon.
protected  void init()
          Initialisation code performed before calling YModule.mainrun().
 boolean isAbortable()
          Returns whether or not this module is abortable.
protected abstract  void mainrun()
          Main execution code to be implemented by any subclassed module.
protected  void run()
          Calls the canonic module execution sequence: YModule.init() - YModule.mainrun() - YModule.dispose().
protected  void setExitStatus(short status)
          Sets the exit status of this module.
 void setGraph2D(Graph2D graph)
          Sets the graph being acted upon.
 void setModuleName(String name)
          Sets name of this module.
 void setOptionHandler(OptionHandler oh)
          Sets the option handler for this method.
 void start(Graph2D graph)
          Main module startup routine.
 void startAsThread(Graph2D graph)
          Starts this module as a thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUCCESS

public static final short SUCCESS
Exit state constant. Signals successful termination of this module/

See Also:
Constant Field Values

FAILED

public static final short FAILED
Exit state constant. Signals a failure of this module.

See Also:
Constant Field Values

PRECONDITION_VIOLATED

public static final short PRECONDITION_VIOLATED
Exit state constant. Signals that a precondition for this module was not met.

See Also:
Constant Field Values
Constructor Detail

YModule

public YModule(String moduleName,
               String authorName,
               String description)
Instantiates a YModule. Specify name, author and a short description for this module.

Method Detail

getModuleName

public String getModuleName()
Returns the name of this module.


setModuleName

public void setModuleName(String name)
Sets name of this module.


getAuthor

public String getAuthor()
Returns the name of this module's author


getDescription

public String getDescription()
Returns a short description of what this module does


getTimer

protected Timer getTimer()
Grants access to a timer object associated with this module. Note that the timer does not start automatically when the module is launched.


setGraph2D

public void setGraph2D(Graph2D graph)
Sets the graph being acted upon.


getGraph2D

protected Graph2D getGraph2D()
Grants access to the graph2D acted upon.


getView

protected View getView()
Grants access to the current view this module acts upon.


getGraph2DView

protected Graph2DView getGraph2DView()
Grants access to the current view this module acts upon. Returns null if the current view is not of type Graph2DView.


fitGraph2DView

protected void fitGraph2DView()
Fits the content if the current view is of type Graph2DView.


getOptionHandler

public OptionHandler getOptionHandler()
Returns the option handler of this module. Module writers can provide an option handler by overwriting createOptionHandler. If this module does not provide an option handler null is returned.


createOptionHandler

protected OptionHandler createOptionHandler()
Creates an option handler for this class. Module writers should override this method to provide an appropriate option handler.

Returns:
The option handler for this module, null by default.

setOptionHandler

public void setOptionHandler(OptionHandler oh)
Sets the option handler for this method. One should not use this method with modules that provide their own option handlers, since they depend on a specific option handler configuration.


start

public void start(Graph2D graph)
Main module startup routine. Modules should be always launched by this method.

Parameters:
graph - the graph being acted upon

startAsThread

public void startAsThread(Graph2D graph)
Starts this module as a thread. Modules should specify if they want to launched as a thread.

Parameters:
graph - the graph being acted upon.

isAbortable

public boolean isAbortable()
Returns whether or not this module is abortable. An abortable Module can handle InterruptedExceptions gracefully. By default modules are not abortable.


getExitStatus

public short getExitStatus()
Ask how the the module succeeded. Note that this makes generally only sense after the algorithms has run.

Returns:
One of the values YModule.SUCCESS, YModule.FAILED, or YModule.PRECONDITION_VIOLATED

setExitStatus

protected void setExitStatus(short status)
Sets the exit status of this module. This method should be invoked when the algorithm has finished.

Parameters:
status - One of the values SUCCESS, FAILED AND PRECONDITION_VIOLATED.

init

protected void init()
Initialisation code performed before calling YModule.mainrun().


mainrun

protected abstract void mainrun()
Main execution code to be implemented by any subclassed module.


dispose

protected void dispose()
Disposition code performed after the execution of YModule.mainrun() was finished.


run

protected void run()
Calls the canonic module execution sequence: YModule.init() - YModule.mainrun() - YModule.dispose().


© Copyright 2000-2003,
yWorks GmbH.
All rights reserved.

2003