net.sf.freecol.client.control
Class InGameInputHandler

java.lang.Object
  extended by net.sf.freecol.client.control.InputHandler
      extended by net.sf.freecol.client.control.InGameInputHandler
All Implemented Interfaces:
MessageHandler

public final class InGameInputHandler
extends InputHandler

Handles the network messages that arrives while in the getGame().


Nested Class Summary
(package private)  class InGameInputHandler.LootCargoSwingTask
          This class displays a dialog that lets the player choose goods to loot.
(package private)  class InGameInputHandler.NewLandNameSwingTask
           
(package private)  class InGameInputHandler.NewRegionNameSwingTask
           
(package private)  class InGameInputHandler.NoResultCanvasSwingTask
          Base class for Swing tasks that need to do a simple update without return value, and use the canvas.
(package private)  class InGameInputHandler.ReconnectSwingTask
          This task reconnects to the server.
(package private)  class InGameInputHandler.RefreshCanvasSwingTask
          This task refreshes the entire canvas.
(package private)  class InGameInputHandler.RefreshTilesSwingTask
           
(package private)  class InGameInputHandler.ShowConfirmDialogSwingTask
          This class shows a dialog and saves the answer (ok/cancel).
(package private)  class InGameInputHandler.ShowErrorMessageSwingTask
          This class shows an error dialog.
(package private)  class InGameInputHandler.ShowInformationMessageSwingTask
          This class shows an informational dialog.
(package private)  class InGameInputHandler.ShowInputDialogSwingTask
          This class shows a an input dialog and saves the answer (ok/cancel).
(package private)  class InGameInputHandler.ShowMessageSwingTask
          Base class for dialog SwingTasks.
(package private)  class InGameInputHandler.ShowModelMessageSwingTask
          This class shows a model message.
(package private)  class InGameInputHandler.ShowMonarchPanelSwingTask
          This class shows the monarch panel.
(package private)  class InGameInputHandler.ShowSelectSwingTask
          This class displays a dialog that lets the player pick a Founding Father.
(package private)  class InGameInputHandler.ShowVictoryPanelSwingTask
          This task shows the victory panel.
(package private)  class InGameInputHandler.SpyColonySwingTask
          This task shows an enhanced colony panel, then restores the normal information when it closes.
(package private) static class InGameInputHandler.SwingTask
          This utility class is the base class for tasks that need to run in the event dispatch thread.
(package private)  class InGameInputHandler.UnitAttackAnimationCanvasSwingTask
          This task plays an unit attack animation in the Canvas.
(package private)  class InGameInputHandler.UnitMoveAnimationCanvasSwingTask
          This task plays an unit movement animation in the Canvas.
(package private)  class InGameInputHandler.UpdateMenuBarSwingTask
          This task updates the menu bar.
 
Field Summary
private  Unit lastAnimatedUnit
           
private static java.util.logging.Logger logger
           
 
Fields inherited from class net.sf.freecol.client.control.InputHandler
gui
 
Constructor Summary
InGameInputHandler(FreeColClient freeColClient, GUI gui)
          The constructor to use.
 
Method Summary
 org.w3c.dom.Element addObject(org.w3c.dom.Element element)
          Add the objects which are the children of this Element.
private  org.w3c.dom.Element addPlayer(org.w3c.dom.Element element)
          Handles an "addPlayer"-message.
private  org.w3c.dom.Element animateAttack(org.w3c.dom.Element element)
          Handles an "animateAttack"-message.
private  org.w3c.dom.Element animateMove(org.w3c.dom.Element element)
          Handles an "animateMove"-message.
private  org.w3c.dom.Element chat(org.w3c.dom.Element element)
          Handles a "chat"-message.
private  org.w3c.dom.Element chooseFoundingFather(org.w3c.dom.Element element)
          Handles an "chooseFoundingFather"-request.
 org.w3c.dom.Element closeMenus()
          Trivial handler to allow the server to signal to the client that an offer that caused a popup (for example, a native demand or diplomacy proposal) has not been answered quickly enough and that the offering player has assumed this player has refused-by-inaction, and therefore, the popup needs to be closed.
private  org.w3c.dom.Element diplomacy(org.w3c.dom.Element element)
          Handles a "diplomacy"-request.
 org.w3c.dom.Element disposeUnits(org.w3c.dom.Element element)
          Disposes of the Units which are the children of this Element.
