ggz.cards
Class CardGamePanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by ggz.games.GamePanel
                      extended by ggz.cards.CardGamePanel
All Implemented Interfaces:
CardGameHandler, ModEventHandler, java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, java.util.prefs.PreferenceChangeListener, javax.accessibility.Accessible

public class CardGamePanel
extends GamePanel
implements CardGameHandler, java.awt.event.ActionListener, java.util.prefs.PreferenceChangeListener

See Also:
Serialized Form

Nested Class Summary
protected  class CardGamePanel.PopupListener
           
protected  class CardGamePanel.PreferencesAction
           
protected  class CardGamePanel.QuitAction
           
protected  class CardGamePanel.SpriteHighlighter
          Listener class used to highlight a sprite to indicate that it has the focus.
protected  class CardGamePanel.ViewOptionsAction
           
protected  class CardGamePanel.ViewPreviousHandAction
           
protected  class CardGamePanel.ViewScoresAction
           
 
Nested classes/interfaces inherited from class ggz.games.GamePanel
GamePanel.SeatBootAction, GamePanel.SeatBotAction, GamePanel.SeatOpenAction, GamePanel.SeatSitAction, GamePanel.SeatStandAction, GamePanel.TableChatAction
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
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  BidPanel bidPanel
           
protected  Client cardClient
           
protected  int handILastPlayedFrom
           
protected  HyperlinkLabel howToPlayLabel
           
protected  boolean isSingleClickToPlayCardEnabled
           
protected  javax.swing.JButton lastTrickButton
           
protected  HyperlinkLabel optionsLabel
           
protected  javax.swing.Icon[] playerIcons
           
protected  PlayerLabel[] playerLabels
           
protected  HyperlinkLabel preferencesLabel
           
protected  HyperlinkLabel previousHandLabel
           
protected  HyperlinkLabel quitLabel
           
protected  javax.swing.JPanel scorePanel
           
protected  ScoresDialog scoresDialog
           
protected  HyperlinkLabel scoresLabel
           
protected  javax.swing.JPanel southEastPanel
           
protected  CardGamePanel.SpriteHighlighter spriteHighlighter
           
protected  Sprite[] spriteInTrick
           
protected  Sprite[][] sprites
           
protected  TablePanel table
           
protected  TableLayout tableLayout
           
protected  javax.swing.JLabel themScoreLabel
           
protected  javax.swing.JLabel usScoreLabel
           
 
Fields inherited from class ggz.games.GamePanel
chatPanel, ggzMod, playerListPanel
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
CardGamePanel()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
           
 void alert_badplay(java.lang.String err_msg)
           
 void alert_bid(int bidder, Bid bid)
           
 void alert_hand_size(int max_hand_size)
           
 void alert_newgame(CardSetType cardset_type)
           
 void alert_newhand()
           
 void alert_num_players(int numplayers, int old_numplayers)
           
 void alert_play(int player_num, Card card)
           
 void alert_player(int seat_num, SeatType old_type, java.lang.String old_name)
          Invoked when seat information changes or is first received for a given seat.
 void alert_players_status()
          Called when the status of one or more players has changed.
 void alert_scores(int hand_num)
          Called when each team's score is received from the server.
 void alert_server(java.net.Socket fd)
           
 void alert_state(Client.GameState oldState, Client.GameState newState)
           
 void alert_table()
          A table message tells you all the cards on the table.
 void alert_trick(int winner)
          A trick message tells you about the end of a trick (and who won).
 void alert_tricks_count()
          Called when the number of tricks that a player has won is received from the server.
 void alert_trump()
          Called when the trump suit is known for the current hand.
 void beep()
           
protected  void createOrAddBidPanel(int firstBidder)
          Creates a new bid panel if bidding has just started.
protected  void display_hand_impl(int player_num)
          This method is run on a separate thread in display_hand() above.
 void display_hand(int player_num)
           
protected  java.lang.String formatTeamScore(int teamIndex)
           
 void get_bid(Bid[] bid_choices, java.lang.String[] bid_texts, java.lang.String[] bid_descs)
           
 void get_newgame()
          Server has requested the client to OK a new game.
 boolean get_options(java.lang.String[] types, java.lang.String[] descs, int[] defaults, java.lang.String[][] option_choices)
          An options request asks you to pick a set of options.
 void get_play(int play_hand, Card[] valid_cards)
           
 Client getCardClient()
           
protected  int getCardOrientation(int player_num)
           
protected  javax.swing.Icon getPlayerIcon(SeatType type)
           
 void handle_disconnect()
          Called when the socket disconnects.
 void handle_game_message(GGZCardInputStream in, java.lang.String gametype)
          Called when game-specific data is received by the client.
 void handle_gameover(Player[] winners)
           
 void handleServer(java.net.Socket fd)
          A new server connection has been made.
 void handleState(ModState oldState)
          Module status changed.
 void init(ModGame mod)
           
protected  void initPopupMenu(int seat_num, int ggz_seat_num, SeatType type)
           
protected  void initScorePanel()
           
 void preferenceChange(java.util.prefs.PreferenceChangeEvent event)
           
