cz.zcu.fav.kiv.jsim.gui
Class JSimMainWindow

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 cz.zcu.fav.kiv.jsim.gui.JSimMainWindow
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants

public class JSimMainWindow
extends javax.swing.JFrame

The JSimMainWindow class provides services for graphic output. You should never use this class directly since the JSimSimulation class contains methods for running in graphic mode.

Since:
J-Sim version 0.1.1
Version:
J-Sim version 0.6.0
Author:
Pavel DOMECKÝ, Jarda KAČER
See Also:
Serialized Form

Nested Class Summary
(package private)  class JSimMainWindow.CommonChanges
          An observer responsible for disabling control buttons when the main window is waiting for its closure by the user.
(package private)  class JSimMainWindow.JFieldCurrentTime
          Shows the simulation's current time and its changes.
(package private)  class JSimMainWindow.MyActionAdapter
          The main window's action adapter.
(package private)  class JSimMainWindow.MyMouseAdapter
          The main window's mouse adapter.
(package private)  class JSimMainWindow.MyWindowAdapter
           
 
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  javax.swing.JButton buttonContinue
           
private  javax.swing.JButton buttonNoOfSteps
           
private  javax.swing.JButton buttonOneStep
           
private  javax.swing.JPanel buttonPanel
           
private  javax.swing.JButton buttonPause
           
private  javax.swing.JButton buttonQuit
           
private  javax.swing.JButton buttonUntil
           
private  boolean canClose
          Flag saying whether it is possible to close the window.
private  JSimMainWindow.CommonChanges commonCh
           
private  java.lang.Object endLock
          The lock used to notify the main thread while the simulation waits in waitForWindowClosure().
private  JSimMainWindow.JFieldCurrentTime fieldCurrentTime
           
private  javax.swing.JTextField fieldNoOfSteps
           
private  javax.swing.JTextField fieldUntil
           
private  java.lang.Object graphicLock
          The lock used to suspend the main thread while the window is open.
private  JSimChange guiUpdate
          The main dispatcher of changes generated during simulation progress.
static int LIST_TYPE_PROCESS
           
static int LIST_TYPE_QUEUE
           
static int LIST_TYPE_SEMAPHORE
           
private static java.util.logging.Logger logger
          Common logger for all instances of this class.
private  JSimSimulationMode mode
          The simulation mode: text, GUI batch, or GUI interactive.
private  JSimMainWindow.MyActionAdapter myActionListener
          The main window's action listener.
private  JSimMainWindow.MyMouseAdapter myMouseListener
          The main window's mouse listener.
private  JSimSimulation myParent
          Simulation this window belongs to.
private  JSimMainWindow.MyWindowAdapter myWindowListener
          The main window's window listener.
private  java.lang.String newLine
          The new-line property of the OS used.
private  java.util.ArrayList<JSimDisplayable> openDetailedWindows
          A list of open detailed info windows.
private  boolean paused
          Flag saying whether the pause button has been pressed.
private  javax.swing.JPanel processesPanel
           
private  JSimMainWindowList processList
           
private  javax.swing.JScrollPane processListScrollPane
           
private  JSimMainWindowList queueList
           
private  javax.swing.JScrollPane queueListScrollPane
           
private  javax.swing.JPanel queuesPanel
           
private  boolean quitPressed
          Flag saying whether the quit button has been pressed.
private static long serialVersionUID
          Serialization identification.
private  javax.swing.JSplitPane splitListPane
           
private  javax.swing.JSplitPane splitPane
           
private  java.lang.Object stepLock
          The lock used to notify the main thread while the simulation is paused in GUI batch mode.
private  javax.swing.JTextArea userOutput
           
private  javax.swing.JScrollPane userOutputScrollPane
           
 
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
JSimMainWindow(JSimSimulation simulation, JSimSimulationMode simMode)
          Creates a new main window with several buttons, input fields and a text area.
 
Method Summary
private  void actionContinue()
          Unblocks the simulation.
private  void actionPause()
          Suspends the simulation.
private  void actionQuit()
          Closes the window, notifies the main thread and returns control to the simulation.
