net.sf.freecol.client
Class FreeColClient

java.lang.Object
  extended by net.sf.freecol.client.FreeColClient

public final class FreeColClient
extends java.lang.Object

The main control class for the FreeCol client. This class both starts and keeps references to the GUI and the control objects.


Field Summary
private  ActionManager actionManager
           
private  Client client
          The network Client that can be used to send messages to the server.
private  ClientOptions clientOptions
           
private  ConnectController connectController
           
private  FreeColServer freeColServer
          The server that has been started from the client-GUI.
private  Game game
           
private  GUI gui
           
private  boolean headless
          Describe headless here.
private  boolean inGame
          Indicates if the game has started, has nothing to do with whether or not the client is logged in.
private  InGameController inGameController
           
private  InGameInputHandler inGameInputHandler
           
private  boolean isRetired
           
private  boolean loggedIn
          Indicated whether or not there is an open connection to the server.
private static java.util.logging.Logger logger
           
private  boolean mapEditor
           
private  MapEditorController mapEditorController
           
private  Player player
          The player "owning" this client.
private  PreGameController preGameController
           
private  PreGameInputHandler preGameInputHandler
           
private  ServerAPI serverAPI
           
private  boolean singleplayer
           
 Worker worker
           
 
Constructor Summary
FreeColClient(java.io.File savedGame, java.awt.Dimension size, boolean sound, java.lang.String splashFilename, boolean showOpeningVideo, java.lang.String fontName)
          Creates a new FreeColClient.
 
Method Summary
 ServerAPI askServer()
          Meaningfully named access to the ServerAPI.
 void askToQuit()
          Quits the application.
 boolean canSaveCurrentGame()
          Verifies if this client can save the current game Clients that do not have the server running, or that have not the required permissions cannot save and should have the menu entry disabled
 void continuePlaying()
          Continue playing after winning the game.
 boolean currentPlayerIsMyPlayer()
           
private  void exitActions()
           
 ActionManager getActionManager()
          Gets the object responsible for keeping and updating the actions.
 Client getClient()
          Gets the Client that can be used to send messages to the server.
 ClientOptions getClientOptions()
          Returns the object keeping the current client options.
 ConnectController getConnectController()
          Gets the controller responsible for starting a server and connecting to it.
 FreeColServer getFreeColServer()
          Gets the FreeColServer started by the client.
 Game getGame()
          Gets the Game that we are currently playing.
 GUI getGUI()
           
 InGameController getInGameController()
          Gets the controller that will be used when the game has been started.
 InGameInputHandler getInGameInputHandler()
          Gets the input handler that will be used when the game has been started.
 MapEditorController getMapEditorController()
           
 Player getMyPlayer()
          Gets the Player that uses this client.
 PreGameController getPreGameController()
          Gets the controller that will be used before the game has been started.
 PreGameInputHandler getPreGameInputHandler()
          Gets the input handler that will be used before the game has been started.
 boolean isAdmin()
          Checks if this client is the game admin.
 boolean isHeadless()
          Get the Headless value.
 boolean isInGame()
          Checks if the game has started.
 boolean isLoggedIn()
          Returns true if this client is logged in to a server or false otherwise.
 boolean isMapEditor()
           
 boolean isSingleplayer()
          Is the user playing in singleplayer mode.
private  void loadClientOptions(java.io.File savedGame)
          Loads the client options.
 void newGame()
          Displays a quit dialog and, if desired, logs out of the current game and shows the new game panel.
 void quit()
          Quits the application without any questions.
 void retire()
          Quits the application.
 void setClient(Client client)
          Sets the Client that shall be used to send messages to the server.
 void setFreeColServer(FreeColServer freeColServer)
          Sets the FreeColServer which has been started by the client gui.
 void setGame(Game game)
          Sets the Game that we are currently playing.
 void setHeadless(boolean newHeadless)
          Set the Headless value.
 void setInGame(boolean inGame)
          Notifies this GUI that the game has started or ended.
 void setIsRetired(boolean isRetired)
          Sets whether or not the user has retired the game.
 void setLoggedIn(boolean loggedIn)
          Sets whether or not this client is logged in to a server.
 void setMapEditor(boolean mapEditor)
           
 void setMyPlayer(Player player)
          Sets the Player that uses this client.
 void setSingleplayer(boolean singleplayer)
          Sets whether or not this game is a singleplayer game.
 void skipTurns(int turns)
          Start the game skipping turns.
 
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

