megamek.client.ui.AWT
Class ClientGUI

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by megamek.client.ui.AWT.ClientGUI
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.WindowListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, BoardViewListener

public class ClientGUI
extends java.awt.Panel
implements java.awt.event.WindowListener, java.awt.event.ActionListener, BoardViewListener

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
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
(package private)  java.applet.AudioClip bingClip
          Cache for the "bing" soundclip.
(package private)  BoardSelectionDialog boardSelectionDialog
           
 IBoardView bv
           
(package private)  ChatterBox cb
           
 ChatLounge chatlounge
           
 Client client
           
protected  java.awt.Component curPanel
           
 java.awt.Frame frame
           
protected  GameListener gameListener
           
(package private)  GameOptionsDialog gameOptionsDialog
           
 MechDisplay mechD
           
 java.awt.Dialog mechW
           
protected  CommonMenuBar menuBar
           
 MiniMap minimap
           
 java.awt.Dialog minimapW
           
(package private)  java.util.HashMap<java.lang.String,java.awt.Component> phaseComponents
          Map phase component names to phase component objects.
 java.awt.PopupMenu popup
           
 Ruler ruler
           
(package private)  int selectedEntityNum
          Current Selected entity
static java.lang.String VIEW_LOS_SETTING
           
static java.lang.String VIEW_MEK_DISPLAY
           
static java.lang.String VIEW_MINI_MAP
           
static java.lang.String VIEW_TOGGLE_ISOMETRIC
           
static java.lang.String VIEW_UNIT_OVERVIEW
           
static java.lang.String VIEW_ZOOM_IN
           
static java.lang.String VIEW_ZOOM_OUT
           
 
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
ClientGUI(Client client)
          Construct a client which will display itself in a new frame.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
          Implement the ActionListener interface.
protected  void addBag(java.awt.Component comp, java.awt.GridBagLayout gridbag, java.awt.GridBagConstraints c)
           
 void bing()
          Make a "bing" sound.
 void boardHexHighlighted(BoardViewEvent b)
          Sent when Hex is highlighted.
 void die()
          Shuts down threads and sockets
 void doAlertDialog(java.lang.String title, java.lang.String message)
          Pops up a dialog box showing an alert
 int[] doChoiceDialog(java.lang.String title, java.lang.String question, java.lang.String[] choices)
          Pops up a dialog box giving the player a series of choices that are not mutually exclusive.
 ConfirmDialog doYesNoBotherDialog(java.lang.String title, java.lang.String question)
          Pops up a dialog box asking a yes/no question

The player will be given a chance to not show the dialog again.

 boolean doYesNoDialog(java.lang.String title, java.lang.String question)
          Pops up a dialog box asking a yes/no question
protected  void fillPopup(Coords coords)
           
 void finishedMovingUnits(BoardViewEvent b)
          Sent when moving units is finished.
 void firstLOSHex(BoardViewEvent b)
          Sent when firstLOS is set.
 BoardSelectionDialog getBoardSelectionDialog()
          Returns the board selection dialog, creating it on the first call
 IBoardView getBoardView()
           
 java.util.Map<java.lang.String,Client> getBots()
           
 Client getClient()
           
 CustomFighterSquadronDialog getCustomFSDialog()
           
 CustomInitiativeDialog getCustomInitiativeDialog()
           
 java.awt.Frame getFrame()
           
 GameOptionsDialog getGameOptionsDialog()
           
 MechSelectorDialog getMechSelectorDialog()
           
 CommonMenuBar getMenuBar()
          Get the menu bar for this client.
 PlanetaryConditionsDialog getPlanetaryConditionsDialog()
           
 RandomArmyDialog getRandomArmyDialog()
           
 RandomSkillDialog getRandomSkillDialog()
           
 int getSelectedEntityNum()
           
 StartingPositionDialog getStartingPositionDialog()
           
 void hexCursor(BoardViewEvent b)
          Sent when BoardView 'cursor' is set to Hex.
 void hexMoused(BoardViewEvent b)
          Sent when user clicks, double clicks or drags hex.
 void hexSelected(BoardViewEvent b)
          Sent when Hex is selected.
 void initialize()
          Have the client register itself as a listener wherever it's needed.
