soc.client
Class SOCPlayerClient.GameAwtDisplay

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by soc.client.SOCPlayerClient.GameAwtDisplay
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, SOCPlayerClient.GameDisplay
Enclosing class:
SOCPlayerClient

public static class SOCPlayerClient.GameAwtDisplay
extends java.awt.Panel
implements SOCPlayerClient.GameDisplay

A SOCPlayerClient.GameDisplay implementation for AWT.

Before v2.0.00, most of these fields and methods were part of the main SOCPlayerClient class.

Since:
2.0.00
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
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
protected  java.awt.CardLayout cardLayout
          This class displays one of several panels to the user: MAIN_PANEL, MESSAGE_PANEL or (if launched from jar, or with no command-line arguments) CONNECT_OR_PRACTICE_PANEL.
protected  java.awt.TextField channel
          Chat channel name to create or join with jc button.
protected  java.util.Hashtable<java.lang.String,ChannelFrame> channels
          the channels we've joined
protected  java.awt.List chlist
          List of chat channels that can be joined with jc button or by double-click.
private  SOCPlayerClient client
           
private static java.lang.String CONNECT_OR_PRACTICE_PANEL
          Connect-or-practice panel (if jar launch), in cardlayout.
protected  SOCConnectOrPracticePanel connectOrPracticePane
          If applicable, is set up in initVisualElements().
protected  java.util.Timer eventTimer
          Utility for time-driven events in the display.
protected  SOCPlayerClient.GameOptionDefaultsTimeoutTask gameOptsDefsTask
          Task for timeout when asking remote server for game options defaults.
protected  SOCPlayerClient.GameOptionsTimeoutTask gameOptsTask
          Task for timeout when asking remote server for game options info.
protected  java.awt.Button gi
          "Game Info" button, shows a game's SOCGameOptions.
protected  java.awt.List gmlist
          List of games that can be joined with jg button or by double-click, or detail info displayed with gi button.
protected  boolean hasConnectOrPractice
          If true, we'll give the user a choice to connect to a server, start a local server, or a local practice game.
protected  boolean hasJoinedServer
          Once true, disable "nick" textfield, etc.
protected  java.awt.Button jc
          "Join Channel" button, for channel currently highlighted in chlist, or create new channel named in channel.
protected  java.awt.Button jg
          "Join Game" button
private  java.awt.Label localTCPServerLabel
          Local Server indicator in main panel: blank, or 'server is running' if localTCPServer has been started.
private static java.lang.String MAIN_PANEL
          main panel, in cardlayout
private  java.awt.GridBagConstraints mainGBC
          Constraints for mainGBL
private  java.awt.GridBagLayout mainGBL
          Layout for mainPane
private  java.awt.Panel mainPane
          MainPanel GUI, initialized in initVisualElements() and initMainPanelLayout(boolean, SOCServerFeatures).
private  boolean mainPaneLayoutIsDone
          Flags for tracking mainPane layout status, in case initMainPanelLayout(boolean, SOCServerFeatures) is called again after losing connection and then connecting to another server or starting a hosted tcp server.
private  boolean mainPaneLayoutIsDone_hasChannels
          Flags for tracking mainPane layout status, in case initMainPanelLayout(boolean, SOCServerFeatures) is called again after losing connection and then connecting to another server or starting a hosted tcp server.
private static java.lang.String MESSAGE_PANEL
          message panel, in cardlayout
protected  java.awt.Label messageLabel
           
protected  java.awt.Label messageLabel_top
           
 java.lang.String NEED_NICKNAME_BEFORE_JOIN
          Hint message if they try to join a game or channel without entering a nickname.
 java.lang.String NEED_NICKNAME_BEFORE_JOIN_2
          Stronger hint message if they still try to join a game or channel without entering a nickname.
 java.lang.String NEED_NICKNAME_BEFORE_JOIN_G
          Hint message if they try to join a game without entering a nickname, on a server which doesn't support chat channels.
 java.lang.String NEED_NICKNAME_BEFORE_JOIN_G2
          Stronger hint message if they still try to join a game without entering a nickname, on a server which doesn't support chat channels.
 java.lang.String NET_UNAVAIL_CAN_PRACTICE_MSG
          For practice games, reminder message for network problems.
 NewGameOptionsFrame newGameOptsFrame
          The currently showing new-game options frame, or null
protected  java.awt.Button ng
          "New Game..." button, brings up NewGameOptionsFrame window
protected  java.awt.TextField nick
          Nickname (username) to connect to server and use in games
protected  java.awt.TextField pass
          Password for nick while connecting to server, or blank