connectController

private ConnectController connectController

preGameController

private PreGameController preGameController

preGameInputHandler

private PreGameInputHandler preGameInputHandler

inGameController

private InGameController inGameController

inGameInputHandler

private InGameInputHandler inGameInputHandler

mapEditorController

private MapEditorController mapEditorController

serverAPI

private ServerAPI serverAPI

gui

private GUI gui

client

private Client client
The network Client that can be used to send messages to the server.


game

private Game game

player

private Player player
The player "owning" this client.


isRetired

private boolean isRetired

inGame

private boolean inGame
Indicates if the game has started, has nothing to do with whether or not the client is logged in.


freeColServer

private FreeColServer freeColServer
The server that has been started from the client-GUI.


mapEditor

private boolean mapEditor

singleplayer

private boolean singleplayer

actionManager

private final ActionManager actionManager

clientOptions

private ClientOptions clientOptions

worker

public final Worker worker

loggedIn

private boolean loggedIn
Indicated whether or not there is an open connection to the server. This is not an indication of the existence of a Connection Object, but instead it is an indication of an approved login to a server.


headless

private boolean headless
Describe headless here.

Constructor Detail

FreeColClient

public FreeColClient(java.io.File savedGame,
                     java.awt.Dimension size,
                     boolean sound,
                     java.lang.String splashFilename,
                     boolean showOpeningVideo,
                     java.lang.String fontName)
Creates a new FreeColClient. Creates the control objects and starts the GUI.

Parameters:
savedGame - An optional saved game.
size - An optional window size.
sound - True if sounds should be played
splashFilename - The name of the splash image.
showOpeningVideo - Display the opening video.
fontName - An optional override of the main font.
Method Detail

askServer

public ServerAPI askServer()
Meaningfully named access to the ServerAPI.

Returns:
A ServerAPI.

askToQuit

public void askToQuit()
Quits the application. This method uses #showConfirmDialog in order to get a "Are you sure"-confirmation from the user.


canSaveCurrentGame

public boolean canSaveCurrentGame()
Verifies if this client can save the current game Clients that do not have the server running, or that have not the required permissions cannot save and should have the menu entry disabled

Returns:
true if this client can save the game in progress, false otherwise

continuePlaying

public void continuePlaying()
Continue playing after winning the game.


currentPlayerIsMyPlayer

public boolean currentPlayerIsMyPlayer()

getActionManager

public ActionManager getActionManager()
Gets the object responsible for keeping and updating the actions.

Returns:
The ActionManager.

getClient

public Client getClient()
Gets the Client that can be used to send messages to the server.

Returns:
the Client
See Also:
setClient(net.sf.freecol.client.networking.Client)

getClientOptions

public ClientOptions getClientOptions()
Returns the object keeping the current client options.

Returns:
The ClientOptions.

getConnectController

public ConnectController getConnectController()
Gets the controller responsible for starting a server and connecting to it.

Returns:
The ConnectController.

getFreeColServer

public FreeColServer getFreeColServer()
Gets the FreeColServer started by the client.

Returns:
The FreeColServer or null if no server has been started.

getGame

public Game getGame()
Gets the Game that we are currently playing.

Returns:
The Game.
See Also:
setGame(net.sf.freecol.common.model.Game)

getGUI

public GUI getGUI()

getInGameController

public InGameController getInGameController()
Gets the controller that will be used when the game has been started.

Returns:
The InGameController.