private  org.w3c.dom.Element error(org.w3c.dom.Element element)
          Handles an "error"-message.
 org.w3c.dom.Element fountainOfYouth(org.w3c.dom.Element element)
          Ask the player to choose migrants from a fountain of youth event.
private  org.w3c.dom.Element gameEnded(org.w3c.dom.Element element)
          Handles a "gameEnded"-message.
 org.w3c.dom.Element handle(Connection connection, org.w3c.dom.Element element)
          Deals with incoming messages that have just been received.
private  org.w3c.dom.Element indianDemand(org.w3c.dom.Element element)
          Handles an "indianDemand"-request.
 org.w3c.dom.Element lootCargo(org.w3c.dom.Element element)
          Ask the player to choose something to loot.
private  org.w3c.dom.Element monarchAction(org.w3c.dom.Element element)
          Handles a "monarchAction"-request.
 org.w3c.dom.Element multiple(Connection connection, org.w3c.dom.Element element)
          Handle all the children of this element.
 org.w3c.dom.Element newLandName(org.w3c.dom.Element element)
          Ask the player to name the new land.
 org.w3c.dom.Element newRegionName(org.w3c.dom.Element element)
          Ask the player to name a new region.
private  org.w3c.dom.Element newTurn(org.w3c.dom.Element element)
          Handles a "newTurn"-message.
private  org.w3c.dom.Element reconnect(org.w3c.dom.Element element)
          Handles an "reconnect"-message.
private  org.w3c.dom.Element remove(org.w3c.dom.Element removeElement)
          Handles a "remove"-message.
private static Unit selectUnitFromElement(Game game, org.w3c.dom.Element element, java.lang.String id)
          Sometimes units appear which the client does not know about, and are passed in as the children of the parent element.
private  org.w3c.dom.Element setAI(org.w3c.dom.Element element)
          Handles a "setAI"-message.
private  org.w3c.dom.Element setCurrentPlayer(org.w3c.dom.Element element)
          Handles a "setCurrentPlayer"-message.
private  org.w3c.dom.Element setDead(org.w3c.dom.Element element)
          Handles a "setDead"-message.
private  org.w3c.dom.Element setStance(org.w3c.dom.Element element)
          Handles a "setStance"-request.
private  org.w3c.dom.Element spyResult(org.w3c.dom.Element element)
          Handles a "spyResult" message.
private  void takeTurn(Player player, boolean newTurn)
           
 org.w3c.dom.Element update(org.w3c.dom.Element updateElement)
          Handles an "update"-message.
private  void updateGameObjects(org.w3c.dom.NodeList nodeList)
          Updates all FreeColGameObjects from the childNodes of the message
 
Methods inherited from class net.sf.freecol.client.control.InputHandler
disconnect, getFreeColClient, getGame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

lastAnimatedUnit

private Unit lastAnimatedUnit
Constructor Detail

InGameInputHandler

public InGameInputHandler(FreeColClient freeColClient,
                          GUI gui)
The constructor to use.

Parameters:
freeColClient - The main controller.
Method Detail

handle

public org.w3c.dom.Element handle(Connection connection,
                                  org.w3c.dom.Element element)
Deals with incoming messages that have just been received.

Specified by:
handle in interface MessageHandler
Specified by:
handle in class InputHandler
Parameters:
connection - The Connection the message was received on.
element - The root element of the message.
Returns:
The reply.

reconnect

private org.w3c.dom.Element reconnect(org.w3c.dom.Element element)
Handles an "reconnect"-message.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

update

public org.w3c.dom.Element update(org.w3c.dom.Element updateElement)
Handles an "update"-message.

Parameters:
updateElement - The element (root element in a DOM-parsed XML tree) that holds all the information.
Returns:
The reply.

updateGameObjects

private void updateGameObjects(org.w3c.dom.NodeList nodeList)
Updates all FreeColGameObjects from the childNodes of the message

Parameters:
nodeList - The list of nodes from the message

remove

private org.w3c.dom.Element remove(org.w3c.dom.Element removeElement)
Handles a "remove"-message.

Parameters:
removeElement - The element (root element in a DOM-parsed XML tree) that holds all the information.

selectUnitFromElement

private static Unit selectUnitFromElement(Game game,
                                          org.w3c.dom.Element element,
                                          java.lang.String id)
Sometimes units appear which the client does not know about, and are passed in as the children of the parent element.

Parameters:
game - The Game to add the unit to.
element - The Element to find a unit in.
id - The id of the unit to find.
Returns:
A unit or null if none found.

