klaus.components
Class ChessBoard

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 klaus.components.ChessBoard
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ChessBoard
extends JPanel

This component draws a chess board (what a surprise!).

Since:
2009-03-11
Author:
Stephan Hillebrand
See Also:
Serialized Form

Nested Class Summary
 
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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  ChessBackend backend
          The backend used by this board
private  Font coordsFont
           
private  int dndXOffset
          Position inside the piece (X) (drag'n'drop)
private  int dndXPOS
          Do not draw the piece at this X position (drag'n'drop)
private  int dndYOffset
          Position inside the piece (Y) (drag'n'drop)
private  int dndYPOS
          Do not draw the piece at this Y position (drag'n'drop)
private  double fieldsize
           
private  Vector<ChessBoardListener> listeners
           
private  Result result
           
private  int size
           
private  boolean turned
          Is the board turned?
private  int xposition
           
private  int yposition
           
 
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
ChessBoard(ChessBackend chessBackend)
           
 
Method Summary
 void addChessBoardListener(ChessBoardListener listener)
           
private  void calculateSize()
           
 void fireListeners()
           
 ChessBackend getBackend()
           
 Party getParty()
           
private  int getSquareX(int mouseX)
          Convert the mouse coordinates to the coords of a square (X coord)
private  int getSquareY(int mouseY)
          Convert the mouse coordinates to the coords of a square (Y coord)
private  int getXOnScreen(int squareX)
           
private  int getYOnScreen(int squareY)
           
 boolean isTurned()
           
 void paintComponent(Graphics g)
          Paint the board
private  String pieceToFileName(char piece)
           
 void removeChessBoardListener(ChessBoardListener listener)
           
 void setBackend(ChessBackend backend)
           
 void setTurned(boolean turned)
           
 
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, 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

backend

private ChessBackend backend
The backend used by this board


dndXPOS

private int dndXPOS
Do not draw the piece at this X position (drag'n'drop)


dndYPOS

private int dndYPOS
Do not draw the piece at this Y position (drag'n'drop)


dndXOffset

private int dndXOffset
Position inside the piece (X) (drag'n'drop)


dndYOffset

private int dndYOffset
Position inside the piece (Y) (drag'n'drop)


size

private int size

xposition

private int xposition

yposition

private int yposition

fieldsize

private double fieldsize

coordsFont

private Font coordsFont

result

private Result result

turned

private boolean turned
Is the board turned? False will mean the white pieces are at the bottom of the board, true means the opposite. So this should be true whenever the player has the black pieces.


listeners

private Vector<ChessBoardListener> listeners
Constructor Detail

ChessBoard

public ChessBoard(ChessBackend chessBackend)
Method Detail

getSquareX

private int getSquareX(int mouseX)
Convert the mouse coordinates to the coords of a square (X coord)


getSquareY

private int getSquareY(int mouseY)
Convert the mouse coordinates to the coords of a square (Y coord)


getXOnScreen

private int getXOnScreen(int squareX)

getYOnScreen

private int getYOnScreen(int squareY)

calculateSize

private void calculateSize()

paintComponent

public void paintComponent(Graphics g)
Paint the board

Overrides:
paintComponent in class JComponent

pieceToFileName

private String pieceToFileName(char piece)

getBackend

public ChessBackend getBackend()

getParty

public Party getParty()

setBackend

public void setBackend(ChessBackend backend)

addChessBoardListener

public void addChessBoardListener(ChessBoardListener listener)

removeChessBoardListener

public void removeChessBoardListener(ChessBoardListener listener)

fireListeners

public void fireListeners()

isTurned

public boolean isTurned()

setTurned

public void setTurned(boolean turned)