gecco.client
Class Board

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

public class Board
extends JPanel

The board is what is displayed to the user of the game. It paints the map and the pieces. The board needs to know of a Game object, whose pieces are to be painted on the board.

The board contains scrollbars used for scrolling when the map does not fit the screen. It also contain zoom buttons for zooming in or out on the board. The zoom buttons use some gif images in the icons catalog (zoomin.gif and zoomout.gif).

All painting is done in an offscreen buffer and is then copied to the screen. Use method repaintBoard, to repaint the board to reflect changes in the game.

Author:
Andreas Enblom
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent, JComponent.ActionStandin, JComponent.IntVector, JComponent.KeyboardState
 
Inner classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.AWTTreeLock
 
Field Summary
(package private)  JComponent board
          Description of the Field
(package private)  double boardHeight
          Description of the Field
(package private)  Point boardUpperLeft
          Description of the Field
(package private)  double boardWidth
          Description of the Field
(package private)  Game game
          Description of the Field
static int HEIGHT
          The height of the area on which the map and the pieces are painted.
(package private)  JScrollBar horizontalScrollbar
          Description of the Field
(package private)  AdjustmentListener horScrollListener
          Description of the Field
(package private)  Map map
          Description of the Field
(package private)  Dimension mapSize
          Description of the Field
(package private)  Point mapUpperLeft
          Description of the Field
(package private)  Image offscreenBuffer
          Description of the Field
(package private)  JScrollBar verticalScrollbar
          Description of the Field
(package private)  AdjustmentListener vertScrollListener
          Description of the Field
static int WIDTH
          The width of the area on which the map and the pieces are painted.
(package private)  int zoomFactor
          Description of the Field
(package private)  JButton zoomInButton
          Description of the Field
(package private)  JButton zoomOutButton
          Description of the Field
 
Fields inherited from class javax.swing.JPanel
defaultLayout, uiClassID
 
Fields inherited from class javax.swing.JComponent
_bounds, accessibleContext, actionMap, ACTIONMAP_CREATED, alignmentX, alignmentY, ANCESTOR_INPUTMAP_CREATED, ANCESTOR_USING_BUFFER, ancestorInputMap, ancestorNotifier, autoscroller, border, changeSupport, clientProperties, CREATED_DOUBLE_BUFFER, flags, FOCUS_INPUTMAP_CREATED, focusInputMap, HAS_FOCUS, htmlKey, htmlView, inputVerifier, IS_DOUBLE_BUFFERED, IS_OPAQUE, IS_PAINTING_TILE, IS_PRINTING, IS_PRINTING_ALL, KEY_EVENTS_ENABLED, KEYBOARD_BINDINGS_KEY, listenerList, maximumSize, minimumSize, NEXT_FOCUS, paintImmediatelyClip, paintingChild, preferredSize, readObjectCallbacks, REQUEST_FOCUS_DISABLED, tmpRect, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, verifyInputWhenFocusTarget, vetoableChangeSupport, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, WHEN_IN_FOCUSED_WINDOW_BINDINGS, WIF_INPUTMAP_CREATED, windowInputMap
 
Fields inherited from class java.awt.Container
component, containerListener, containerSerializedDataVersion, dbg, dispatcher, layoutMgr, listeningBoundsChildren, listeningChildren, maxSize, ncomponents, printing, printingThreads, serialVersionUID
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, graphicsConfig, hasFocus, height, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, privateKey, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowClosingException, windowListenerK, x, y
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, PROPERTIES, SOMEBITS
 
Constructor Summary
Board(Game game)
           
 
Method Summary
 void addBoardMouseListener(MouseListener ml)
          Adds the given mouse listener the the area where the map and the pieces are painted.
 void addBoardMouseMotionListener(MouseMotionListener mml)
          Adds the given MouseMotionListener to the area of the board where the map and the pieces are painted.
 void clearMap()
          Description of the Method
 Rectangle getPieceBounds(Piece piece)
          Returns the bounding rectangle of the given piece.
 Position getPositionAt(Point p)
          Converts a screen point to the Position corresponding to that point.
 Point getScreenPoint(Position p)
          Converts the given Position of the map to the actual screen Point in the map-and-pieces component's coordinate system.
 void invisibilizeMapPoint(Point p)
          Makes the given point of the map invisible.
 void loadMap(Map m, Point mapUpperLeft)
          Sets the map of the board with the given point as upper left corner.
 void mapUpdate(Point p, int color)
          Updates the given point of the map to the given color.
 void repaintBoard()
          Repaints the part of the board where the map and pieces are.
(package private)  void repaintBoardArea(Rectangle r)
          Repaint the given area of the board.
 void setBoardCursor(Cursor cursor)
          Set the cursor for the map area of the board.
 void zoom(boolean out)
          Zooms in or out on the board.
 void zoom(int magnification)
          Zoom the board to the given magnification.
 
Methods inherited from class javax.swing.JPanel
, getAccessibleContext, getUIClassID, paramString, updateUI, writeObject
 