protected  java.awt.Button pg
          Practice Game button: Create game to play against practiceServer, not localTCPServer.
protected  java.awt.Button pgm
           
private  java.util.Map<java.lang.String,SOCPlayerInterface> playerInterfaces
          the player interfaces for the games
protected static java.lang.String STATSPREFEX
          Game statistics prefix
protected  java.awt.TextField status
          Status from server, or progress/error message updated by client
 java.lang.String STATUS_CANNOT_JOIN_THIS_GAME
          Status text to indicate client cannot join a game.
private  java.awt.Label versionOrlocalTCPPortLabel
          When connected to a remote server, shows its version number.
 
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
SOCPlayerClient.GameAwtDisplay(boolean hasConnectOrPractice, SOCPlayerClient client)
          Create a new GameAwtDisplay for this client.
 
Method Summary
 void addToGameList(boolean cannotJoin, java.lang.String gameName, java.lang.String gameOptsStr, boolean addToSrvList)
          Add a new game to the initial window's list of games.
 void addToList(java.lang.String thing, java.awt.List lst)
          add a new channel or game, put it in the list in alphabetical order
 void askStartGameWithOptions(java.lang.String gmName, boolean forPracticeServer, java.util.Map<java.lang.String,SOCGameOption> opts)
          Ask server to start a game with options.
 void channelCreated(java.lang.String channelName)
           
 void channelDeleted(java.lang.String channelName)
           
 void channelJoined(java.lang.String channelName)
           
 void channelJoined(java.lang.String channelName, java.lang.String nickname)
           
 void channelLeft(java.lang.String channelName)
           
 void channelLeft(java.lang.String channelName, java.lang.String nickname)
           
 void channelList(java.util.Collection<java.lang.String> channelNames, boolean isPractice)
           
 void channelMemberList(java.lang.String channel, java.util.Collection<java.lang.String> members)
           
 void channelsClosed(java.lang.String message)
           
 void chSend(java.lang.String ch, java.lang.String mes)
          send a text message to a channel
 void clickPracticeButton()
          Act as if the "practice game" button has been clicked.
 void connect(java.lang.String cpass, java.lang.String cuser)
          Prepare to connect, give feedback by showing MESSAGE_PANEL.
 java.awt.event.WindowAdapter createWindowAdapter()
           
 boolean deleteFromGameList(java.lang.String gameName, boolean isPractice)
          Delete a game from the list.
 void deleteFromList(java.lang.String thing, java.awt.List lst)
          delete a group
 boolean doLocalCommand(java.lang.String ch, java.lang.String cmd)
          Handle local client commands for channels.
 void enableOptions()
           
protected  SOCPlayerInterface findAnyActiveGame(boolean fromPracticeServer)
          Look for active games that we're playing
 void focusPassword()
          If the password field is currently visible, focus the cursor there for the user to type something.
 PlayerClientListener gameJoined(SOCGame game)
           
private  void gameOptionsCancelTimeoutTask()
          Cancel the game-options info timeout.
private  void gameOptionsSetTimeoutTask()
          Start the game-options info timeout (SOCPlayerClient.GameOptionsTimeoutTask) at 5 seconds.
 void gameWithOptionsBeginSetup(boolean forPracticeServer, boolean didAuth)
          Want to start a new game, on a server which supports options.
 SOCPlayerClient getClient()
           
 java.util.Timer getEventTimer()
          Utility for time-driven events in the client.
 SOCPlayerClient.GameManager getGameManager()
           
 java.lang.String getNickname()
           
protected  java.lang.String getPassword()
          Validate and return the password textfield contents; may be 0-length.
protected  java.lang.String getValidNickname(boolean precheckOnly)
          Validate and return the nickname textfield, or null if blank or not ready.
private  boolean guardedActionPerform_channels(java.lang.Object target)
          GuardedActionPerform when a channels-related button or field is clicked
private  boolean guardedActionPerform_games(java.lang.Object target)
          GuardedActionPerform when a games-related button or field is clicked
private  void guardedActionPerform(java.lang.Object target)
          Wrapped version of actionPerformed() for easier encapsulation.
private  void initMainPanelLayout(boolean isStatusRow, SOCServerFeatures feats)
          Lay out the Main Panel: status text, name, password, game/channel names and lists, buttons.
 void initVisualElements()
          Init the visual elements.
 void leaveGame(SOCGame game)
           
 void messageBroadcast(java.lang.String message)
           
 void messageReceived(java.lang.String channelName, java.lang.String nickname, java.lang.String message)
           
 void optionsReceived(ServerGametypeInfo opts, boolean isPractice)
          Server has sent its game option default values for new games.
 void optionsReceived(ServerGametypeInfo opts, boolean isPractice, boolean isDash, boolean hasAllNow)
          Server has sent info about a single game option.
 void optionsRequested()
           
 void practiceGameStarting()
          When a practice game is starting, it may take a while to start server & game.
