dk.brics.bisim.view
Class GameView

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by dk.brics.bisim.view.GameView
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class GameView
extends javax.swing.JPanel

The game view.

The game view consists of two LTS panels, left and right, a status panel below, and a chat and button panel above.

Author:
Martin Mosegaard martinm@daimi.au.dk
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
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
static int GAME_VIEW_CLIENT
          A client does not have a reset button.
static int GAME_VIEW_LOCAL
          A local game does not have a chat function.
static int GAME_VIEW_SERVER
          A server gets both a chat function and a reset button.
private  java.awt.Dimension graphDimension
           
private  LTSPanel leftLTSPanel
          A panel for the left LTS.
private  java.awt.Image loserImage
           
private  javax.swing.ImageIcon loserImageIcon
           
private  LTSPanel rightLTSPanel
          A panel for the right LTS.
private static long serialVersionUID
           
static java.lang.String STYLE_ACTION
           
static java.lang.String STYLE_COMMAND
           
static java.lang.String STYLE_GAMEOVER
           
static java.lang.String STYLE_STATE
           
static java.lang.String STYLE_STATUS
           
private  javax.swing.JTextPane trace
          A text pane inside the trace scroll pane.
private  java.awt.Dimension traceDimension
           
private  javax.swing.JScrollPane traceScrollPane
          A scroll pane for the trace.
private  int upperHeight
           
private  GameViewUpperPanel upperPanel
          The upper (north) panel of a game view.
private  int width
           
private  java.awt.Image winnerImage
           
private  javax.swing.ImageIcon winnerImageIcon
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
GameView(int width, int height)
          Constructs a game view but does not construct the lower panel.
 
Method Summary
private  void createImages()
          Load gif images from the jar file.
 void createUpperPanel(int gameViewType)
          Creates the lower panel of a game view, based on game options
 void displayLTSs(att.grappa.Graph leftLTS, att.grappa.Graph rightLTS, att.grappa.GrappaAdapter ga)
          Display the two LTSs.
 void displayLTSTitles(java.lang.String leftLTSTitle, java.lang.String rightLTSTitle)
          Display the titles of the two LTSs.
 LTSPanel getLeftLTSPanel()
           
 GameViewUpperPanel getLowerPanel()
           
 LTSPanel getRightLTSPanel()
           
private  void insertTraceStyles()
          Generate the different styles used for writing in the trace text pane.
 void resetTrace()
          Clear the text in the trace scroll pane.
 void updateTrace(java.lang.String message, boolean doAutoScroll)
          Update the trace with a message.
 void updateTrace(java.lang.String message, boolean doAutoScroll, java.lang.String styleName)
          Update the trace with a styled message.
private  void updateTrace(java.lang.String message, boolean doAutoScroll, javax.swing.text.StyledDocument doc, javax.swing.text.Style style)
           
 void updateTrace(java.lang.String message, java.lang.String styleName, boolean winner)
          Update the trace with a message and an icon (winner or loser).
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getWidth, getVisibleRect, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

GAME_VIEW_LOCAL

public static final int GAME_VIEW_LOCAL
A local game does not have a chat function.

See Also:
Constant Field Values

GAME_VIEW_SERVER

public static final int GAME_VIEW_SERVER
A server gets both a chat function and a reset button.

See Also:
Constant Field Values

GAME_VIEW_CLIENT

public static final int GAME_VIEW_CLIENT
A client does not have a reset button.

See Also:
Constant Field Values

leftLTSPanel

private LTSPanel leftLTSPanel
A panel for the left LTS.


rightLTSPanel

private LTSPanel rightLTSPanel
A panel for the right LTS.


upperPanel

private GameViewUpperPanel upperPanel
The upper (north) panel of a game view.


traceScrollPane

private javax.swing.JScrollPane traceScrollPane
A scroll pane for the trace.


trace

private javax.swing.JTextPane trace
A text pane inside the trace scroll pane.


STYLE_STATE

public static final java.lang.String STYLE_STATE
See Also:
Constant Field Values

STYLE_ACTION

