soc.client
Class AskDialog

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
              extended byjava.awt.Dialog
                  extended bysoc.client.AskDialog
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.event.KeyListener, java.awt.MenuContainer, java.awt.event.MouseListener, java.io.Serializable, java.awt.event.WindowListener
Direct Known Subclasses:
SOCPlayerInterface.ResetBoardVoteDialog, SOCPracticeAskDialog, SOCQuitAllConfirmDialog, SOCQuitConfirmDialog

public abstract class AskDialog
extends java.awt.Dialog
implements java.awt.event.ActionListener, java.awt.event.WindowListener, java.awt.event.KeyListener, java.awt.event.MouseListener

This is the generic dialog to ask players a two- or three-choice question.

To react to button presses, override the abstract methods button1Chosen(), button2Chosen(), windowCloseChosen(), and (for a three-choice question) override button3Chosen().

Author:
Jeremy D Monin
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Dialog
java.awt.Dialog.AccessibleAWTDialog
 
Nested classes inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.awt.Button choice1But
          Button for first choice.
protected  java.awt.Button choice2But
          Button for second choice.
protected  java.awt.Button choice3But
          Optional button for third choice, or null.
protected  int choiceDefault
          Default button (0 for none, or button 1, 2, or 3)
protected  boolean didReqFocus
          Have we requested focus yet?
protected  java.awt.Label msg
          Prompt message, or null
protected  int padH
          Padding beyond desired size; not known until windowOpened()
protected  int padW
          Padding beyond desired size; not known until windowOpened()
protected  SOCPlayerClient pcli
          Player client; passed to constructor, not null
protected  SOCPlayerInterface pi
          Player interface; passed to constructor; may be null if the question is related to the entire client, and not to a specific game
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
 
Fields inherited from class java.awt.Window
 
Fields inherited from class java.awt.Container
 
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
AskDialog(SOCPlayerClient cli, java.awt.Frame parentFr, java.lang.String titlebar, java.lang.String prompt, java.lang.String choice1, java.lang.String choice2, boolean default1, boolean default2)
          Creates a new AskDialog with two buttons, not about a specific game.
AskDialog(SOCPlayerClient cli, java.awt.Frame parentFr, java.lang.String titlebar, java.lang.String prompt, java.lang.String choice1, java.lang.String choice2, java.lang.String choice3, int defaultChoice)
          Creates a new AskDialog with three buttons, not about a specific game.
AskDialog(SOCPlayerClient cli, SOCPlayerInterface gamePI, java.lang.String titlebar, java.lang.String prompt, java.lang.String choice1, java.lang.String choice2, boolean default1, boolean default2)
          Creates a new AskDialog with two buttons, about a specific game.
AskDialog(SOCPlayerClient cli, SOCPlayerInterface gamePI, java.lang.String titlebar, java.lang.String prompt, java.lang.String choice1, java.lang.String choice2, java.lang.String choice3, int defaultChoice)
          Creates a new AskDialog with three buttons, about a specific game.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          A button has been chosen by the user.
abstract  void button1Chosen()
          Button 1 has been chosen by the user.
abstract  void button2Chosen()
          Button 2 has been chosen by the user.
 void button3Chosen()
          The optional button 3 has been chosen by the user.
protected  void checkSizeAndFocus()
          Adjust size (vs insets) and set focus to the default button (if any).
 void keyPressed(java.awt.event.KeyEvent e)
          Handle Enter or Esc key
 void keyReleased(java.awt.event.KeyEvent arg0)
          Stub required by KeyListener
 void keyTyped(java.awt.event.KeyEvent arg0)
          Stub required by KeyListener
 void mouseClicked(java.awt.event.MouseEvent e)
          Stub required by MouseListener
 void mouseEntered(java.awt.event.MouseEvent e)
          Check vs.
 void mouseExited(java.awt.event.MouseEvent e)
          Stub required by MouseListener
 void mousePressed(java.awt.event.MouseEvent e)
          Stub required by MouseListener
 void mouseReleased(java.awt.event.MouseEvent e)
          Stub required by MouseListener
