au.com.solidsoftware.multimahjong.mmc.usergui
Class ActionPane

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--au.com.solidsoftware.multimahjong.mmc.usergui.ActionPane

public class ActionPane
extends javax.swing.JPanel

The pane containing the action buttons allowing the user to interact with the underlying MultiMahjong game engine. There seven action buttons in this pane. In order from top to bottom, these buttons allow the user to "Declare Kong", "Pickup", "Discard", "Chow", "Pung", "Kong" and "Mahjong":

Each button may be either disabled or enabled. The state of the button is determined by the Game object and is dependent upon the legal moves that user may carry out. The diagram below shows the disabled and enabled state of the action buttons:

 

When enabled, the appearance of the button will change when the user moves the cursor over it. The appearance of the button will also change when the user clicks on it. The diagram below shows the rollover and pressed state of the action buttons:

 

To prevent users from spending too long deciding on whether to execute a game action, a timer is built into the action pane. This timer will become activated when the user is given the option to Pung, Kong, or Mahjong. After a delay of 10 seconds, the option will expire, and a Pass action is sent automatically. A countdown is shown unobstructive in the bottom-right hand corner of the action pane to inform the user of the time remaining. In the diagram below, the user has five seconds remaining before making a decision to Pung:

Author:
Victor H. Leung
See Also:
Serialized Form

Inner Class Summary
private  class ActionPane.RolloverButton
          A specialised rollover-enabled button which corrects some quirks/annoyances within JButton, making it more suited for use with graphical buttons.
 
Inner classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent, javax.swing.JComponent.IntVector, javax.swing.JComponent.KeyboardBinding, javax.swing.JComponent.KeyboardState
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AWTTreeLock
 
Field Summary
private  javax.swing.Timer autopass
          The timer that fires off an action events every second.
static int CHOW
          Symbolic constant used to refer to the "Chow" button.
private  ActionPane.RolloverButton chowButton
          The "Chow" button.
private  int countdown
          The time in seconds remaining before we automatically pass for the player.
private  javax.swing.JLabel countdownLabel
          The label showing the seconds remaining before we automatically pass for the player.
static int DECLARE
          Symbolic constant used to refer to the "Declare Kong" button.
private  ActionPane.RolloverButton declareButton
          The "Declare Kong" button.
static int DISCARD
          Symbolic constant used to refer to the "Discard" button.
private  ActionPane.RolloverButton discardButton
          The "Discard" button.
static int KONG
          Symbolic constant used to refer to the "Kong" button.
private  ActionPane.RolloverButton kongButton
          The "Kong" button.
static int MAHJONG
          Symbolic constant used to refer to the "Mahjong" button.
private  ActionPane.RolloverButton mahjongButton
          The "Mahjong" button.
static int PICKUP
          Symbolic constant used to refer to the "Pickup" button.
private  ActionPane.RolloverButton pickupButton
          The "Pickup" button.
static int PUNG
          Symbolic constant used to refer to the "Pung" button.
private  ActionPane.RolloverButton pungButton
          The "Pung" button.
private  Tile selected
          The tile that has been selected by the user in the UserPane.
private  UserGUI userGUI
          A reference to the parent UserGUI object.
 
Fields inherited from class javax.swing.JPanel
defaultLayout, uiClassID
 
Fields inherited from class javax.swing.JComponent
_bounds, accessibleContext, alignmentX, alignmentY, ANCESTOR_USING_BUFFER, ancestorNotifier, autoscroller, border, changeSupport, clientProperties, flags, HAS_FOCUS, IS_DOUBLE_BUFFERED, IS_OPAQUE, IS_PAINTING_TILE, KEYBOARD_BINDINGS_KEY, listenerList, maximumSize, minimumSize, NEXT_FOCUS, paintImmediatelyClip, preferredSize, readObjectCallbacks, REQUEST_FOCUS_DISABLED, tmpRect, TOOL_TIP_TEXT_KEY, ui, uiClassID, UNDEFINED_CONDITION, vetoableChangeSupport, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
component, containerListener, containerSerializedDataVersion, dispatcher, layoutMgr, maxSize, ncomponents, serialVersionUID
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, assert, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, hasFocus, height, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, RIGHT_ALIGNMENT, serialVersionUID, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowListenerK, x, y
 