public static final java.lang.String STYLE_ACTION
See Also:
Constant Field Values

STYLE_COMMAND

public static final java.lang.String STYLE_COMMAND
See Also:
Constant Field Values

STYLE_STATUS

public static final java.lang.String STYLE_STATUS
See Also:
Constant Field Values

STYLE_GAMEOVER

public static final java.lang.String STYLE_GAMEOVER
See Also:
Constant Field Values

winnerImage

private java.awt.Image winnerImage

loserImage

private java.awt.Image loserImage

winnerImageIcon

private javax.swing.ImageIcon winnerImageIcon

loserImageIcon

private javax.swing.ImageIcon loserImageIcon

graphDimension

private java.awt.Dimension graphDimension

traceDimension

private java.awt.Dimension traceDimension

width

private int width

upperHeight

private int upperHeight
Constructor Detail

GameView

public GameView(int width,
                int height)
         throws javax.swing.text.BadLocationException
Constructs a game view but does not construct the lower panel. This is deferred until the player has chosen options.

Parameters:
width - Width of the main window
height - Height of the main window
Throws:
javax.swing.text.BadLocationException - Caused by using JTextPane. Should never be thrown
Method Detail

createImages

private void createImages()
Load gif images from the jar file.


createUpperPanel

public void createUpperPanel(int gameViewType)
Creates the lower panel of a game view, based on game options

Parameters:
gameViewType - Type of game view

resetTrace

public void resetTrace()
                throws javax.swing.text.BadLocationException
Clear the text in the trace scroll pane.

Throws:
javax.swing.text.BadLocationException - Caused by using JTextPane. Should never be thrown

insertTraceStyles

private void insertTraceStyles()
Generate the different styles used for writing in the trace text pane.


displayLTSTitles

public void displayLTSTitles(java.lang.String leftLTSTitle,
                             java.lang.String rightLTSTitle)
Display the titles of the two LTSs.

Parameters:
leftLTSTitle - Title of the left LTS
rightLTSTitle - Title of the right LTS

displayLTSs

public void displayLTSs(att.grappa.Graph leftLTS,
                        att.grappa.Graph rightLTS,
                        att.grappa.GrappaAdapter ga)
Display the two LTSs.

Parameters:
leftLTS - Left LTS
rightLTS - Right LTS
ga - A Grappa adapter

getLeftLTSPanel

public LTSPanel getLeftLTSPanel()
Returns:
The left LTS panel

getRightLTSPanel

public LTSPanel getRightLTSPanel()
Returns:
The right LTS panel

updateTrace

public void updateTrace(java.lang.String message,
                        boolean doAutoScroll)
                 throws javax.swing.text.BadLocationException
Update the trace with a message. Possibly auto-scroll to the bottom.

Parameters:
message - A message
doAutoScroll - Whether or not to auto-scroll
Throws:
javax.swing.text.BadLocationException - Should never be thrown

updateTrace

public void updateTrace(java.lang.String message,
                        boolean doAutoScroll,
                        java.lang.String styleName)
                 throws javax.swing.text.BadLocationException
Update the trace with a styled message. Possibly auto-scroll to the bottom.

Parameters:
message - A message
doAutoScroll - Whether or not to auto-scroll
styleName - Name of the style to write in
Throws:
javax.swing.text.BadLocationException - Should never be thrown

updateTrace

private void updateTrace(java.lang.String message,
                         boolean doAutoScroll,
                         javax.swing.text.StyledDocument doc,
                         javax.swing.text.Style style)
                  throws javax.swing.text.BadLocationException
Throws:
javax.swing.text.BadLocationException

updateTrace

public void updateTrace(java.lang.String message,
                        java.lang.String styleName,
                        boolean winner)
                 throws javax.swing.text.BadLocationException
Update the trace with a message and an icon (winner or loser).

Parameters:
message - A message
styleName - The style to write in
winner - Whether or not to use the winner icon
Throws:
javax.swing.text.BadLocationException - Should never be thrown

getLowerPanel

public GameViewUpperPanel getLowerPanel()
Returns:
The lower panel of the game view