getInGameInputHandler

public InGameInputHandler getInGameInputHandler()
Gets the input handler that will be used when the game has been started.

Returns:
The InGameInputHandler.

getMapEditorController

public MapEditorController getMapEditorController()

getMyPlayer

public Player getMyPlayer()
Gets the Player that uses this client.

Returns:
The Player made to represent this clients user.
See Also:
setMyPlayer(Player)

getPreGameController

public PreGameController getPreGameController()
Gets the controller that will be used before the game has been started.

Returns:
The PreGameController.

getPreGameInputHandler

public PreGameInputHandler getPreGameInputHandler()
Gets the input handler that will be used before the game has been started.

Returns:
The PreGameInputHandler.

isAdmin

public boolean isAdmin()
Checks if this client is the game admin.

Returns:
true if the client is the game admin and false otherwise. false is also returned if a game have not yet been started.

isHeadless

public boolean isHeadless()
Get the Headless value.

Returns:
a boolean value

isInGame

public boolean isInGame()
Checks if the game has started.

Returns:
true if the game has started.
See Also:
setInGame(boolean)

isLoggedIn

public boolean isLoggedIn()
Returns true if this client is logged in to a server or false otherwise.

Returns:
true if this client is logged in to a server or false otherwise.

isMapEditor

public boolean isMapEditor()

isSingleplayer

public boolean isSingleplayer()
Is the user playing in singleplayer mode.

Returns:
true if the user is playing in singleplayer mode and false otherwise.
See Also:
setSingleplayer(boolean)

newGame

public void newGame()
Displays a quit dialog and, if desired, logs out of the current game and shows the new game panel.


quit

public void quit()
Quits the application without any questions.


retire

public void retire()
Quits the application. This method uses #showConfirmDialog in order to get a "Are you sure"-confirmation from the user.


setClient

public void setClient(Client client)
Sets the Client that shall be used to send messages to the server.

Parameters:
client - the Client
See Also:
getClient()

setFreeColServer

public void setFreeColServer(FreeColServer freeColServer)
Sets the FreeColServer which has been started by the client gui.

Parameters:
freeColServer - The FreeColServer.
See Also:
getFreeColServer()

setGame

public void setGame(Game game)
Sets the Game that we are currently playing.

Parameters:
game - The Game.
See Also:
getGame()

setHeadless

public void setHeadless(boolean newHeadless)
Set the Headless value.

Parameters:
newHeadless - The new Headless value.

setInGame

public void setInGame(boolean inGame)
Notifies this GUI that the game has started or ended.

Parameters:
inGame - Indicates whether or not the game has started.

setIsRetired

public void setIsRetired(boolean isRetired)
Sets whether or not the user has retired the game.

Parameters:
isRetired - Indicates whether or not the user has retired the game.

setLoggedIn

public void setLoggedIn(boolean loggedIn)
Sets whether or not this client is logged in to a server.

Parameters:
loggedIn - An indication of whether or not this client is logged in to a server.

setMapEditor

public void setMapEditor(boolean mapEditor)

setMyPlayer

public void setMyPlayer(Player player)
Sets the Player that uses this client.

Parameters:
player - The Player made to represent this clients user.
See Also:
getMyPlayer()

setSingleplayer

public void setSingleplayer(boolean singleplayer)
Sets whether or not this game is a singleplayer game.

Parameters:
singleplayer - Indicates whether or not this game is a singleplayer game.
See Also:
isSingleplayer()

skipTurns

public void skipTurns(int turns)
Start the game skipping turns.

Parameters:
turns - The number of turns to skip.

exitActions

private void exitActions()

loadClientOptions

private void loadClientOptions(java.io.File savedGame)
Loads the client options. There are several sources: 1) Base options (set in the ClientOptions constructor with ClientOptions.addDefaultOptions()) 2) Standard action manager actions 3) Saved game 4) User options

Parameters:
savedGame - An optional File to load options from.