org.jscience.architecture.traffic
Class Controller

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by org.jscience.architecture.traffic.Controller
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, XMLSerializable
Direct Known Subclasses:
EditController, SimController

public abstract class Controller
extends java.awt.Frame
implements XMLSerializable

The main controller of the application . It starts the user interface and takes care of interaction with the user.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Frame
java.awt.Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  ConfigDialog configDialog
          The configuration dialog
protected  java.lang.String currentFilename
          The name of the currently opened file, as used by 'Save'
protected  Selection currentSelection
          The current selection on the main view
protected  Tool currentTool
          The currently selected tool
protected static HelpViewer helpViewer
          Provides the online help system.
protected static Controller mainController
          The controller that started the app
protected  Model model
          The Model (needed to change its observers)
protected  Settings settings
          The current settings
protected  java.awt.Label statusBar
          The statusbar (positioned at the bottom of the frame)
protected  TrafficToolBar toolBar
          The toolbar of this controller
protected  java.awt.Panel toolPanel
          DOCUMENT ME!
protected  MainView view
          The MainView showing the model, controlled by this Controller
protected  ViewScroller viewScroller
          ViewScroller that holds the view
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Controller(Model m, boolean splash)
          Constructs a new Controller.
 
Method Summary
protected abstract  java.lang.String appName()
          DOCUMENT ME!
 void changeTool(Tool t)
          Changes the current tool
protected abstract  java.awt.MenuBar createMenuBar()
          DOCUMENT ME!
protected abstract  TrafficToolBar createToolBar()
          DOCUMENT ME!
protected abstract  void doLoad(java.lang.String filename)
          Load state from disk.
protected abstract  void doSave(java.lang.String filename)
          Save the current state to disk.
 ConfigDialog getConfigDialog()
          Returns the configuration dialog
 Selection getCurrentSelection()
          Returns the current selection
 Tool getCurrentTool()
          Returns the current tool
static Controller getMainController()
          Returns the main controller
 Model getModel()
          Returns the current model
abstract  java.awt.PopupMenu getPopupMenuFor(Selectable obj)
          DOCUMENT ME!
 java.lang.String getStatus()
          Returns the text on the status bar
 java.awt.Panel getToolPanel()
          Returns the current tool panel
 View getView()
          Returns the current View
 ViewScroller getViewScroller()
          Returns the container of the view
 java.lang.String getXMLName()
          DOCUMENT ME!
 boolean isViewEnabled()
          Returns true if the view is currently enabled
 void load(XMLElement myElement, XMLLoader loader)
          Load this XMLSerializable
protected  void loadAll(XMLLoader loader, Model model)
          Loads a model,the current view and the current controller from a XMLLoader
 void newFile()
           
 void newInfrastructure(Infrastructure infra)
          Set a new infrastructure
 void openFile()
          User wants to load a file
 void quit()
          User wants to quit
static void reportError(java.lang.Throwable e)
          Reports unsuspected errors
protected  void resizeComponents()
          Resizes all Components in the frame to make them all fit.
protected  void saveAll(XMLSaver saver, Model model)
          Saves a model,the current view and the current controller to a XMLSaver
 void saveChilds(XMLSaver saver)
          DOCUMENT ME!
 void saveFile()
          User wants to save
 void saveFileAs()
          User wants to save file as...
 XMLElement saveSelf()
          DOCUMENT ME!
 void setConfigDialog(ConfigDialog cd)
          Sets the configuration dialog
 void setCurrentFilename(java.lang.String name)
          Sets name to be the currently opened file.
 void setCurrentSelection(Selection s)
          Sets thec current selection
 void setCurrentTool(Tool t)
          Sets the current tool
static void setMainController(Controller c)
          Sets the main controller
 void setParentName(java.lang.String parentName)
          DOCUMENT ME!
 void setStatus(java.lang.String s)
          Sets the text on the status bar
 void setToolPanel(java.awt.Panel p)
          Sets the current tool panel
 void setViewEnabled(boolean b)
          Sets visibility of View
 void showConfigDialog()
          Shows the configuration dialog
 void showError(java.lang.String msg)
          Shows an error dialog.
abstract  void showFilePropertiesDialog()
          DOCUMENT ME!
 void showHelp(int helpItem)
          Opens a help HTML-page.
protected  java.lang.String showSaveAsDialog()
          Shows the 'Save as...' dialog and returns the filename chosen
 void showSettings()
          Shows the configuration dialog with the general panel.
 void switchConfigDialog()
          Shows the configuration dialog if it is hidden, hides it, if it is currently showing
protected  void tryLoad(java.lang.String filename)
          Try to load a file, process exceptions
protected  void trySave(java.lang.String filename)
          Try to save file , process exceptions
 boolean validateInfra()
          Runs the validator on the current infrastructure
protected  void zoomChanged()
          DOCUMENT ME!
 void zoomIn(java.awt.Point p)
          Zooms the main view one step in
 void zoomOut(java.awt.Point p)
          Zooms the main view one step out
 void zoomTo(int index)
          Zooms the main view to the specified zoom factor index
 
