soc.client
Class SOCBoardPanel

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Canvas
          extended bysoc.client.SOCBoardPanel
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable

public class SOCBoardPanel
extends java.awt.Canvas
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

This is a component that can display a Settlers of Catan Board. It can be used in an applet or an application. It loads gifs from a directory named "images" in the same directory at the code.

See Also:
Serialized Form

Nested Class Summary
protected  class SOCBoardPanel.BoardPanelSendBuildTask
          Used for the delay between sending a build-request message, and receiving a game-state message.
private  class SOCBoardPanel.BoardPopupMenu
          This class creates a popup menu on the board, to trade or build or cancel building.
protected  class SOCBoardPanel.BoardToolTip
           
protected static class SOCBoardPanel.DelayedRepaint
          With a recent board resize, one or more rescaled images still hasn't been completed after 7 seconds.
(package private) static class SOCBoardPanel.ResourceTradeAllMenu
          Menu for right-click on 3-for-1 port to trade all resource types with bank/port.
 
Nested classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private static java.awt.Color ARROW_COLOR
          Arrow color: cyan: r=106,g=183,b=183
private static int ARROW_SZ
          Arrow fits in a 37 x 37 square.
private static int[] arrowXL
          Arrow, left-pointing.
private static int[] arrowXR
          Arrow, right-pointing.
private static int[] arrowY
          Arrow, y-coordinates: same whether pointing left or right.
private  SOCBoard board
          The board in the game
private  java.awt.Image buffer
          offscreen buffer
protected static int BUILD_REQUEST_MAX_DELAY_SEC
          for popup-menu build request, network send maximum delay (seconds)
protected  SOCBoardPanel.BoardPanelSendBuildTask buildReqTimerTask
          For right-click build menu; used for fallback part of client-server-client communication of a build request.
private static int[] cityX
          city
private static int[] cityY
           
static int CONSIDER_LM_CITY
           
static int CONSIDER_LM_ROAD
           
static int CONSIDER_LM_SETTLEMENT
           
static int CONSIDER_LT_CITY
           
static int CONSIDER_LT_ROAD
           
static int CONSIDER_LT_SETTLEMENT
           
private static int deltaX
           
private static int deltaY
           
private static java.awt.Image[] dice
          dice number pix (for arrow).
private static int DICE_SZ
          Dice number fits in a 25 x 25 square.
private static int[] downRoadX
          road looks like "\"
private static int[] downRoadY
           
private  int[] edgeMap
          Map grid sectors to hex edges
private  SOCGame game
          The game which this board is a part of
static int GAME_FORMING
           
static int GAME_OVER
           
private static int halfdeltaX
           
private static java.awt.Image[] hexes
          Hex pix - shared unscaled original-resolution from GIF files.
private  int HEXHEIGHT
           
private  int[] hexIDtoNum
          translate hex ID to number to get coords
private  int[] hexMap
          Map grid sectors to hexes
private  int HEXWIDTH
          hex size, in unscaled internal-pixels
private static int[] hexX
          hex coordinates for drawing
private static int[] hexY
           
private  int hilight
          Edge or node being pointed to.
static int HOVER_OFFSET_X_FOR_INIT_PLACE
          During initial-piece placement, the tooltip is moved this far over to make room.
static int HOVER_OFFSET_X_FOR_ROBBER
          During robber placement, the tooltip is moved this far over to make room.
private  SOCBoardPanel.BoardToolTip hoverTip
          (tooltip) Hover text.
private static java.lang.String IMAGEDIR
           
private  int initstlmt
          This holds the coord of the last stlmt placed in the initial phase.
protected  boolean isScaled
          The board is currently scaled larger than PANELX x PANELY pixels.
private  int mode
          modes of interaction; for correlation to game state, see updateMode().
private  int[] nodeMap
          Map grid sectors to hex nodes
static int NONE
           
private static java.awt.Image[] numbers
          number pix (for hexes)
private  SOCPlayer otherPlayer
          When in "consider" mode, this is the player we're talking to
static int PANELX
          size of the whole panel, internal-pixels "scale"; also minimum acceptable size in screen pixels.
static int PANELY
          size of the whole panel, internal-pixels "scale"; also minimum acceptable size in screen pixels.
