com.realtime.crossfire.jxclient.window
Class GuiManager

java.lang.Object
  extended by com.realtime.crossfire.jxclient.window.GuiManager

public class GuiManager
extends java.lang.Object

Maintains the application's main GUI state.


Field Summary
private  JXCConnection connection
          The JXCConnection to use.
private  CrossfireDrawextinfoListener crossfireDrawextinfoListener
          The CrossfireDrawextinfoListener attached to server.
private  boolean currentQueryDialogIsNamePrompt
          Whether the currently shown query dialog is the character name prompt.
private  Gui dialogConnect
          The "connect in progress" dialog.
private  AbstractLabel dialogConnectLabel
          The "message" field within dialogConnect.
private  Gui dialogDisconnect
          The "really disconnect?" dialog.
private  Gui dialogQuit
          The "really quit?" dialog.
private  GuiFactory guiFactory
          The GuiFactory for creating Gui instances.
private  GuiStateListener guiStateListener
          The GuiStateListener for detecting established or dropped connections.
private  Gui keybindDialog
          The keybindings dialog.
private  KeybindingsManager keybindingsManager
          The key bindings manager for this window.
private  Gui queryDialog
          The query dialog.
private  CrossfireServerConnection server
          The CrossfireServerConnection instance to monitor.
private  Settings settings
          The Settings to use.
private  JXCSkin skin
          The currently active skin.
private  TooltipManager tooltipManager
          The TooltipManager for this window.
private  JXCWindowRenderer windowRenderer
          The JXCWindowRenderer used to paint the gui.
 
Constructor Summary
GuiManager(GuiStateManager guiStateManager, TooltipManager tooltipManager, Settings settings, CrossfireServerConnection server, JXCWindowRenderer windowRenderer, GuiFactory guiFactory, KeybindingsManager keybindingsManager, JXCConnection connection)
          Creates a new instance.
 
Method Summary
private  GUIText activateCommandInput()
          Activates the command input text field.
 void activateCommandInput(java.lang.String newText)
          Activates the command input text field.
private  void activateMetaserverGui()
          Called when the server selection GUI becomes active.
 void closeDialog(Gui dialog)
          Closes the given dialog.
private  void closeDialogByName(java.lang.String name)
          Closes a dialog by name.
 void closeKeybindDialog()
          Closes the keybinding dialog.
 void closeQueryDialog()
          Closes the "query" dialog.
private  void closeTransientDialogs()
          Closes all transient dialogs: disconnect, quit, connect, query, and book dialogs.
 boolean createKeyBinding(boolean perCharacter, CommandList cmdList)
          Adds a key binding.
 int escPressed(boolean connected)
          The ESC key has been pressed.
 CommandList getCommandList(java.lang.String args)
          Returns a named command list.
 void hideAccountWindows()
          Hides all account-related windows.
 void manageAccount()
          Displays the main account dialog, to let the player login or create a new account.
 boolean openDialog(Gui dialog, boolean autoCloseOnDeactivate)
          Opens a dialog.
private  boolean openDialogByName(java.lang.String name)
          Opens a dialog by name.
private  void openKeybindDialog()
          Opens the keybinding dialog.
 void openQueryDialog(java.lang.String prompt, int queryType)
          Opens the "query" dialog.
 boolean openQuitDialog()
          Opens the "quit" dialog.
 void playerReceived()
          A "player" protocol command has been received.
 boolean removeKeyBinding(boolean perCharacter)
          Removes a key binding.
 void selectCharacter(java.lang.String accountName, java.lang.String characterName)
          Updates the selected character name in an account.
 void setAccountName(java.lang.String accountName)
          Updates the current account name.
 void setSkin(JXCSkin skin)
          Sets a new skin.
 void showCharacters()
          Displays the window with the characters for an account.
private  void showGUIMain()
          Displays the "main" GUI.
private  void showGUIMeta()
          Displays the "server selection" GUI.
private  void showGUIStart()
          Displays the "start" GUI.
 void term()
           
 void toggleDialog(Gui dialog)
          Toggles a dialog.
 void unsetSkin()
          Unsets the current skin.
private  void updateConnectLabel(ClientSocketState clientSocketState, java.lang.String param)
          Updates the "message" field of the connect dialog.
 void updatePlayerName(java.lang.String playerName)
          Sets the current player name.
