org.vizzini.ui.game.boardgame
Class GridBoardUISwing

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 org.vizzini.ui.game.AbstractEnvironmentUISwing
                      extended by org.vizzini.ui.game.boardgame.AbstractGridBoardUISwing
                          extended by org.vizzini.ui.game.boardgame.GridBoardUISwing
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, IScoreListener, IStateListener, IGridBoardUI, IGridBoardUISwing, IEnvironmentUI, IListener
Direct Known Subclasses:
GridBoardUISwing

public abstract class GridBoardUISwing
extends AbstractGridBoardUISwing
implements IGridBoardUISwing

Provides functionality for Swing 2D grid board environment user interfaces in the game framework. The grid is formed by applying the grid color to this component's background, which is overlaid by the token UIs. The token UIs are set to opaque, and their backgrounds set to the desired grid board background color.

Since:
v0.1
Version:
v0.3
Author:
Jeffrey M. Thompson
See Also:
Serialized Form

Nested Class Summary
(package private) static class GridBoardUISwing.MyGridLayout
          Provides a grid layout which uses the Component.getWidth() and Component.getHeight() method instead of directly accessing member variables.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static double LINE_WIDTH_FRACTION
          Constant for determining the grid line width.
 
Fields inherited from class org.vizzini.ui.game.boardgame.AbstractGridBoardUISwing
LABEL_PAINTED_PROPERTY
 
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
GridBoardUISwing()
          Construct this object.
 
Method Summary
 void add(HighlightData highlightData)
          Add the given highlight data.
protected  void applyHighlightData(HighlightData highlightData)
          Apply the given highlight data.
 void clearHighlights()
          Clear the highlighted positions.
protected  void computeDimensions()
          Compute the dimensions.
protected  void createAndPlaceTokenUI(IToken token, int file, int rank)
          Create and place a new token user interface component.
protected  JComponent createBlank()
          Create a blank component.
protected abstract  ITokenUI createTokenUI(IToken token)
          Create a token user interface component for the given token.
protected  void createTokenUIs()
          Create the initial token user interface components.
protected  JComponent getComponent(int file, int rank)
          Return the index of the component for the given coordinates.
 int getFileCount()
          Return the file count.
 int getHeight()
          Returns the current height of this component.
 IPosition getPositionForPoint(Point point)
          Map the screen coordinates to a board position.
 Dimension getSize()
          Returns the size of this component in the form of a Dimension object.
 int getWidth()
          Returns the current width of this component.
 void paintComponent(Graphics g)
          Paint this component.
protected  void placeTokenUI(JComponent tokenUI, int file, int rank)
          Create and place a new token user interface component.
protected  void reApplyHighlights()
          Re-apply the highlighted positions.
protected  void reconcileBoard(IGridBoard board)
          Reconcile the token UIs with the real board environment.
 void remove(HighlightData highlightData)
          Remove the given highlight data.
protected  void setCurrentHighlightData(HighlightData highlightData)
           
 void setDimensions(int fileCount, int rankCount)
          Construct this object with the given dimensions.
 void setEnvironment(IEnvironment environment)
          Set the environment this UI represents.
 void setGridLineColor(Color color)
          Set the grid line color.
 
Methods inherited from class org.vizzini.ui.game.boardgame.AbstractGridBoardUISwing
clearCurrentHighlight, clearLastMoveHighlight, clearSelectionHighlight, configure, fillAdditionalViewMenuItems, getBoardColor, getCurrentColor, getCurrentHighlightWidth, getFirstColor, getGridLineColor, getLabelColor, getLastMoveColor, getLastMoveHighlightWidth, getPlacementAudioClip, getSecondColor, getSelectionColor, getSelectionHighlightData, getSelectionHighlightWidth, highlightCurrentPosition, highlightLastMovePosition, highlightSelectedPosition, isLabelPainted, isPositionUsable, setBoardColor, setCurrentColor, setCurrentHighlightWidth, setFirstColor, setLabelColor, setLabelPainted, setLastMoveColor, setLastMoveHighlightWidth, setSecondColor, setSelectionColor, setSelectionHighlightData, setSelectionHighlightWidth, stateChange
 
Methods inherited from class org.vizzini.ui.game.AbstractEnvironmentUISwing
assignAgentListener, assignAgentListeners, getEnvironment, getSupport, init, isAudioOn, removeAgentListener, removeAgentListeners, reset, scoreChange, setAudioOn
 
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, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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, 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
 
Methods inherited from interface org.vizzini.ui.game.boardgame.IGridBoardUISwing
clearCurrentHighlight, clearLastMoveHighlight, clearSelectionHighlight, getBoardColor, getCurrentColor, getCurrentHighlightWidth, getFirstColor, getGridLineColor, getLabelColor, getLastMoveColor, getLastMoveHighlightWidth, getSecondColor, getSelectionColor, getSelectionHighlightWidth, highlightCurrentPosition, highlightLastMovePosition, highlightSelectedPosition, isLabelPainted, setBoardColor, setCurrentColor, setCurrentHighlightWidth, setFirstColor, setLabelColor, setLabelPainted, setLastMoveColor, setLastMoveHighlightWidth, setSecondColor, setSelectionColor, setSelectionHighlightWidth
 
