de.htwdd.rosenkoenig.gui.genuts
Class GenutsGUI

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 de.htwdd.rosenkoenig.gui.genuts.GenutsGUI
All Implemented Interfaces:
GUI, java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class GenutsGUI
extends javax.swing.JPanel
implements GUI, java.awt.event.MouseListener

This implementation of GUI provides Rosenkoenig with a graphical user interface based on the Genuts library.
The GenutsGUI also implements MouseListener and extends JPanel, so it can be used as part of a Swing dialog.

See Also:
GUI, Serialized Form

Nested Class Summary
 
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
private  Sprite board
           
private  OkButton btnOk
           
private  java.util.EnumMap<Color,Position[]> cardPositions
           
private  SpriteCollisionManager collisionManager
           
private  java.util.EnumMap<Color,Counter> counters
           
private  ImageSequenceSprite crown
           
private  java.util.EnumMap<Color,GUICard[]> decks
           
private static int DISTANCE
           
private  DrawDeck drawDeck
           
private  Game game
           
private  ImageList imageList
           
private static boolean imagesLoaded
           
private  java.util.EnumMap<Color,Knights> knights
           
private  java.util.EnumMap<Color,Name> names
           
private  ImageSequenceSprite playedCards
           
private  ImageSequenceSprite playedSword
           
private  PlayField playfield
           
private static long serialVersionUID
           
 
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
GenutsGUI()
          Creates a new GenutsGUI, initializes the Genuts library and forces ImageList to load all needed images (if necessary).
 
Method Summary
 void activatePlayer(Color color, boolean activate)
          Activate or deactivate the player's name string.
 void disablePlayer(Color color)
          Disables all controls of a single player.
 void enableDrawDeck(ImageState state)
          Enables / disables the draw deck.
 void enableEndTurn(ImageState state)
          Enables / disables the GUI element that ends a player's turn
 void hideScoreChange(Color color)
          This method tells the GUI to hide a player's score increase.
 void initGUI(Game game, java.lang.String nameRed, java.lang.String nameWhite)
          Initializes the graphical user interface: creates the board creates and positions the decks, the knights and the end-turn-button creates and initializes the player's scores sets the crown to its initial position initializes the player names Use this method to perform initialization.
 void mouseClicked(java.awt.event.MouseEvent event)
          Whenever the user clicks the GenutsGUI, this method checks if the mouse click hit an object of type Clickable and eventually toggles its click method.
 void mouseEntered(java.awt.event.MouseEvent e)
          unused, just to satisfy MouseListener
 void mouseExited(java.awt.event.MouseEvent e)
          unused, just to satisfy MouseListener
 void mousePressed(java.awt.event.MouseEvent e)
          unused, just to satisfy MouseListener
 void mouseReleased(java.awt.event.MouseEvent e)
          unused, just to satisfy MouseListener
 void redrawGUI()
          forces the GUI to show all changes taken since the last call of redrawGUI.
 void setBoard(Color[][] board)
          setBoard is called to replace the complete board.
 void setCards(Color color, java.util.List<Card> cards)
          This method is called whenever a player's card deck has changed and sets a player's card deck.
 void setCardState(Color color, ImageState state, int card, boolean knightable)
          setCardState is called whenever a card's state has changed.
 void setCrown(Position position)
          This method is called to specify the position of the crown on the board.
 void setDrawDeck(int number)
          Sets the number of cards left in the draw deck.
 void setKnights(Color color, int number)
          Sets the number of knights a player has left.
 void setKnightState(Color color, ImageState state)
          This method is called whenever a player's knights are enabled or disabled.
 void setPlayedDeck(int number, Card playedCard)
          Sets the number of cards left in the played cards deck.
 void setScore(Color color, int score)
          Updates a player's score.
 void setScoreChange(Color color, int score)
          After the player selects the card he wants to play, the GUI shows the possible score increase.
private  void setStone(Color color, boolean transparent, int x, int y)
          This method puts a stone to the specified logical position on the board.
 void setStone(Color color, Position position, boolean perhaps)
          Sets a stone on the board.
 
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, transferFocusBackward, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

DISTANCE

private static final int DISTANCE
See Also:
Constant Field Values

collisionManager

private SpriteCollisionManager collisionManager

playfield

private PlayField playfield

playedCards

private ImageSequenceSprite playedCards

playedSword

private ImageSequenceSprite playedSword

crown

private ImageSequenceSprite crown

drawDeck

private DrawDeck drawDeck

btnOk

private OkButton btnOk

counters

private java.util.EnumMap<Color,Counter> counters

decks

private java.util.EnumMap<Color,GUICard[]> decks

cardPositions

private java.util.EnumMap<Color,Position[]> cardPositions

knights

private java.util.EnumMap<Color,Knights> knights

names

private java.util.EnumMap<Color,Name> names

game

private Game game

imageList

private ImageList imageList

imagesLoaded

private static boolean imagesLoaded

board