static int PLACE_CITY
           
static int PLACE_INIT_ROAD
           
static int PLACE_INIT_SETTLEMENT
           
static int PLACE_ROAD
           
static int PLACE_ROBBER
           
static int PLACE_SETTLEMENT
           
private  SOCPlayer player
          The player that is using this interface
private  SOCPlayerInterface playerInterface
          the player interface that this board is a part of
private  int playerNumber
          player number if in a game, or -1.
protected static int POPUP_MENU_IGNORE_MS
          for popup-menu build request, length of time after popup to ignore further mouse-clicks.
private  SOCBoardPanel.BoardPopupMenu popupMenu
          Context menu for build/cancel-build
private  long popupMenuSystime
          Tracks last menu-popup time.
private static java.awt.Image[] ports
           
private  int ptrOldX
          Old pointer coords for interface
private  int ptrOldY
           
protected  java.awt.Color[] robberGhostFill
          Cached colors, for use for robber's "ghost" (previous position) when moving the robber.
protected  java.awt.Color[] robberGhostOutline
          Cached colors, for use for robber's "ghost" (previous position) when moving the robber.
private static int[] robberX
          robber
private static int[] robberY
           
private  int[] scaledArrowXL
          arrow, left-pointing and right-pointing.
private  int[] scaledArrowXR
          arrow, left-pointing and right-pointing.
private  int[] scaledArrowY
          arrow, left-pointing and right-pointing.
protected  long scaledAt
          Time of last resize, as returned by System.currentTimeMillis().
private  int[] scaledCityX
          city
private  int[] scaledCityY
          city
private  int[] scaledDownRoadX
          road looks like "\"
private  int[] scaledDownRoadY
          road looks like "\"
private  java.awt.Image[] scaledHexes
          Hex pix - private scaled copy, if isScaled.
private  boolean[] scaledHexFail
          Hex pix - Flag to check if rescaling failed, if isScaled.
protected  boolean scaledMissedImage
          Flag used while drawing a scaled board.
private  boolean[] scaledNumberFail
           
private  java.awt.Image[] scaledNumbers
           
protected  int scaledPanelX
          actual size on-screen, not internal-pixels size (PANELX, PANELY)
protected  int scaledPanelY
          actual size on-screen, not internal-pixels size (PANELX, PANELY)
private  boolean[] scaledPortFail
           
private  java.awt.Image[] scaledPorts
           
private  int[] scaledRobberX
          robber
private  int[] scaledRobberY
          robber
private  int[] scaledSettlementX
          settlement
private  int[] scaledSettlementY
          settlement
private  int[] scaledUpRoadX
          road looks like "/"
private  int[] scaledUpRoadY
          road looks like "/"
private  int[] scaledVertRoadX
          Coordinate arrays for drawing the playing pieces.
private  int[] scaledVertRoadY
          Coordinate arrays for drawing the playing pieces.
private static int[] settlementX
          settlement
private static int[] settlementY
           
private static int[] upRoadX
          road looks like "/"
private static int[] upRoadY
           
private static int[] vertRoadX
          road looks like "|"
private static int[] vertRoadY
           
 
Fields inherited from class java.awt.Canvas
 
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
SOCBoardPanel(SOCPlayerInterface pi)
          create a new board panel in an applet
 
Method Summary
protected  void clearModeAndHilight()
           
protected  void doBoardMenuPopup(int x, int y)
          Bring up the popup menu; called from mousePressed.
private  void drawArrow(java.awt.Graphics g, int pnum, int diceResult)
          draw the arrow that shows whose turn it is.
private  void drawBoard(java.awt.Graphics g)
          draw the whole board
private  void drawCity(java.awt.Graphics g, int nodeNum, int pn, boolean isHilight)
          draw a city
private  void drawHex(java.awt.Graphics g, int hexNum)
          draw a board tile
private  void drawRoad(java.awt.Graphics g, int edgeNum, int pn, boolean isHilight)
          draw a road
private  void drawRobber(java.awt.Graphics g, int hexID, boolean fullNotGhost)
          draw the robber
private  void drawSettlement(java.awt.Graphics g, int nodeNum, int pn, boolean isHilight)
          draw a settlement
private  int findEdge(int x, int y)
          given a pixel on the board, find the edge that contains it