Methods inherited from interface org.vizzini.ui.game.IEnvironmentUI
assignAgentListeners, configure, getEnvironment, isAudioOn, removeAgentListeners, reset, setAudioOn
 
Methods inherited from interface org.vizzini.game.event.IStateListener
stateChange
 
Methods inherited from interface org.vizzini.game.event.IScoreListener
scoreChange
 

Field Detail

LINE_WIDTH_FRACTION

public static final double LINE_WIDTH_FRACTION
Constant for determining the grid line width.

See Also:
Constant Field Values
Constructor Detail

GridBoardUISwing

public GridBoardUISwing()
Construct this object.

Since:
v0.1
Method Detail

add

public void add(HighlightData highlightData)
Add the given highlight data.

Specified by:
add in interface IGridBoardUISwing
Since:
v0.1

clearHighlights

public void clearHighlights()
Clear the highlighted positions.

Specified by:
clearHighlights in interface IGridBoardUISwing
Since:
v0.1

getFileCount

public int getFileCount()
Return the file count.

Since:
v0.1

getHeight

public int getHeight()
Returns the current height of this component.

Overrides:
getHeight in class JComponent
Since:
v0.1

getPositionForPoint

public IPosition getPositionForPoint(Point point)
Map the screen coordinates to a board position.

Specified by:
getPositionForPoint in interface IGridBoardUISwing
Parameters:
point - A mouse click point.
Since:
v0.1

getSize

public Dimension getSize()
Returns the size of this component in the form of a Dimension object.

Overrides:
getSize in class Component
Since:
v0.1

getWidth

public int getWidth()
Returns the current width of this component.

Overrides:
getWidth in class JComponent
Since:
v0.1

paintComponent

public void paintComponent(Graphics g)
Paint this component.

Overrides:
paintComponent in class JComponent
Parameters:
g - The graphics object.
Since:
v0.1

remove

public void remove(HighlightData highlightData)
Remove the given highlight data.

Specified by:
remove in interface IGridBoardUISwing
Since:
v0.3

setDimensions

public void setDimensions(int fileCount,
                          int rankCount)
Construct this object with the given dimensions.

Parameters:
fileCount - The file count.
rankCount - The rank count.
Since:
v0.1

setEnvironment

public void setEnvironment(IEnvironment environment)
Set the environment this UI represents.

Specified by:
setEnvironment in interface IEnvironmentUI
Overrides:
setEnvironment in class AbstractEnvironmentUISwing
Parameters:
environment - Environment.
Since:
v0.1

setGridLineColor

public void setGridLineColor(Color color)
Set the grid line color. Extends the super method to set the background of this component.

Specified by:
setGridLineColor in interface IGridBoardUISwing
Overrides:
setGridLineColor in class AbstractGridBoardUISwing
Since:
v0.2

createTokenUI

protected abstract ITokenUI createTokenUI(IToken token)
Create a token user interface component for the given token.

Parameters:
token - The token.
Since:
v0.1

applyHighlightData

protected void applyHighlightData(HighlightData highlightData)
Apply the given highlight data.

Parameters:
highlightData - Highlight data.
Since:
v0.3

computeDimensions

protected void computeDimensions()
Compute the dimensions.

Since:
v0.1

createAndPlaceTokenUI

protected void createAndPlaceTokenUI(IToken token,
                                     int file,
                                     int rank)
Create and place a new token user interface component.

Parameters:
token - The token.
file - The file position.
rank - The rank position.
Since:
v0.1

createBlank

protected JComponent createBlank()
Create a blank component.

Since:
v0.2

createTokenUIs

protected void createTokenUIs()
Create the initial token user interface components.

Since:
v0.1

getComponent

protected JComponent getComponent(int file,
                                  int rank)
Return the index of the component for the given coordinates.

Since:
v0.1

placeTokenUI

protected void placeTokenUI(JComponent tokenUI,
                            int file,
                            int rank)
Create and place a new token user interface component.

Parameters:
tokenUI - The token user interface.
file - The file position.
rank - The rank position.
Since:
v0.1

reApplyHighlights

protected void reApplyHighlights()
Re-apply the highlighted positions.

Since:
v0.3

reconcileBoard

protected void reconcileBoard(IGridBoard board)
Reconcile the token UIs with the real board environment.

Specified by:
reconcileBoard in class AbstractGridBoardUISwing
Parameters:
board - The current board environment.
Since:
v0.1

setCurrentHighlightData

protected void setCurrentHighlightData(HighlightData highlightData)
Overrides:
setCurrentHighlightData in class AbstractGridBoardUISwing
Parameters:
highlightData - The highlightData to set.
Since:
v0.3


Copyright 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02