Constructor Summary
ActionPane(UserGUI userGUI)
          Creates an instance of ActionPane with all the buttons initially in a disabled, greyed-out state.
 
Method Summary
 void disableAll()
          Disables all the action buttons in this pane.
 void enableButton(int button)
          Enables a specific action button in this pane.
static void main(java.lang.String[] args)
          Driver code used for unit testing.
 void setSelected(Tile tile)
          Stores the tile that has been selected by the user in the PlayArea.
private  void showChowSelectionDialog(UserGUI userGUI)
          Displays a dialog box allowing the user to select between the possible ways of forming an exposed chow with the last discard.
 void showRobKongDialogBox(UserGUI userGUI)
          Shows a confirm dialog box allowing the user to choose whether to rob a kong when the opportunity arises.
 
Methods inherited from class javax.swing.JPanel
, getAccessibleContext, getUIClassID, paramString, updateUI, writeObject
 
Methods inherited from class javax.swing.JComponent
_paintImmediately, addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, adjustPaintFlags, alwaysOnTop, bindingForKeyStroke, computeVisibleRect, computeVisibleRect, contains, createToolTip, enableSerialization, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperties, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getFlag, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, keyboardBindings, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paintWithBuffer, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyBindings, processKeyBindingsForAllComponents, processKeyEvent, processMouseMotionEvent, putClientProperty, readObject, rectangleIsObscured, registerKeyboardAction, registerKeyboardAction, registerWithKeyboardManager, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFlag, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, shouldDebugGraphics, superProcessMouseMotionEvent, unregisterKeyboardAction, unregisterWithKeyboardManager, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyOrientation, countComponents, deliverEvent, dispatchEventImpl, dispatchEventToSelf, doLayout, eventEnabled, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getLayout, getMouseEventTarget, getWindow, initIDs, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPrint, list, list, locate, minimumSize, nextFocus, paintComponents, postProcessKeyEvent, postsOldMouseEvents, preferredSize, preProcessKeyEvent, print, printComponents, printOneComponent, processContainerEvent, processEvent, proxyEnableEvents, proxyRequestFocus, remove, remove, removeAll, removeContainerListener, setFocusOwner, setLayout, transferFocus, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkImage, checkImage, coalesceEvents, constructComponentName, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getToolkit, getToolkitImpl, getTreeLock, getWindowForObject, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isEnabledImpl, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

DECLARE

public static final int DECLARE
Symbolic constant used to refer to the "Declare Kong" button. This is used as the argument to the enableButton method.


PICKUP

public static final int PICKUP
Symbolic constant used to refer to the "Pickup" button. This is used as the argument to the enableButton method.


DISCARD

public static final int DISCARD
Symbolic constant used to refer to the "Discard" button. This is used as the argument to the enableButton method.


CHOW

public static final int CHOW
Symbolic constant used to refer to the "Chow" button. This is used as the argument to the enableButton method.


PUNG

public static final int PUNG
Symbolic constant used to refer to the "Pung" button. This is used as the argument to the enableButton method.


KONG

public static final int KONG
Symbolic constant used to refer to the "Kong" button. This is used as the argument to the enableButton method.


MAHJONG

public static final int MAHJONG
Symbolic constant used to refer to the "Mahjong" button. This is used as the argument to the enableButton method.


declareButton

private ActionPane.RolloverButton declareButton
The "Declare Kong" button. The ActionListener attached to this button invokes the Human.setMove(selected, Player.DECLARE) method upon receiving an ActionEvent.

See Also:
Human.setMove(au.com.solidsoftware.multimahjong.shared.Tile, int)

pickupButton

private ActionPane.RolloverButton pickupButton
The "Pickup" button. The ActionListener attached to this button invokes Human.setSelection(Player.PICKUP) upon receiving an ActionEvent.

See Also:
Human.setSelection(int)

discardButton

private ActionPane.RolloverButton discardButton
The "Discard" button. The ActionListener attached to this button invokes Human.setMove(selected, Player.DISCARD) upon receiving an ActionEvent.

See Also:
Human.setMove(au.com.solidsoftware.multimahjong.shared.Tile, int)