private  int findHex(int x, int y)
          given a pixel on the board, find the hex that contains it
private  int findNode(int x, int y)
          given a pixel on the board, find the node that contains it
 java.awt.Dimension getMinimumSize()
          DOCUMENT ME!
 int getMode()
          get the interaction mode
 java.awt.Dimension getPreferredSize()
          DOCUMENT ME!
private  void initEdgeMapAux(int x1, int y1, int x2, int y2, int startHex)
           
private  void initHexIDtoNumAux(int begin, int end, int num)
           
private  void initHexMapAux(int x1, int y1, int x2, int y2, int startHex)
           
private  void initNodeMapAux(int x1, int y1, int x2, int y2, int startHex)
           
 boolean isScaled()
          Is the board is currently scaled larger than PANELX x PANELY pixels? If so, use scaleToActualX(int), scaleFromActualY(int), etc to convert between internal and actual screen pixel coordinates.
private static void loadImages(java.awt.Component c)
          load the images for the board we need to know if this board is in an applet or an application
 void mouseClicked(java.awt.event.MouseEvent evt)
          DOCUMENT ME!
 void mouseDragged(java.awt.event.MouseEvent e)
          DOCUMENT ME!
 void mouseEntered(java.awt.event.MouseEvent e)
          Handle Events
 void mouseExited(java.awt.event.MouseEvent e)
          Mouse has left the panel; hide tooltip and any hovering piece.
 void mouseMoved(java.awt.event.MouseEvent e)
          DOCUMENT ME!
 void mousePressed(java.awt.event.MouseEvent e)
          DOCUMENT ME!
 void mouseReleased(java.awt.event.MouseEvent e)
          DOCUMENT ME!
 void paint(java.awt.Graphics g)
          Redraw the board using double buffering.
 void popupClearBuildRequest()
           
 boolean popupExpectingBuildRequest()
          If the client has used the board popup menu to request building a piece, this method is used in client network-receive message treatment.
 void popupFireBuildingRequest()
          Have received gamestate placing message; send the building request in reply.
 void popupSetBuildRequest(int coord, int ptype)
           
private  void rescaleBoard(int newW, int newH)
          Set the board fields to a new size, rescale graphics if needed.
private  void rescaleCoordinateArrays()
          Scale coordinate arrays for drawing pieces, or (if not isScaled) point to static arrays.
 int[] scaleCopyToActualX(int[] xorig)
          Rescale to actual screen coordinates - Create a copy of array, and scale the copy's elements as X coordinates.
 int[] scaleCopyToActualY(int[] yorig)
          Rescale to actual screen coordinates - Create a copy of array, and scale the copy's elements as Y coordinates.
 int scaleFromActualX(int x)
          Convert an x-coordinate from actual-scaled to internal-scaled coordinates.
 int scaleFromActualY(int y)
          Convert a y-coordinate from actual-scaled to internal-scaled coordinates.
 int scaleToActualX(int x)
          Scale x-coordinate from internal to actual screen-pixel coordinates.
 void scaleToActualX(int[] xa)
          Scale x-array from internal to actual screen-pixel coordinates.
 int scaleToActualY(int y)
          Scale y-coordinate from internal to actual screen-pixel coordinates.
 void scaleToActualY(int[] ya)
          Scale y-array from internal to actual screen-pixel coordinates.
 void setBounds(int x, int y, int w, int h)
          Set the board to a new location and size, rescale graphics and repaint if needed.
 void setMode(int m)
          set the interaction mode
 void setOtherPlayer(SOCPlayer op)
          set the other player
 void setPlayer()
          set the player that is using this board panel.
 void setSize(java.awt.Dimension sz)
          Set the board to a new size, rescale graphics and repaint if needed.
 void setSize(int newW, int newH)
          Set the board to a new size, rescale graphics and repaint if needed.
 void update(java.awt.Graphics g)
          Overriden so the peer isn't painted, which clears background.
protected  void updateHoverTipToMode()
           
 void updateMode()
          update the type of interaction mode
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IMAGEDIR

private static java.lang.String IMAGEDIR

PANELX

public static final int PANELX
size of the whole panel, internal-pixels "scale"; also minimum acceptable size in screen pixels. For actual current size in screen pixels, see scaledPanelX scaledPanelY;

