uk.org.arlott.simon.hw.f24.lbsta
Class MainWindow

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 javax.swing.JFrame
                      extended by uk.org.arlott.simon.hw.f24.lbsta.MainWindow
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ChangeListener, javax.swing.RootPaneContainer, javax.swing.WindowConstants

public class MainWindow
extends javax.swing.JFrame
implements java.awt.event.ActionListener, javax.swing.event.ChangeListener

The main window of the application.

See Also:
Serialized Form

Nested Class Summary
private  class MainWindow.NetworkPanel
          Network panel displayed on the main window.
 
Nested classes/interfaces inherited from class javax.swing.JFrame
javax.swing.JFrame.AccessibleJFrame
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  CommonInterface currentMode
          The current mode.
private  java.lang.Object hover
          The current network object the mouse is hovering over.
private  boolean hoverEnabled
          Indicates whether or not to update the hover value on mouseover.
private  javax.swing.JPanel innerMainPanel
          The inner main panel of the window, holds the network panel and the status text.
private  javax.swing.JPanel mainPanel
          The main panel of the window.
private  MainWindow mainWindow
          Constant reference to the instance of this object.
private  javax.swing.JMenuBar menuBar
          The application menu bar.
private  javax.swing.JMenu mnuEdit
          The Edit menu.
private  javax.swing.JRadioButtonMenuItem mnuEditCreateBridge
          The Edit - Create Bridge menu item.
private  javax.swing.JRadioButtonMenuItem mnuEditCreateHost
          The Edit - Create Host menu item.
private  javax.swing.JRadioButtonMenuItem mnuEditCreateLAN
          The Edit - Create LAN menu item.
private  javax.swing.JRadioButtonMenuItem mnuEditModifyObject
          The Edit - Modify Object menu item.
private  javax.swing.JMenu mnuFile
          The File menu.
private  javax.swing.JMenuItem mnuFileExit
          The File - Exit menu item.
private  javax.swing.JMenuItem mnuFileNew
          The File - New menu item.
private  javax.swing.JMenuItem mnuFileOpen
          The File - Open menu item.
private  javax.swing.JMenuItem mnuFileSave
          The File - Save menu item.
private  javax.swing.JMenuItem mnuFileSaveAs
          The File - Save As menu item.
private  javax.swing.JMenu mnuHelp
          The Help menu.
private  javax.swing.JMenuItem mnuHelpAbout
          The Help - About menu item.
private  javax.swing.JMenuItem mnuHelpLegend
          The Help - Legend menu item.
private  javax.swing.JMenu mnuMode
          The Mode menu.
private  javax.swing.JRadioButtonMenuItem mnuModeEdit
          The Mode - Edit menu item.
private  javax.swing.JRadioButtonMenuItem mnuModeScript
          The Mode - Script menu item.
private  javax.swing.JRadioButtonMenuItem mnuModeView
          The Mode - View menu item.
private  javax.swing.JMenu mnuOptions
          The Options menu.
private  javax.swing.JRadioButtonMenuItem mnuOptionsLeftSidebar
          The Options - Left Sidebar menu item.
private  javax.swing.JRadioButtonMenuItem mnuOptionsRightSidebar
          The Options - Right Sidebar menu item.
private  javax.swing.JMenu mnuSimulation
          The Simultion menu.
private  javax.swing.JMenuItem mnuSimulationRestart
          The Simulation - Restart menu item.
private  javax.swing.JMenuItem mnuSimulationStart
          The Simulation - Start menu item.
private  javax.swing.JMenuItem mnuSimulationStep
          The Simulation - Step menu item.
private  Network network
          Constant reference to the Network.
private  NetworkEdit networkEdit
          The network edit mode.
private  MainWindow.NetworkPanel networkPanel
          The network panel where the network is drawn.
private  NetworkView networkView
          The network view mode.
private  javax.swing.ImageIcon pauseIcon
          The Pause menu and toolbar icon.
private  Script script
          Constant reference to the Script