static void styleAsDefault(java.awt.Button b)
          Since we can't designate as default visually through the standard AWT API, try to bold the button text or set its color to white.
 void windowActivated(java.awt.event.WindowEvent e)
          Stub required by WindowListener
abstract  void windowCloseChosen()
          The dialog window was closed by the user, or ESC was pressed.
 void windowClosed(java.awt.event.WindowEvent e)
          Stub required by WindowListener
 void windowClosing(java.awt.event.WindowEvent e)
          Dialog close requested by user.
 void windowDeactivated(java.awt.event.WindowEvent e)
          Stub required by WindowListener
 void windowDeiconified(java.awt.event.WindowEvent e)
          Stub required by WindowListener
 void windowIconified(java.awt.event.WindowEvent e)
          Stub required by WindowListener
 void windowOpened(java.awt.event.WindowEvent e)
          Window is appearing - check the size and the default button keyboard focus
 
Methods inherited from class java.awt.Dialog
addNotify, dispose, getAccessibleContext, getTitle, hide, isModal, isResizable, isUndecorated, paramString, setModal, setResizable, setTitle, setUndecorated, show
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, finalize, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, 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, 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, isOpaque, 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, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pcli

protected final SOCPlayerClient pcli
Player client; passed to constructor, not null


pi

protected SOCPlayerInterface pi
Player interface; passed to constructor; may be null if the question is related to the entire client, and not to a specific game


msg

protected final java.awt.Label msg
Prompt message, or null


choice1But

protected final java.awt.Button choice1But
Button for first choice.

See Also:
button1Chosen()

choice2But

protected final java.awt.Button choice2But
Button for second choice.

See Also:
button2Chosen()

choice3But

protected java.awt.Button choice3But
Optional button for third choice, or null.

See Also:
button3Chosen()

choiceDefault

protected final int choiceDefault
Default button (0 for none, or button 1, 2, or 3)


wantW

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


wantH

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


padW

protected int padW
Padding beyond desired size; not known until windowOpened()


padH

protected int padH
Padding beyond desired size; not known until windowOpened()


didReqFocus

protected boolean didReqFocus
Have we requested focus yet?

Constructor Detail

AskDialog

public AskDialog(SOCPlayerClient cli,
                 SOCPlayerInterface gamePI,
                 java.lang.String titlebar,
                 java.lang.String prompt,
                 java.lang.String choice1,
                 java.lang.String choice2,
                 boolean default1,
                 boolean default2)
          throws java.lang.IllegalArgumentException
Creates a new AskDialog with two buttons, about a specific game.

Parameters:
cli - Player client interface
gamePI - Current game's player interface
titlebar - Title bar text
prompt - Prompting text shown above buttons, or null
choice1 - First choice button text
choice2 - Second choice button text
default1 - First choice is default
default2 - Second choice is default
Throws:
java.lang.IllegalArgumentException - If both default1 and default2 are true, or if any of these is null: cli, gamePI, prompt, choice1, choice2.

AskDialog

public AskDialog(SOCPlayerClient cli,
                 java.awt.Frame parentFr,
                 java.lang.String titlebar,
                 java.lang.String prompt,
                 java.lang.String choice1,
                 java.lang.String choice2,
                 boolean default1,
                 boolean default2)
          throws java.lang.IllegalArgumentException
Creates a new AskDialog with two buttons, not about a specific game.

Parameters:
cli - Player client interface
parentFr - SOCPlayerClient or other parent frame
titlebar - Title bar text
prompt - Prompting text shown above buttons, or null
choice1 - First choice button text
choice2 - Second choice button text
default1 - First choice is default
default2 - Second choice is default
Throws:
java.lang.IllegalArgumentException - If both default1 and default2 are true, or if any of these is null: cli, gamePI, prompt, choice1, choice2.

AskDialog

public AskDialog(SOCPlayerClient cli,
                 SOCPlayerInterface gamePI,
                 java.lang.String titlebar,
                 java.lang.String prompt,
                 java.lang.String choice1,
                 java.lang.String choice2,
                 java.lang.String choice3,
                 int defaultChoice)
          throws java.lang.IllegalArgumentException
Creates a new AskDialog with three buttons, about a specific game. Also can create with two.