protected  void loadListFile()
          Allow the player to select a MegaMek Unit List file to load.
 void loadPreviewImage(BufferedPanel bp, Entity entity)
           
 void loadPreviewImage(BufferedPanel bp, Entity entity, Player player)
           
 void loadSoundClip()
           
protected  void saveListFile(java.util.ArrayList<Entity> unitList)
          Allow the player to save a list of entities to a MegaMek Unit List file.
 void saveSettings()
          Saves the current settings to the cfg file.
 void secondLOSHex(BoardViewEvent b, Coords c)
          Sent when secondLOS is set.
 void setDisplayVisible(boolean visible)
          Sets the visibility of the entity display window
protected  void setHelpFileName(java.lang.String fileName)
          Change the default help file name for this client.
 void setMapVisible(boolean visible)
          Sets the visibility of the minimap window
 void setSelectedEntityNum(int selectedEntityNum)
           
protected  void showBoardPopup(Coords c)
           
 void showHelp()
          Called when the user selects the "Help->Contents" menu item.
 void showLOSSettingDialog()
           
(package private)  void switchPanel(IGame.Phase phase)
           
 void systemMessage(java.lang.String message)
          Display a system message in the chat box.
 void toggleDisplay()
          Toggles the entity display window
 void toggleMap()
          Toggles the minimap window Also, toggles the minimap enabled setting
 void toggleUnitOverview()
           
 void unitSelected(BoardViewEvent b)
          Sent when Unit is selected.
 void windowActivated(java.awt.event.WindowEvent windowEvent)
           
 void windowClosed(java.awt.event.WindowEvent windowEvent)
           
 void windowClosing(java.awt.event.WindowEvent windowEvent)
           
 void windowDeactivated(java.awt.event.WindowEvent windowEvent)
           
 void windowDeiconified(java.awt.event.WindowEvent windowEvent)
           
 void windowIconified(java.awt.event.WindowEvent windowEvent)
           
 void windowOpened(java.awt.event.WindowEvent windowEvent)
           
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, 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, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, 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, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VIEW_MEK_DISPLAY

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

VIEW_MINI_MAP

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

VIEW_LOS_SETTING

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

VIEW_UNIT_OVERVIEW

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

VIEW_ZOOM_IN

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

VIEW_ZOOM_OUT

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

VIEW_TOGGLE_ISOMETRIC

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

frame

public java.awt.Frame frame

menuBar

protected CommonMenuBar menuBar

cb

ChatterBox cb

bv

public IBoardView bv

mechW

public java.awt.Dialog mechW

mechD

public MechDisplay mechD

minimapW

public java.awt.Dialog minimapW

minimap

public MiniMap minimap

popup

public java.awt.PopupMenu popup

ruler

public Ruler ruler

curPanel

protected java.awt.Component curPanel

chatlounge

public ChatLounge chatlounge

boardSelectionDialog

BoardSelectionDialog boardSelectionDialog

gameOptionsDialog

GameOptionsDialog gameOptionsDialog

client

public Client client

bingClip

java.applet.AudioClip bingClip
Cache for the "bing" soundclip.


phaseComponents

java.util.HashMap<java.lang.String,java.awt.Component> phaseComponents
Map phase component names to phase component objects.


selectedEntityNum

int selectedEntityNum
Current Selected entity


gameListener

protected GameListener gameListener
Constructor Detail

ClientGUI

public ClientGUI(Client client)
Construct a client which will display itself in a new frame. It will not try to connect to a server yet. When the frame closes, this client will clean up after itself as much as possible, but will not call System.exit().

Method Detail

getBoardView

public IBoardView getBoardView()

loadSoundClip

public void loadSoundClip()

systemMessage

public void systemMessage(java.lang.String message)
Display a system message in the chat box.

Parameters:
message - the String message to be shown.

initialize

public void initialize()
Have the client register itself as a listener wherever it's needed.

According to http://www-106.ibm.com/developerworks/java/library/j-jtp0618.html it is a major bad no-no to perform these registrations before the constructor finishes, so this function has to be called after the Client is created.


getMenuBar

public CommonMenuBar getMenuBar()
Get the menu bar for this client.