protected  void printIgnoreList(ChannelFrame fr)
          Print the current chat ignorelist in a channel.
protected  void printIgnoreList(SOCPlayerInterface pi)
          Print the current chat ignorelist in a playerinterface.
 boolean readValidNicknameAndPassword()
          Read and validate username and password GUI fields into client's data fields.
 void setMessage(java.lang.String message)
           
 void setPassword(java.lang.String pw)
          Set the contents of the password field.
 void showErrorDialog(java.lang.String errMessage, java.lang.String buttonText)
          Show an error dialog which has one button.
 void showErrorPanel(java.lang.String err, boolean canPractice)
          After network trouble, show the error panel (MESSAGE_PANEL) instead of the main user/password/games/channels panel (MAIN_PANEL).
 void showStatus(java.lang.String statusText, boolean debugWarn)
          Show server welcome banner or status text.
 void showVersion(int vers, java.lang.String versionString, java.lang.String buildString, SOCServerFeatures feats)
          After connecting, display the remote server's version on main panel, and update display based on its active SOCServerFeatures.
 void startLocalTCPServer(int tport)
          Setup for locally hosting a TCP server.
 void updateGameStats(java.lang.String gameName, int[] scores, boolean[] robots)
          Update this game's stats in the game list display.
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAIN_PANEL

private static final java.lang.String MAIN_PANEL
main panel, in cardlayout

See Also:
Constant Field Values

MESSAGE_PANEL

private static final java.lang.String MESSAGE_PANEL
message panel, in cardlayout

See Also:
Constant Field Values

CONNECT_OR_PRACTICE_PANEL

private static final java.lang.String CONNECT_OR_PRACTICE_PANEL
Connect-or-practice panel (if jar launch), in cardlayout. Panel field is connectOrPracticePane. Available if hasConnectOrPractice.

See Also:
Constant Field Values

STATSPREFEX

protected static final java.lang.String STATSPREFEX
Game statistics prefix

See Also:
Constant Field Values

NET_UNAVAIL_CAN_PRACTICE_MSG

public final java.lang.String NET_UNAVAIL_CAN_PRACTICE_MSG
For practice games, reminder message for network problems.


NEED_NICKNAME_BEFORE_JOIN

public final java.lang.String NEED_NICKNAME_BEFORE_JOIN
Hint message if they try to join a game or channel without entering a nickname.

See Also:
NEED_NICKNAME_BEFORE_JOIN_2, NEED_NICKNAME_BEFORE_JOIN_G

NEED_NICKNAME_BEFORE_JOIN_2

public final java.lang.String NEED_NICKNAME_BEFORE_JOIN_2
Stronger hint message if they still try to join a game or channel without entering a nickname.

See Also:
NEED_NICKNAME_BEFORE_JOIN, NEED_NICKNAME_BEFORE_JOIN_G2

NEED_NICKNAME_BEFORE_JOIN_G

public final java.lang.String NEED_NICKNAME_BEFORE_JOIN_G
Hint message if they try to join a game without entering a nickname, on a server which doesn't support chat channels.

Since:
1.1.19
See Also:
NEED_NICKNAME_BEFORE_JOIN_G2, NEED_NICKNAME_BEFORE_JOIN

NEED_NICKNAME_BEFORE_JOIN_G2

public final java.lang.String NEED_NICKNAME_BEFORE_JOIN_G2
Stronger hint message if they still try to join a game without entering a nickname, on a server which doesn't support chat channels.

Since:
1.1.19
See Also:
NEED_NICKNAME_BEFORE_JOIN_G, NEED_NICKNAME_BEFORE_JOIN_2

STATUS_CANNOT_JOIN_THIS_GAME

public final java.lang.String STATUS_CANNOT_JOIN_THIS_GAME
Status text to indicate client cannot join a game.

Since:
1.1.06

client

private SOCPlayerClient client

playerInterfaces

private final java.util.Map<java.lang.String,SOCPlayerInterface> playerInterfaces
the player interfaces for the games


gameOptsTask

protected SOCPlayerClient.GameOptionsTimeoutTask gameOptsTask
Task for timeout when asking remote server for game options info. Set up when sending GAMEOPTIONGETINFOS. In case of slow connection or server bug.

Since:
1.1.07
See Also:
gameOptionsSetTimeoutTask()

gameOptsDefsTask

