|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container java.awt.Window java.awt.Dialog soc.client.AskDialog
public abstract class AskDialog
This is the generic modal dialog to ask players a two- or three-choice question;
to present a one-button message, see NotifyDialog
.
Since 1.1.07: If dialog text contains \n, multiple lines will be created. If title bar text contains \n, only its first line (before \n) is used.
To react to button presses, override the abstract methods
button1Chosen()
, button2Chosen()
,
windowCloseChosen()
, and (for a three-choice
question) override button3Chosen()
.
For convenience with EventQueue.invokeLater(Runnable)
,
contains a run()
method which calls setVisible(true)
.
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 | |
---|---|
protected java.awt.Button |
choice1But
Button for first choice. |
protected java.awt.Button |
choice2But
Button for second choice, or null. |
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 boolean |
isMsgMultiLine
Is the prompt multi-line? If so, assume it might be larger than usual, and adjust height when checkSizeAndFocus() is called. |
private boolean |
isSizeCheckedAlready
Has checkSizeAndFocus() already set the size
of a multi-line dialog? |
protected javax.swing.JComponent |
msg
Prompt message Label, or Panel for multi-line prompt ( isMsgMultiLine ), or null |
private static int |
MSG_BORDER
Border width around msg . |
protected int |
padH
Padding beyond desired size; not known until windowOpened() |
protected int |
padW
Padding beyond desired size; not known until windowOpened() |
protected javax.swing.JPanel |
pBtns
Button area, for resizing multi-line dialog height in checkSizeAndFocus() . |
protected SOCPlayerClient.GameAwtDisplay |
pcli
Player client; passed to constructor, not null; used for actions in subclasses when dialog buttons are chosen |
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 |
---|
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 | |
---|---|
protected |
AskDialog(SOCPlayerClient.GameAwtDisplay cli,
java.awt.Frame parentFr,
java.lang.String titlebar,
java.lang.String prompt,
java.lang.String btnText,
boolean hasDefault)
Creates a new AskDialog with one button, not about a specific game. |
|
AskDialog(SOCPlayerClient.GameAwtDisplay 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.GameAwtDisplay 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 one, two, or three buttons, not about a specific game. |
|
AskDialog(SOCPlayerClient.GameAwtDisplay 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.GameAwtDisplay 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). |
static java.lang.String |
firstLine(java.lang.String f)
Extract the first line (up to \n) if f is multi-line. |
static java.awt.Frame |
getParentFrame(java.awt.Component c)
Gets the top-level frame of c. |
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 versus minimum size: calls (@link #checkSizeAndFocus()} |
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 |
void |
run()
In the AWT event thread, show ourselves. |
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, getAccessibleContext, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, paramString, setModal, setModalityType, setResizable, setTitle, setUndecorated, setVisible, 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, doLayout, 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 |
---|
private static final int MSG_BORDER
msg
.
protected final SOCPlayerClient.GameAwtDisplay pcli
protected SOCPlayerInterface pi
protected javax.swing.JComponent msg
isMsgMultiLine
), or null
protected final javax.swing.JPanel pBtns
checkSizeAndFocus()
.
protected final boolean isMsgMultiLine
checkSizeAndFocus()
is called.
private boolean isSizeCheckedAlready
checkSizeAndFocus()
already set the size
of a multi-line dialog?
protected final java.awt.Button choice1But
button1Chosen()
protected final java.awt.Button choice2But
button2Chosen()
protected java.awt.Button choice3But
button3Chosen()
protected final int choiceDefault
protected int wantW
protected int wantH
protected int padW
protected int padH
protected boolean didReqFocus
Constructor Detail |
---|
public AskDialog(SOCPlayerClient.GameAwtDisplay 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
cli
- Player client interface; will be used for actions in subclasses when dialog buttons are chosen.gamePI
- Current game's player interface;
Cannot be null, use the other constructor if not asking
about a specific game.titlebar
- Title bar text; if text contains \n, only the portion before \n is usedprompt
- Prompting text shown above buttons, or nullchoice1
- First choice button textchoice2
- Second choice button textdefault1
- First choice is defaultdefault2
- Second choice is default
java.lang.IllegalArgumentException
- If both default1 and default2 are true,
or if any of these is null: cli, gamePI, prompt, choice1, choice2.protected AskDialog(SOCPlayerClient.GameAwtDisplay cli, java.awt.Frame parentFr, java.lang.String titlebar, java.lang.String prompt, java.lang.String btnText, boolean hasDefault) throws java.lang.IllegalArgumentException
NotifyDialog
.
parentFr cannot be null; use getParentFrame(Component)
to find it.
java.lang.IllegalArgumentException
public AskDialog(SOCPlayerClient.GameAwtDisplay 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
cli
- Player client interface; will be used for actions in subclasses when dialog buttons are chosenparentFr
- SOCPlayerClient or other parent frametitlebar
- Title bar text; if text contains \n, only the portion before \n is usedprompt
- Prompting text shown above buttons, or nullchoice1
- First choice button textchoice2
- Second choice button textdefault1
- First choice is defaultdefault2
- Second choice is default
java.lang.IllegalArgumentException
- If both default1 and default2 are true,
or if any of these is null: cli, gamePI, prompt, choice1, choice2.public AskDialog(SOCPlayerClient.GameAwtDisplay 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
cli
- Player client interface; will be used for actions in subclasses when dialog buttons are chosengamePI
- Current game's player interfacetitlebar
- Title bar text; if text contains \n, only the portion before \n is usedprompt
- Prompting text shown above buttons, or nullchoice1
- First choice button textchoice2
- Second choice button textchoice3
- Third choice button text, or null if 2 buttonsdefaultChoice
- Default button (1, 2, 3, or 0 for none)
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.public AskDialog(SOCPlayerClient.GameAwtDisplay 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
cli
- Player client interface; will be used for actions in subclasses when dialog buttons are chosenparentFr
- SOCPlayerClient or other parent frametitlebar
- Title bar text; if text contains \n, only the portion before \n is usedprompt
- Prompting text shown above buttons, or null.
Can be multi-line, use "\n" within your string to separate them.choice1
- First choice button textchoice2
- Second choice button text, or null if 1 buttonchoice3
- Third choice button text, or null if 1 or 2 buttonsdefaultChoice
- Default button (1, 2, 3, or 0 for none)
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 |
---|
protected void checkSizeAndFocus()
public static void styleAsDefault(java.awt.Button b)
b
- Button to style visually as default. Please add button to
dialog layout before calling, so we can query the font.public void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed
in interface java.awt.event.ActionListener
public abstract void button1Chosen()
public abstract void button2Chosen()
public void button3Chosen()
public abstract void windowCloseChosen()
public void windowClosing(java.awt.event.WindowEvent e)
windowClosing
in interface java.awt.event.WindowListener
public void windowOpened(java.awt.event.WindowEvent e)
windowOpened
in interface java.awt.event.WindowListener
public void windowActivated(java.awt.event.WindowEvent e)
windowActivated
in interface java.awt.event.WindowListener
public void windowClosed(java.awt.event.WindowEvent e)
windowClosed
in interface java.awt.event.WindowListener
public void windowDeactivated(java.awt.event.WindowEvent e)
windowDeactivated
in interface java.awt.event.WindowListener
public void windowDeiconified(java.awt.event.WindowEvent e)
windowDeiconified
in interface java.awt.event.WindowListener
public void windowIconified(java.awt.event.WindowEvent e)
windowIconified
in interface java.awt.event.WindowListener
public void keyPressed(java.awt.event.KeyEvent e)
keyPressed
in interface java.awt.event.KeyListener
public void keyReleased(java.awt.event.KeyEvent arg0)
keyReleased
in interface java.awt.event.KeyListener
public void keyTyped(java.awt.event.KeyEvent arg0)
keyTyped
in interface java.awt.event.KeyListener
public void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered
in interface java.awt.event.MouseListener
public void mouseExited(java.awt.event.MouseEvent e)
mouseExited
in interface java.awt.event.MouseListener
public void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked
in interface java.awt.event.MouseListener
public void mousePressed(java.awt.event.MouseEvent e)
mousePressed
in interface java.awt.event.MouseListener
public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
public static java.awt.Frame getParentFrame(java.awt.Component c) throws java.lang.IllegalStateException
c
- The Component.
java.lang.IllegalStateException
- if we find a null parent
before a Frame, or if any parent == itselfpublic static java.lang.String firstLine(java.lang.String f)
f
is multi-line.
f
- A string, possibly containing \n. Should not start with \n.
f
's first line, or all of f
if no \npublic void run()
EventQueue.invokeLater(thisDialog)
.
This method just calls setVisible(true)
, and if any error occurs
calls Throwable.printStackTrace()
.
run
in interface java.lang.Runnable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |