frams_client_3d
Class MainWindow

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
              extended byjava.awt.Frame
                  extended byjavax.swing.JFrame
                      extended byframs_client_3d.MainWindow
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.RootPaneContainer, java.io.Serializable, javax.swing.WindowConstants

public class MainWindow
extends javax.swing.JFrame

The client main window class.

Author:
MoMaT
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JFrame
javax.swing.JFrame.AccessibleJFrame
 
Nested classes inherited from class java.awt.Frame
java.awt.Frame.AccessibleAWTFrame
 
Nested classes inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  Communication comm
           
private  java.util.ArrayList creatureEvents
           
private  java.util.ArrayList creatures
           
private  java.util.Vector creaturesCount
           
private  java.lang.String groupEvent
           
private  java.util.ArrayList groups
           
private  javax.swing.JPanel jContentPane
           
private  javax.swing.JSplitPane jSplitPane
           
private  javax.swing.JSplitPane jSplitPane1
           
private  boolean listening
           
private  java.lang.String messageEvent
           
private  java.util.ArrayList messages
           
private  Log networkLogs
           
private  Options options
           
private  boolean running
           
private  java.lang.String runningEvent
           
private  boolean showSelected
           
private  StatusBar statusBar
           
private  ViewGL viewGL
           
 
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.Window
 
Fields inherited from class java.awt.Container
 
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()
          This is the default constructor
 
Method Summary
private  javax.swing.tree.DefaultTreeModel buildTree()
          Read creatures and build the tree.
private  void connect(java.lang.Object value)
          Connect/disconnect action.
 boolean getChangedCreatures()
          Read changes on event-registered creatures lists.
 boolean getChangedGroups()
          Read changes on groups list.
 boolean getChangedRunningState()
          Read running state.
private  javax.swing.JPanel getJContentPane()
          This method initializes jContentPane
private  javax.swing.JSplitPane getJSplitPane()
          This method initializes jSplitPane
private  javax.swing.JSplitPane getJSplitPane1()
          This method initializes jSplitPane1
 boolean getMessages()
          Read simulation messages.
 Options getOptions()
          This method initializes options
private  StatusBar getStatusBar()
          This method initializes statusBar
private  ViewGL getViewGL()
          This method initializes viewGL
private  void handleCommunicationErrorException(CommunicationErrorException e)
          Protocol error handling.
private  void handleException(java.lang.Exception e)
          Error handling for unexpected exceptions.
private  void handleIOException(java.io.IOException e)
          Communication error handling.
private  void initialize()
          This method initializes this
 boolean isListening()
          Listening property getter.