animateMove

private org.w3c.dom.Element animateMove(org.w3c.dom.Element element)
Handles an "animateMove"-message. This only performs animation, if required. It does not actually change unit positions, which happens in an "update".

Parameters:
element - An element (root element in a DOM-parsed XML tree) that holds attributes for the old and new tiles and an element for the unit that is moving (which are used solely to operate the animation).

animateAttack

private org.w3c.dom.Element animateAttack(org.w3c.dom.Element element)
Handles an "animateAttack"-message. This only performs animation, if required. It does not actually perform any attacks.

Parameters:
element - An element (root element in a DOM-parsed XML tree) that holds attributes for the old and new tiles and an element for the unit that is moving (which are used solely to operate the animation).

takeTurn

private void takeTurn(Player player,
                      boolean newTurn)

setCurrentPlayer

private org.w3c.dom.Element setCurrentPlayer(org.w3c.dom.Element element)
Handles a "setCurrentPlayer"-message.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.
Returns:
an Element value

newTurn

private org.w3c.dom.Element newTurn(org.w3c.dom.Element element)
Handles a "newTurn"-message.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

setDead

private org.w3c.dom.Element setDead(org.w3c.dom.Element element)
Handles a "setDead"-message.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

gameEnded

private org.w3c.dom.Element gameEnded(org.w3c.dom.Element element)
Handles a "gameEnded"-message.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

chat

private org.w3c.dom.Element chat(org.w3c.dom.Element element)
Handles a "chat"-message.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

error

private org.w3c.dom.Element error(org.w3c.dom.Element element)
Handles an "error"-message.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

setAI

private org.w3c.dom.Element setAI(org.w3c.dom.Element element)
Handles a "setAI"-message.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

chooseFoundingFather

private org.w3c.dom.Element chooseFoundingFather(org.w3c.dom.Element element)
Handles an "chooseFoundingFather"-request.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

diplomacy

private org.w3c.dom.Element diplomacy(org.w3c.dom.Element element)
Handles a "diplomacy"-request. If the message informs of an acceptance or rejection then display the result and return null. If the message is a proposal, then ask the user about it and return the response with appropriate response set.

Parameters:
element - The element (root element in a DOM-parsed XML tree) containing a "diplomacy"-message.
Returns:
A diplomacy response, or null if none required.

indianDemand

private org.w3c.dom.Element indianDemand(org.w3c.dom.Element element)
Handles an "indianDemand"-request.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

spyResult

private org.w3c.dom.Element spyResult(org.w3c.dom.Element element)
Handles a "spyResult" message.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

monarchAction

private org.w3c.dom.Element monarchAction(org.w3c.dom.Element element)
Handles a "monarchAction"-request.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

setStance

private org.w3c.dom.Element setStance(org.w3c.dom.Element element)
Handles a "setStance"-request.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

addPlayer

private org.w3c.dom.Element addPlayer(org.w3c.dom.Element element)
Handles an "addPlayer"-message.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

disposeUnits

public org.w3c.dom.Element disposeUnits(org.w3c.dom.Element element)
Disposes of the Units which are the children of this Element.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

addObject

public org.w3c.dom.Element addObject(org.w3c.dom.Element element)
Add the objects which are the children of this Element.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

newLandName

public org.w3c.dom.Element newLandName(org.w3c.dom.Element element)
Ask the player to name the new land.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

newRegionName

public org.w3c.dom.Element newRegionName(org.w3c.dom.Element element)
Ask the player to name a new region.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

fountainOfYouth

public org.w3c.dom.Element fountainOfYouth(org.w3c.dom.Element element)
Ask the player to choose migrants from a fountain of youth event.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

lootCargo

public org.w3c.dom.Element lootCargo(org.w3c.dom.Element element)
Ask the player to choose something to loot.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information.

closeMenus

public org.w3c.dom.Element closeMenus()
Trivial handler to allow the server to signal to the client that an offer that caused a popup (for example, a native demand or diplomacy proposal) has not been answered quickly enough and that the offering player has assumed this player has refused-by-inaction, and therefore, the popup needs to be closed.

Returns:
Null.

multiple

public org.w3c.dom.Element multiple(Connection connection,
                                    org.w3c.dom.Element element)
Handle all the children of this element.

Parameters:
connection - The Connection the element arrived on.
element - The Element to process.
Returns:
An Element containing the response/s.