private  ScriptEdit scriptEdit
          The script edit mode.
private  java.lang.Object selected
          The currently selected network object.
private  java.awt.Component sidePanel
          The current side panel.
private  java.lang.String sidePanelPosition
          The position of the side panel, either EAST or WEST.
private  javax.swing.JSlider speedSelect
          The speed selection slider.
private  javax.swing.JLabel speedValue
          The current speed text.
private  javax.swing.ImageIcon startIcon
          The Start menu and toolbar icon.
private  javax.swing.JLabel statusText
          The status text label.
private  javax.swing.ImageIcon stepIcon
          The Step menu and toolbar icon.
private  javax.swing.JToggleButton tlbEdit
          The Edit mode toolbar button.
private  javax.swing.JToggleButton tlbEditCreateBridge
          The Create Bridge toolbar button.
private  javax.swing.JToggleButton tlbEditCreateHost
          The Create Host toolbar button.
private  javax.swing.JToggleButton tlbEditCreateLAN
          The Create LAN toolbar button.
private  javax.swing.JToggleButton tlbEditModifyObject
          The Modify Object toolbar button.
private  javax.swing.JToolBar.Separator tlbEditSeparator
          The Edit mode toolbar separator.
private  javax.swing.JButton tlbNew
          The New toolbar button.
private  javax.swing.JButton tlbOpen
          The New toolbar button.
private  javax.swing.JButton tlbSave
          The Save toolbar button.
private  javax.swing.JToggleButton tlbScript
          The Script mode toolbar button.
private  javax.swing.JToggleButton tlbView
          The View mode toolbar button.
private  javax.swing.JButton tlbViewRestart
          The Restart toolbar button.
private  javax.swing.JToggleButton tlbViewStart
          The Start toolbar button.
private  javax.swing.JToggleButton tlbViewStep
          The Step toolbar button.
private  javax.swing.JToolBar toolBar
          The application tool bar.
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
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 javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
MainWindow()
          Creates a new MainWindow object with the starting mode the network edit mode.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent ae)
          Action event handler.
 void deSelect()
          Deselects the currently selected network object.
private  void doToolbarButton(java.lang.Object o)
          Performs the action associated with a toolbar button.
 void enableHover(boolean enabled)
          Enables or disables hover detection mode.
 java.lang.Object getHover()
          Gets the current network object the mouse is hovering over.
 java.lang.Object getSelected()
          Gets the currently selected network object.
 void repaintNetworkPanel()
          Repaints the network panel.
 void requestNetworkPanelFocus()
          Requests that the network panel is given focus.
private  boolean saveOrDiscard(java.lang.String title)
          Checks if the network has been saved and if the changes should be discarded.
 boolean scriptExists()
          Returns if a script exists or not.
 void select()
          Selects the network object currently being hovered over.
 void setPanel(java.awt.Component p)
          Changes the side panel.
 void setScriptState(boolean exists)
          Updates the state of the step button, disabling it if a script exists.
 void setSimulationState(boolean running, boolean stepping, boolean activeMode)
          Updates the simulation state.
 void setSpeed(int speed)
          Updates the actual speed of the simulation.
 void setStatusText(java.lang.String text)
          Changes the status text.
 void stateChanged(javax.swing.event.ChangeEvent ce)
          Change event handler.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Frame
addNotify, finalize, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, 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, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, 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, 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, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

mainWindow

private final MainWindow mainWindow
Constant reference to the instance of this object.


network

private final Network network
Constant reference to the Network.


networkPanel

private MainWindow.NetworkPanel networkPanel
The network panel where the network is drawn.


script

private final Script script
Constant reference to the Script


networkView

private NetworkView networkView
The network view mode.


networkEdit

private NetworkEdit networkEdit
The network edit mode.


scriptEdit

private ScriptEdit scriptEdit
The script edit mode.


currentMode

private CommonInterface currentMode
The current mode.


hover

private java.lang.Object hover
The current network object the mouse is hovering over.