Methods inherited from class java.awt.Frame
addNotify, getAccessibleContext, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, paramString, remove, removeNotify, setCursor, setExtendedState, setIconImage, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

helpViewer

protected static HelpViewer helpViewer
Provides the online help system.


mainController

protected static Controller mainController
The controller that started the app


model

protected Model model
The Model (needed to change its observers)


view

protected MainView view
The MainView showing the model, controlled by this Controller


viewScroller

protected ViewScroller viewScroller
ViewScroller that holds the view


toolBar

protected TrafficToolBar toolBar
The toolbar of this controller


toolPanel

protected java.awt.Panel toolPanel
DOCUMENT ME!


statusBar

protected java.awt.Label statusBar
The statusbar (positioned at the bottom of the frame)


settings

protected Settings settings
The current settings


currentTool

protected Tool currentTool
The currently selected tool


currentFilename

protected java.lang.String currentFilename
The name of the currently opened file, as used by 'Save'


currentSelection

protected Selection currentSelection
The current selection on the main view


configDialog

protected ConfigDialog configDialog
The configuration dialog

Constructor Detail

Controller

public Controller(Model m,
                  boolean splash)
Constructs a new Controller. Initializes the whole frame and it components.

Parameters:
m - The Model to control.
splash - DOCUMENT ME!
Method Detail

getConfigDialog

public ConfigDialog getConfigDialog()
Returns the configuration dialog

Returns:
DOCUMENT ME!

setConfigDialog

public void setConfigDialog(ConfigDialog cd)
Sets the configuration dialog

Parameters:
cd - DOCUMENT ME!

getMainController

public static Controller getMainController()
Returns the main controller

Returns:
DOCUMENT ME!

setMainController

public static void setMainController(Controller c)
Sets the main controller

Parameters:
c - DOCUMENT ME!

getToolPanel

public java.awt.Panel getToolPanel()
Returns the current tool panel

Returns:
DOCUMENT ME!

setToolPanel

public void setToolPanel(java.awt.Panel p)
Sets the current tool panel

Parameters:
p - DOCUMENT ME!

getCurrentSelection

public Selection getCurrentSelection()
Returns the current selection

Returns:
DOCUMENT ME!

setCurrentSelection

public void setCurrentSelection(Selection s)
Sets thec current selection

Parameters:
s - DOCUMENT ME!

getCurrentTool

public Tool getCurrentTool()
Returns the current tool

Returns:
DOCUMENT ME!

getModel

public Model getModel()
Returns the current model

Returns:
DOCUMENT ME!

setCurrentTool

public void setCurrentTool(Tool t)
Sets the current tool

Parameters:
t - DOCUMENT ME!

getView

public View getView()
Returns the current View

Returns:
DOCUMENT ME!

getViewScroller

public ViewScroller getViewScroller()
Returns the container of the view

Returns:
DOCUMENT ME!

getStatus

public java.lang.String getStatus()
Returns the text on the status bar

Returns:
DOCUMENT ME!

setStatus

public void setStatus(java.lang.String s)
Sets the text on the status bar

Parameters:
s - DOCUMENT ME!

setViewEnabled

public void setViewEnabled(boolean b)
Sets visibility of View

Parameters:
b - DOCUMENT ME!

isViewEnabled

public boolean isViewEnabled()
Returns true if the view is currently enabled

Returns:
DOCUMENT ME!

setCurrentFilename

public void setCurrentFilename(java.lang.String name)
Sets name to be the currently opened file.

Parameters:
name - DOCUMENT ME!

quit

public void quit()
User wants to quit


resizeComponents

protected void resizeComponents()
Resizes all Components in the frame to make them all fit.


showError

public void showError(java.lang.String msg)
Shows an error dialog.

Parameters:
msg - The message to be shown.

showHelp

public void showHelp(int helpItem)
Opens a help HTML-page.

Parameters:
helpItem - The specified item to be opened. (One of defined 'HelpViewer.HELP_xxx' constants.)

switchConfigDialog

public void switchConfigDialog()
Shows the configuration dialog if it is hidden, hides it, if it is currently showing


showConfigDialog

public void showConfigDialog()
Shows the configuration dialog


showSettings

public void showSettings()
Shows the configuration dialog with the general panel.


reportError

public static void reportError(java.lang.Throwable e)
Reports unsuspected errors

Parameters:
e - DOCUMENT ME!

zoomTo

public void zoomTo(int index)
Zooms the main view to the specified zoom factor index

Parameters:
index - DOCUMENT ME!

zoomIn

public void zoomIn(java.awt.Point p)
Zooms the main view one step in

Parameters:
p - DOCUMENT ME!

zoomOut

public void zoomOut(java.awt.Point p)
Zooms the main view one step out

Parameters:
p - The Point to be centered at after zoom out

zoomChanged

protected void zoomChanged()
DOCUMENT ME!


validateInfra

public boolean validateInfra()
Runs the validator on the current infrastructure

Returns:
DOCUMENT ME!

newInfrastructure

