org.moyoman.client.reference
Class Board

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--org.moyoman.client.reference.Board
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable

public class Board
extends JPanel

Provides a Go board user interface.

Since:
v0.01
Version:
v0.17
Author:
Jeffrey M. Thompson
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  ActionManager _actionManager
          Handle to the action manager.
private  double _annotationFontFraction
          The annotation font size as a fraction of _squareSize.
private  Annotation[][] _annotations
          The intersection annotations.
private  Color _boardColor
          The board color.
private  int _borderSize
          Border size.
private  AudioClip _click
          Click audio clip.
private  int _dimension
          The grid dimension.
private  boolean _doCompute
          Flag indicating if parameters need to be computed.
private  double _dotFraction
          Dot radius as a fraction of _squareSize.
private  int _fileHeight
          Height of the file label area.
private  Color _gridColor
          The grid color.
private  Color _highlightColor
          The highlight color.
private  double _highlightFraction
          Highlight radius as a fraction of _squareSize.
private  Point _highlightIntersection
          The last highlighted intersection.
private  boolean _isLabelPainted
          Flag indicating the coordinate labels are painted.
private  boolean _isLastMoveMarked
          Flag indicating the last move is marked.
private  boolean _isSoundOn
          Flag indicating whether to use sound.
private  double _labelFraction
          Label border fraction.
private  Color _markColor
          The mark color.
private  Stone _markedToken
          Token to be marked.
private  double _markFraction
          Mark radius as a fraction of _squareSize.
private  Point _max
          The maximum point of the grid in screen coordinates.
private  Point _min
          The minimum point of the grid in screen coordinates.
private  int _offset
          Border size.
private  double _offsetFraction
          Grid offset as a fraction of _squareSize.
private  JPopupMenu _popupMenu
          The popup menu.
private  Dimension _previousSize
          The previous panel size.
private  int _rankWidth
          Width of the rank label area.
private  Rectangle _rectangle
          Board rectangle.
private  Map _sizeToFont
          Font cache, stored by size.
private  int _squareSize
          Square size.
private  Color _textColor
          The text color.
private  double _tokenFraction
          Token radius as a fraction of _squareSize.
private  List _tokens
          The tokens on the board
private static String[] FILE_STRINGS
          String representations of file index.
static String LABEL_PAINTED_PROPERTY
          Name of the label painted property.
static String LAST_MOVE_MARKED_PROPERTY
          Name of the label painted property.
 
Fields inherited from class javax.swing.JPanel
 
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.Container
 
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
Board()
          Construct this object.
 
Method Summary
 void add(Stone stone)
          Add the given token to the board.
 void add(Stone[] stones)
          Add the given tokens to the board.
protected  void add(Stone stone, boolean repaint, boolean doSound)
          Add the given token to the board.
 void clear()
          Clear the tokens and annotations from the board.
 void clearAnnotations()
          Clear all annotations.
protected  void computeParameters()
          Compute the board parameters.
protected  Point computeScreenPoint(int x, int y)
          Compute and return the screen coordinates for the given intersection.
protected  void computeScreenPoint(int x, int y, Point point)
          Compute and return the screen coordinates for the given intersection.
protected  int computeSize(double fraction)
          Compute a size based upon the given fraction and the square size.
 JCheckBoxMenuItem createLabelPaintedUI()
          Create a label painted user interface widget.
 JCheckBoxMenuItem createLastMoveMarkedUI()
          Create a last move marked user interface widget.
protected  JPopupMenu createPopupMenu()
          Create and configure the popup menu.
protected  void drawCircle(Graphics2D g, int centerX, int centerY, int radius, boolean filled)
          Draw a circle at the given coordinates.
protected  void drawString(Graphics2D g, String string, int centerX, int centerY, Font font)
          Draw the given string using the given font.
 void drawStringAt(String string, Point intersection)
          Draw the given string at the given intersection.
 void drawStringAt(String string, Point intersection, Font font)
          Draw the given string at the given intersection using the given font.
 Annotation get(int x, int y)
          Return the annotation at the given intersection.
 int getDimension()
          Return the dimension of this board.
static String getFileString(int file)
          Return the alphabetic file designation for the given index.
 Point getIntersectionFor(Point point)
          Return the nearest intersection to the given screen point.
static String getPositionString(int x, int y)
          Return the formatted string representation of the given position.
