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, Karl Hasselström
- See Also:
- Serialized Form
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, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, 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, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus |
Board
public Board(Game game)
- Parameters:
game
- The Game object whose pieces are supposed to be painted on
this board.
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
- A pixel in the board coordinate system.- Returns:
- The corresponding position in the map coordinate system.
getScreenPoint
public Point getScreenPoint(Position p)
- Converts the given Position of the map to the actual screen Point in the
board's coordinate system.
- Parameters:
p
- A position in the map coordinate system.- Returns:
- The corresponding pixel in the board coordinate system.
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
- A piece.- Returns:
- A bounding rectangle for the piece.
loadMap
public void loadMap(Map m)
- Sets the map of the board.
- Parameters:
m
- Description of Parameter
clearMap
public void clearMap()
- Description of the Method
mapUpdate
public void mapUpdate(int x,
int y,
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:
x
- Description of Parametery
- Description of Parametercolor
- Description of Parameter
hideMapPoint
public void hideMapPoint(int x,
int y)
- Makes the given point of the map invisible. If it has already been set
as invisible, nothing is done.
- Parameters:
x
- Description of Parametery
- 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 new mouse listener.
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 new mouse motion listener.
repaintBoard
public void repaintBoard()
- Repaints the part of the board where the map and pieces are.
boardSize
public Dimension boardSize()
- Returns the size of the actual board, not counting the scroll bars and
zoom buttons.
- Returns:
- The size of the board.