private  void updateServerSettings()
          Updates server based settings to current screen size.
 void updateWindowSize(java.awt.Dimension size)
          Sets a new window size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connection

@NotNull
private final JXCConnection connection
The JXCConnection to use.


crossfireDrawextinfoListener

@NotNull
private final CrossfireDrawextinfoListener crossfireDrawextinfoListener
The CrossfireDrawextinfoListener attached to server.


currentQueryDialogIsNamePrompt

private boolean currentQueryDialogIsNamePrompt
Whether the currently shown query dialog is the character name prompt.


dialogConnect

@Nullable
private Gui dialogConnect
The "connect in progress" dialog. Set to null if the skin does not define this dialog.


dialogConnectLabel

@Nullable
private AbstractLabel dialogConnectLabel
The "message" field within dialogConnect. Set to null if the dialog does not define a "message" label.


dialogDisconnect

@Nullable
private Gui dialogDisconnect
The "really disconnect?" dialog. Set to null if the skin does not define this dialog.


dialogQuit

@Nullable
private Gui dialogQuit
The "really quit?" dialog. Set to null if the skin does not define this dialog.


guiFactory

@NotNull
private final GuiFactory guiFactory
The GuiFactory for creating Gui instances.


guiStateListener

@NotNull
private final GuiStateListener guiStateListener
The GuiStateListener for detecting established or dropped connections.


keybindDialog

@Nullable
private Gui keybindDialog
The keybindings dialog.


keybindingsManager

@NotNull
private final KeybindingsManager keybindingsManager
The key bindings manager for this window.


queryDialog

@Nullable
private Gui queryDialog
The query dialog.


server

@NotNull
private final CrossfireServerConnection server
The CrossfireServerConnection instance to monitor.


settings

@NotNull
private final Settings settings
The Settings to use.


skin

@Nullable
private JXCSkin skin
The currently active skin. Set to null if no skin is set.


tooltipManager

@NotNull
private final TooltipManager tooltipManager
The TooltipManager for this window.


windowRenderer

@NotNull
private final JXCWindowRenderer windowRenderer
The JXCWindowRenderer used to paint the gui.

Constructor Detail

GuiManager

public GuiManager(@NotNull
                  GuiStateManager guiStateManager,
                  @NotNull
                  TooltipManager tooltipManager,
                  @NotNull
                  Settings settings,
                  @NotNull
                  CrossfireServerConnection server,
                  @NotNull
                  JXCWindowRenderer windowRenderer,
                  @NotNull
                  GuiFactory guiFactory,
                  @NotNull
                  KeybindingsManager keybindingsManager,
                  @NotNull
                  JXCConnection connection)
Creates a new instance.

Parameters:
guiStateManager - the gui state manager to watch
tooltipManager - the tooltip manager to update
settings - the settings to use
server - the crossfire server connection to monitor
windowRenderer - the window renderer to use
guiFactory - the gui factory for creating gui instances
keybindingsManager - the keybindings manager to use
connection - the connection to use
Method Detail

activateCommandInput

@Nullable
private GUIText activateCommandInput()
Activates the command input text field. If the skin defined more than one input field, the first matching one is selected.

If neither the main gui nor any visible dialog has an input text field, invisible GUIs are checked as well. If one is found, it is made visible.

Returns:
the command input text field, or null if the skin has no command input text field defined

activateCommandInput

public void activateCommandInput(@Nullable
                                 java.lang.String newText)
Activates the command input text field. If the skin defines more than one input field, the first matching one is selected.

If neither the main gui nor any visible dialog has an input text field, invisible GUIs are checked as well. If one is found, it is made visible.

Parameters:
newText - the new command text if non-null

activateMetaserverGui

private void activateMetaserverGui()
Called when the server selection GUI becomes active. Selects the last used server entry.


closeDialog

public void closeDialog(@NotNull
                        Gui dialog)
Closes the given dialog. Does nothing if the dialog is not opened.

Parameters:
dialog - the dialog to close

closeDialogByName

private void closeDialogByName(@NotNull
                               java.lang.String name)
Closes a dialog by name.

Parameters:
name - the dialog name

closeKeybindDialog

public void closeKeybindDialog()
Closes the keybinding dialog. Does nothing if the dialog is not opened.


closeQueryDialog

public void closeQueryDialog()
Closes the "query" dialog. Does nothing if the dialog is not open.