protected  Font getRelativeFont(double fraction, Font font)
          Return the font sized relative to the given fraction.
 List getState()
          Return the current board state.
 void highlightIntersection(Point point)
          Highlight the given intersection.
 boolean isSoundOn()
          Return true if sound is on.
 void labelPaintedActionPerformed(ActionEvent event)
          Callback for the label painted action.
 void lastMoveMarkedActionPerformed(ActionEvent event)
          Callback for the last move marked action.
 void markToken(Stone stone)
          Mark the token at the given position.
protected  void paintAnnotations(Graphics2D g)
          Paint the annotations.
protected  void paintBoard(Graphics2D g)
          Paint the grid lines.
protected  void paintComponent(Graphics g)
          Paint this component.
protected  void paintCoordinateLabels(Graphics2D g)
          Paint the coordinate labels.
protected  void paintHighlight(Graphics2D g)
          Paint the intersection highlight, if any.
protected  void paintTokens(Graphics2D g)
          Paint the tokens.
protected  void rangeCheck(String label, int x)
          Perform a range check.
 void remove(Stone stone)
          Remove the given token from the board.
 void remove(Stone[] stones)
          Remove the given tokens from the board.
 void remove(Stone stone, boolean repaint)
          Remove the given token from the board.
 void setAnnotation(int x, int y, String text, Color foreground, Color background, boolean isEllipseVisible, boolean append)
          Set the given parameters on the annotation at the given intersection.
 void setAnnotation(int x, int y, String text, Color foreground, Color background, boolean isEllipseVisible, boolean append, Object clientKey, Object clientValue)
          Set the given parameters on the annotation at the given intersection.
 void setBoardBorderWidth(int width)
          Set the board board width.
 void setBoardColor(Color color)
          Set the board color.
 void setDimension(int dimension)
          Set the dimension of this board.
 void setFont(Font font)
          Set the font.
 void setGridColor(Color color)
          Set the grid color.
 void setHighlightColor(Color color)
          Set the highlight color.
 void setLabelPainted(boolean isLabelPainted)
          Set the flag indicating this should draw coordinate labels.
 void setLastMoveMarked(boolean isLastMoveMarked)
          Set the flag indicating this should mark the last move.
 void setMarkColor(Color color)
          Set the mark color.
 void setSoundOn(boolean isSoundOn)
          Set the sound flag.
 void setState(List state)
          Set the board state.
 void setTextColor(Color color)
          Set the text color.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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

LABEL_PAINTED_PROPERTY

public static final String LABEL_PAINTED_PROPERTY
Name of the label painted property.

See Also:
Constant Field Values

LAST_MOVE_MARKED_PROPERTY

public static final String LAST_MOVE_MARKED_PROPERTY
Name of the label painted property.

See Also:
Constant Field Values

FILE_STRINGS

private static final String[] FILE_STRINGS
String representations of file index.


_actionManager

private ActionManager _actionManager
Handle to the action manager.


_click

private AudioClip _click
Click audio clip.


_boardColor

private Color _boardColor
The board color.


_gridColor

private Color _gridColor
The grid color.


_highlightColor

private Color _highlightColor
The highlight color.


_markColor

private Color _markColor
The mark color.


_textColor

private Color _textColor
The text color.


_previousSize

private Dimension _previousSize
The previous panel size.


_popupMenu

private JPopupMenu _popupMenu
The popup menu.


_tokens

private List _tokens
The tokens on the board


_sizeToFont

private Map _sizeToFont
Font cache, stored by size.


_highlightIntersection

private Point _highlightIntersection
The last highlighted intersection.


_max

private Point _max
The maximum point of the grid in screen coordinates.


_min

private Point _min
The minimum point of the grid in screen coordinates.


_rectangle

private Rectangle _rectangle
Board rectangle.


_markedToken

private Stone _markedToken
Token to be marked.


_annotations

private Annotation[][] _annotations
The intersection annotations.


_doCompute

private boolean _doCompute
Flag indicating if parameters need to be computed.


_isLabelPainted

private boolean _isLabelPainted
Flag indicating the coordinate labels are painted.


_isLastMoveMarked

private boolean _isLastMoveMarked
Flag indicating the last move is marked.


_isSoundOn

private boolean _isSoundOn
Flag indicating whether to use sound.


_annotationFontFraction