See Also:
Constant Field Values

PANELY

public static final int PANELY
size of the whole panel, internal-pixels "scale"; also minimum acceptable size in screen pixels. For actual current size in screen pixels, see scaledPanelX scaledPanelY;

See Also:
Constant Field Values

deltaY

private static final int deltaY
See Also:
Constant Field Values

deltaX

private static final int deltaX
See Also:
Constant Field Values

halfdeltaX

private static final int halfdeltaX
See Also:
Constant Field Values

hexX

private static final int[] hexX
hex coordinates for drawing


hexY

private static final int[] hexY

vertRoadX

private static final int[] vertRoadX
road looks like "|"


vertRoadY

private static final int[] vertRoadY

upRoadX

private static final int[] upRoadX
road looks like "/"


upRoadY

private static final int[] upRoadY

downRoadX

private static final int[] downRoadX
road looks like "\"


downRoadY

private static final int[] downRoadY

settlementX

private static final int[] settlementX
settlement


settlementY

private static final int[] settlementY

cityX

private static final int[] cityX
city


cityY

private static final int[] cityY

robberX

private static final int[] robberX
robber


robberY

private static final int[] robberY

arrowXL

private static final int[] arrowXL
Arrow, left-pointing. First point is top of arrow-tip's bevel, last point is bottom of tip. arrowXL[4] is rightmost X coordinate. (These points are important for adjustment when scaling in rescaleCoordinateArrays())

See Also:
arrowY, ARROW_SZ

arrowXR

private static int[] arrowXR
Arrow, right-pointing. Calculated when needed by flipping arrowXL in rescaleCoordinateArrays().


arrowY

private static final int[] arrowY
Arrow, y-coordinates: same whether pointing left or right. First point is top of arrow-tip's bevel, last point is bottom of tip.


ARROW_SZ

private static final int ARROW_SZ
Arrow fits in a 37 x 37 square. @see #arrowXL

See Also:
Constant Field Values

ARROW_COLOR

private static final java.awt.Color ARROW_COLOR
Arrow color: cyan: r=106,g=183,b=183


NONE

public static final int NONE
See Also:
Constant Field Values

PLACE_ROAD

public static final int PLACE_ROAD
See Also:
Constant Field Values

PLACE_SETTLEMENT

public static final int PLACE_SETTLEMENT
See Also:
Constant Field Values

PLACE_CITY

public static final int PLACE_CITY
See Also:
Constant Field Values

PLACE_ROBBER

public static final int PLACE_ROBBER
See Also:
Constant Field Values

PLACE_INIT_SETTLEMENT

public static final int PLACE_INIT_SETTLEMENT
See Also:
Constant Field Values

PLACE_INIT_ROAD

public static final int PLACE_INIT_ROAD
See Also:
Constant Field Values

CONSIDER_LM_SETTLEMENT

public static final int CONSIDER_LM_SETTLEMENT
See Also:
Constant Field Values

CONSIDER_LM_ROAD

public static final int CONSIDER_LM_ROAD
See Also:
Constant Field Values

CONSIDER_LM_CITY

public static final int CONSIDER_LM_CITY
See Also:
Constant Field Values

CONSIDER_LT_SETTLEMENT

public static final int CONSIDER_LT_SETTLEMENT
See Also:
Constant Field Values

CONSIDER_LT_ROAD

public static final int CONSIDER_LT_ROAD
See Also:
Constant Field Values

CONSIDER_LT_CITY

public static final int CONSIDER_LT_CITY
See Also:
Constant Field Values

GAME_FORMING

public static final int GAME_FORMING
See Also:
Constant Field Values

GAME_OVER

public static final int GAME_OVER
See Also:
Constant Field Values

HOVER_OFFSET_X_FOR_INIT_PLACE

public static final int HOVER_OFFSET_X_FOR_INIT_PLACE
During initial-piece placement, the tooltip is moved this far over to make room.

See Also:
Constant Field Values

HOVER_OFFSET_X_FOR_ROBBER

public static final int HOVER_OFFSET_X_FOR_ROBBER
During robber placement, the tooltip is moved this far over to make room.

See Also:
Constant Field Values

BUILD_REQUEST_MAX_DELAY_SEC