protected  void putNextPlayersCardsOnTop(int player_num)
           
protected  void repaint_player_labels()
           
 void set_cardlist_message(java.lang.String mark, Card[][] cardlist)
          Called by server just before trick winner is announced to reinform the client of all the cards in the last trick.
 void set_player_message(int player_num, java.lang.String message)
           
 void set_text_message(java.lang.String mark, java.lang.String message)
           
 void setRulesURL(java.lang.String url)
          Adds a label in the top left corner that contains a hyperlink to the rules of the game.
protected  void showLastTrick()
           
protected  void showOptions()
           
protected  void showPreviousHand()
           
protected  void showScores()
           
protected  void spriteClicked(Sprite sprite)
          Called when a sprite is clicked.
 
Methods inherited from class ggz.games.GamePanel
getChatPanel, getPreferredWindowSize, handleChat, handleError, handleException, handleInfo, handlePlayer, handleSeat, handleSpectatorSeat, handleStats, invokeAndWait, quit
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cardClient

protected Client cardClient

playerIcons

protected javax.swing.Icon[] playerIcons

playerLabels

protected PlayerLabel[] playerLabels

sprites

protected Sprite[][] sprites

spriteInTrick

protected Sprite[] spriteInTrick

tableLayout

protected TableLayout tableLayout

table

protected TablePanel table

handILastPlayedFrom

protected int handILastPlayedFrom

spriteHighlighter

protected CardGamePanel.SpriteHighlighter spriteHighlighter

bidPanel

protected BidPanel bidPanel

southEastPanel

protected javax.swing.JPanel southEastPanel

scoresDialog

protected ScoresDialog scoresDialog

lastTrickButton

protected javax.swing.JButton lastTrickButton

isSingleClickToPlayCardEnabled

protected boolean isSingleClickToPlayCardEnabled

scorePanel

protected javax.swing.JPanel scorePanel

usScoreLabel

protected javax.swing.JLabel usScoreLabel

themScoreLabel

protected javax.swing.JLabel themScoreLabel

quitLabel

protected HyperlinkLabel quitLabel

scoresLabel

protected HyperlinkLabel scoresLabel

optionsLabel

protected HyperlinkLabel optionsLabel

previousHandLabel

protected HyperlinkLabel previousHandLabel

preferencesLabel

protected HyperlinkLabel preferencesLabel

howToPlayLabel

protected HyperlinkLabel howToPlayLabel
Constructor Detail

CardGamePanel

public CardGamePanel()
Method Detail

init

public void init(ModGame mod)
          throws java.io.IOException
Specified by:
init in interface ModEventHandler
Overrides:
init in class GamePanel
Throws:
java.io.IOException

createOrAddBidPanel

protected void createOrAddBidPanel(int firstBidder)
Creates a new bid panel if bidding has just started.

Parameters:
firstBidder -

alert_state

public void alert_state(Client.GameState oldState,
                        Client.GameState newState)
Specified by:
alert_state in interface CardGameHandler

alert_badplay

public void alert_badplay(java.lang.String err_msg)
Specified by:
alert_badplay in interface CardGameHandler

alert_bid

public void alert_bid(int bidder,
                      Bid bid)
Specified by:
alert_bid in interface CardGameHandler

alert_hand_size

public void alert_hand_size(int max_hand_size)
Specified by:
alert_hand_size in interface CardGameHandler

alert_newgame

public void alert_newgame(CardSetType cardset_type)
Specified by:
alert_newgame in interface CardGameHandler

alert_newhand

public void alert_newhand()
Specified by:
alert_newhand in interface CardGameHandler

alert_trump

public void alert_trump()
Description copied from interface: CardGameHandler
Called when the trump suit is known for the current hand.

Specified by:
alert_trump in interface CardGameHandler

alert_num_players

public void alert_num_players(int numplayers,
                              int old_numplayers)
Specified by:
alert_num_players in interface CardGameHandler

alert_player

public void alert_player(int seat_num,
                         SeatType old_type,
                         java.lang.String old_name)
Invoked when seat information changes or is first received for a given seat.

Specified by:
alert_player in interface CardGameHandler

getPlayerIcon

protected javax.swing.Icon getPlayerIcon(SeatType type)

initPopupMenu

protected void initPopupMenu(int seat_num,
                             int ggz_seat_num,
                             SeatType type)

initScorePanel

protected void initScorePanel()

getCardOrientation

protected int getCardOrientation(int player_num)

alert_play

public void alert_play(int player_num,
                       Card card)
Specified by:
alert_play in interface CardGameHandler

alert_players_status

public void alert_players_status()
Description copied from interface: CardGameHandler
Called when the status of one or more players has changed. The Players bidding and playing property will be true for each player that is either playing or bidding respectively.

Specified by:
alert_players_status in interface CardGameHandler

repaint_player_labels

protected void repaint_player_labels()

putNextPlayersCardsOnTop

protected void putNextPlayersCardsOnTop(int player_num)

showLastTrick

protected void showLastTrick()
                      throws java.io.IOException
Throws:
java.io.IOException

showPreviousHand

protected void showPreviousHand()
                         throws java.io.IOException