hoverEnabled

private boolean hoverEnabled
Indicates whether or not to update the hover value on mouseover.


selected

private java.lang.Object selected
The currently selected network object.


mainPanel

private javax.swing.JPanel mainPanel
The main panel of the window.


innerMainPanel

private javax.swing.JPanel innerMainPanel
The inner main panel of the window, holds the network panel and the status text.


sidePanel

private java.awt.Component sidePanel
The current side panel.


sidePanelPosition

private java.lang.String sidePanelPosition
The position of the side panel, either EAST or WEST.


statusText

private javax.swing.JLabel statusText
The status text label.


menuBar

private javax.swing.JMenuBar menuBar
The application menu bar.


toolBar

private javax.swing.JToolBar toolBar
The application tool bar.


tlbNew

private javax.swing.JButton tlbNew
The New toolbar button.


tlbOpen

private javax.swing.JButton tlbOpen
The New toolbar button.


tlbSave

private javax.swing.JButton tlbSave
The Save toolbar button.


tlbView

private javax.swing.JToggleButton tlbView
The View mode toolbar button.


tlbViewRestart

private javax.swing.JButton tlbViewRestart
The Restart toolbar button.


startIcon

private javax.swing.ImageIcon startIcon
The Start menu and toolbar icon.


stepIcon

private javax.swing.ImageIcon stepIcon
The Step menu and toolbar icon.


pauseIcon

private javax.swing.ImageIcon pauseIcon
The Pause menu and toolbar icon.


tlbViewStart

private javax.swing.JToggleButton tlbViewStart
The Start toolbar button.


tlbViewStep

private javax.swing.JToggleButton tlbViewStep
The Step toolbar button.


tlbEdit

private javax.swing.JToggleButton tlbEdit
The Edit mode toolbar button.


tlbEditSeparator

private javax.swing.JToolBar.Separator tlbEditSeparator
The Edit mode toolbar separator.


tlbEditModifyObject

private javax.swing.JToggleButton tlbEditModifyObject
The Modify Object toolbar button.


tlbEditCreateLAN

private javax.swing.JToggleButton tlbEditCreateLAN
The Create LAN toolbar button.


tlbEditCreateHost

private javax.swing.JToggleButton tlbEditCreateHost
The Create Host toolbar button.


tlbEditCreateBridge

private javax.swing.JToggleButton tlbEditCreateBridge
The Create Bridge toolbar button.


tlbScript

private javax.swing.JToggleButton tlbScript
The Script mode toolbar button.


speedSelect

private javax.swing.JSlider speedSelect
The speed selection slider.


speedValue

private javax.swing.JLabel speedValue
The current speed text.


mnuFile

private javax.swing.JMenu mnuFile
The File menu.


mnuFileNew

private javax.swing.JMenuItem mnuFileNew
The File - New menu item.


mnuFileOpen

private javax.swing.JMenuItem mnuFileOpen
The File - Open menu item.


mnuFileSave

private javax.swing.JMenuItem mnuFileSave
The File - Save menu item.


mnuFileSaveAs

private javax.swing.JMenuItem mnuFileSaveAs
The File - Save As menu item.


mnuFileExit

private javax.swing.JMenuItem mnuFileExit
The File - Exit menu item.


mnuMode

private javax.swing.JMenu mnuMode
The Mode menu.


mnuModeView

private javax.swing.JRadioButtonMenuItem mnuModeView
The Mode - View menu item.


mnuModeEdit

private javax.swing.JRadioButtonMenuItem mnuModeEdit
The Mode - Edit menu item.


mnuModeScript

private javax.swing.JRadioButtonMenuItem mnuModeScript
The Mode - Script menu item.


mnuEdit

private javax.swing.JMenu mnuEdit
The Edit menu.


mnuEditModifyObject

private javax.swing.JRadioButtonMenuItem mnuEditModifyObject
The Edit - Modify Object menu item.


mnuEditCreateLAN