protected static int BUILD_REQUEST_MAX_DELAY_SEC
for popup-menu build request, network send maximum delay (seconds)


POPUP_MENU_IGNORE_MS

protected static int POPUP_MENU_IGNORE_MS
for popup-menu build request, length of time after popup to ignore further mouse-clicks. Avoids Windows accidental build by popup-click during game's initial piece placement. (150 ms)


HEXWIDTH

private final int HEXWIDTH
hex size, in unscaled internal-pixels

See Also:
Constant Field Values

HEXHEIGHT

private final int HEXHEIGHT
See Also:
Constant Field Values

scaledPanelX

protected int scaledPanelX
actual size on-screen, not internal-pixels size (PANELX, PANELY)


scaledPanelY

protected int scaledPanelY
actual size on-screen, not internal-pixels size (PANELX, PANELY)


isScaled

protected boolean isScaled
The board is currently scaled larger than PANELX x PANELY pixels. Use scaleToActualX(int), scaleFromActualX(int), etc to convert between internal and actual screen pixel coordinates.


scaledAt

protected long scaledAt
Time of last resize, as returned by System.currentTimeMillis(). Used with scaledMissedImage.


scaledMissedImage

protected boolean scaledMissedImage
Flag used while drawing a scaled board. If board size was recently changed, could be waiting for an image to resize. If it still hasn't appeared after 7 seconds, we'll give up and create a new one. (This can happen due to AWT bugs.) Set in drawHex(Graphics, int), checked in drawBoard(Graphics).

See Also:
scaledHexFail

hexIDtoNum

private int[] hexIDtoNum
translate hex ID to number to get coords


hexes

private static java.awt.Image[] hexes
Hex pix - shared unscaled original-resolution from GIF files.

See Also:
scaledHexes

ports

private static java.awt.Image[] ports

scaledHexes

private java.awt.Image[] scaledHexes
Hex pix - private scaled copy, if isScaled. Otherwise points to static copies.

See Also:
hexes

scaledPorts

private java.awt.Image[] scaledPorts

scaledHexFail

private boolean[] scaledHexFail
Hex pix - Flag to check if rescaling failed, if isScaled.

See Also:
scaledHexes, drawHex(Graphics, int)

scaledPortFail

private boolean[] scaledPortFail

numbers

private static java.awt.Image[] numbers
number pix (for hexes)


scaledNumbers

private java.awt.Image[] scaledNumbers

scaledNumberFail

private boolean[] scaledNumberFail

dice

private static java.awt.Image[] dice
dice number pix (for arrow). @see #DICE_SZ


DICE_SZ

private static final int DICE_SZ
Dice number fits in a 25 x 25 square. @see #dice

See Also:
Constant Field Values

scaledVertRoadX

private int[] scaledVertRoadX
Coordinate arrays for drawing the playing pieces. Local copy if isScaled, otherwise points to static arrays.


scaledVertRoadY

private int[] scaledVertRoadY
Coordinate arrays for drawing the playing pieces. Local copy if isScaled, otherwise points to static arrays.


scaledUpRoadX

private int[] scaledUpRoadX
road looks like "/"


scaledUpRoadY

private int[] scaledUpRoadY
road looks like "/"


scaledDownRoadX

private int[] scaledDownRoadX
road looks like "\"


scaledDownRoadY

private int[] scaledDownRoadY
road looks like "\"


scaledSettlementX

private int[] scaledSettlementX
settlement


scaledSettlementY

private int[] scaledSettlementY
settlement


scaledCityX

private int[] scaledCityX
city


scaledCityY

private int[] scaledCityY
city


scaledRobberX

private int[] scaledRobberX
robber


scaledRobberY

private int[] scaledRobberY
robber


scaledArrowXL

private int[] scaledArrowXL
arrow, left-pointing and right-pointing.

See Also:
rescaleCoordinateArrays()

scaledArrowXR

private int[] scaledArrowXR
arrow, left-pointing and right-pointing.

See Also:
rescaleCoordinateArrays()

scaledArrowY

private int[] scaledArrowY
arrow, left-pointing and right-pointing.

See Also:
rescaleCoordinateArrays()

ptrOldX

private int ptrOldX
Old pointer coords for interface