static void main(java.lang.String[] args)
           
 void passObjectsToView()
          Pass objects to the viewGL window (according to GUI option all creatures are passed or just those selected on a creatures tree.
private  Creature readCreature(int group, int index)
          Read the creature data from a server.
private  java.lang.String readGroup(int index)
          Read a group name from a server.
private  java.util.ArrayList[] readHeighfield()
          Read terrain map.
private  void readInitialData()
          Read terrain map and creatures lists data.
private  java.lang.Integer readRunningState()
          Read if simulation is running.
private  void registerOnCreaturesChanged(int group, boolean isAdd)
          Register for creatures list change in given group.
private  void registerOnGroupsChanged()
          Register for groups change.
private  void registerOnMessages()
          Register for simulator messages.
private  void registerOnRunningChanged()
          Register for simulation start/stop change.
private  java.util.ArrayList sendRequest(java.lang.String request)
          Send request to server and receive a respond.
 void setListening(boolean state)
          Listening property setter.
private  void startSimulation()
          Simulation begin action.
private  void stopSimulation()
          Simulation end action.
private  void updateCreature(int type, Creature creature)
          Update creatures data in a group.
private  void updateGroup(int type, int position, java.lang.String name)
          Update group data in a tree.
 void updateLog()
          Update network communication log.
 void updateMessages()
          Show received messages in log window.
 void updateRunningState()
          Activate/disactivate buttons.
 void updateTree()
          Pass data of updated objects to the tree and GL View.
 
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, 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, 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, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, 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, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, 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, 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, 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, isOpaque, 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, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, 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

comm

private Communication comm

networkLogs

private Log networkLogs

listening

private boolean listening

showSelected

private boolean showSelected

creatureEvents

private java.util.ArrayList creatureEvents

messageEvent

private java.lang.String messageEvent

runningEvent

private java.lang.String runningEvent

groupEvent

private java.lang.String groupEvent

creaturesCount

private java.util.Vector creaturesCount

groups

private java.util.ArrayList groups

creatures

private java.util.ArrayList creatures

messages

private java.util.ArrayList messages

running

private boolean running

jContentPane

private javax.swing.JPanel jContentPane

jSplitPane

private javax.swing.JSplitPane jSplitPane

jSplitPane1

private javax.swing.JSplitPane jSplitPane1

options

private Options options

viewGL

private ViewGL viewGL

statusBar

private StatusBar statusBar
Constructor Detail

MainWindow

public MainWindow()
This is the default constructor

Method Detail

main

public static void main(java.lang.String[] args)

initialize

private void initialize()
This method initializes this

Returns:
void

getJContentPane

private javax.swing.JPanel getJContentPane()
This method initializes jContentPane

Returns:
javax.swing.JPanel

getJSplitPane

private javax.swing.JSplitPane getJSplitPane()
This method initializes jSplitPane

Returns:
javax.swing.JSplitPane

getJSplitPane1

private javax.swing.JSplitPane getJSplitPane1()
This method initializes jSplitPane1

Returns:
javax.swing.JSplitPane

getOptions

public Options getOptions()
This method initializes options

Returns:
frams_client_3d.Options

getStatusBar

private StatusBar getStatusBar()
This method initializes statusBar

Returns:
frams_client_3d.StatusBar

getViewGL

private ViewGL getViewGL()
This method initializes viewGL

Returns:
frams_client_3d.ViewGL

connect

private void connect(java.lang.Object value)
Connect/disconnect action.

Parameters:
value - true for connection, false for disconnection

readInitialData

private void readInitialData()
Read terrain map and creatures lists data.


handleIOException

private void handleIOException(java.io.IOException e)
Communication error handling.

Parameters:
e - catched exception

handleCommunicationErrorException

private void handleCommunicationErrorException(CommunicationErrorException e)
Protocol error handling.

Parameters:
e - catched exception

handleException

private void handleException(java.lang.Exception e)
Error handling for unexpected exceptions.

Parameters:
e - catched exception

startSimulation

private void startSimulation()
Simulation begin action.


stopSimulation

private void stopSimulation()
Simulation end action.


readRunningState

private java.lang.Integer readRunningState()
                                    throws java.io.IOException,
                                           CommunicationErrorException
Read if simulation is running.

Returns:
Integer initialized to the value of a running property
Throws:
java.io.IOException
CommunicationErrorException

readHeighfield

private java.util.ArrayList[] readHeighfield()
                                      throws java.io.IOException,
                                             CommunicationErrorException
Read terrain map.

Throws:
CommunicationErrorException
java.io.IOException

buildTree

private javax.swing.tree.DefaultTreeModel buildTree()
                                             throws java.io.IOException,
                                                    CommunicationErrorException
Read creatures and build the tree.

Returns:
tree model
Throws:
java.io.IOException
CommunicationErrorException

readCreature

private Creature readCreature(int group,
                              int index)
                       throws java.io.IOException,
                              CommunicationErrorException
Read the creature data from a server.

Parameters:
group - creature group
index - creature index in the group
Returns:
creature object
Throws:
java.io.IOException
CommunicationErrorException

readGroup

private java.lang.String readGroup(int index)
                            throws java.io.IOException,
                                   CommunicationErrorException
Read a group name from a server.

Parameters:
index - group index in populations
Returns:
a name of the group
Throws:
java.io.IOException
CommunicationErrorException

registerOnMessages

private void registerOnMessages()
                         throws java.io.IOException,
                                CommunicationErrorException
Register for simulator messages.

Throws:
java.io.IOException
CommunicationErrorException

registerOnCreaturesChanged

private void registerOnCreaturesChanged(int group,
                                        boolean isAdd)
                                 throws java.io.IOException,
                                        CommunicationErrorException
Register for creatures list change in given group.

Parameters:
group - index of a group
Throws:
java.io.IOException
CommunicationErrorException

registerOnRunningChanged

private void registerOnRunningChanged()
                               throws java.io.IOException,
                                      CommunicationErrorException
Register for simulation start/stop change.

Throws:
java.io.IOException
CommunicationErrorException

registerOnGroupsChanged

private void registerOnGroupsChanged()
                              throws java.io.IOException,
                                     CommunicationErrorException
Register for groups change.

Throws:
java.io.IOException
CommunicationErrorException

sendRequest

private java.util.ArrayList sendRequest(java.lang.String request)
                                 throws java.io.IOException,
                                        CommunicationErrorException
Send request to server and receive a respond.

Parameters:
request -
Returns:
response
Throws:
java.io.IOException
CommunicationErrorException

updateLog

public void updateLog()
Update network communication log.


passObjectsToView

public void passObjectsToView()
Pass objects to the viewGL window (according to GUI option all creatures are passed or just those selected on a creatures tree.


isListening

public boolean isListening()
Listening property getter.

Returns:
true if events listening has been started

setListening

public void setListening(boolean state)
Listening property setter.

Parameters:
state - new value

getChangedCreatures

public boolean getChangedCreatures()
                            throws java.io.IOException,
                                   CommunicationErrorException
Read changes on event-registered creatures lists.

Returns:
true if any changes read
Throws:
java.io.IOException - Thrown on I/O error
CommunicationErrorException - Thrown on protocol error

getMessages

public boolean getMessages()
                    throws java.io.IOException,
                           CommunicationErrorException
Read simulation messages.

Returns:
true if any messages read
Throws:
java.io.IOException - Thrown on I/O error
CommunicationErrorException - Thrown on protocol error

getChangedRunningState

public boolean getChangedRunningState()
                               throws java.io.IOException,
                                      CommunicationErrorException
Read running state.

Returns:
true if running state has changed
Throws:
java.io.IOException - Thrown on I/O error
CommunicationErrorException - Thrown on protocol error

getChangedGroups

public boolean getChangedGroups()
                         throws java.io.IOException,
                                CommunicationErrorException
Read changes on groups list.

Returns:
true if any changes read
Throws:
java.io.IOException - Thrown on I/O error
CommunicationErrorException - Thrown on protocol error

updateTree

public void updateTree()
Pass data of updated objects to the tree and GL View. It takes care of groups and creatures.


updateGroup

private void updateGroup(int type,
                         int position,
                         java.lang.String name)
Update group data in a tree.

Parameters:
type - update type (0-add, 1-remove, 2-modify)
position - group position on population list
name - a name of a group

updateCreature

private void updateCreature(int type,
                            Creature creature)
Update creatures data in a group.

Parameters:
type - update type (0-add, 1-remove, 2-modify)
creature - object

updateMessages

public void updateMessages()
Show received messages in log window.


updateRunningState

public void updateRunningState()
Activate/disactivate buttons. Add message to status bar.