soc.client
Class SOCBoardPanel.BoardToolTip

java.lang.Object
  extended by soc.client.SOCBoardPanel.BoardToolTip
Enclosing class:
SOCBoardPanel

protected class SOCBoardPanel.BoardToolTip
extends java.lang.Object

(tooltip) Hover text for info on pieces/parts of the board. Its mode uses boardpanel mode constants: Will be NONE, PLACE_ROAD, PLACE_SETTLEMENT, PLACE_ROBBER for hex, or PLACE_INIT_SETTLEMENT for port. Also contains "hovering" road/settlement/city near mouse pointer, distinct from SOCBoardPanel.hilight.

Since:
1.1.00
Author:
jdmonin

Field Summary
private  int boxH
          Our size.
private  int boxW
          Our size.
private  int boxX
          Our position (upper-left of tooltip box)
private  int boxY
          Our position (upper-left of tooltip box)
private  SOCBoardPanel bpanel
           
(package private)  int hoverCityID
          hover settlement or city node ID, or 0.
private  int hoverID
          "ID" of coord as returned by findNode, findEdge, findHex
(package private)  boolean hoverIsPort
          Is hover a port at coordinate hoverID?
private  boolean hoverIsShipMovable
          Is hover a ship owned by our player, movable from its current position? If true, hoverShipID is also set.
private  boolean hoverIsWarship
          Is hover a warship owned by our player, for scenario option _SC_PIRI? If true, hoverShipID is also set.
private  int hoverMode
          Uses board mode constants: Will be NONE, PLACE_ROAD, PLACE_SHIP, PLACE_SETTLEMENT, PLACE_ROBBER for hex, or PLACE_INIT_SETTLEMENT for port.
private  SOCPlayingPiece hoverPiece
          Object last pointed at; null for hexes and ports
(package private)  int hoverRoadID
          hover road ID, or 0.
(package private)  int hoverSettlementID
          hover settlement or city node ID, or 0.
(package private)  int hoverShipID
          hover ship ID, or 0.
private  java.lang.String hoverText
          Text to hover-display, or null if nothing to show
private  int mouseX
          Mouse position
private  int mouseY
          Mouse position
private  int offsetX
          Requested X-offset from mouse pointer of tooltip box (used for robber placement)
private  int PADDING_HORIZ
           
private  boolean setHoverText_modeChangedOrMouseMoved
          Flag to tell setHoverText(String, int) to repaint, even if text hasn't changed.
private  int TEXT_INSET
           
 
Constructor Summary
SOCBoardPanel.BoardToolTip(SOCBoardPanel ourBoardPanel)
           
 
Method Summary
 java.lang.String getHoverText()
          Currently displayed text.
private  void handleHover(int x, int y)
          Mouse is hovering during normal play; look for info for tooltip text.
 void hideHoverAndPieces()
          Clear hover text, and cancel any hovering roads/settlements/cities.
 boolean isVisible()
          Is the hoverText tip non-null, or is any hover ID non-zero? (hoverRoadID, etc)
 void paint(java.awt.Graphics g)
          Draw; Graphics should be the boardpanel's gc, as seen in its paint method.
 java.lang.String portDescAtNode(int id)
          Check at this node coordinate for a port, and return its descriptive text.
 void positionToMouse(int x, int y)
          Show tooltip at appropriate location when mouse is at (x,y) relative to the board.
 void setHoverText(java.lang.String t, int coord)
          Set the hover text (tooltip) based on where the mouse is now, and repaint the board.
 void setHoverText(java.lang.String t, int coord, int x, int y)
          Set tooltip text (or hide tooltip if text is null) and show tooltip at appropriate location when mouse is at (x,y) relative to the board.
 void setOffsetX(int ofsX)
          Set the hover tip (tooltip) x-position, but don't repaint the board.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bpanel

private final SOCBoardPanel bpanel

hoverText

private java.lang.String hoverText
Text to hover-display, or null if nothing to show


hoverMode

private int hoverMode
Uses board mode constants: Will be NONE, PLACE_ROAD, PLACE_SHIP, PLACE_SETTLEMENT, PLACE_ROBBER for hex, or PLACE_INIT_SETTLEMENT for port. Updated in handleHover(int, int).


hoverID

private int hoverID
"ID" of coord as returned by findNode, findEdge, findHex


hoverPiece

private SOCPlayingPiece hoverPiece
Object last pointed at; null for hexes and ports


hoverRoadID

int hoverRoadID
hover road ID, or 0. Readonly please from outside this inner class. Drawn in paint(Graphics). value is -1 for a road at edge 0x00.

If both hoverRoadID and hoverShipID are non-zero, they must be the same coordinate, never different non-zero values.


hoverSettlementID

int hoverSettlementID
hover settlement or city node ID, or 0. Readonly please from outside this inner class. Drawn in paint(Graphics).


hoverCityID

int hoverCityID
hover settlement or city node ID, or 0. Readonly please from outside this inner class. Drawn in paint(Graphics).


hoverShipID

int hoverShipID
hover ship ID, or 0. Readonly please from outside this inner class. Drawn in paint(Graphics).

If both hoverRoadID and hoverShipID are non-zero, they must be the same coordinate, never different non-zero values.

When setting this field, also set or clear hoverIsWarship.

Since:
2.0.00

hoverIsPort