ptrOldY

private int ptrOldY

hoverTip

private SOCBoardPanel.BoardToolTip hoverTip
(tooltip) Hover text. Its mode uses boardpanel mode constants: Will be NONE, PLACE_ROAD, PLACE_SETTLEMENT, PLACE_ROBBER for hex, or PLACE_INIT_SETTLEMENT for port.


popupMenu

private SOCBoardPanel.BoardPopupMenu popupMenu
Context menu for build/cancel-build


popupMenuSystime

private long popupMenuSystime
Tracks last menu-popup time. Avoids misinterpretation of popup-click with placement-click during initial placement: On Windows, popup-click must be caught in mouseReleased, but mousePressed is called immediately afterwards.


buildReqTimerTask

protected SOCBoardPanel.BoardPanelSendBuildTask buildReqTimerTask
For right-click build menu; used for fallback part of client-server-client communication of a build request. Created whenever right-click build request sent. This is the fallback for the normal method:
  SOCBoardPanel.popupExpectingBuildRequest
  SOCPlayerInterface.updateAtGameState
  SOCBoardPanel.popupFireBuildingRequest
 


hilight

private int hilight
Edge or node being pointed to.


edgeMap

private int[] edgeMap
Map grid sectors to hex edges


nodeMap

private int[] nodeMap
Map grid sectors to hex nodes


hexMap

private int[] hexMap
Map grid sectors to hexes


game

private SOCGame game
The game which this board is a part of


board

private SOCBoard board
The board in the game


player

private SOCPlayer player
The player that is using this interface


playerNumber

private int playerNumber
player number if in a game, or -1.


otherPlayer

private SOCPlayer otherPlayer
When in "consider" mode, this is the player we're talking to


buffer

private java.awt.Image buffer
offscreen buffer


mode

private int mode
modes of interaction; for correlation to game state, see updateMode().


initstlmt

private int initstlmt
This holds the coord of the last stlmt placed in the initial phase.


playerInterface

private SOCPlayerInterface playerInterface
the player interface that this board is a part of


robberGhostFill

protected java.awt.Color[] robberGhostFill
Cached colors, for use for robber's "ghost" (previous position) when moving the robber. Values are determined the first time the robber is ghosted on that type of tile. Index ranges from 0 to SOCBoard.MAX_ROBBER_HEX.

See Also:
ColorSquare, drawRobber(Graphics, int, boolean)

robberGhostOutline

protected java.awt.Color[] robberGhostOutline
Cached colors, for use for robber's "ghost" (previous position) when moving the robber. Values are determined the first time the robber is ghosted on that type of tile. Index ranges from 0 to SOCBoard.MAX_ROBBER_HEX.

See Also:
ColorSquare, drawRobber(Graphics, int, boolean)
Constructor Detail

SOCBoardPanel

public SOCBoardPanel(SOCPlayerInterface pi)
create a new board panel in an applet

Parameters:
pi - the player interface that spawned us
Method Detail

initEdgeMapAux

private final void initEdgeMapAux(int x1,
                                  int y1,
                                  int x2,
                                  int y2,
                                  int startHex)

initHexMapAux

private final void initHexMapAux(int x1,
                                 int y1,
                                 int x2,
                                 int y2,
                                 int startHex)

initNodeMapAux

private final void initNodeMapAux(int x1,
                                  int y1,
                                  int x2,
                                  int y2,
                                  int startHex)

initHexIDtoNumAux

private final void initHexIDtoNumAux(int begin,
                                     int end,
                                     int num)

getPreferredSize

public java.awt.Dimension getPreferredSize()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getMinimumSize

public java.awt.Dimension getMinimumSize()
DOCUMENT ME!

Returns:
DOCUMENT ME!

setSize

public void setSize(int newW,
                    int newH)
             throws java.lang.IllegalArgumentException
Set the board to a new size, rescale graphics and repaint if needed.

Parameters:
newW - New width in pixels, no less than PANELX
newH - New height in pixels, no less than PANELY
Throws:
java.lang.IllegalArgumentException - if newW or newH is too small but not 0. During initial layout, the layoutmanager may make calls to setSize(0,0); such a call is passed to super without scaling graphics.

setSize