Methods inherited from class javax.swing.JComponent
_paintImmediately, addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, adjustPaintFlags, alwaysOnTop, checkIfChildObscuredBySibling, clearFocusOwners, componentInputMapChanged, computeVisibleRect, computeVisibleRect, compWriteObjectNotify, contains, createToolTip, disable, enable, enableSerialization, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperties, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getCreatedDoubleBuffer, getDebugGraphicsOptions, getFlag, getGraphics, getHeight, getInputMap, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paintWithBuffer, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyBindings, processKeyBindingsForAllComponents, processKeyEvent, processMouseMotionEvent, putClientProperty, readObject, rectangleIsObscured, rectangleIsObscuredBySibling, registerKeyboardAction, registerKeyboardAction, registerWithKeyboardManager, registerWithKeyboardManager, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setCreatedDoubleBuffer, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFlag, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPaintingChild, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, shouldDebugGraphics, superProcessMouseMotionEvent, unregisterKeyboardAction, unregisterWithKeyboardManager, unregisterWithKeyboardManager, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, adjustListeningChildren, applyOrientation, checkGD, countComponents, createChildHierarchyEvents, createHierarchyEvents, deliverEvent, dispatchEventImpl, dispatchEventToSelf, doLayout, eventEnabled, findComponentAt, findComponentAt, findComponentAt, getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getLayout, getMouseEventTarget, getWindow, initIDs, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPaint, lightweightPrint, list, list, locate, minimumSize, nextFocus, numListening, paintComponents, paintHeavyweightComponents, postProcessKeyEvent, postsOldMouseEvents, preferredSize, preProcessKeyEvent, printComponents, printHeavyweightComponents, processContainerEvent, processEvent, proxyEnableEvents, proxyRequestFocus, remove, remove, removeAll, removeContainerListener, setFocusOwner, setLayout, transferFocus, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, areInputMethodsEnabled, bounds, checkImage, checkImage, checkWindowClosingException, coalesceEvents, constructComponentName, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getAccessibleIndexInParent, getAccessibleStateSet, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen_NoTreeLock, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getToolkit, getToolkitImpl, getTreeLock, getWindowForObject, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isEnabledImpl, isLightweight, isRecursivelyVisible, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resetGC, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

game

Game game
Description of the Field

board

JComponent board
Description of the Field

horizontalScrollbar

JScrollBar horizontalScrollbar
Description of the Field

verticalScrollbar

JScrollBar verticalScrollbar
Description of the Field

horScrollListener

AdjustmentListener horScrollListener
Description of the Field

vertScrollListener

AdjustmentListener vertScrollListener
Description of the Field

zoomInButton

JButton zoomInButton
Description of the Field

zoomOutButton

JButton zoomOutButton
Description of the Field

offscreenBuffer

Image offscreenBuffer
Description of the Field

boardUpperLeft

Point boardUpperLeft
Description of the Field

boardWidth

double boardWidth
Description of the Field

boardHeight

double boardHeight
Description of the Field

zoomFactor

int zoomFactor
Description of the Field

map

Map map
Description of the Field

mapUpperLeft

Point mapUpperLeft
Description of the Field

mapSize

Dimension mapSize
Description of the Field

WIDTH

public static final int WIDTH
The width of the area on which the map and the pieces are painted.

HEIGHT

public static final int HEIGHT
The height of the area on which the map and the pieces are painted.
Constructor Detail

Board

public Board(Game game)
Parameters:
game - The Game object whose pieces are supposed to be painted on this board.
Method Detail

setBoardCursor

public void setBoardCursor(Cursor cursor)
Set the cursor for the map area of the board.
Parameters:
cursor - The new BoardCursor value

getPositionAt

public Position getPositionAt(Point p)
Converts a screen point to the Position corresponding to that point. Things like zoom factor and scrollbar position are taken into account.
Parameters:
p - Description of Parameter
Returns:
The PositionAt value

getScreenPoint

public Point getScreenPoint(Position p)
Converts the given Position of the map to the actual screen Point in the map-and-pieces component's coordinate system.
Parameters:
p - Description of Parameter
Returns:
The ScreenPoint value

getPieceBounds

public Rectangle getPieceBounds(Piece piece)
Returns the bounding rectangle of the given piece. The rectangle is given in actual screen coordinates (i.e. the coordinates of the map-and-pieces component).
Parameters:
piece - Description of Parameter
Returns:
The PieceBounds value

loadMap

public void loadMap(Map m,
                    Point mapUpperLeft)
Sets the map of the board with the given point as upper left corner.
Parameters:
m - Description of Parameter
mapUpperLeft - Description of Parameter

clearMap

public void clearMap()
Description of the Method

mapUpdate

public void mapUpdate(Point p,
                      int color)
Updates the given point of the map to the given color. Colors are given as integers as decribed in java.awt.Color.
Parameters:
p - Description of Parameter
color - Description of Parameter

invisibilizeMapPoint

public void invisibilizeMapPoint(Point p)
Makes the given point of the map invisible. If it has already been set as invisible, nothing is done.
Parameters:
p - Description of Parameter

addBoardMouseListener

public void addBoardMouseListener(MouseListener ml)
Adds the given mouse listener the the area where the map and the pieces are painted. Use this method to assign the preferred behavior to the board (such as mouse clicks for selecting pieces).
Parameters:
ml - The feature to be added to the BoardMouseListener attribute

addBoardMouseMotionListener

public void addBoardMouseMotionListener(MouseMotionListener mml)
Adds the given MouseMotionListener to the area of the board where the map and the pieces are painted.
Parameters:
mml - The feature to be added to the BoardMouseMotionListener attribute

repaintBoard

public void repaintBoard()
Repaints the part of the board where the map and pieces are.

zoom

public void zoom(boolean out)
Zooms in or out on the board.
Parameters:
out - Indicates whether or not the board should be zoomed out.

zoom

public void zoom(int magnification)
Zoom the board to the given magnification. If the magnification is zero the board is initilized the proper values according to the map.
Parameters:
magnification - The magnification; zero is no magnification and n+1 is twice as much as n.

repaintBoardArea

void repaintBoardArea(Rectangle r)
Repaint the given area of the board. The coordinates are given relative to the component on which the map and pieces are painted.
Parameters:
r - Description of Parameter