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

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

public class TabbedPane
extends javax.swing.JTabbedPane

A tabbed pane that contains three tabs - a "Scores" tab, a "Discards" tab, and an "Options" tab. The "Scores" tab contains four rows, one for each player. Each row shows, from left to right, the player's icon, name and score.

The "Discards" tab contains a scrollpane which manages a scrollable client. The scrollable client displays dead tiles in the order in which they were discarded. Dead tiles are displayed from left to right, from bottom to top. By adding new dead tiles to the top of the scrollable client, we eliminate the need for the user to continuously scroll down to see new dead tiles.

The "Options" tab contains a check box allowing the user to toggle sound effects on and off. It also contains a "Leave Game" button, which will display a leave game dialog if pressed.

Author:
Victor H. Leung
See Also:
Serialized Form

Inner Class Summary
private  class TabbedPane.DiscardsPane
          An custom inner class used that overrides the paint method in JLayeredPane, permitting each of the discardTileImages to be drawn properly in a layered pane.
private  class TabbedPane.DiscardTileImage
          An inner class used primarily for storing the x- and y-coordinate of a discarded tile, relative to the top-left corner of the discardsPane.
 
Inner classes inherited from class javax.swing.JTabbedPane
javax.swing.JTabbedPane.AccessibleJTabbedPane, javax.swing.JTabbedPane.ModelListener
 
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  TabbedPane.DiscardsPane discardsPane
          A reference to the scrollable client within the "Discards" tab.
private  TabbedPane.DiscardTileImage[] discardTileImages
          This stores the images of all the tiles in the discardsPane.
private  javax.swing.JLabel[] playerLabel
          An array of labels showing the icon and name for each of the players.
private  javax.swing.JLabel[] scoreLabel
          An array of text-only labels showing the scores for each of the players.
private  UserGUI userGUI
          A reference to the parent UserGUI object.
 
Fields inherited from class javax.swing.JTabbedPane
changeEvent, changeListener, haveRegistered, model, pages, tabPlacement, 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
TabbedPane(UserGUI userGUI, Player[] players, int playerID)
          Creates an instance of TabbedPane showing the icons and names of all the players in the game, along with their initial scores, in the "Scores" tab.
 
Method Summary
 void addDeadTile(Tile tile)
          Adds a dead tile to the scrollable client within the "Discards" tab.
 void clearDeadTiles()
          Clears the scrollable client within the "Discards" tab of all dead tiles.
static void main(java.lang.String[] args)
          Driver code used for unit testing.
private  void showLeaveGameConfirmation()
          Displays a dialog box asking the user to confirm their decision to leave the game and return to the game type selection screen.
 void updateScores(Player[] players)
          Updates the scores for all the players present in the "Scores" tab.
 
Methods inherited from class javax.swing.JTabbedPane
add, add, add, add, add, addChangeListener, addTab, addTab, addTab, createChangeListener, fireStateChanged, getAccessibleContext, getBackgroundAt, getBoundsAt, getComponentAt, getDisabledIconAt, getForegroundAt, getIconAt, getModel, getSelectedComponent, getSelectedIndex, getTabCount, getTabPlacement, getTabRunCount, getTitleAt, getToolTipText, getUI, getUIClassID, indexOfComponent, indexOfTab, indexOfTab, insertTab, isEnabledAt, paramString, remove, removeAll, removeChangeListener, removeTabAt, setBackgroundAt, setComponentAt, setDisabledIconAt, setEnabledAt, setForegroundAt, setIconAt, setModel, setSelectedComponent, setSelectedIndex, setTabPlacement, setTitleAt, setUI, 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, 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
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, 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

userGUI

private UserGUI userGUI
A reference to the parent UserGUI object.


playerLabel

private javax.swing.JLabel[] playerLabel
An array of labels showing the icon and name for each of the players. The array indices of this array matches with that of the players array supplied in the class constructor and in the updateScores method.


scoreLabel

private javax.swing.JLabel[] scoreLabel
An array of text-only labels showing the scores for each of the players. The array indices of this array matches with that of the players array supplied in the class constructor and in the updateScores method.


discardsPane

private TabbedPane.DiscardsPane discardsPane
A reference to the scrollable client within the "Discards" tab. This pane displays dead tiles in the order in which they were discarded. Dead tiles are displayed from left to right, from top to bottom.


discardTileImages

private TabbedPane.DiscardTileImage[] discardTileImages
This stores the images of all the tiles in the discardsPane.

Constructor Detail

TabbedPane

public TabbedPane(UserGUI userGUI,
                  Player[] players,
                  int playerID)
Creates an instance of TabbedPane showing the icons and names of all the players in the game, along with their initial scores, in the "Scores" tab. The name and score corresponding to the user is uniquely displayed in a different colour.

The scrollable client in the "Discards" tab displaying the dead tiles is initially empty.

TODO: Sound effects are not implemented in this version, so the "Enable sound effects" checkbox in the "Options" tab is disabled and permanently unchecked.

An ActionListener is added to the "Leave Game" button. This will display a dialog box asking the user to confirm their decision to leave the game and return to the game type selection screen.

Parameters:
userGUI - A reference to the parent UserGUI object.
players - An array which stores information specific for each of the players. In this method, we are interested only in extracting the players' icons, names and scores from this array.
playerID - The array index that refers to the user's entry in the players array. Since there are a maximum of four players in a game of Mahjong, this value is in the range [0,3].
Method Detail

updateScores

public void updateScores(Player[] players)
Updates the scores for all the players present in the "Scores" tab. The score corresponding to the user is uniquely displayed in a different colour. This method updates the scores by changing the text displayed in the each of the elements in the scoreLabel array.

Parameters:
players - An array which stores information specific for each of the players. In this method, we are interested only in extracting the players' names and scores from this array.

addDeadTile

public void addDeadTile(Tile tile)
Adds a dead tile to the scrollable client within the "Discards" tab. This method uses a direct reference to the scrollable client discardsPane and adds to it a single tile image. The tile is always added to the top row of the discardsPane. The tiles already present in the pane will be shifted down. This eliminates the need for the user to scroll down.

Parameters:
tile - The dead tile to be added to the scrollable client.

clearDeadTiles

public void clearDeadTiles()
Clears the scrollable client within the "Discards" tab of all dead tiles. This method uses a direct reference to the scrollable client discardsPane and effectively resets this pane to its initial (empty) state.


showLeaveGameConfirmation

private void showLeaveGameConfirmation()
Displays a dialog box asking the user to confirm their decision to leave the game and return to the game type selection screen. This dialog box is displayed upon the user clicking the "Leave Game" button in the "Options" tab.


main

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