Throws:
java.io.IOException

showScores

protected void showScores()

showOptions

protected void showOptions()

getCardClient

public Client getCardClient()

alert_server

public void alert_server(java.net.Socket fd)
Specified by:
alert_server in interface CardGameHandler

alert_table

public void alert_table()
Description copied from interface: CardGameHandler
A table message tells you all the cards on the table. Each player only gets one card.

Specified by:
alert_table in interface CardGameHandler

alert_trick

public void alert_trick(int winner)
Description copied from interface: CardGameHandler
A trick message tells you about the end of a trick (and who won).

Specified by:
alert_trick in interface CardGameHandler

alert_scores

public void alert_scores(int hand_num)
Description copied from interface: CardGameHandler
Called when each team's score is received from the server.

Specified by:
alert_scores in interface CardGameHandler

formatTeamScore

protected java.lang.String formatTeamScore(int teamIndex)

alert_tricks_count

public void alert_tricks_count()
Description copied from interface: CardGameHandler
Called when the number of tricks that a player has won is received from the server.

Specified by:
alert_tricks_count in interface CardGameHandler

display_hand

public void display_hand(int player_num)
Specified by:
display_hand in interface CardGameHandler

display_hand_impl

protected void display_hand_impl(int player_num)
This method is run on a separate thread in display_hand() above.

Parameters:
player_num -

get_bid

public void get_bid(Bid[] bid_choices,
                    java.lang.String[] bid_texts,
                    java.lang.String[] bid_descs)
Specified by:
get_bid in interface CardGameHandler

get_newgame

public void get_newgame()
Description copied from interface: CardGameHandler
Server has requested the client to OK a new game. This is sent at the start of a new game before the game begins.

Specified by:
get_newgame in interface CardGameHandler

get_options

public boolean get_options(java.lang.String[] types,
                           java.lang.String[] descs,
                           int[] defaults,
                           java.lang.String[][] option_choices)
                    throws java.io.IOException
Description copied from interface: CardGameHandler
An options request asks you to pick a set of options. Each "option" gives a list of choices so that you pick one choice for each option. An option with only one choice is a special case: a boolean option.

Specified by:
get_options in interface CardGameHandler
Throws:
java.io.IOException

get_play

public void get_play(int play_hand,
                     Card[] valid_cards)
Specified by:
get_play in interface CardGameHandler

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

preferenceChange

public void preferenceChange(java.util.prefs.PreferenceChangeEvent event)
Specified by:
preferenceChange in interface java.util.prefs.PreferenceChangeListener

spriteClicked

protected void spriteClicked(Sprite sprite)
Called when a sprite is clicked.

Parameters:
sprite -

handle_game_message

public void handle_game_message(GGZCardInputStream in,
                                java.lang.String gametype)
                         throws java.io.IOException
Description copied from interface: CardGameHandler
Called when game-specific data is received by the client. The client will skip over any remaining bytes that were not read by the handler.

Specified by:
handle_game_message in interface CardGameHandler
Throws:
java.io.IOException

handle_gameover

public void handle_gameover(Player[] winners)
Specified by:
handle_gameover in interface CardGameHandler

handle_disconnect

public void handle_disconnect()
Description copied from interface: CardGameHandler
Called when the socket disconnects.

Specified by:
handle_disconnect in interface CardGameHandler

set_cardlist_message

public void set_cardlist_message(java.lang.String mark,
                                 Card[][] cardlist)
Called by server just before trick winner is announced to reinform the client of all the cards in the last trick. It's also sent after a hand is played to inform the client of the cards that all players held at the bigging of the hand.

Specified by:
set_cardlist_message in interface CardGameHandler
Parameters:
mark - Last Trick or Previous Hand
cardlist - the list contains as many arrays as there are players in the game.

set_player_message

public void set_player_message(int player_num,
                               java.lang.String message)
Specified by:
set_player_message in interface CardGameHandler

set_text_message

public void set_text_message(java.lang.String mark,
                             java.lang.String message)
Specified by:
set_text_message in interface CardGameHandler

setRulesURL

public void setRulesURL(java.lang.String url)
                 throws java.net.MalformedURLException
Adds a label in the top left corner that contains a hyperlink to the rules of the game. It strips any leading text and removes any trailing dot since that's the format the message currently comes from the server.

Parameters:
url -
Throws:
java.net.MalformedURLException

handleState

public void handleState(ModState oldState)
Description copied from interface: ModEventHandler
Module status changed. This event occurs when the game's status changes. The old state (a ModState) is passed as the event's data.

Specified by:
handleState in interface ModEventHandler
Overrides:
handleState in class GamePanel
See Also:
ModState

handleServer

public void handleServer(java.net.Socket fd)
                  throws java.io.IOException
Description copied from interface: ModEventHandler
A new server connection has been made. This event occurs when a new connection to the game server has been made, either by the core client or by the game client itself. The socket is passed as the event's data.

Specified by:
handleServer in interface ModEventHandler
Overrides:
handleServer in class GamePanel
Throws:
java.io.IOException
See Also:
ModGame.connect()

beep

public void beep()