megamek.client.ui.swing
Class ClientGUI

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 megamek.client.ui.swing.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 javax.swing.JPanel
implements java.awt.event.WindowListener, BoardViewListener, java.awt.event.ActionListener

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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 IBoardView bv
           
(package private)  ChatterBox cb
           
(package private)  ChatterBox2 cb2
           
 ChatLounge chatlounge
           
protected  javax.swing.JComponent curPanel
           
 javax.swing.JFrame frame
           
(package private)  GameOptionsDialog gameOptionsDialog
           
 MechDisplay mechD
           
 javax.swing.JDialog mechW
           
protected  CommonMenuBar menuBar
           
 MiniMap minimap
           
 javax.swing.JDialog minimapW
           
(package private)  java.util.HashMap<java.lang.String,javax.swing.JComponent> phaseComponents
          Map phase component names to phase component objects.
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 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
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.
(package private)  void bing()
          Make a "bing" sound.
 void boardHexHighlighted(BoardViewEvent b)
          Sent when Hex is highlighted.
(package private)  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
 void finishedMovingUnits(BoardViewEvent b)
          Sent when moving units is finished.
 void firstLOSHex(BoardViewEvent b)
          Sent when firstLOS is set.
 IBoardView getBoardView()
           
 java.util.Map<java.lang.String,Client> getBots()
           
 Client getClient()
           
 CustomFighterSquadronDialog getCustomFSDialog()
           
 javax.swing.JFrame 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(javax.swing.JLabel bp, Entity entity)
           
 void loadPreviewImage(javax.swing.JLabel bp, Entity entity, Player player)
           
protected  void saveListFile(java.util.ArrayList<Entity> unitList)
          Allow the player to save a list of entities to a MegaMek Unit List file.
(package private)  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
(package private)  void setMapVisible(boolean visible)
          Sets the visibility of the minimap window
 void setSelectedEntityNum(int selectedEntityNum)
           
protected  void showBoardPopup(Coords c)
           
(package private)  void switchPanel(IGame.Phase phase)
           
 void systemMessage(java.lang.String message)
          Display a system message in the chat box.
 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 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, getBaseline, getBaselineResizeBehavior, 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, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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, 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, 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 javax.swing.JFrame frame

menuBar

protected CommonMenuBar menuBar

cb

ChatterBox cb

cb2

ChatterBox2 cb2

bv

public IBoardView bv

mechW

public javax.swing.JDialog mechW

mechD

public MechDisplay mechD

minimapW

public javax.swing.JDialog minimapW

minimap

public MiniMap minimap

curPanel

protected javax.swing.JComponent curPanel

chatlounge

public ChatLounge chatlounge

gameOptionsDialog

GameOptionsDialog gameOptionsDialog

phaseComponents

java.util.HashMap<java.lang.String,javax.swing.JComponent> phaseComponents
Map phase component names to phase component objects.

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()

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.

actionPerformed

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

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

saveSettings

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


die

void die()
Shuts down threads and sockets


getGameOptionsDialog

public GameOptionsDialog getGameOptionsDialog()

getMechSelectorDialog

public MechSelectorDialog getMechSelectorDialog()

getCustomFSDialog

public CustomFighterSquadronDialog getCustomFSDialog()

getStartingPositionDialog

public StartingPositionDialog getStartingPositionDialog()

getPlanetaryConditionsDialog

public PlanetaryConditionsDialog getPlanetaryConditionsDialog()

switchPanel

void switchPanel(IGame.Phase phase)

showBoardPopup

protected void showBoardPopup(Coords c)

setDisplayVisible

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


setMapVisible

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


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 javax.swing.JFrame getFrame()
Returns:
the frame this client is displayed in

loadPreviewImage

public void loadPreviewImage(javax.swing.JLabel bp,
                             Entity entity)

loadPreviewImage

public void loadPreviewImage(javax.swing.JLabel bp,
                             Entity entity,
                             Player player)

bing

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