Returns:
the CommonMenuBar of this client.

setHelpFileName

protected void setHelpFileName(java.lang.String fileName)
Change the default help file name for this client.

This method should only be called by the constructor of subclasses.

Parameters:
fileName - the String name of the help file for this Client subclass. This value should not be null.

showHelp

public void showHelp()
Called when the user selects the "Help->Contents" menu item.

This method can be called by subclasses.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
Implement the ActionListener interface.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

saveSettings

public void saveSettings()
Saves the current settings to the cfg file.


die

public void die()
Shuts down threads and sockets


getBoardSelectionDialog

public BoardSelectionDialog getBoardSelectionDialog()
Returns the board selection dialog, creating it on the first call


getGameOptionsDialog

public GameOptionsDialog getGameOptionsDialog()

getMechSelectorDialog

public MechSelectorDialog getMechSelectorDialog()

getCustomFSDialog

public CustomFighterSquadronDialog getCustomFSDialog()

getStartingPositionDialog

public StartingPositionDialog getStartingPositionDialog()

getCustomInitiativeDialog

public CustomInitiativeDialog getCustomInitiativeDialog()

getPlanetaryConditionsDialog

public PlanetaryConditionsDialog getPlanetaryConditionsDialog()

switchPanel

void switchPanel(IGame.Phase phase)

addBag

protected void addBag(java.awt.Component comp,
                      java.awt.GridBagLayout gridbag,
                      java.awt.GridBagConstraints c)

showBoardPopup

protected void showBoardPopup(Coords c)

toggleDisplay

public void toggleDisplay()
Toggles the entity display window


setDisplayVisible

public void setDisplayVisible(boolean visible)
Sets the visibility of the entity display window


toggleUnitOverview

public void toggleUnitOverview()

toggleMap

public void toggleMap()
Toggles the minimap window Also, toggles the minimap enabled setting


setMapVisible

public void setMapVisible(boolean visible)
Sets the visibility of the minimap window


fillPopup

protected void fillPopup(Coords coords)

doChoiceDialog

public int[] doChoiceDialog(java.lang.String title,
                            java.lang.String question,
                            java.lang.String[] choices)
Pops up a dialog box giving the player a series of choices that are not mutually exclusive.

Parameters:
title - the String title of the dialog box.
question - the String question that has a "Yes" or "No" answer. The question will be split across multiple line on the '\n' characters.
choices - the array of String choices that the player can select from.
Returns:
The array of the int indexes of the from the input array that match the selected choices. If no choices were available, if the player did not select a choice, or if the player canceled the choice, a null value is returned.

doAlertDialog

public void doAlertDialog(java.lang.String title,
                          java.lang.String message)
Pops up a dialog box showing an alert


doYesNoDialog

public boolean doYesNoDialog(java.lang.String title,
                             java.lang.String question)
Pops up a dialog box asking a yes/no question

Parameters:
title - the String title of the dialog box.
question - the String question that has a "Yes" or "No" answer. The question will be split across multiple line on the '\n' characters.
Returns:
true if yes

doYesNoBotherDialog

public ConfirmDialog doYesNoBotherDialog(java.lang.String title,
                                         java.lang.String question)
Pops up a dialog box asking a yes/no question

The player will be given a chance to not show the dialog again.

Parameters:
title - the String title of the dialog box.
question - the String question that has a "Yes" or "No" answer. The question will be split across multiple line on the '\n' characters.
Returns:
the ConfirmDialog containing the player's responses. The dialog will already have been shown to the player, and is only being returned so the calling function can see the answer to the question and the state of the "Show again?" question.

loadListFile

protected void loadListFile()
Allow the player to select a MegaMek Unit List file to load. The Entitys in the file will replace any that the player has already selected. As such, this method should only be called in the chat lounge. The file can record damage sustained, non- standard munitions selected, and ammunition expended in a prior engagement.


saveListFile

protected void saveListFile(java.util.ArrayList<Entity> unitList)
Allow the player to save a list of entities to a MegaMek Unit List file. A "Save As" dialog will be displayed that allows the user to select the file's name and directory. The player can later load this file to quickly select the units for a new game. The file will record damage sustained, non-standard munitions selected, and ammunition expended during the course of the current engagement.