Parameters:
cli - Player client interface
gamePI - Current game's player interface
titlebar - Title bar text
prompt - Prompting text shown above buttons, or null
choice1 - First choice button text
choice2 - Second choice button text
choice3 - Third choice button text, or null if 2 buttons
defaultChoice - Default button (1, 2, 3, or 0 for none)
Throws:
java.lang.IllegalArgumentException - If defaultChoice out of range 0..3, or if any of these is null: cli, gamePI, prompt, choice1, choice2, or if choice3 is null and defaultChoice is 3.

AskDialog

public AskDialog(SOCPlayerClient cli,
                 java.awt.Frame parentFr,
                 java.lang.String titlebar,
                 java.lang.String prompt,
                 java.lang.String choice1,
                 java.lang.String choice2,
                 java.lang.String choice3,
                 int defaultChoice)
          throws java.lang.IllegalArgumentException
Creates a new AskDialog with three buttons, not about a specific game. Also can create with two.

Parameters:
cli - Player client interface
parentFr - SOCPlayerClient or other parent frame
titlebar - Title bar text
prompt - Prompting text shown above buttons, or null
choice1 - First choice button text
choice2 - Second choice button text
choice3 - Third choice button text, or null if 2 buttons
defaultChoice - Default button (1, 2, 3, or 0 for none)
Throws:
java.lang.IllegalArgumentException - If defaultChoice out of range 0..3, or if any of these is null: cli, parentFr, prompt, choice1, choice2, or if choice3 is null and defaultChoice is 3.
Method Detail

checkSizeAndFocus

protected void checkSizeAndFocus()
Adjust size (vs insets) and set focus to the default button (if any).


styleAsDefault

public static void styleAsDefault(java.awt.Button b)
Since we can't designate as default visually through the standard AWT API, try to bold the button text or set its color to white.

Parameters:
b - Button to style visually as default. Please add button to dialog layout before calling, so we can query the font.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
A button has been chosen by the user. Call button1Chosen, button2Chosen or button3chosen, and dispose of this dialog.

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

button1Chosen

public abstract void button1Chosen()
Button 1 has been chosen by the user. React accordingly. actionPerformed has already called dialog.dispose().


button2Chosen

public abstract void button2Chosen()
Button 2 has been chosen by the user. React accordingly. actionPerformed has already called dialog.dispose().


button3Chosen

public void button3Chosen()
The optional button 3 has been chosen by the user. React accordingly. actionPerformed has already called dialog.dispose(). Please override this empty stub if you have a third button.


windowCloseChosen

public abstract void windowCloseChosen()
The dialog window was closed by the user, or ESC was pressed. React accordingly. AskDialog has already called dialog.dispose().


windowClosing

public void windowClosing(java.awt.event.WindowEvent e)
Dialog close requested by user. Dispose and call windowCloseChosen.

Specified by:
windowClosing in interface java.awt.event.WindowListener

windowOpened

public void windowOpened(java.awt.event.WindowEvent e)
Window is appearing - check the size and the default button keyboard focus

Specified by:
windowOpened in interface java.awt.event.WindowListener

windowActivated

public void windowActivated(java.awt.event.WindowEvent e)
Stub required by WindowListener

Specified by:
windowActivated in interface java.awt.event.WindowListener

windowClosed

public void windowClosed(java.awt.event.WindowEvent e)
Stub required by WindowListener

Specified by:
windowClosed in interface java.awt.event.WindowListener

windowDeactivated

public void windowDeactivated(java.awt.event.WindowEvent e)
Stub required by WindowListener

Specified by:
windowDeactivated in interface java.awt.event.WindowListener

windowDeiconified

public void windowDeiconified(java.awt.event.WindowEvent e)
Stub required by WindowListener

Specified by:
windowDeiconified in interface java.awt.event.WindowListener

windowIconified

public void windowIconified(java.awt.event.WindowEvent e)
Stub required by WindowListener

Specified by:
windowIconified in interface java.awt.event.WindowListener

keyPressed

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

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

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Check vs. minimum size

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Stub required by MouseListener

Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Stub required by MouseListener

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Stub required by MouseListener

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Stub required by MouseListener

Specified by:
mouseReleased in interface java.awt.event.MouseListener