closeTransientDialogs

private void closeTransientDialogs()
Closes all transient dialogs: disconnect, quit, connect, query, and book dialogs.


createKeyBinding

public boolean createKeyBinding(boolean perCharacter,
                                @NotNull
                                CommandList cmdList)
Adds a key binding.

Parameters:
perCharacter - whether a per-character key binding should be added
cmdList - the command list to execute on key press
Returns:
whether the key bindings dialog should be opened

escPressed

public int escPressed(boolean connected)
The ESC key has been pressed.

Parameters:
connected - whether a connection to the server is active
Returns:
whether how the key has been consumed: 0=ignore key, 1=disconnect from server, quit=quit application

getCommandList

@NotNull
public CommandList getCommandList(@NotNull
                                          java.lang.String args)
                           throws NoSuchCommandException
Returns a named command list.

Parameters:
args - the name of the command list
Returns:
the command list
Throws:
NoSuchCommandException - if the command list does not exist

hideAccountWindows

public void hideAccountWindows()
Hides all account-related windows.


manageAccount

public void manageAccount()
Displays the main account dialog, to let the player login or create a new account.


openDialog

public boolean openDialog(@NotNull
                          Gui dialog,
                          boolean autoCloseOnDeactivate)
Opens a dialog. Raises the dialog if it is open.

Parameters:
dialog - the dialog to show
autoCloseOnDeactivate - whether the dialog should auto-close when it becomes inactive; ignored if the dialog is already open
Returns:
whether the dialog was opened or raised; false if the dialog already was opened as the topmost dialog

openDialogByName

private boolean openDialogByName(@NotNull
                                 java.lang.String name)
Opens a dialog by name.

Parameters:
name - the dialog name
Returns:
whether the dialog exists

openKeybindDialog

private void openKeybindDialog()
Opens the keybinding dialog. Does nothing if the dialog is opened.


openQueryDialog

public void openQueryDialog(@NotNull
                            java.lang.String prompt,
                            int queryType)
Opens the "query" dialog.

Parameters:
prompt - the query prompt
queryType - the query type

openQuitDialog

public boolean openQuitDialog()
Opens the "quit" dialog. Does nothing if the dialog is open.

Returns:
whether the dialog has been opened

playerReceived

public void playerReceived()
A "player" protocol command has been received.


removeKeyBinding

public boolean removeKeyBinding(boolean perCharacter)
Removes a key binding.

Parameters:
perCharacter - whether a per-character key binding should be removed
Returns:
whether the key bindings dialog should be opened

selectCharacter

public void selectCharacter(@NotNull
                            java.lang.String accountName,
                            @NotNull
                            java.lang.String characterName)
Updates the selected character name in an account.

Parameters:
accountName - the account name
characterName - the character name

setAccountName

public void setAccountName(@NotNull
                           java.lang.String accountName)
Updates the current account name.

Parameters:
accountName - the current account name

setSkin

public void setSkin(@NotNull
                    JXCSkin skin)
Sets a new skin.

Parameters:
skin - the new skin

showCharacters

public void showCharacters()
Displays the window with the characters for an account.


showGUIMain

private void showGUIMain()
Displays the "main" GUI.


showGUIMeta

private void showGUIMeta()
Displays the "server selection" GUI.


showGUIStart

private void showGUIStart()
Displays the "start" GUI.


term

public void term()

toggleDialog

public void toggleDialog(@NotNull
                         Gui dialog)
Toggles a dialog.

Parameters:
dialog - the dialog to toggle

unsetSkin

public void unsetSkin()
Unsets the current skin.


updateConnectLabel

private void updateConnectLabel(@NotNull
                                ClientSocketState clientSocketState,
                                @Nullable
                                java.lang.String param)
Updates the "message" field of the connect dialog. Does nothing if the dialog is not open, does not exist, or if the dialog does not define a "message" field.

Parameters:
clientSocketState - the client socket state
param - a parameter to display

updatePlayerName

public void updatePlayerName(@NotNull
                             java.lang.String playerName)
Sets the current player name. Does nothing if not currently in the character name prompt.

Parameters:
playerName - the player name

updateServerSettings

private void updateServerSettings()
Updates server based settings to current screen size.


updateWindowSize

public void updateWindowSize(@NotNull
                             java.awt.Dimension size)
Sets a new window size.

Parameters:
size - the new window size