soc.client
Class SOCConnectOrPracticePanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by soc.client.SOCConnectOrPracticePanel
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.KeyListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class SOCConnectOrPracticePanel
extends java.awt.Panel
implements java.awt.event.ActionListener, java.awt.event.KeyListener

This is the dialog for standalone client startup (JAR or otherwise) if no command-line arguments. Give choice of connect to server, start local server, or create practice game. Prompt for parameters for connect or start-server.

Author:
Jeremy D Monin
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
private  boolean canLaunchServer
          Do we have security to run a TCP server? Determined by calling checkCanLaunchServer().
private  SOCPlayerClient.ClientNetwork clientNetwork
           
private  java.awt.Button conn_cancel
           
private  java.awt.Button conn_connect
           
private  java.awt.TextField conn_pass
           
private  java.awt.TextField conn_servhost
           
private  java.awt.TextField conn_servport
           
private  java.awt.TextField conn_user
           
private  java.awt.Button connserv
          "Connect to server"
private  SOCPlayerClient.GameAwtDisplay gd
           
private static java.awt.Color HEADER_LABEL_BG
           
private static java.awt.Color HEADER_LABEL_FG
           
private  java.awt.Panel panel_conn
          Contains GUI elements for details in connserv
private  java.awt.Panel panel_run
          Contains GUI elements for details in runserv, or null if can't run.
private  java.awt.Button prac
          "Practice"
private  java.awt.Button run_cancel
           
private  java.awt.TextField run_servport
           
private  java.awt.Button run_startserv
           
private  java.awt.Button runserv
          "Start a server"
private static SOCStringManager strings
          i18n text strings; will use same locale as SOCPlayerClient's string manager.
private  java.awt.Label topText
          Welcome message, or error after disconnect
 
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
SOCConnectOrPracticePanel(SOCPlayerClient.GameAwtDisplay gd)
          Creates a new SOCConnectOrPracticePanel.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent ae)
          React to button clicks
static boolean checkCanLaunchServer()
          Check with the SecurityManager about being a tcp server.
 void clickConnCancel()
          Hide fields used to connect to server.
private  void clickConnConnect()
          "Connect..." from connect setup; check fields, set WAIT_CURSOR, ask cli to connect
private  void clickRunCancel()
          Hide fields used to start a server
private  void clickRunStartserv()
          Actually start a server, on port from run_servport
private  java.awt.Panel initInterface_conn()
          panel_conn setup
private  java.awt.Panel initInterface_run()
          panel_run setup
private  void initInterfaceElements()
          Interface setup for constructor.
 void keyPressed(java.awt.event.KeyEvent e)
          Handle Enter or Esc key (KeyListener)
 void keyReleased(java.awt.event.KeyEvent arg0)
          Stub required by KeyListener
 void keyTyped(java.awt.event.KeyEvent arg0)
          Stub required by KeyListener
private  int parsePortNumberOrDefault(java.awt.TextField tf)
          Parse a server TCP port number from a text field.
 void setTopText(java.lang.String newText)
          Set the line of text displayed at the top of the panel.
 void startedLocalServer()
          A local server has been started; disable other options ("Connect", etc) but not Practice.
 
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

gd

private final SOCPlayerClient.GameAwtDisplay gd

clientNetwork

private final SOCPlayerClient.ClientNetwork clientNetwork

topText

private java.awt.Label topText
Welcome message, or error after disconnect


prac

private java.awt.Button prac
"Practice"


connserv

private java.awt.Button connserv
"Connect to server"


panel_conn

private java.awt.Panel panel_conn
Contains GUI elements for details in connserv


conn_servhost

private java.awt.TextField conn_servhost

conn_servport

private java.awt.TextField conn_servport

conn_user

private java.awt.TextField conn_user

conn_pass

private java.awt.TextField conn_pass

conn_connect

private java.awt.Button conn_connect

conn_cancel

private java.awt.Button conn_cancel

runserv

private java.awt.Button runserv
"Start a server"


panel_run

private java.awt.Panel panel_run
Contains GUI elements for details in runserv, or null if can't run.


run_servport

private java.awt.TextField run_servport

run_startserv

private java.awt.Button run_startserv

run_cancel

private java.awt.Button run_cancel

canLaunchServer

private final boolean canLaunchServer
Do we have security to run a TCP server? Determined by calling checkCanLaunchServer().


HEADER_LABEL_BG

private static final java.awt.Color HEADER_LABEL_BG

HEADER_LABEL_FG

private static final java.awt.Color HEADER_LABEL_FG

strings

private static final SOCStringManager strings
i18n text strings; will use same locale as SOCPlayerClient's string manager.

Since:
2.0.00
Constructor Detail

SOCConnectOrPracticePanel

public SOCConnectOrPracticePanel(SOCPlayerClient.GameAwtDisplay gd)
Creates a new SOCConnectOrPracticePanel.

Parameters:
gd - Player client display
Method Detail

checkCanLaunchServer

public static boolean checkCanLaunchServer()
Check with the SecurityManager about being a tcp server. Port SOCPlayerClient.ClientNetwork.SOC_PORT_DEFAULT and some subsequent ports are checked (to be above 1024).

Returns:
True if we have perms to start a server and listen on a port

initInterfaceElements

private void initInterfaceElements()
Interface setup for constructor. Most elements are part of a sub-panel occupying most of this Panel, and using FlowLayout. The exception is a Label at bottom with the version and build number.


initInterface_conn

private java.awt.Panel initInterface_conn()
panel_conn setup


initInterface_run

private java.awt.Panel initInterface_run()
panel_run setup


startedLocalServer

public void startedLocalServer()
A local server has been started; disable other options ("Connect", etc) but not Practice. Called from client, once the server is started in SOCPlayerClient.GameAwtDisplay.startLocalTCPServer(int).


setTopText

public void setTopText(java.lang.String newText)
Set the line of text displayed at the top of the panel.

Parameters:
newText - New text to display
Since:
1.1.16

parsePortNumberOrDefault

private final int parsePortNumberOrDefault(java.awt.TextField tf)
Parse a server TCP port number from a text field. If the field is empty after trimming whitespace, use this client's default from clientNetwork.getPort(), which is usually SOCPlayerClient.ClientNetwork.SOC_PORT_DEFAULT.

Parameters:
tf - Text field with the port number, such as conn_servport or run_servport
Returns:
the port number, or clientNetwork.getPort() if empty, or 0 if cannot be parsed or if outside the valid range 1-65535
Since:
1.1.19

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent ae)
React to button clicks

Specified by:
actionPerformed in interface java.awt.event.ActionListener

clickConnConnect

private void clickConnConnect()
"Connect..." from connect setup; check fields, set WAIT_CURSOR, ask cli to connect


clickConnCancel

public void clickConnCancel()
Hide fields used to connect to server. Called by client after a network error.


clickRunStartserv

private void clickRunStartserv()
Actually start a server, on port from run_servport


clickRunCancel

private void clickRunCancel()
Hide fields used to start a server


keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Handle Enter or Esc key (KeyListener)

Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent arg0)
Stub required by KeyListener

Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent arg0)
Stub required by KeyListener

Specified by:
keyTyped in interface java.awt.event.KeyListener