private  void actionRunNumberOfSteps()
          Runs the number of steps specified in the `Number of steps to run' input field.
private  void actionRunOneStep()
          Runs one simulation step.
private  void actionRunUntilTimeLimit()
          Runs an unspecified number of simulation steps until the simulation time is equal to or greater than the time specified in the `Time Limit' input field.
private  void disableRunButtons()
          Disables all buttons except of the `Quit' button.
private  void enableRunButtons()
          Enables all buttons except of the `Quit' button.
 boolean getPausePressed()
          Returns true if the 'Pause' button has been pressed.
 boolean getQuitPressed()
          Returns true if the 'Quit' button has been pressed.
 JSimSimulation getSimulation()
          Returns the simulation object to which this window belongs to.
private  void openUpDetailedInfoWindow(JSimMainWindowList list)
          Creates and displays a detailed info window that displays detailed characteristics of the object corresponding to the selected item from a list placed inside the main window.
 void printString(java.lang.String s, int code, boolean appendNewLine)
          Prints out a string to the user text area at the bottom of the window.
 void removeDisplayableFromOpenInfoWindows(JSimDisplayable jsd)
          When a detailed info window shuts up, it should invoke its main window's removeDisplayableFromInfoWindows() method in order to inform it that its displayable object is no longer showing.
 
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, 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, checkImage, checkImage, 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

serialVersionUID

private static final long serialVersionUID
Serialization identification.

See Also:
Constant Field Values

LIST_TYPE_PROCESS

public static final int LIST_TYPE_PROCESS
See Also:
Constant Field Values

LIST_TYPE_QUEUE

public static final int LIST_TYPE_QUEUE
See Also:
Constant Field Values

LIST_TYPE_SEMAPHORE

public static final int LIST_TYPE_SEMAPHORE
See Also:
Constant Field Values

logger

private static final java.util.logging.Logger logger
Common logger for all instances of this class. By default, all logging information goes to a file. Only severe events go to the console, in addition to a file.


myParent

private JSimSimulation myParent
Simulation this window belongs to.


mode

private JSimSimulationMode mode
The simulation mode: text, GUI batch, or GUI interactive.


graphicLock

private java.lang.Object graphicLock
The lock used to suspend the main thread while the window is open.


stepLock

private java.lang.Object stepLock
The lock used to notify the main thread while the simulation is paused in GUI batch mode.


endLock

private java.lang.Object endLock
The lock used to notify the main thread while the simulation waits in waitForWindowClosure().


myActionListener

private JSimMainWindow.MyActionAdapter myActionListener
The main window's action listener.


myMouseListener

private JSimMainWindow.MyMouseAdapter myMouseListener
The main window's mouse listener.


myWindowListener

private JSimMainWindow.MyWindowAdapter myWindowListener
The main window's window listener.


buttonPanel

private javax.swing.JPanel buttonPanel

processesPanel

private javax.swing.JPanel processesPanel

queuesPanel

private javax.swing.JPanel queuesPanel

fieldUntil

private javax.swing.JTextField fieldUntil

fieldNoOfSteps

private javax.swing.JTextField fieldNoOfSteps

fieldCurrentTime

private JSimMainWindow.JFieldCurrentTime fieldCurrentTime

commonCh

private JSimMainWindow.CommonChanges commonCh

buttonQuit

private javax.swing.JButton buttonQuit

buttonOneStep

private javax.swing.JButton buttonOneStep

buttonUntil

private javax.swing.JButton buttonUntil

buttonNoOfSteps

private javax.swing.JButton buttonNoOfSteps

buttonPause

private javax.swing.JButton buttonPause

buttonContinue

private javax.swing.JButton buttonContinue

splitPane

private javax.swing.JSplitPane splitPane

splitListPane

private javax.swing.JSplitPane splitListPane

userOutputScrollPane

private javax.swing.JScrollPane userOutputScrollPane

processListScrollPane

private javax.swing.JScrollPane processListScrollPane

queueListScrollPane

private javax.swing.JScrollPane queueListScrollPane

processList

private JSimMainWindowList processList

queueList

private JSimMainWindowList queueList

userOutput