protected SOCPlayerClient.GameOptionDefaultsTimeoutTask gameOptsDefsTask
Task for timeout when asking remote server for game options defaults. Set up when sending GAMEOPTIONGETDEFAULTS. In case of slow connection or server bug.

Since:
1.1.07
See Also:
gameWithOptionsBeginSetup(boolean, boolean)

hasJoinedServer

protected boolean hasJoinedServer
Once true, disable "nick" textfield, etc. Remains true, even if connected becomes false.


hasConnectOrPractice

protected final boolean hasConnectOrPractice
If true, we'll give the user a choice to connect to a server, start a local server, or a local practice game. Used for when we're started from a jar, or from the command line with no arguments. Uses SOCConnectOrPracticePanel.

See Also:
cardLayout

connectOrPracticePane

protected SOCConnectOrPracticePanel connectOrPracticePane
If applicable, is set up in initVisualElements(). Key for cardLayout is CONNECT_OR_PRACTICE_PANEL.

See Also:
hasConnectOrPractice

newGameOptsFrame

public NewGameOptionsFrame newGameOptsFrame
The currently showing new-game options frame, or null

Since:
1.1.07

mainPane

private java.awt.Panel mainPane
MainPanel GUI, initialized in initVisualElements() and initMainPanelLayout(boolean, SOCServerFeatures).