Parameters:
unitList - - the Vector of Entitys to be saved to a file. If this value is null or empty, the "Save As" dialog will not be displayed.

windowActivated

public void windowActivated(java.awt.event.WindowEvent windowEvent)
Specified by:
windowActivated in interface java.awt.event.WindowListener

windowClosed

public void windowClosed(java.awt.event.WindowEvent windowEvent)
Specified by:
windowClosed in interface java.awt.event.WindowListener

windowClosing

public void windowClosing(java.awt.event.WindowEvent windowEvent)
Specified by:
windowClosing in interface java.awt.event.WindowListener

windowDeactivated

public void windowDeactivated(java.awt.event.WindowEvent windowEvent)
Specified by:
windowDeactivated in interface java.awt.event.WindowListener

windowDeiconified

public void windowDeiconified(java.awt.event.WindowEvent windowEvent)
Specified by:
windowDeiconified in interface java.awt.event.WindowListener

windowIconified

public void windowIconified(java.awt.event.WindowEvent windowEvent)
Specified by:
windowIconified in interface java.awt.event.WindowListener

windowOpened

public void windowOpened(java.awt.event.WindowEvent windowEvent)
Specified by:
windowOpened in interface java.awt.event.WindowListener

getFrame

public java.awt.Frame getFrame()
Returns:
the frame this client is displayed in

showLOSSettingDialog

public void showLOSSettingDialog()

loadPreviewImage

public void loadPreviewImage(BufferedPanel bp,
                             Entity entity)

loadPreviewImage

public void loadPreviewImage(BufferedPanel bp,
                             Entity entity,
                             Player player)

bing

public void bing()
Make a "bing" sound.


getClient

public Client getClient()

getBots

public java.util.Map<java.lang.String,Client> getBots()

getSelectedEntityNum

public int getSelectedEntityNum()
Returns:
Returns the selectedEntityNum.

setSelectedEntityNum

public void setSelectedEntityNum(int selectedEntityNum)
Parameters:
selectedEntityNum - The selectedEntityNum to set.

getRandomArmyDialog

public RandomArmyDialog getRandomArmyDialog()

getRandomSkillDialog

public RandomSkillDialog getRandomSkillDialog()

hexMoused

public void hexMoused(BoardViewEvent b)
Description copied from interface: BoardViewListener
Sent when user clicks, double clicks or drags hex.

Specified by:
hexMoused in interface BoardViewListener
Parameters:
b - an event

hexCursor

public void hexCursor(BoardViewEvent b)
Description copied from interface: BoardViewListener
Sent when BoardView 'cursor' is set to Hex.

Specified by:
hexCursor in interface BoardViewListener
Parameters:
b - an event

boardHexHighlighted

public void boardHexHighlighted(BoardViewEvent b)
Description copied from interface: BoardViewListener
Sent when Hex is highlighted.

Specified by:
boardHexHighlighted in interface BoardViewListener
Parameters:
b - an event

hexSelected

public void hexSelected(BoardViewEvent b)
Description copied from interface: BoardViewListener
Sent when Hex is selected.

Specified by:
hexSelected in interface BoardViewListener
Parameters:
b - an event

firstLOSHex

public void firstLOSHex(BoardViewEvent b)
Description copied from interface: BoardViewListener
Sent when firstLOS is set.

Specified by:
firstLOSHex in interface BoardViewListener
Parameters:
b - an event

secondLOSHex

public void secondLOSHex(BoardViewEvent b,
                         Coords c)
Description copied from interface: BoardViewListener
Sent when secondLOS is set.

Specified by:
secondLOSHex in interface BoardViewListener
Parameters:
b - an event

finishedMovingUnits

public void finishedMovingUnits(BoardViewEvent b)
Description copied from interface: BoardViewListener
Sent when moving units is finished.

Specified by:
finishedMovingUnits in interface BoardViewListener
Parameters:
b - an event

unitSelected

public void unitSelected(BoardViewEvent b)
Description copied from interface: BoardViewListener
Sent when Unit is selected.

Specified by:
unitSelected in interface BoardViewListener
Parameters:
b - an event