chowButton

private ActionPane.RolloverButton chowButton
The "Chow" button. The ActionListener attached to this button invokes the showChowSelectionDialog() method upon receiving an ActionEvent.

See Also:
Human.setSelection(int)

pungButton

private ActionPane.RolloverButton pungButton
The "Pung" button. The ActionListener attached to this button invokes Human.setSelection(Player.PUNG) upon receiving an ActionEvent.

See Also:
Human.setSelection(int)

kongButton

private ActionPane.RolloverButton kongButton
The "Kong" button. The ActionListener attached to this button invokes Human.setSelection(Player.KONG) upon receiving an ActionEvent.

See Also:
Human.setSelection(int)

mahjongButton

private ActionPane.RolloverButton mahjongButton
The "Mahjong" button. The ActionListener attached to this button invokes Human.setSelection(Player.MAHJONG) upon receiving an ActionEvent.

See Also:
Human.setSelection(int)

userGUI

private UserGUI userGUI
A reference to the parent UserGUI object.

selected

private Tile selected
The tile that has been selected by the user in the UserPane. This field can be updated via the setSelected method.


autopass

private javax.swing.Timer autopass
The timer that fires off an action events every second. After 10 of these events, the Human.setSelection(Player.NO_MOVE) method is invoked. In effect, this gives the user exactly ten seconds to decide whether to execute a game action - when these ten seconds lapse, an automatic "Pass" is assumed.

See Also:
Human.setSelection(int)

countdown

private int countdown
The time in seconds remaining before we automatically pass for the player.


countdownLabel

private javax.swing.JLabel countdownLabel
The label showing the seconds remaining before we automatically pass for the player.

Constructor Detail

ActionPane

public ActionPane(UserGUI userGUI)
Creates an instance of ActionPane with all the buttons initially in a disabled, greyed-out state. Seven action buttons are added to this pane. In order from top to bottom, these buttons allow the user to "Declare Kong", "Pickup", "Discard", "Chow", "Pung", "Kong" and "Mahjong". An ActionListener is added to each of these buttons to invoke the Human.setSelection(int) or Human.setMove(au.com.solidsoftware.multimahjong.shared.Tile, int) method upon receiving an ActionEvent, which in turn registers the action with the Game object.

Parameters:
userGUI - a reference to the parent UserGUI object
Method Detail

disableAll

public void disableAll()
Disables all the action buttons in this pane. When a button is disabled, it will become greyed-out, and will no longer change its appearance if the user moves the mouse cursor over it. The button will also becomes completely unresponsive to mouse clicks.


enableButton

public void enableButton(int button)
Enables a specific action button in this pane. When a button is enabled, it will become highlighted, and will change its appearance if the user moves the mouse cursor over it. Pressing an enabled button will trigger off an ActionEvent, which is then passed to every ActionListener that have registered to receive this via the button's addActionListener method.

Parameters:
button - A symbolic constant referring to the action button to be enabled. If an unrecognisable symbolic contant is encountered, no action will be carried out.

setSelected

public void setSelected(Tile tile)
Stores the tile that has been selected by the user in the PlayArea. The selected tile must be stored locally because some ActionListeners invoke the Human.setMove(au.com.solidsoftware.multimahjong.shared.Tile, int) method, which takes the selected tile as an argument.

Parameters:
tile - The tile that has been selected by the user in the PlayArea. This may be null, signifying that there are no tiles selected in the UserPane.

showChowSelectionDialog

private void showChowSelectionDialog(UserGUI userGUI)
Displays a dialog box allowing the user to select between the possible ways of forming an exposed chow with the last discard. This dialog is displayed only if there is more than one way of forming the exposed chow. If there is only one way, this method automatically selects the only alternative, bypassing the dialog altogether.

Parameters:
userGUI - A reference to the parent UserGUI object.

showRobKongDialogBox

public void showRobKongDialogBox(UserGUI userGUI)
Shows a confirm dialog box allowing the user to choose whether to rob a kong when the opportunity arises. This method is called by Human.
Parameters:
userGUI - a reference to the parent UserGUI object

main

public static void main(java.lang.String[] args)
Driver code used for unit testing.