public void setSize(java.awt.Dimension sz)
             throws java.lang.IllegalArgumentException
Set the board to a new size, rescale graphics and repaint if needed.

Parameters:
sz - New size in pixels, no less than PANELX wide by PANELY tall
Throws:
java.lang.IllegalArgumentException - if sz is too small but not 0. During initial layout, the layoutmanager may make calls to setSize(0,0); such a call is passed to super without scaling graphics.

setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
               throws java.lang.IllegalArgumentException
Set the board to a new location and size, rescale graphics and repaint if needed. Called from SOCPlayerInterface.doLayout().

Parameters:
x - New location's x-coordinate
y - new location's y-coordinate
w - New width in pixels, no less than PANELX
h - New height in pixels, no less than PANELY
Throws:
java.lang.IllegalArgumentException - if w or h is too small but not 0. During initial layout, the layoutmanager may make calls to setBounds(0,0,0,0); such a call is passed to super without scaling graphics.

rescaleBoard

private void rescaleBoard(int newW,
                          int newH)
                   throws java.lang.IllegalArgumentException
Set the board fields to a new size, rescale graphics if needed. Does not call repaint. Does not call setSize.

Parameters:
newW - New width in pixels, no less than PANELX
newH - New height in pixels, no less than PANELY
Throws:
java.lang.IllegalArgumentException - if newW or newH is too small but not 0. During initial layout, the layoutmanager may cause calls to rescaleBoard(0,0); such a call is ignored, no rescaling of graphics is done.

rescaleCoordinateArrays

private void rescaleCoordinateArrays()
Scale coordinate arrays for drawing pieces, or (if not isScaled) point to static arrays. Called from constructor and rescaleBoard.


scaleCopyToActualX

public int[] scaleCopyToActualX(int[] xorig)
Rescale to actual screen coordinates - Create a copy of array, and scale the copy's elements as X coordinates.

Parameters:
xorig - Int array to be scaled; each member is an x-coordinate.
Returns:
Scaled copy of xorig
See Also:
scaleToActualX(int[])

scaleCopyToActualY

public int[] scaleCopyToActualY(int[] yorig)
Rescale to actual screen coordinates - Create a copy of array, and scale the copy's elements as Y coordinates.

Parameters:
yorig - Int array to be scaled; each member is a y-coordinate.
Returns:
Scaled copy of yorig
See Also:
scaleToActualY(int[])

paint

public void paint(java.awt.Graphics g)
Redraw the board using double buffering. Don't call this directly, use Component.repaint() instead.


update

public void update(java.awt.Graphics g)
Overriden so the peer isn't painted, which clears background. Don't call this directly, use Component.repaint() instead.


drawHex

private final void drawHex(java.awt.Graphics g,
                           int hexNum)
draw a board tile


drawRobber

private final void drawRobber(java.awt.Graphics g,
                              int hexID,
                              boolean fullNotGhost)
draw the robber

Parameters:
g - Graphics context
hexID - Board hex encoded position
fullNotGhost - Draw normally, not "ghost" of previous position (as during PLACE_ROBBER movement)

drawRoad

private final void drawRoad(java.awt.Graphics g,
                            int edgeNum,
                            int pn,
                            boolean isHilight)
draw a road


drawSettlement

private final void drawSettlement(java.awt.Graphics g,
                                  int nodeNum,
                                  int pn,
                                  boolean isHilight)
draw a settlement


drawCity

private final void drawCity(java.awt.Graphics g,
                            int nodeNum,
                            int pn,
                            boolean isHilight)
draw a city


drawArrow

private final void drawArrow(java.awt.Graphics g,
                             int pnum,
                             int diceResult)
draw the arrow that shows whose turn it is.

Parameters:
g - Graphics
pnum - Player position: 0 for top-left, 1 for top-right, 2 for bottom-right, 3 for bottom-left
diceResult - Roll result to show, if rolled. To show, diceResult must be at least 2, and gamestate not SOCGame.PLAY.

drawBoard

private void drawBoard(java.awt.Graphics g)
draw the whole board


scaleToActualX

public void scaleToActualX(int[] xa)
Scale x-array from internal to actual screen-pixel coordinates. If not isScaled, do nothing.

Parameters:
xa - Int array to be scaled; each member is an x-coordinate.
See Also:
scaleCopyToActualX(int[])