mainPane, mainGBL, and mainGBC are fields not locals so that the layout can be changed after initialization if needed. Most of the Main Panel elements are initialized in initVisualElements() but not laid out or made visible until a later call to initMainPanelLayout(boolean, SOCServerFeatures) (from (showVersion(....)) when the version and features are known.

Since:
1.1.19

mainGBL

private java.awt.GridBagLayout mainGBL
Layout for mainPane


mainGBC

private java.awt.GridBagConstraints mainGBC
Constraints for mainGBL


mainPaneLayoutIsDone

private boolean mainPaneLayoutIsDone
Flags for tracking mainPane layout status, in case initMainPanelLayout(boolean, SOCServerFeatures) is called again after losing connection and then connecting to another server or starting a hosted tcp server.

Since:
1.1.19

mainPaneLayoutIsDone_hasChannels

private boolean mainPaneLayoutIsDone_hasChannels
Flags for tracking mainPane layout status, in case initMainPanelLayout(boolean, SOCServerFeatures) is called again after losing connection and then connecting to another server or starting a hosted tcp server.

Since:
1.1.19

nick

protected java.awt.TextField nick
Nickname (username) to connect to server and use in games


pass

protected java.awt.TextField pass
Password for nick while connecting to server, or blank


status

protected java.awt.TextField status
Status from server, or progress/error message updated by client


channel

protected java.awt.TextField channel
Chat channel name to create or join with jc button. Hidden in v1.1.19+ if server is missing SOCServerFeatures.FEAT_CHANNELS.


chlist

protected java.awt.List chlist
List of chat channels that can be joined with jc button or by double-click. Hidden in v1.1.19+ if server is missing SOCServerFeatures.FEAT_CHANNELS.


gmlist

protected java.awt.List gmlist
List of games that can be joined with jg button or by double-click, or detail info displayed with gi button. Contains all games on server if connected, and any Practice Games created with pg button.


ng

protected java.awt.Button ng
"New Game..." button, brings up NewGameOptionsFrame window

Since:
1.1.07

jc

protected java.awt.Button jc
"Join Channel" button, for channel currently highlighted in chlist, or create new channel named in channel. Hidden in v1.1.19+ if server is missing SOCServerFeatures.FEAT_CHANNELS.


jg

protected java.awt.Button jg
"Join Game" button


pg

protected java.awt.Button pg
Practice Game button: Create game to play against practiceServer, not localTCPServer.


gi

protected java.awt.Button gi
"Game Info" button, shows a game's SOCGameOptions.

Renamed in 2.0.00 to 'gi'; previously 'so' Show Options.

Since:
1.1.07

localTCPServerLabel

private java.awt.Label localTCPServerLabel
Local Server indicator in main panel: blank, or 'server is running' if localTCPServer has been started. If so, localTCPServer's port number is shown in versionOrlocalTCPPortLabel.


versionOrlocalTCPPortLabel

private java.awt.Label versionOrlocalTCPPortLabel
When connected to a remote server, shows its version number. When running localTCPServer, shows that server's port number (see also localTCPServerLabel). In either mode, has a tooltip with more info.


messageLabel

protected java.awt.Label messageLabel

messageLabel_top

protected java.awt.Label messageLabel_top

pgm

protected java.awt.Button pgm

cardLayout

protected java.awt.CardLayout cardLayout
This class displays one of several panels to the user: MAIN_PANEL, MESSAGE_PANEL or (if launched from jar, or with no command-line arguments) CONNECT_OR_PRACTICE_PANEL.

See Also:
hasConnectOrPractice

channels

protected java.util.Hashtable<java.lang.String,ChannelFrame> channels
the channels we've joined


eventTimer

protected java.util.Timer eventTimer
Utility for time-driven events in the display. For users, search for where-used of this field and of getEventTimer().

Since:
1.1.07
Constructor Detail

SOCPlayerClient.GameAwtDisplay

public SOCPlayerClient.GameAwtDisplay(boolean hasConnectOrPractice,
                                      SOCPlayerClient client)
                               throws java.lang.IllegalArgumentException
Create a new GameAwtDisplay for this client. Must call initVisualElements() after this constructor.

Parameters:
hasConnectOrPractice - True if should initially display SOCConnectOrPracticePanel and ask for a server to connect to, false if the server is known and should display the main panel (game list, channel list, etc).
client - Client using this display; client.strings must not be null
Throws:
java.lang.IllegalArgumentException - if client is null
Method Detail

getClient

public SOCPlayerClient getClient()

getGameManager

public SOCPlayerClient.GameManager getGameManager()

createWindowAdapter

public java.awt.event.WindowAdapter createWindowAdapter()

setMessage

public void setMessage(java.lang.String message)
Specified by:
setMessage in interface SOCPlayerClient.GameDisplay

showErrorDialog

public void showErrorDialog(java.lang.String errMessage,
                            java.lang.String buttonText)
Show an error dialog which has one button.

Uses NotifyDialog#createAndShow(GameAwtDisplay, Frame, String, String, boolean) which calls EventQueue.invokeLater(Runnable) to ensure it displays from the proper thread.

Specified by:
showErrorDialog in interface SOCPlayerClient.GameDisplay
Parameters:
errMessage - Error message to show
buttonText - Button text, or null for "OK"

initVisualElements

public void initVisualElements()
Description copied from interface: SOCPlayerClient.GameDisplay
Init the visual elements. Done before connecting to server, so we don't know its version or active SOCServerFeatures. So, most of the Main Panel elements are initialized here but not laid out or made visible until a later call to SOCPlayerClient.GameDisplay.showVersion(int, String, String, SOCServerFeatures) when the version and features are known.

Specified by:
initVisualElements in interface SOCPlayerClient.GameDisplay

initMainPanelLayout

private void initMainPanelLayout(boolean isStatusRow,
                                 SOCServerFeatures feats)
                          throws java.lang.IllegalArgumentException
Lay out the Main Panel: status text, name, password, game/channel names and lists, buttons. This method is called twice: First during client init to lay out the status display only, and then again once the server is connected and its features and version are known.

Because mainPane is part of a larger layout, this method does not call validate(). Be sure to call validate() afterwards once the entire layout is ready.

This was part of initVisualElements() before v1.1.19.

Parameters:
isStatusRow - If true, this is an initial call and only the status row should be laid out. If false, assumes status was already done and adds the rest of the rows.
feats - Active optional server features, for second call with isStatusRow == false. Null when isStatusRow == true. See showVersion(int, String, String, SOCServerFeatures) javadoc for expected contents when an older server does not report features.
Throws:
java.lang.IllegalArgumentException - if feats is null but isStatusRow is false
Since:
1.1.19

connect

public void connect(java.lang.String cpass,
                    java.lang.String cuser)
Prepare to connect, give feedback by showing MESSAGE_PANEL. Prepare to connect and give feedback by showing a message panel. Stores the given username and password in the user interface.

Does not make a network connection. Call SOCPlayerClient.ClientNetwork.connect(String, int) when ready to make the connection.

User login and authentication don't occur until a game or channel join is requested; at that time, the user interface will read the name and password stored here.

Specified by:
connect in interface SOCPlayerClient.GameDisplay
Parameters:
cpass - Password text to put into that TextField (obscured)
cuser - User nickname text to put into that TextField

getNickname

public java.lang.String getNickname()

clickPracticeButton

public void clickPracticeButton()
Description copied from interface: SOCPlayerClient.GameDisplay
Act as if the "practice game" button has been clicked. Assumes the dialog panels are all initialized.

Specified by:
clickPracticeButton in interface SOCPlayerClient.GameDisplay

guardedActionPerform

private void guardedActionPerform(java.lang.Object target)
Wrapped version of actionPerformed() for easier encapsulation.

Parameters:
target - Action source, from ActionEvent.getSource()

guardedActionPerform_channels

private boolean guardedActionPerform_channels(java.lang.Object target)
GuardedActionPerform when a channels-related button or field is clicked

Parameters:
target - Target as in actionPerformed
Returns:
True if OK, false if caller needs to show popup "cannot join"
Since:
1.1.06

readValidNicknameAndPassword

public boolean readValidNicknameAndPassword()
Read and validate username and password GUI fields into client's data fields. This method may set status bar to a hint message if username is empty, such as NEED_NICKNAME_BEFORE_JOIN.

Returns:
true if OK, false if blank or not ready
Since:
1.1.07
See Also:
getValidNickname(boolean)

guardedActionPerform_games

private boolean guardedActionPerform_games(java.lang.Object target)
GuardedActionPerform when a games-related button or field is clicked

Parameters:
target - Target as in actionPerformed
Returns:
True if OK, false if caller needs to show popup "cannot join"
Since:
1.1.06

getValidNickname

protected java.lang.String getValidNickname(boolean precheckOnly)
Validate and return the nickname textfield, or null if blank or not ready. If successful, also set SOCPlayerClient.nickname field.

Parameters:
precheckOnly - If true, only validate the name, don't set SOCPlayerClient.nickname.
Since:
1.1.07
See Also:
readValidNicknameAndPassword()

getPassword

protected java.lang.String getPassword()
Validate and return the password textfield contents; may be 0-length. Also set SOCPlayerClient.password field. If SOCPlayerClient.gotPassword already, return current password without checking textfield.

Since:
1.1.07

getEventTimer

public java.util.Timer getEventTimer()
Utility for time-driven events in the client. For some users, see where-used of this and of SOCPlayerInterface.getEventTimer().

Returns:
the timer
Since:
1.1.07

gameWithOptionsBeginSetup

public void gameWithOptionsBeginSetup(boolean forPracticeServer,
                                      boolean didAuth)
Want to start a new game, on a server which supports options. Do we know the valid options already? If so, bring up the options window. If not, ask the server for them. If a NewGameOptionsFrame is already showing, give it focus instead of creating a new one.

For a summary of the flags and variables involved with game options, and the client/server interaction about their values, see ServerGametypeInfo.

Updates tcpServGameOpts, practiceServGameOpts, newGameOptsFrame.

Specified by:
gameWithOptionsBeginSetup in interface SOCPlayerClient.GameDisplay
Parameters:
forPracticeServer - Ask SOCPlayerClient.ClientNetwork.practiceServer, instead of TCP server?
didAuth - If true, the server has authenticated our username and password; set those input fields read-only.
Since:
1.1.07

askStartGameWithOptions

public void askStartGameWithOptions(java.lang.String gmName,
                                    boolean forPracticeServer,
                                    java.util.Map<java.lang.String,SOCGameOption> opts)
Ask server to start a game with options. If it's practice, will call SOCPlayerClient.startPracticeGame(String, Map, boolean). Otherwise, ask tcp server, and also set WAIT_CURSOR and status line ("Talking to server...").

Assumes getValidNickname(true), getPassword(), SOCPlayerClient.ClientNetwork.host, and SOCPlayerClient.gotPassword are already called and valid.

Parameters:
gmName - Game name; for practice, null is allowed
forPracticeServer - Is this for a new game on the practice (not tcp) server?
opts - Set of game options to use, or null
Since:
1.1.07
See Also:
readValidNicknameAndPassword()

findAnyActiveGame

protected SOCPlayerInterface findAnyActiveGame(boolean fromPracticeServer)
Look for active games that we're playing

Parameters:
fromPracticeServer - Enumerate games from SOCPlayerClient.ClientNetwork.practiceServer, instead of playerInterfaces?
Returns:
Any found game of ours which is active (state not OVER), or null if none.
See Also:
SOCPlayerClient.ClientNetwork.anyHostedActiveGames()

showErrorPanel

public void showErrorPanel(java.lang.String err,
                           boolean canPractice)
After network trouble, show the error panel (MESSAGE_PANEL) instead of the main user/password/games/channels panel (MAIN_PANEL).

If we have the startup panel (started as JAR client app, not applet) with buttons to connect to a server or practice, we'll show that instead of the simpler practice-only message panel.

Specified by:
showErrorPanel in interface SOCPlayerClient.GameDisplay
Parameters:
err - Error message to show
canPractice - In current state of client, can we start a practice game?
Since:
1.1.16

enableOptions

public void enableOptions()
Specified by:
enableOptions in interface SOCPlayerClient.GameDisplay

showVersion

public void showVersion(int vers,
                        java.lang.String versionString,
                        java.lang.String buildString,
                        SOCServerFeatures feats)
After connecting, display the remote server's version on main panel, and update display based on its active SOCServerFeatures. Not called for practice server. If we're running a server, display its listening port # instead.

showVersion calls initMainPanelLayout(false, feats) to complete layout of the Main Panel with the server's version and active features.

Specified by:
showVersion in interface SOCPlayerClient.GameDisplay
Parameters:
vers - Version number, like 1119, from server's Version.versionNumber()
versionString - Version string, like "1.1.19", from server's Version.version()
buildString - Build number, from server's Version.buildnum()
feats - Active optional server features; never null. If server is older than v1.1.19, use the SOCServerFeatures(true) constructor.

showStatus

public void showStatus(java.lang.String statusText,
                       boolean debugWarn)
Description copied from interface: SOCPlayerClient.GameDisplay
Show server welcome banner or status text. If status during initial connect includes warning that the server's in Debug Mode, show that.

Specified by:
showStatus in interface SOCPlayerClient.GameDisplay
Parameters:
statusText - Status message text from server
debugWarn - True if server has Debug Mode active

focusPassword

public void focusPassword()
Description copied from interface: SOCPlayerClient.GameDisplay
If the password field is currently visible, focus the cursor there for the user to type something.

Specified by:
focusPassword in interface SOCPlayerClient.GameDisplay

setPassword

public void setPassword(java.lang.String pw)
Description copied from interface: SOCPlayerClient.GameDisplay
Set the contents of the password field.

Specified by:
setPassword in interface SOCPlayerClient.GameDisplay

channelJoined

public void channelJoined(java.lang.String channelName)
Specified by:
channelJoined in interface SOCPlayerClient.GameDisplay

channelJoined

public void channelJoined(java.lang.String channelName,
                          java.lang.String nickname)
Specified by:
channelJoined in interface SOCPlayerClient.GameDisplay

channelLeft

public void channelLeft(java.lang.String channelName)
Specified by:
channelLeft in interface SOCPlayerClient.GameDisplay

channelLeft

public void channelLeft(java.lang.String channelName,
                        java.lang.String nickname)
Specified by:
channelLeft in interface SOCPlayerClient.GameDisplay

channelMemberList

public void channelMemberList(java.lang.String channel,
                              java.util.Collection<java.lang.String> members)
Specified by:
channelMemberList in interface SOCPlayerClient.GameDisplay

channelDeleted

public void channelDeleted(java.lang.String channelName)
Specified by:
channelDeleted in interface SOCPlayerClient.GameDisplay

channelsClosed

public void channelsClosed(java.lang.String message)
Specified by:
channelsClosed in interface SOCPlayerClient.GameDisplay

addToList

public void addToList(java.lang.String thing,
                      java.awt.List lst)
add a new channel or game, put it in the list in alphabetical order

Parameters:
thing - the thing to add to the list
lst - the list

deleteFromList

public void deleteFromList(java.lang.String thing,
                           java.awt.List lst)
delete a group

Parameters:
thing - the thing to remove
lst - the list

channelCreated

public void channelCreated(java.lang.String channelName)
Specified by:
channelCreated in interface SOCPlayerClient.GameDisplay

channelList

public void channelList(java.util.Collection<java.lang.String> channelNames,
                        boolean isPractice)
Specified by:
channelList in interface SOCPlayerClient.GameDisplay

messageBroadcast

public void messageBroadcast(java.lang.String message)
Specified by:
messageBroadcast in interface SOCPlayerClient.GameDisplay

messageReceived

public void messageReceived(java.lang.String channelName,
                            java.lang.String nickname,
                            java.lang.String message)
Specified by:
messageReceived in interface SOCPlayerClient.GameDisplay

leaveGame

public void leaveGame(SOCGame game)

gameJoined

public PlayerClientListener gameJoined(SOCGame game)
Specified by:
gameJoined in interface SOCPlayerClient.GameDisplay

gameOptionsSetTimeoutTask

private void gameOptionsSetTimeoutTask()
Start the game-options info timeout (SOCPlayerClient.GameOptionsTimeoutTask) at 5 seconds.

Since:
1.1.07
See Also:
gameOptionsCancelTimeoutTask()

gameOptionsCancelTimeoutTask

private void gameOptionsCancelTimeoutTask()
Cancel the game-options info timeout.

Since:
1.1.07
See Also:
gameOptionsSetTimeoutTask()

optionsRequested

public void optionsRequested()
Specified by:
optionsRequested in interface SOCPlayerClient.GameDisplay

optionsReceived

public void optionsReceived(ServerGametypeInfo opts,
                            boolean isPractice)
Description copied from interface: SOCPlayerClient.GameDisplay
Server has sent its game option default values for new games. Called when ServerGametypeInfo.newGameWaitingForOpts flag was set and has just been cleared. Client should show dialog to create a new game which will have game options.

Specified by:
optionsReceived in interface SOCPlayerClient.GameDisplay
Parameters:
opts - Client's game option info, tracking the TCP or local practice server
isPractice - True if received from SOCPlayerClient.ClientNetwork.practiceServer, instead of TCP server

optionsReceived

public void optionsReceived(ServerGametypeInfo opts,
                            boolean isPractice,
                            boolean isDash,
                            boolean hasAllNow)
Description copied from interface: SOCPlayerClient.GameDisplay
Server has sent info about a single game option. If hasAllNow, client should check ServerGametypeInfo.newGameWaitingForOpts and ServerGametypeInfo.gameInfoWaitingForOpts, and if either of these were waiting, show a game info/options dialog for a new game or existing game.

Specified by:
optionsReceived in interface SOCPlayerClient.GameDisplay
Parameters:
opts - Client's game option info, tracking the TCP or local practice server
isPractice - True if received from SOCPlayerClient.ClientNetwork.practiceServer, instead of TCP server
isDash - True if the game option was "-", indicating the end of the list. If so, no further options will be sent and any running timeout task related to the game options can be cancelled.
hasAllNow - If true, all game option info has now been received by the client

addToGameList

public void addToGameList(boolean cannotJoin,
                          java.lang.String gameName,
                          java.lang.String gameOptsStr,
                          boolean addToSrvList)
Description copied from interface: SOCPlayerClient.GameDisplay
Add a new game to the initial window's list of games. If client can't join, makes sure the game is marked as unjoinable in the SOCPlayerClient.serverGames list.

Specified by:
addToGameList in interface SOCPlayerClient.GameDisplay
Parameters:
cannotJoin - Can we not join this game?
gameName - the game name to add to the list; must not have the prefix SOCGames.MARKER_THIS_GAME_UNJOINABLE.
gameOptsStr - String of packed game options, or null
addToSrvList - Should this game be added to the list of remote-server games? Practice games should not be added.

updateGameStats

public void updateGameStats(java.lang.String gameName,
                            int[] scores,
                            boolean[] robots)
Description copied from interface: SOCPlayerClient.GameDisplay
Update this game's stats in the game list display.

Specified by:
updateGameStats in interface SOCPlayerClient.GameDisplay
Parameters:
gameName - Name of game to update
scores - Each player position's score
robots - Is this position a robot?
See Also:
SOCGameStats

deleteFromGameList

public boolean deleteFromGameList(java.lang.String gameName,
                                  boolean isPractice)
Description copied from interface: SOCPlayerClient.GameDisplay
Delete a game from the list. If it's on the list, also remove from SOCPlayerClient.serverGames.

Specified by:
deleteFromGameList in interface SOCPlayerClient.GameDisplay
Parameters:
gameName - the game to remove
isPractice - Game is practice, not at tcp server?
Returns:
true if deleted, false if not found in list

chSend

public void chSend(java.lang.String ch,
                   java.lang.String mes)
send a text message to a channel

Parameters:
ch - the name of the channel
mes - the message

doLocalCommand

public boolean doLocalCommand(java.lang.String ch,
                              java.lang.String cmd)
Handle local client commands for channels.

Parameters:
cmd - Local client command string, such as \ignore or \­unignore
Returns:
true if a command was handled
See Also:
SOCPlayerInterface.doLocalCommand(String)

printIgnoreList

protected void printIgnoreList(ChannelFrame fr)
Print the current chat ignorelist in a channel.


printIgnoreList

protected void printIgnoreList(SOCPlayerInterface pi)
Print the current chat ignorelist in a playerinterface.


practiceGameStarting

public void practiceGameStarting()
When a practice game is starting, it may take a while to start server & game. Set Cursor.WAIT_CURSOR. The new-game window will clear this cursor back to default.

Specified by:
practiceGameStarting in interface SOCPlayerClient.GameDisplay

startLocalTCPServer

public void startLocalTCPServer(int tport)
                         throws java.lang.IllegalArgumentException,
                                java.lang.IllegalStateException
Setup for locally hosting a TCP server. If needed, a local server and robots are started, and client connects to it. If parent is a Frame, set titlebar to show "server" and port#. Show port number in versionOrlocalTCPPortLabel. If the SOCPlayerClient.ClientNetwork.localTCPServer is already created, does nothing. If connected already, does nothing.

Parameters:
tport - Port number to host on; must be greater than zero.
Throws:
java.lang.IllegalArgumentException - If port is 0 or negative
java.lang.IllegalStateException - if already connected to a server