private double _annotationFontFraction
The annotation font size as a fraction of _squareSize.


_dotFraction

private double _dotFraction
Dot radius as a fraction of _squareSize.


_highlightFraction

private double _highlightFraction
Highlight radius as a fraction of _squareSize.


_labelFraction

private double _labelFraction
Label border fraction.


_markFraction

private double _markFraction
Mark radius as a fraction of _squareSize.


_offsetFraction

private double _offsetFraction
Grid offset as a fraction of _squareSize.


_tokenFraction

private double _tokenFraction
Token radius as a fraction of _squareSize.


_borderSize

private int _borderSize
Border size.


_dimension

private int _dimension
The grid dimension.


_fileHeight

private int _fileHeight
Height of the file label area.


_offset

private int _offset
Border size.


_rankWidth

private int _rankWidth
Width of the rank label area.


_squareSize

private int _squareSize
Square size.

Constructor Detail

Board

public Board()
Construct this object.

Since:
v0.01
Method Detail

setAnnotation

public void setAnnotation(int x,
                          int y,
                          String text,
                          Color foreground,
                          Color background,
                          boolean isEllipseVisible,
                          boolean append)
Set the given parameters on the annotation at the given intersection.

Parameters:
x - X coordinate.
y - Y coordinate.
text - Annotation text.
foreground - Foreground color.
background - Background color.
isEllipseVisible - Flag indicating if the annotation should show an ellipse.
append - Flag indicating if the text should be appended to existing text.
Since:
v0.01

setAnnotation

public void setAnnotation(int x,
                          int y,
                          String text,
                          Color foreground,
                          Color background,
                          boolean isEllipseVisible,
                          boolean append,
                          Object clientKey,
                          Object clientValue)
Set the given parameters on the annotation at the given intersection.

Parameters:
x - X coordinate.
y - Y coordinate.
text - Annotation text.
foreground - Foreground color.
background - Background color.
isEllipseVisible - Flag indicating if the annotation should show an ellipse.
append - Flag indicating if the text should be appended to existing text.
clientKey - Client property key.
clientValue - Client property value.
Since:
v0.01

setBoardBorderWidth

public void setBoardBorderWidth(int width)
Set the board board width.

Since:
v0.01

setBoardColor

public void setBoardColor(Color color)
Set the board color.

Since:
v0.01

setDimension

public void setDimension(int dimension)
Set the dimension of this board. The board is assumed to be square.

Since:
v0.01

getDimension

public int getDimension()
Return the dimension of this board.


getFileString

public static String getFileString(int file)
Return the alphabetic file designation for the given index.

Since:
v0.01

getPositionString

public static String getPositionString(int x,
                                       int y)
Return the formatted string representation of the given position.

Since:
v0.16

setFont

public void setFont(Font font)
Set the font. Override the super method to clear the font cache.

Overrides:
setFont in class JComponent

setGridColor

public void setGridColor(Color color)
Set the grid color.

Since:
v0.01

setHighlightColor

public void setHighlightColor(Color color)
Set the highlight color.

Since:
v0.01

getIntersectionFor

public Point getIntersectionFor(Point point)
Return the nearest intersection to the given screen point.

Since:
v0.01

setLabelPainted

public void setLabelPainted(boolean isLabelPainted)
Set the flag indicating this should draw coordinate labels.

Since:
v0.01

setLastMoveMarked

public void setLastMoveMarked(boolean isLastMoveMarked)
Set the flag indicating this should mark the last move.

Since:
v0.01

setMarkColor

public void setMarkColor(Color color)
Set the mark color.

Since:
v0.01

setSoundOn

public void setSoundOn(boolean isSoundOn)
Set the sound flag.

Since:
v0.03

isSoundOn

public boolean isSoundOn()
Return true if sound is on.

Since:
v0.03

setState

public void setState(List state)
Set the board state.

Parameters:
state - List of Stones.
Since:
v0.01

getState

public List getState()
Return the current board state.

Since:
v0.01

setTextColor

public void setTextColor(Color color)
Set the text color.

Since:
v0.01

add

public void add(Stone stone)
Add the given token to the board.

Since:
v0.01

add

public void add(Stone[] stones)
Add the given tokens to the board.

Since:
v0.01

clear

public void clear()
Clear the tokens and annotations from the board.

Since:
v0.01

clearAnnotations