scaleToActualY

public void scaleToActualY(int[] ya)
Scale y-array from internal to actual screen-pixel coordinates. If not isScaled, do nothing.

Parameters:
ya - Int array to be scaled; each member is an y-coordinate.
See Also:
scaleCopyToActualY(int[])

scaleToActualX

public int scaleToActualX(int x)
Scale x-coordinate from internal to actual screen-pixel coordinates. If not isScaled, return input.

Parameters:
x - x-coordinate to be scaled

scaleToActualY

public int scaleToActualY(int y)
Scale y-coordinate from internal to actual screen-pixel coordinates. If not isScaled, return input.

Parameters:
y - y-coordinate to be scaled

scaleFromActualX

public int scaleFromActualX(int x)
Convert an x-coordinate from actual-scaled to internal-scaled coordinates. If not isScaled, return input.

Parameters:
x - x-coordinate to be scaled

scaleFromActualY

public int scaleFromActualY(int y)
Convert a y-coordinate from actual-scaled to internal-scaled coordinates. If not isScaled, return input.

Parameters:
y - y-coordinate to be scaled

isScaled

public boolean isScaled()
Is the board is currently scaled larger than PANELX x PANELY pixels? If so, use scaleToActualX(int), scaleFromActualY(int), etc to convert between internal and actual screen pixel coordinates.

Returns:
Is the board scaled larger than default size?

updateMode

public void updateMode()
update the type of interaction mode


updateHoverTipToMode

protected void updateHoverTipToMode()

clearModeAndHilight

protected void clearModeAndHilight()

setPlayer

public void setPlayer()
set the player that is using this board panel.


setOtherPlayer

public void setOtherPlayer(SOCPlayer op)
set the other player

Parameters:
op - the other player

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Handle Events

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
DOCUMENT ME!

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - DOCUMENT ME!

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
DOCUMENT ME!

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - DOCUMENT ME!

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
DOCUMENT ME!

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - DOCUMENT ME!

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Mouse has left the panel; hide tooltip and any hovering piece.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - MouseEvent

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
DOCUMENT ME!

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - DOCUMENT ME!

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent evt)
DOCUMENT ME!

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
evt - DOCUMENT ME!

doBoardMenuPopup

protected void doBoardMenuPopup(int x,
                                int y)
Bring up the popup menu; called from mousePressed.

Parameters:
x - x-coordinate of click, actual screen pixels (not unscaled internal)
y - y-coordinate of click, actual screen pixels (not unscaled internal)

popupExpectingBuildRequest

public boolean popupExpectingBuildRequest()
If the client has used the board popup menu to request building a piece, this method is used in client network-receive message treatment.


popupSetBuildRequest

public void popupSetBuildRequest(int coord,
                                 int ptype)

popupClearBuildRequest

public void popupClearBuildRequest()

popupFireBuildingRequest

public void popupFireBuildingRequest()
Have received gamestate placing message; send the building request in reply.


findEdge

private final int findEdge(int x,
                           int y)
given a pixel on the board, find the edge that contains it

Parameters:
x - x coordinate, in unscaled board, not actual pixels; use scaleFromActualX(int) to convert
y - y coordinate, in unscaled board, not actual pixels
Returns:
the coordinates of the edge, or 0 if none

findNode

private final int findNode(int x,
                           int y)
given a pixel on the board, find the node that contains it

Parameters:
x - x coordinate, in unscaled board, not actual pixels; use scaleFromActualX(int) to convert
y - y coordinate, in unscaled board, not actual pixels
Returns:
the coordinates of the node, or 0 if none

findHex

private final int findHex(int x,
                          int y)
given a pixel on the board, find the hex that contains it

Parameters:
x - x coordinate, in unscaled board, not actual pixels; use scaleFromActualX(int) to convert
y - y coordinate, in unscaled board, not actual pixels
Returns:
the coordinates of the hex, or 0 if none

setMode

public void setMode(int m)
set the interaction mode

Parameters:
m - mode
See Also:
updateMode()

getMode

public int getMode()
get the interaction mode

Returns:
the mode

loadImages

private static void loadImages(java.awt.Component c)
load the images for the board we need to know if this board is in an applet or an application