private javax.swing.JRadioButtonMenuItem mnuEditCreateLAN
The Edit - Create LAN menu item.


mnuEditCreateHost

private javax.swing.JRadioButtonMenuItem mnuEditCreateHost
The Edit - Create Host menu item.


mnuEditCreateBridge

private javax.swing.JRadioButtonMenuItem mnuEditCreateBridge
The Edit - Create Bridge menu item.


mnuSimulation

private javax.swing.JMenu mnuSimulation
The Simultion menu.


mnuSimulationRestart

private javax.swing.JMenuItem mnuSimulationRestart
The Simulation - Restart menu item.


mnuSimulationStart

private javax.swing.JMenuItem mnuSimulationStart
The Simulation - Start menu item.


mnuSimulationStep

private javax.swing.JMenuItem mnuSimulationStep
The Simulation - Step menu item.


mnuOptions

private javax.swing.JMenu mnuOptions
The Options menu.


mnuOptionsLeftSidebar

private javax.swing.JRadioButtonMenuItem mnuOptionsLeftSidebar
The Options - Left Sidebar menu item.


mnuOptionsRightSidebar

private javax.swing.JRadioButtonMenuItem mnuOptionsRightSidebar
The Options - Right Sidebar menu item.


mnuHelp

private javax.swing.JMenu mnuHelp
The Help menu.


mnuHelpLegend

private javax.swing.JMenuItem mnuHelpLegend
The Help - Legend menu item.


mnuHelpAbout

private javax.swing.JMenuItem mnuHelpAbout
The Help - About menu item.

Constructor Detail

MainWindow

public MainWindow()
Creates a new MainWindow object with the starting mode the network edit mode.

Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent ae)
Action event handler.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
ae - The ActionEvent to be handled.

doToolbarButton

private void doToolbarButton(java.lang.Object o)
Performs the action associated with a toolbar button. Called from the toolbar button event handling and the equivalent menu item event handling.

Parameters:
o - The toolbar button that has been pressed.

setSimulationState

public void setSimulationState(boolean running,
                               boolean stepping,
                               boolean activeMode)
Updates the simulation state.

Parameters:
running - Current running/paused state.
stepping - Stepping mode in use or not.
activeMode - Simulation mode is the active mode.

setScriptState

public void setScriptState(boolean exists)
Updates the state of the step button, disabling it if a script exists.

Parameters:
exists - Indicates that a script exists.

scriptExists

public boolean scriptExists()
Returns if a script exists or not.

Returns:
true if a script exists.

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent ce)
Change event handler.

Specified by:
stateChanged in interface javax.swing.event.ChangeListener
Parameters:
ce - The ChangeEvent to be handled.

setSpeed

public void setSpeed(int speed)
Updates the actual speed of the simulation.

Parameters:
speed - The new speed in milliseconds.

saveOrDiscard

private boolean saveOrDiscard(java.lang.String title)
Checks if the network has been saved and if the changes should be discarded.

Parameters:
title - The title of the prompt.
Returns:
true if the network can be overwritten.

getHover

public java.lang.Object getHover()
Gets the current network object the mouse is hovering over.

Returns:
The current hover object.

enableHover

public void enableHover(boolean enabled)
Enables or disables hover detection mode.

Parameters:
enabled - New state of hover mode.

getSelected

public java.lang.Object getSelected()
Gets the currently selected network object.

Returns:
The current selected object.

select

public void select()
Selects the network object currently being hovered over.


deSelect

public void deSelect()
Deselects the currently selected network object.


requestNetworkPanelFocus

public void requestNetworkPanelFocus()
Requests that the network panel is given focus.


repaintNetworkPanel

public void repaintNetworkPanel()
Repaints the network panel.


setPanel

public void setPanel(java.awt.Component p)
Changes the side panel.

Parameters:
p - The new side panel, may be null to remove.

setStatusText

public void setStatusText(java.lang.String text)
Changes the status text.

Parameters:
text - The new status text, may be null to remove.