private Sprite board
Constructor Detail

GenutsGUI

public GenutsGUI()
Creates a new GenutsGUI, initializes the Genuts library and forces ImageList to load all needed images (if necessary).

Method Detail

initGUI

public void initGUI(Game game,
                    java.lang.String nameRed,
                    java.lang.String nameWhite)
Initializes the graphical user interface: Use this method to perform initialization.

Specified by:
initGUI in interface GUI
Parameters:
game - the game this GUI belongs to
nameRed - the red player's name
nameWhite - the white player's name
See Also:
Game

redrawGUI

public void redrawGUI()
forces the GUI to show all changes taken since the last call of redrawGUI.

Specified by:
redrawGUI in interface GUI

setCards

public void setCards(Color color,
                     java.util.List<Card> cards)
This method is called whenever a player's card deck has changed and sets a player's card deck.

Specified by:
setCards in interface GUI
Parameters:
color - player
cards - card deck (up to five cards)

setCardState

public void setCardState(Color color,
                         ImageState state,
                         int card,
                         boolean knightable)
setCardState is called whenever a card's state has changed.

Specified by:
setCardState in interface GUI
Parameters:
color - player
state - enabled, disabled, selected
card - index of the card that will be changed
knightable - if set to true, the selected card is marked knightable

setBoard

public void setBoard(Color[][] board)
setBoard is called to replace the complete board.

Specified by:
setBoard in interface GUI
Parameters:
board - array (dimensions habe to be 9x9) of stones. A color represents a stone, null represents an empty field

setStone

public void setStone(Color color,
                     Position position,
                     boolean perhaps)
Sets a stone on the board. This method is also called if a stone has changed its color.

Specified by:
setStone in interface GUI
Parameters:
color - color of the stone or null to remove the stone
position - the stone's position
perhaps - if set to true, the stone is drawn "misty"

setStone

private void setStone(Color color,
                      boolean transparent,
                      int x,
                      int y)
This method puts a stone to the specified logical position on the board. If another stone is already present on the specified position, the old stone is removed.

Parameters:
color - the stone's color
transparent - if set to true, the stone is drawn half transparent
x - logical x-position on the board
y - logical y-position on the board

setKnights

public void setKnights(Color color,
                       int number)
Sets the number of knights a player has left.

Specified by:
setKnights in interface GUI
Parameters:
color - player
number - number of knights left

setKnightState

public void setKnightState(Color color,
                           ImageState state)
This method is called whenever a player's knights are enabled or disabled.

Specified by:
setKnightState in interface GUI
Parameters:
color - player
state - enabled, disabled

setScore

public void setScore(Color color,
                     int score)
Updates a player's score.

Specified by:
setScore in interface GUI
Parameters:
color - player
score - new score

disablePlayer

public void disablePlayer(Color color)
Disables all controls of a single player.

Specified by:
disablePlayer in interface GUI
Parameters:
color - player

activatePlayer

public void activatePlayer(Color color,
                           boolean activate)
Activate or deactivate the player's name string. This method is called at the beginning and at the end of each turn.

Specified by:
activatePlayer in interface GUI
Parameters:
color - the player's color
activate - whether to activate the player or not

setScoreChange

public void setScoreChange(Color color,
                           int score)
After the player selects the card he wants to play, the GUI shows the possible score increase.

Specified by:
setScoreChange in interface GUI
Parameters:
color - player
score - score increase

hideScoreChange

public void hideScoreChange(Color color)
This method tells the GUI to hide a player's score increase.

Specified by:
hideScoreChange in interface GUI
Parameters:
color - the player whose score increase is to be hidden

setDrawDeck

public void setDrawDeck(int number)
Sets the number of cards left in the draw deck.

Specified by:
setDrawDeck in interface GUI
Parameters:
number - number of cards left

setPlayedDeck

public void setPlayedDeck(int number,
                          Card playedCard)
Sets the number of cards left in the played cards deck.

Specified by:
setPlayedDeck in interface GUI
Parameters:
number - number of cards left
playedCard - the card that was played last

enableDrawDeck

public void enableDrawDeck(ImageState state)
Enables / disables the draw deck.

Specified by:
enableDrawDeck in interface GUI
Parameters:
state - enabled or disabled

enableEndTurn

public void enableEndTurn(ImageState state)
Enables / disables the GUI element that ends a player's turn

Specified by:
enableEndTurn in interface GUI
Parameters:
state - enabled or disabled

setCrown

public void setCrown(Position position)
This method is called to specify the position of the crown on the board.

Specified by:
setCrown in interface GUI
Parameters:
position - the crown's position

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent event)
Whenever the user clicks the GenutsGUI, this method checks if the mouse click hit an object of type Clickable and eventually toggles its click method.

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

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
unused, just to satisfy MouseListener

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

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
unused, just to satisfy MouseListener

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

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
unused, just to satisfy MouseListener

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

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
unused, just to satisfy MouseListener

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