boolean hoverIsPort
Is hover a port at coordinate hoverID?

See Also:
SOCBoardPanel.PLACE_INIT_SETTLEMENT

hoverIsShipMovable

private boolean hoverIsShipMovable
Is hover a ship owned by our player, movable from its current position? If true, hoverShipID is also set.

Since:
2.0.00

hoverIsWarship

private boolean hoverIsWarship
Is hover a warship owned by our player, for scenario option _SC_PIRI? If true, hoverShipID is also set.

Since:
2.0.00

mouseX

private int mouseX
Mouse position


mouseY

private int mouseY
Mouse position


setHoverText_modeChangedOrMouseMoved

private boolean setHoverText_modeChangedOrMouseMoved
Flag to tell setHoverText(String, int) to repaint, even if text hasn't changed.

Since:
1.1.17

boxX

private int boxX
Our position (upper-left of tooltip box)


boxY

private int boxY
Our position (upper-left of tooltip box)


offsetX

private int offsetX
Requested X-offset from mouse pointer of tooltip box (used for robber placement)


boxW

private int boxW
Our size. If boxw == 0, also indicates need fontmetrics - will be set in paint().


boxH

private int boxH
Our size. If boxw == 0, also indicates need fontmetrics - will be set in paint().


TEXT_INSET

private final int TEXT_INSET
See Also:
Constant Field Values

PADDING_HORIZ

private final int PADDING_HORIZ
See Also:
Constant Field Values
Constructor Detail

SOCBoardPanel.BoardToolTip

SOCBoardPanel.BoardToolTip(SOCBoardPanel ourBoardPanel)
Method Detail

getHoverText

public java.lang.String getHoverText()
Currently displayed text.

Returns:
Tooltip text, or null if nothing.

isVisible

public boolean isVisible()
Is the hoverText tip non-null, or is any hover ID non-zero? (hoverRoadID, etc)


positionToMouse

public void positionToMouse(int x,
                            int y)
Show tooltip at appropriate location when mouse is at (x,y) relative to the board. Repaint the board.

Parameters:
x - x-coordinate of mouse, actual screen pixels (not unscaled internal)
y - y-coordinate of mouse, actual screen pixels (not unscaled internal)
See Also:
setHoverText(String, int), setHoverText(String, int, int, int)

setOffsetX

public void setOffsetX(int ofsX)
Set the hover tip (tooltip) x-position, but don't repaint the board. Used in robber placement.

Parameters:
ofsX - New offset

setHoverText

public void setHoverText(java.lang.String t,
                         int coord)
Set the hover text (tooltip) based on where the mouse is now, and repaint the board.

Calls positionToMouse(mouseX,mouseY).

Parameters:
t - Hover text contents, or null to clear that text (but not hovering pieces) and repaint. Do nothing if text is already equal to t, or if both are null.
coord - Cursor's board coordinates shown when "show coordinates" debug flag is set, or -1. Ignored if t is null. To show only the coordinate, use "" for t.
See Also:
setHoverText(String, int, int, int), hideHoverAndPieces(), SOCBoardPanel.setDebugShowCoordsFlag(boolean)

setHoverText

public void setHoverText(java.lang.String t,
                         int coord,
                         int x,
                         int y)
Set tooltip text (or hide tooltip if text is null) and show tooltip at appropriate location when mouse is at (x,y) relative to the board. Repaint the board.

Convenience method, calls positionToMouse(int, int) and setHoverText(String, int).

Parameters:
t - Hover text contents, or null to clear that text (but not hovering pieces) and repaint. Do nothing if text is already equal to t, or if both are null.
coord - Cursor's board coordinates shown when "show coordinates" debug flag is set, or -1. Ignored if t is null. To show only the coordinate, use "" for t.
x - x-coordinate of mouse, actual screen pixels (not unscaled internal)
y - y-coordinate of mouse, actual screen pixels (not unscaled internal)
Since:
2.0.00

hideHoverAndPieces

public void hideHoverAndPieces()
Clear hover text, and cancel any hovering roads/settlements/cities. Repaint the board. The next call to handleHover(int, int) will set up the hovering pieces/text for the current mode.


paint

public void paint(java.awt.Graphics g)
Draw; Graphics should be the boardpanel's gc, as seen in its paint method.


handleHover

private void handleHover(int x,
                         int y)
Mouse is hovering during normal play; look for info for tooltip text. Assumes x or y has changed since last call. Does not affect the "hilight" variable used by SOCBoardPanel during initial placement, and during placement from clicking "Buy" buttons.

If the board mode doesn't allow hovering pieces (ghost pieces), will clear hoverRoadID, hoverSettlementID, and hoverCityID to 0. Otherwise, these are set when the mouse is at a location where the player can build or upgrade, and they have resources to build.

Priority when hovering over a point on the board:

Parameters:
x - Cursor x, from upper-left of board: actual coordinates, not board-internal coordinates
y - Cursor y, from upper-left of board: actual coordinates, not board-internal coordinates

portDescAtNode

public java.lang.String portDescAtNode(int id)
Check at this node coordinate for a port, and return its descriptive text. Does not check for players' settlements or cities, only for the port.

Parameters:
id - Node coordinate ID for potential port
Returns:
String key with port text description for StringManager.get(String), or null if no port at that node id. Text format of string key's value is "3:1 Port" or "2:1 Wood port".