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
 Worker worker
           
 
Constructor Summary
FreeColClient(boolean windowed, java.awt.Dimension innerWindowSize, ImageLibrary imageLibrary, MusicLibrary musicLibrary, SfxLibrary sfxLibrary, boolean showOpeningVideo)
          Creates a new FreeColClient.
 
Method Summary
 boolean canPlayMusic()
          Verifies if the client can play music
 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 changeWindowedMode(boolean windowed)
          Change the windowed mode.
 void continuePlaying()
          Continue playing after win the game
 ActionManager getActionManager()
          Gets the object responsible for keeping and updating the actions.
 Canvas getCanvas()
          Gets the Canvas this client uses to display the GUI-components.
 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.
 javax.swing.JFrame getFrame()
          Describe getFrame method here.
 FreeColServer getFreeColServer()
          Gets the FreeColServer started by the client.
 Game getGame()
          Gets the Game that we are currently playing.
 GUI getGUI()
          Gets the GUI that is being used to draw the map on the Canvas.
 ImageLibrary getImageLibrary()
          Gets the ImageLibrary.
 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()
           
 ClientModelController getModelController()
          Gets the ClientModelController.
 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 isLoggedIn()
          Returns true if this client is logged in to a server or false otherwise.
 boolean isMapEditor()
           
 boolean isRetired()
          Has the user retired the game.
 boolean isSingleplayer()
          Is the user playing in singleplayer mode.
 boolean isWindowed()
          Checks if the application is displayed in a window.
 void loadClientOptions()
          Reads the ClientOptions from the given file.
 void loadClientOptions(java.io.File loadFile)
          Reads the ClientOptions from the given file.
 void playMusic(java.lang.String music)
          Plays the music.
 void playMusicOnce(java.lang.String music)
          Plays a random music from the given playlist.
 void playMusicOnce(java.lang.String music, int delay)
          Plays a random music from the given playlist.
 void playSound(SoundLibrary.SoundEffect sound)
          Plays the given sound effect.
 void playSound(java.lang.String sound)
          Plays the given sound effect.
 void quit()
          Quits the application without any questions.
 boolean retire()
          Retires the player from the game.
 void saveClientOptions()
          Writes the client options to the default location.
 void saveClientOptions(java.io.File saveFile)
          Writes the client options to the given file.
 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 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 updateMenuBar()
          Describe updateMenuBar method here.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

worker

public final Worker worker
Constructor Detail

FreeColClient

public FreeColClient(boolean windowed,
                     java.awt.Dimension innerWindowSize,
                     ImageLibrary imageLibrary,
                     MusicLibrary musicLibrary,
                     SfxLibrary sfxLibrary,
                     boolean showOpeningVideo)
Creates a new FreeColClient. Creates the control objects and starts the GUI.

Parameters:
windowed - Determines if the Canvas should be displayed within a JFrame (when true) or in fullscreen mode (when false).
innerWindowSize - The inner size of the window (borders not included).
imageLibrary - The object holding the images.
musicLibrary - The object holding the music.
sfxLibrary - The object holding the sound effects.
showOpeningVideo - Display the opening video.
Method Detail

isHeadless

public boolean isHeadless()
Get the Headless value.

Returns:
a boolean value

setHeadless

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

Parameters:
newHeadless - The new Headless value.

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

getFrame

public javax.swing.JFrame getFrame()
Describe getFrame method here.

Returns:
a JFrame value

updateMenuBar

public void updateMenuBar()
Describe updateMenuBar method here.


changeWindowedMode

public void changeWindowedMode(boolean windowed)
Change the windowed mode.

Parameters:
windowed - Use true for windowed mode and false for fullscreen mode.

isWindowed

public boolean isWindowed()
Checks if the application is displayed in a window.

Returns:
true if the application is currently displayed in a frame, and false if currently in fullscreen mode.
See Also:
changeWindowedMode(boolean)

saveClientOptions

public void saveClientOptions()
Writes the client options to the default location.

See Also:
ClientOptions

setMapEditor

public void setMapEditor(boolean mapEditor)

isMapEditor

public boolean isMapEditor()

saveClientOptions

public void saveClientOptions(java.io.File saveFile)
Writes the client options to the given file.

Parameters:
saveFile - The file where the client options should be written.
See Also:
ClientOptions

getImageLibrary

public ImageLibrary getImageLibrary()
Gets the ImageLibrary.

Returns:
The ImageLibrary.

loadClientOptions

public void loadClientOptions()
Reads the ClientOptions from the given file.


loadClientOptions

public void loadClientOptions(java.io.File loadFile)
Reads the ClientOptions from the given file.

Parameters:
loadFile - The File to read the ClientOptions from.

getActionManager

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

Returns:
The ActionManager.

getClientOptions

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

Returns:
The ClientOptions.

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)

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

setFreeColServer

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

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

getFreeColServer

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

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

setGame

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

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

getGame

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

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

getCanvas

public Canvas getCanvas()
Gets the Canvas this client uses to display the GUI-components.

Returns:
The Canvas.

getGUI

public GUI getGUI()
Gets the GUI that is being used to draw the map on the Canvas.

Returns:
The GUI.

quit

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


retire

public boolean retire()
Retires the player from the game. Returns true if the player achieved a new high score.

Returns:
a boolean value

continuePlaying

public void continuePlaying()
Continue playing after win the game


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.

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

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)

setIsRetired

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

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

isRetired

public boolean isRetired()
Has the user retired the game.

Returns:
true if the user has retired the game and false otherwise.

getConnectController

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

Returns:
The ConnectController.

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.

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.

getModelController

public ClientModelController getModelController()
Gets the ClientModelController.

Returns:
The ClientModelController.

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

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)

playMusic

public void playMusic(java.lang.String music)
Plays the music.


playMusicOnce

public void playMusicOnce(java.lang.String music)
Plays a random music from the given playlist.


playMusicOnce

public void playMusicOnce(java.lang.String music,
                          int delay)
Plays a random music from the given playlist.

Parameters:
delay - A delay before playing the sound (ms).

playSound

public void playSound(java.lang.String sound)
Plays the given sound effect.

Parameters:
sound - The key sound effect given by SfxLibrary.

playSound

public void playSound(SoundLibrary.SoundEffect sound)
Plays the given sound effect.

Parameters:
sound - The key sound effect given by SfxLibrary.

canPlayMusic

public boolean canPlayMusic()
Verifies if the client can play music


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.

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.