public void clearAnnotations()
Clear all annotations.

Since:
v0.01

createLabelPaintedUI

public JCheckBoxMenuItem createLabelPaintedUI()
Create a label painted user interface widget.

Since:
v0.01

createLastMoveMarkedUI

public JCheckBoxMenuItem createLastMoveMarkedUI()
Create a last move marked user interface widget.

Since:
v0.01

drawStringAt

public void drawStringAt(String string,
                         Point intersection)
Draw the given string at the given intersection. This method uses the board font.

Parameters:
string - The string being drawn.
intersection - The coordinates of the intersection.
Since:
v2.5

drawStringAt

public void drawStringAt(String string,
                         Point intersection,
                         Font font)
Draw the given string at the given intersection using the given font.

Parameters:
string - The string being drawn.
intersection - The coordinates of the intersection.
font - The font to use.
Since:
v2.5

get

public Annotation get(int x,
                      int y)
Return the annotation at the given intersection.

Since:
v0.01

highlightIntersection

public void highlightIntersection(Point point)
Highlight the given intersection.

Since:
v0.01

labelPaintedActionPerformed

public void labelPaintedActionPerformed(ActionEvent event)
Callback for the label painted action.

Since:
v0.01

lastMoveMarkedActionPerformed

public void lastMoveMarkedActionPerformed(ActionEvent event)
Callback for the last move marked action.

Since:
v0.01

markToken

public void markToken(Stone stone)
Mark the token at the given position.

Since:
v0.01

remove

public void remove(Stone stone)
Remove the given token from the board.

Since:
v0.01

remove

public void remove(Stone stone,
                   boolean repaint)
Remove the given token from the board.

Since:
v0.01

remove

public void remove(Stone[] stones)
Remove the given tokens from the board.

Since:
v0.01

getRelativeFont

protected Font getRelativeFont(double fraction,
                               Font font)
Return the font sized relative to the given fraction.

Since:
v0.01

add

protected void add(Stone stone,
                   boolean repaint,
                   boolean doSound)
Add the given token to the board.

Parameters:
stone - Stone to add.
repaint - Flag indicating whether a repaint should be requested.
doSound - Flag indicating whether to make a sound.
Since:
v0.01

computeParameters

protected void computeParameters()
Compute the board parameters.

Since:
v0.01

computeScreenPoint

protected Point computeScreenPoint(int x,
                                   int y)
Compute and return the screen coordinates for the given intersection.

Since:
v0.01

computeScreenPoint

protected void computeScreenPoint(int x,
                                  int y,
                                  Point point)
Compute and return the screen coordinates for the given intersection.

Parameters:
x - X coordinate.
y - Y coordinate.
point - Point provided to hold the answer.
Since:
v0.14

computeSize

protected int computeSize(double fraction)
Compute a size based upon the given fraction and the square size.

Since:
v0.01

createPopupMenu

protected JPopupMenu createPopupMenu()
Create and configure the popup menu.

Since:
v0.03

drawCircle

protected void drawCircle(Graphics2D g,
                          int centerX,
                          int centerY,
                          int radius,
                          boolean filled)
Draw a circle at the given coordinates.

Since:
v0.01

drawString

protected void drawString(Graphics2D g,
                          String string,
                          int centerX,
                          int centerY,
                          Font font)
Draw the given string using the given font. When the string is drawn it will be centered at the given coordinates.

Parameters:
g - The graphics.
string - The string being drawn.
centerX - The center X coordinate.
centerY - The center Y coordinate.
font - The font to use.
Since:
v0.01

paintAnnotations

protected void paintAnnotations(Graphics2D g)
Paint the annotations.

Since:
v0.01

paintBoard

protected void paintBoard(Graphics2D g)
Paint the grid lines.

Since:
v0.01

paintComponent

protected void paintComponent(Graphics g)
Paint this component.

Overrides:
paintComponent in class JComponent
Since:
v0.01

paintCoordinateLabels

protected void paintCoordinateLabels(Graphics2D g)
Paint the coordinate labels.

Since:
v0.01

paintHighlight

protected void paintHighlight(Graphics2D g)
Paint the intersection highlight, if any.

Since:
v0.01

paintTokens

protected void paintTokens(Graphics2D g)
Paint the tokens.

Since:
v0.01

rangeCheck

protected void rangeCheck(String label,
                          int x)
Perform a range check.