soc.client
Class SOCDiscardOrGainResDialog

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.SOCDiscardOrGainResDialog
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, java.util.EventListener, javax.accessibility.Accessible

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

This is the dialog to ask players what resources they want to discard from rolling a 7, or to gain from the gold hex. Also used for the Discovery/Year of Plenty dev card.

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

Before v2.0.00, this was called SOCDiscardDialog, and Year of Plenty used SOCDiscoveryDialog.

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
private  java.awt.Button clearBut
          Clear button.
(package private)  boolean didSetLocation
          Place window in center when displayed (in doLayout), don't change position afterwards
private  boolean isDiscard
          Are we discarding, not gaining?
(package private)  ColorSquare[] keep
          The 'keep' square resource types/counts only change if isDiscard.
(package private)  java.awt.Label msg
           
private  int numChosen
          Has chosen to discard or gain this many resources so far in pick.
private  int numPickNeeded
          Must discard this many resources from keep, or must gain this many resources.
private  java.awt.Button okBut
          Discard or Pick button
private  ColorSquare[] pick
          Resource types/counts to discard or gain
(package private)  java.awt.Label pickThese
           
(package private)  SOCPlayerInterface playerInterface
           
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)
(package private)  java.awt.Label youHave
           
 
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
SOCDiscardOrGainResDialog(SOCPlayerInterface pi, int rnum, boolean isDiscard)
          Creates a new SOCDiscardOrGainResDialog popup.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          React to clicking Discard/Pick button or Clear button.
 void doLayout()
          Custom layout, and setLocation call, for this dialog.
 void mouseClicked(java.awt.event.MouseEvent e)
          Stub, required for MouseListener.
 void mouseEntered(java.awt.event.MouseEvent e)
          Stub, required for MouseListener.
 void mouseExited(java.awt.event.MouseEvent e)
          Stub, required for MouseListener.
 void mousePressed(java.awt.event.MouseEvent e)
          When a resource's colorsquare is clicked, add/remove 1 from the resource totals as requested; update okBut and clearBut.
 void mouseReleased(java.awt.event.MouseEvent e)
          Stub, required for MouseListener.
 void run()
          Run method, for convenience with EventQueue.invokeLater(Runnable).
 void setVisible(boolean vis)
          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

isDiscard

private final boolean isDiscard
Are we discarding, not gaining?

Since:
2.0.00

clearBut

private java.awt.Button clearBut
Clear button. Reset the pick resource colorsquare counts to 0.

Since:
1.1.14

okBut

private java.awt.Button okBut
Discard or Pick button


keep

ColorSquare[] keep
The 'keep' square resource types/counts only change if isDiscard.


pick

private ColorSquare[] pick
Resource types/counts to discard or gain


msg

java.awt.Label msg

youHave

java.awt.Label youHave

pickThese

java.awt.Label pickThese

playerInterface

SOCPlayerInterface playerInterface

numPickNeeded

private final int numPickNeeded
Must discard this many resources from keep, or must gain this many resources.


numChosen

private int numChosen
Has chosen to discard or gain this many resources so far in pick. okBut is disabled unless proper number of resources (numPickNeeded) are chosen.


wantW

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


wantH

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


didSetLocation

boolean didSetLocation
Place window in center when displayed (in doLayout), don't change position afterwards

Constructor Detail

SOCDiscardOrGainResDialog

public SOCDiscardOrGainResDialog(SOCPlayerInterface pi,
                                 int rnum,
                                 boolean isDiscard)
Creates a new SOCDiscardOrGainResDialog popup. To show it on screen and make it active, call setVisible(true).

Parameters:
pi - Client's player interface
rnum - Player must discard or gain this many resources
isDiscard - True for discard (after 7), false for gain (after gold hex)
Method Detail

setVisible

public void setVisible(boolean vis)
Show or hide this dialog. If showing (vis == true), also sets the initial values of our current resources, based on SOCPlayer.getResources(), and requests focus on the Discard/Pick button.

Overrides:
setVisible in class java.awt.Dialog
Parameters:
vis - True to make visible, false to hide

doLayout

public void doLayout()
Custom layout, and setLocation call, for this dialog.

Overrides:
doLayout in class java.awt.Container

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
React to clicking Discard/Pick button or Clear button.

ColorSquare clicks are handled in mousePressed(MouseEvent).

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - ActionEvent for the click, with EventObject.getSource() == our button

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Stub, required for MouseListener.

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

mouseExited

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

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

mouseClicked

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

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

mouseReleased

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

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

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
When a resource's colorsquare is clicked, add/remove 1 from the resource totals as requested; update okBut and clearBut.

If not isDiscard, will not subtract change the "keep" colorsquare resource counts.

If we only need 1 total, and we've picked one and now pick a different one, zero the previous pick and change our choice to the new one.

Clear/Discard button clicks are handled in actionPerformed(ActionEvent).

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

run

public void run()
Run method, for convenience with EventQueue.invokeLater(Runnable). This method just calls setVisible(true).

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