soc.client
Class SOCChoosePlayerDialog

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

 class SOCChoosePlayerDialog
extends java.awt.Dialog
implements java.awt.event.ActionListener, java.lang.Runnable

This is the dialog to ask a player from whom she wants to steal. One button for each victim player. When a player is chosen, send the server a choose-player command with that player number or (if possible to choose none) SOCChoosePlayer.CHOICE_NO_PLAYER.

For convenience with EventQueue.invokeLater(Runnable), contains a run() method which calls setVisible(true).

Author:
Robert S. Thomas

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Dialog
java.awt.Dialog.AccessibleAWTDialog, java.awt.Dialog.ModalExclusionType, java.awt.Dialog.ModalityType
 
Nested classes/interfaces inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
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
(package private)  java.awt.Button[] buttons
          Player names on each button.
(package private)  boolean didSetLocation
          Flag to place window in center once when displayed (in doLayout()), and not change position again afterwards.
private  boolean hasCustomLayout
          If true, doLayout() should manually lay out component locations.
private static int MAX_ON_SAME_LINE
          Maximum number of #players[] buttons to show on a single horizontal line.
(package private)  java.awt.Label msg
           
(package private)  int number
          Number of players to choose from for buttons and players.
(package private)  SOCPlayerInterface pi
           
(package private)  java.awt.Label[] player_res_lbl
          Show Count of resources of each player.
(package private)  int[] players
          Player index of each to choose.
private static SOCStringManager strings
          i18n text strings; will use same locale as SOCPlayerClient's string manager.
protected  int wantH
          Desired size (visible size inside of insets)
protected  int wantW
          Desired size (visible size inside of insets)
 
Fields inherited from class java.awt.Dialog
DEFAULT_MODALITY_TYPE
 
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
SOCChoosePlayerDialog(SOCPlayerInterface plInt, int num, int[] p, boolean allowChooseNone)
          Creates a new SOCChoosePlayerDialog object.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          A button was clicked to choose a victim player.
 void doLayout()
          Do our dialog's custom layout.
 void run()
          Run method, for convenience with EventQueue.invokeLater(Runnable).
private  void setLocationCentered(int width)
          Put the dialog in the top-center of the game window (pi) and set didSetLocation.
 void setVisible(boolean b)
          Show or hide this dialog.
 
Methods inherited from class java.awt.Dialog
addNotify, getAccessibleContext, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, paramString, setModal, setModalityType, setResizable, setTitle, setUndecorated, show, toBack
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, paint, postEvent, processEvent, processWindowEvent, processWindowFocusEvent, processWindowStateEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, 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, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, 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, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

strings

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

Since:
2.0.00

MAX_ON_SAME_LINE

private static final int MAX_ON_SAME_LINE
Maximum number of #players[] buttons to show on a single horizontal line. If asking about more than this many players (including allowChooseNone), the layout will have each on its own line.

Since:
2.0.00
See Also:
Constant Field Values

buttons

java.awt.Button[] buttons
Player names on each button. This array's elements align with players. Length is number. If constructor is called with allowChooseNone, there's a "decline" (choose none) button.


players

final int[] players
Player index of each to choose. This array's elements align with buttons. Only the first number elements are used. If constructor is called with allowChooseNone, the "decline" button's player number is -1 (SOCChoosePlayer.CHOICE_NO_PLAYER).


player_res_lbl

java.awt.Label[] player_res_lbl
Show Count of resources of each player. Length is number.


number

final int number
Number of players to choose from for buttons and players.


msg

final java.awt.Label msg

pi

final SOCPlayerInterface pi

wantW

protected final int wantW
Desired size (visible size inside of insets)


wantH

protected final int wantH
Desired size (visible size inside of insets)


hasCustomLayout

private final boolean hasCustomLayout
If true, doLayout() should manually lay out component locations. See that method's javadoc for criteria.

Since:
2.0.00

didSetLocation

boolean didSetLocation
Flag to place window in center once when displayed (in doLayout()), and not change position again afterwards. Set in setLocationCentered(int).

Constructor Detail

SOCChoosePlayerDialog

public SOCChoosePlayerDialog(SOCPlayerInterface plInt,
                             int num,
                             int[] p,
                             boolean allowChooseNone)
Creates a new SOCChoosePlayerDialog object. After creation, call setVisible(boolean).

Parameters:
plInt - PlayerInterface that owns this dialog
num - The number of players to choose from
p - The player ids of those players; length of this array may be larger than count (may be SOCGame.maxPlayers). Only the first num elements will be used. If allowChooseNone, p.length must be at least num + 1 to leave room for "no player".
allowChooseNone - If true, player can choose to rob no one (used with game scenario SC_PIRI)
Method Detail

setVisible

public void setVisible(boolean b)
Show or hide this dialog. If showing it, request focus on the first button.

Overrides:
setVisible in class java.awt.Dialog
Parameters:
b - True to show, false to hide

doLayout

public void doLayout()
Do our dialog's custom layout.

With 3 or fewer players[] buttons, all buttons are on the same row:

Please choose a player to steal from:
players[0]players[1]players[2]
player_res_lbl[0]player_res_lbl[1]player_res_lbl[2]

With 4 or more buttons, sharing a row would be too wide, so there is 1 player per row:

Please choose a player to steal from:
players[0]player_res_lbl[0]
players[1]player_res_lbl[1]
......
This occurs with the SC_PIRI scenario, which allows robbing any player with resources or declining to rob.

Overrides:
doLayout in class java.awt.Container

setLocationCentered

private void setLocationCentered(int width)
Put the dialog in the top-center of the game window (pi) and set didSetLocation.

Parameters:
width - Dialog width if known, or 0
Since:
2.0.00

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
A button was clicked to choose a victim player. Find the right buttons[i] and send the server a choose-player command with the corresponding player number players[i].

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - AWT event, from a button source

run

public void run()
Run method, for convenience with EventQueue.invokeLater(Runnable). This method just calls setVisible(true), after calling Window.pack() if applicable.

Specified by:
run in interface java.lang.Runnable
Since:
2.0.00