private javax.swing.JTextArea userOutput

canClose

private boolean canClose
Flag saying whether it is possible to close the window.


quitPressed

private boolean quitPressed
Flag saying whether the quit button has been pressed.


paused

private boolean paused
Flag saying whether the pause button has been pressed.


guiUpdate

private JSimChange guiUpdate
The main dispatcher of changes generated during simulation progress. Used to notify various GUI components.


openDetailedWindows

private java.util.ArrayList<JSimDisplayable> openDetailedWindows
A list of open detailed info windows.


newLine

private java.lang.String newLine
The new-line property of the OS used.

Constructor Detail

JSimMainWindow

public JSimMainWindow(JSimSimulation simulation,
                      JSimSimulationMode simMode)
               throws JSimSimulationAlreadyTerminatedException,
                      JSimInvalidParametersException
Creates a new main window with several buttons, input fields and a text area. Appearance of the window depends on the simulation's mode.

Parameters:
simulation - The simulation object that owns this newly created window. It must not be null.
simMode - The mode in which the simulation runs, design of the window depends on it.
Throws:
JSimSimulationAlreadyTerminatedException - This exception is thrown out if the simulation has already terminated.
JSimInvalidParametersException - This exception is thrown out if the simulation is null or one of its locks cannot be obtained.
Method Detail

getSimulation

public JSimSimulation getSimulation()
Returns the simulation object to which this window belongs to.

Returns:
The simulation object to which this window belongs to.

actionQuit

private void actionQuit()
Closes the window, notifies the main thread and returns control to the simulation. Called when the `Quit' button is pressed.


actionRunOneStep

private void actionRunOneStep()
Runs one simulation step. Called when the `Run one step' button is pressed.


actionRunUntilTimeLimit

private void actionRunUntilTimeLimit()
Runs an unspecified number of simulation steps until the simulation time is equal to or greater than the time specified in the `Time Limit' input field. Called when the `Run until the time limit' button is pressed.


actionRunNumberOfSteps

private void actionRunNumberOfSteps()
Runs the number of steps specified in the `Number of steps to run' input field. Called when the `Run N steps' button is pressed.


actionPause

private void actionPause()
Suspends the simulation. Called when the `Pause' button is pressed. The step() method will blocked after this method is invoked.


actionContinue

private void actionContinue()
Unblocks the simulation. Called when the `Continue' button is pressed. The step() method will be unblocked and it will continue.


getQuitPressed

public final boolean getQuitPressed()
Returns true if the 'Quit' button has been pressed.

Returns:
True if the 'Quit' button has been pressed, false otherwise.

getPausePressed

public final boolean getPausePressed()
Returns true if the 'Pause' button has been pressed.

Returns:
True if the 'Pause' button has been pressed, false otherwise.

printString

public void printString(java.lang.String s,
                        int code,
                        boolean appendNewLine)
Prints out a string to the user text area at the bottom of the window.

Parameters:
s - The string to be printed out.
code - A code saying whether it is an info message (PRN_MESSAGE) or an error message (PRN_ERROR).
appendNewLine - A flag indicating that the new line character should be appended to the text.

openUpDetailedInfoWindow

private void openUpDetailedInfoWindow(JSimMainWindowList list)
Creates and displays a detailed info window that displays detailed characteristics of the object corresponding to the selected item from a list placed inside the main window.

Parameters:
list - The list from which the item is selected.

removeDisplayableFromOpenInfoWindows

public void removeDisplayableFromOpenInfoWindows(JSimDisplayable jsd)
When a detailed info window shuts up, it should invoke its main window's removeDisplayableFromInfoWindows() method in order to inform it that its displayable object is no longer showing. This will allow the main window to open a new detailed info window in the future if the user requests it.

Parameters:
jsd - The JSimDisplayable object whose detailed info window is just shutting up.

disableRunButtons

private void disableRunButtons()
Disables all buttons except of the `Quit' button.


enableRunButtons

private void enableRunButtons()
Enables all buttons except of the `Quit' button.



Copyright © 2000-2006 University of West Bohemia. Licensed under the Academic Free License v. 2.1. Build date 20060812.