public void newInfrastructure(Infrastructure infra)
Set a new infrastructure

Parameters:
infra - DOCUMENT ME!

changeTool

public void changeTool(Tool t)
Changes the current tool

Parameters:
t - DOCUMENT ME!

newFile

public void newFile()

openFile

public void openFile()
User wants to load a file


saveFileAs

public void saveFileAs()
User wants to save file as...


saveFile

public void saveFile()
User wants to save


tryLoad

protected void tryLoad(java.lang.String filename)
Try to load a file, process exceptions

Parameters:
filename - The name of the file to load from

trySave

protected void trySave(java.lang.String filename)
Try to save file , process exceptions

Parameters:
filename - The name of the file to save to

showSaveAsDialog

protected java.lang.String showSaveAsDialog()
Shows the 'Save as...' dialog and returns the filename chosen

Returns:
DOCUMENT ME!

doLoad

protected abstract void doLoad(java.lang.String filename)
                        throws InvalidFilenameException,
                               java.lang.Exception
Load state from disk. Return true upon success.

Parameters:
filename - DOCUMENT ME!
Throws:
InvalidFilenameException - DOCUMENT ME!
java.lang.Exception - DOCUMENT ME!

doSave

protected abstract void doSave(java.lang.String filename)
                        throws InvalidFilenameException,
                               java.lang.Exception
Save the current state to disk. Return true upon success.

Parameters:
filename - DOCUMENT ME!
Throws:
InvalidFilenameException - DOCUMENT ME!
java.lang.Exception - DOCUMENT ME!

loadAll

protected void loadAll(XMLLoader loader,
                       Model model)
                throws java.io.IOException,
                       XMLTreeException,
                       XMLInvalidInputException
Loads a model,the current view and the current controller from a XMLLoader

Parameters:
loader - The loader to load everything from
model - The model to load
Throws:
java.io.IOException - DOCUMENT ME!
XMLTreeException - DOCUMENT ME!
XMLInvalidInputException - DOCUMENT ME!

saveAll

protected void saveAll(XMLSaver saver,
                       Model model)
                throws java.io.IOException,
                       XMLTreeException,
                       XMLCannotSaveException
Saves a model,the current view and the current controller to a XMLSaver

Parameters:
saver - The XMLSaver to save everything to
model - The model to save
Throws:
java.io.IOException - DOCUMENT ME!
XMLTreeException - DOCUMENT ME!
XMLCannotSaveException - DOCUMENT ME!

load

public void load(XMLElement myElement,
                 XMLLoader loader)
          throws XMLTreeException,
                 java.io.IOException,
                 XMLInvalidInputException
Description copied from interface: XMLSerializable
Load this XMLSerializable

Specified by:
load in interface XMLSerializable
Parameters:
myElement - The XMLElement which represents this object in the XML tree. It can contain attributes which hold information about the object.
loader - The XMLLoader which this XMLSerializable can use to load child objects.
Throws:
XMLTreeException - The parser can throw this exception if it is called by the XMLSerializable. The XMLSerializable should NOT throw this exception by itself and preferrably not catch it too.
java.io.IOException - Thrown in case of an read error in the XML file.
XMLInvalidInputException - The XMLSerializable can throw this exception if it cannot load itself or one of its child objects for whatever reason.

saveSelf

public XMLElement saveSelf()
                    throws XMLCannotSaveException
DOCUMENT ME!

Specified by:
saveSelf in interface XMLSerializable
Returns:
DOCUMENT ME!
Throws:
XMLCannotSaveException - DOCUMENT ME!

saveChilds

public void saveChilds(XMLSaver saver)
                throws XMLTreeException,
                       java.io.IOException,
                       XMLCannotSaveException
DOCUMENT ME!

Specified by:
saveChilds in interface XMLSerializable
Parameters:
saver - DOCUMENT ME!
Throws:
XMLTreeException - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!
XMLCannotSaveException - DOCUMENT ME!

getXMLName

public java.lang.String getXMLName()
DOCUMENT ME!

Specified by:
getXMLName in interface XMLSerializable
Returns:
DOCUMENT ME!

setParentName

public void setParentName(java.lang.String parentName)
                   throws XMLTreeException
DOCUMENT ME!

Specified by:
setParentName in interface XMLSerializable
Parameters:
parentName - DOCUMENT ME!
Throws:
XMLTreeException - DOCUMENT ME!

appName

protected abstract java.lang.String appName()
DOCUMENT ME!

Returns:
DOCUMENT ME!

showFilePropertiesDialog

public abstract void showFilePropertiesDialog()
DOCUMENT ME!


getPopupMenuFor

public abstract java.awt.PopupMenu getPopupMenuFor(Selectable obj)
                                            throws PopupException
DOCUMENT ME!

Parameters:
obj - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
PopupException - DOCUMENT ME!

createToolBar

protected abstract TrafficToolBar createToolBar()
DOCUMENT ME!

Returns:
DOCUMENT ME!

createMenuBar

protected abstract java.awt.MenuBar createMenuBar()
DOCUMENT ME!

Returns:
DOCUMENT ME!