net.sf.freecol.client.gui
Class GUI

java.lang.Object
  extended by net.sf.freecol.client.gui.GUI

public final class GUI
extends java.lang.Object

This class is responsible for drawing the map/background on the Canvas. In addition, the graphical state of the map (focus, active unit..) is also a responsibility of this class.


Nested Class Summary
(package private) static class GUI.GrayLayer
          Custom component to paint turn progress.
private  class GUI.IndicatorImageKey
          For performance reason, indicator images are rendered once and cached for reuse.
private  class GUI.StringImageKey
          For performance reason, string images are rendered once and cached for reuse.
 
Field Summary
private  Unit activeUnit
           
static int ALARM_OFFSET_X
           
static int ALARM_OFFSET_Y
           
private  boolean blinkingMarqueeEnabled
           
private  java.util.EnumMap<Map.Direction,java.awt.Dimension> borderPoints
           
private  java.awt.Stroke borderStroke
           
private  int bottomRow
           
private  int bottomRows
           
private  int bottomRowY
           
private  java.util.EnumMap<Map.Direction,java.awt.Dimension> controlPoints
           
private  PathNode currentPath
          A path to be displayed on the map.
private  TerrainCursor cursor
           
private  java.awt.Image cursorImage
           
 boolean debugShowMission
           
 boolean debugShowMissionInfo
           
 boolean displayColonyValue
           
 Player displayColonyValuePlayer
           
 boolean displayCoordinates
           
private  int displayTileText
           
private  Map.Position focus
           
static int FOREST_INDEX
           
private  FreeColClient freeColClient
           
private  PathNode gotoPath
           
private  boolean gotoStarted
           
private  GUI.GrayLayer greyLayer
           
private  java.awt.geom.GeneralPath gridPath
           
private  java.util.HashMap<GUI.IndicatorImageKey,java.awt.image.BufferedImage> indicatorImageCache
           
private  boolean inGame
          Indicates if the game has started, has nothing to do with whether or not the client is logged in.
private  int leftColumn
           
private  int leftColumnX
           
private  int leftSpace
           
private  ImageLibrary lib
          Scaled ImageLibrary only used for map painting.
private static java.util.logging.Logger logger
           
static int MAX_OTHER_UNITS
           
static int MESSAGE_AGE
           
static int MESSAGE_COUNT
           
private  java.util.Vector<GUIMessage> messages
           
static int MISSION_OFFSET_X
           
static int MISSION_OFFSET_Y
           
static int OTHER_UNITS_OFFSET_X
           
static int OTHER_UNITS_OFFSET_Y
           
static int OTHER_UNITS_WIDTH
           
static int OVERLAY_INDEX
           
private  int rightColumn
           
private  int rightSpace
           
static int RUMOUR_OFFSET_X
           
static int RUMOUR_OFFSET_Y
           
private  Map.Position selectedTile
           
private  java.awt.Dimension size
           
static int STATE_OFFSET_X
           
static int STATE_OFFSET_Y
           
private  java.util.HashMap<GUI.StringImageKey,java.awt.image.BufferedImage> stringImageCache
           
static int TEXT_OFFSET_X
           
static int TEXT_OFFSET_Y
           
private  int tileHeight
           
private  int tileWidth
           
private  int topRow
           
private  int topRows
           
private  int topRowY
           
private  int topSpace
           
static int UNIT_OFFSET
           
private  java.util.Map<Unit,java.lang.Integer> unitsOutForAnimation
           
private  java.util.Map<Unit,javax.swing.JLabel> unitsOutForAnimationLabels
           
private  ViewMode viewMode
           
 
Constructor Summary
GUI(FreeColClient freeColClient, java.awt.Dimension size, ImageLibrary lib)
          The constructor to use.
 
Method Summary
 void addMessage(GUIMessage message)
          Adds a message to the list of messages that need to be displayed on the GUI.
 Map.Position convertToMapCoordinates(int x, int y)
          Converts the given screen coordinates to Map coordinates.
private  java.awt.image.BufferedImage createSettlementNameImage(java.awt.Graphics g, Settlement settlement, int maxWidth, int preferredFontSize)
           
 java.awt.image.BufferedImage createStringImage(java.awt.Graphics2D g, java.lang.String nameString, java.awt.Color color, int maxWidth, int preferredFontSize)
          Creates an image with a string of a given color and with a black border around the glyphs.
private  java.awt.image.BufferedImage createStringImage(javax.swing.JComponent c, java.awt.Graphics g, java.lang.String nameString, java.awt.Color color, int maxWidth, int preferredFontSize)
          Creates an image with a string of a given color and with a black border around the glyphs.
 java.awt.image.BufferedImage createStringImage(javax.swing.JComponent c, java.lang.String nameString, java.awt.Color color, int maxWidth, int preferredFontSize)
          Creates an image with a string of a given color and with a black border around the glyphs.
 void display(java.awt.Graphics2D g)
          Displays this GUI onto the given Graphics2D.
private  void displayBaseTile(java.awt.Graphics2D g, Map map, Tile tile, int x, int y, boolean drawUnexploredBorders)
          Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates.
 void displayColonyTile(java.awt.Graphics2D g, Map map, Tile tile, int x, int y, Colony colony)
          Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates.
private  void displayFogOfWar(java.awt.Graphics2D g, Map map, Tile tile, int x, int y)
          Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates.
private  void displayGotoPath(java.awt.Graphics2D g, PathNode gotoPath)
           
private  void displayMap(java.awt.Graphics2D g)
          Displays the Map onto the given Graphics2D object.
 void displayOccupationIndicator(java.awt.Graphics g, Unit unit, int x, int y)
           
private  void displayOptionalValues(java.awt.Graphics2D g, Map map, Tile tile, int x, int y)
          Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates.
private  void displaySettlement(java.awt.Graphics2D g, Map map, Tile tile, int x, int y, boolean withNumber)
          Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates.
 void displayTerrain(java.awt.Graphics2D g, Map map, Tile tile, int x, int y)
          Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates.
 void displayTile(java.awt.Graphics2D g, Map map, Tile tile, int x, int y)
          Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates.
 void displayTile(java.awt.Graphics2D g, Map map, Tile tile, int x, int y, boolean drawUnexploredBorders)
          Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates.
private  void displayTileItems(java.awt.Graphics2D g, Map map, Tile tile, int x, int y)
          Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates.
private  void displayTileOverlays(java.awt.Graphics2D g, Map map, Tile tile, int x, int y, boolean drawUnexploredBorders, boolean withNumber)
          Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates.
private  void displayUnexploredBorders(java.awt.Graphics2D g, Map map, Tile tile, int x, int y)
          Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates.
private  void displayUnit(java.awt.Graphics2D g, Unit unit, int x, int y)
          Displays the given Unit onto the given Graphics2D object at the location specified by the coordinates.
private  void drawCursor(java.awt.Graphics2D g, int x, int y)
           
private  void drawItem(java.awt.Graphics2D g, Tile tile, TileItem item, int x, int y)
           
 void drawRoad(java.awt.Graphics2D g, long seed, int x1, int y1, int x2, int y2)
          Draws a road, between the given points, on the provided Graphics.
private  javax.swing.JLabel enterUnitOutForAnimation(Unit unit, Tile sourceTile)
           
 void executeWithUnitOutForAnimation(Unit unit, Tile sourceTile, OutForAnimationCallback r)
          Run some code with the given unit made invisible.
 void forceReposition()
          Force the next screen repaint to reposition the tiles on the window.
 Unit getActiveUnit()
          Gets the active unit.
 int getBreakingPoint(java.lang.String string)
          Breaks a line between two words.
 TerrainCursor getCursor()
           
 Map.Position getFocus()
          Gets the focus of the map.
private  java.awt.Color getForegroundColor(java.awt.Color background)
           
 PathNode getGotoPath()
          Gets the path to be drawn on the map.
 int getHeight()
          Returns the height of this GUI.
private  int getLeftColumns()
          Returns the amount of columns that are to the left of the Tile that is displayed in the center of the Map.
private  int getLeftColumns(int y)
          Returns the amount of columns that are to the left of the Tile with the given y-coordinate.
 float getMapScale()
          Get the current scale of the map.
 GUIMessage getMessage(int index)
          Gets the message at position 'index'.
 int getMessageCount()
          Gets the amount of message that are currently being displayed on this GUI.
private  java.awt.Image getOccupationIndicatorImage(Unit unit)
           
private  java.awt.Image getPathImage(Unit u)
          Gets an image to represent the path of the given Unit.
private  java.awt.Image getPathNextTurnImage(Unit u)
          Gets an image to represent the path of the given Unit.
private  int getRightColumns()
          Returns the amount of columns that are to the right of the Tile that is displayed in the center of the Map.
private  int getRightColumns(int y)
          Returns the amount of columns that are to the right of the Tile with the given y-coordinate.
 Map.Position getSelectedTile()
          Gets the selected tile.
private  java.awt.Color getStringBorderColor(java.awt.Color color)
           
 java.awt.Rectangle getTileBounds(int x, int y)
          Calculate the bounds of the rectangle containing a Tile on the screen, and return it.
 java.awt.Rectangle getTileBounds(Tile tile)
          Calculate the bounds of the rectangle containing a Tile on the screen, and return it.
 int getTileHeight()
           
 java.awt.Point getTilePosition(Tile t)
          Gets the position of the given Tile on the drawn map.
 int getTileWidth()
           
private  java.awt.Point getUnitImagePositionInTile(java.awt.Image unitImage, int tileX, int tileY)
          Gets the coordinates to draw a unit in a given tile.
private  java.awt.Point getUnitImagePositionInTile(int unitImageWidth, int unitImageHeight, int tileX, int tileY)
          Gets the coordinates to draw a unit in a given tile.
 Unit getUnitInFront(Tile unitTile)
          Gets the unit that should be displayed on the given tile.
private  javax.swing.JLabel getUnitLabel(Unit unit)
          Draw the unit's image and occupation indicator in one JLabel object.
 java.awt.Point getUnitLabelPositionInTile(javax.swing.JLabel unitLabel, java.awt.Point tileP)
          Gets the position where a unitLabel located at tile should be drawn.
 java.awt.Point getUnitLabelPositionInTile(javax.swing.JLabel unitLabel, Tile tile)
          Gets the position where a unitLabel located at tile should be drawn.
 ViewMode getViewMode()
          Get the View Mode object
 int getWidth()
          Returns the width of this GUI.
private  int getXOffset(int clipLeftX, int tileY)
           
 boolean isGotoStarted()
          Checks if there is currently a goto operation on the mapboard.
 boolean isInGame()
          Checks if the game has started.
 boolean isMapNearBottom(int y)
          Returns 'true' if the Tile is near the bottom.
 boolean isMapNearLeft(int x, int y)
          Returns 'true' if the Tile is near the left.
 boolean isMapNearRight(int x, int y)
          Returns 'true' if the Tile is near the right.
 boolean isMapNearTop(int y)
          Returns 'true' if the Tile is near the top.
private  boolean isOutForAnimation(Unit unit)
           
 void moveTileCursor(Map.Direction direction)
           
 boolean onScreen(int x, int y)
          Checks if the Tile/Units at the given coordinates are displayed on the screen (or, if the map is already displayed and the focus has been changed, whether they will be displayed on the screen the next time it'll be redrawn).
 boolean onScreen(Map.Position position)
          Checks if the Tile/Units at the given coordinates are displayed on the screen (or, if the map is already displayed and the focus has been changed, whether they will be displayed on the screen the next time it'll be redrawn).
private  void paintBorders(java.awt.Graphics2D g, Tile tile, int x, int y, boolean opaque)
           
private  void positionMap()
          Position the map so that the Tile at the focus location is displayed at the center.
private  void releaseUnitOutForAnimation(Unit unit)
           
 boolean removeOldMessages()
          Removes all the message that are older than MESSAGE_AGE.
 void restartBlinking()
           
 void scaleMap(float delta)
          Change the scale of the map by delta.
 void setActiveUnit(Unit activeUnit)
          Sets the active unit.
 void setDisplayTileText(DisplayTileTextAction.DisplayText tileTextType)
          Set the type of text drawn in the tiles.
 void setFocus(int x, int y)
          Sets the focus of the map.
 void setFocus(Map.Position focus)
          Sets the focus of the map.
 void setFocusImmediately(Map.Position focus)
          Sets the focus of the map and repaints the screen immediately.
 void setGotoPath(PathNode gotoPath)
          Sets the path to be drawn on the map.
private  void setImageLibrary(ImageLibrary lib)
           
 void setInGame(boolean inGame)
          Notifies this GUI that the game has started or ended.
 void setSelectedTile(Map.Position selectedTile)
          Selects the tile at the specified position, without clearing the orders of the first unit contained.
 void setSelectedTile(Map.Position selectedTile, boolean clearGoToOrders)
          Selects the tile at the specified position.
 void setSize(java.awt.Dimension size)
           
 void showColonyPanel(Map.Position selectedTile)
           
 void startCursorBlinking()
          Starts the unit-selection-cursor blinking animation.
 void startGoto()
          Starts a goto operation on the mapboard.
 void stopBlinking()
           
 void stopGoto()
          Stops any ongoing goto operation on the mapboard.
 void updateGotoPathForActiveUnit()
          Sets the path of the active unit to display it.
private  void updateMapDisplayVariables()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

freeColClient

private final FreeColClient freeColClient

size

private java.awt.Dimension size

lib

private ImageLibrary lib
Scaled ImageLibrary only used for map painting.


cursor

private TerrainCursor cursor

viewMode

private ViewMode viewMode

inGame

private boolean inGame
Indicates if the game has started, has nothing to do with whether or not the client is logged in.


messages

private final java.util.Vector<GUIMessage> messages

selectedTile

private Map.Position selectedTile

focus

private Map.Position focus

activeUnit

private Unit activeUnit

currentPath

private PathNode currentPath
A path to be displayed on the map.


gotoPath

private PathNode gotoPath

gotoStarted

private boolean gotoStarted

tileHeight

private int tileHeight

tileWidth

private int tileWidth

topSpace

private int topSpace

topRows

private int topRows

bottomRows

private int bottomRows

leftSpace

private int leftSpace

rightSpace

private int rightSpace

bottomRow

private int bottomRow

topRow

private int topRow

bottomRowY

private int bottomRowY

topRowY

private int topRowY

leftColumn

private int leftColumn

rightColumn

private int rightColumn

leftColumnX

private int leftColumnX

UNIT_OFFSET

public static final int UNIT_OFFSET
See Also:
Constant Field Values

TEXT_OFFSET_X

public static final int TEXT_OFFSET_X
See Also:
Constant Field Values

TEXT_OFFSET_Y

public static final int TEXT_OFFSET_Y
See Also:
Constant Field Values

STATE_OFFSET_X

public static final int STATE_OFFSET_X
See Also:
Constant Field Values

STATE_OFFSET_Y

public static final int STATE_OFFSET_Y
See Also:
Constant Field Values

ALARM_OFFSET_X

public static final int ALARM_OFFSET_X
See Also:
Constant Field Values

ALARM_OFFSET_Y

public static final int ALARM_OFFSET_Y
See Also:
Constant Field Values

RUMOUR_OFFSET_X

public static final int RUMOUR_OFFSET_X
See Also:
Constant Field Values

RUMOUR_OFFSET_Y

public static final int RUMOUR_OFFSET_Y
See Also:
Constant Field Values

MISSION_OFFSET_X

public static final int MISSION_OFFSET_X
See Also:
Constant Field Values

MISSION_OFFSET_Y

public static final int MISSION_OFFSET_Y
See Also:
Constant Field Values

OTHER_UNITS_OFFSET_X

public static final int OTHER_UNITS_OFFSET_X
See Also:
Constant Field Values

OTHER_UNITS_OFFSET_Y

public static final int OTHER_UNITS_OFFSET_Y
See Also:
Constant Field Values

OTHER_UNITS_WIDTH

public static final int OTHER_UNITS_WIDTH
See Also:
Constant Field Values

MAX_OTHER_UNITS

public static final int MAX_OTHER_UNITS
See Also:
Constant Field Values

MESSAGE_COUNT

public static final int MESSAGE_COUNT
See Also:
Constant Field Values

MESSAGE_AGE

public static final int MESSAGE_AGE
See Also:
Constant Field Values

OVERLAY_INDEX

public static final int OVERLAY_INDEX
See Also:
Constant Field Values

FOREST_INDEX

public static final int FOREST_INDEX
See Also:
Constant Field Values

displayTileText

private int displayTileText

gridPath

private java.awt.geom.GeneralPath gridPath

displayCoordinates

public boolean displayCoordinates

displayColonyValue

public boolean displayColonyValue

displayColonyValuePlayer

public Player displayColonyValuePlayer

debugShowMission

public boolean debugShowMission

debugShowMissionInfo

public boolean debugShowMissionInfo

blinkingMarqueeEnabled

private volatile boolean blinkingMarqueeEnabled

cursorImage

private java.awt.Image cursorImage

greyLayer

private GUI.GrayLayer greyLayer

unitsOutForAnimation

private java.util.Map<Unit,java.lang.Integer> unitsOutForAnimation

unitsOutForAnimationLabels

private java.util.Map<Unit,javax.swing.JLabel> unitsOutForAnimationLabels

borderPoints

private java.util.EnumMap<Map.Direction,java.awt.Dimension> borderPoints

controlPoints

private java.util.EnumMap<Map.Direction,java.awt.Dimension> controlPoints

borderStroke

private java.awt.Stroke borderStroke

stringImageCache

private java.util.HashMap<GUI.StringImageKey,java.awt.image.BufferedImage> stringImageCache

indicatorImageCache

private java.util.HashMap<GUI.IndicatorImageKey,java.awt.image.BufferedImage> indicatorImageCache
Constructor Detail

GUI

public GUI(FreeColClient freeColClient,
           java.awt.Dimension size,
           ImageLibrary lib)
The constructor to use.

Parameters:
freeColClient - The main control class.
size - The size of the GUI (= the entire screen if the app is displayed in full-screen).
lib - The library of images needed to display certain things visually.
Method Detail

setImageLibrary

private void setImageLibrary(ImageLibrary lib)

isOutForAnimation

private boolean isOutForAnimation(Unit unit)

executeWithUnitOutForAnimation

public void executeWithUnitOutForAnimation(Unit unit,
                                           Tile sourceTile,
                                           OutForAnimationCallback r)
Run some code with the given unit made invisible. You can nest several of these method calls in order to hide multiple units. There are no problems related to nested calls with the same unit.

Parameters:
unit - The unit to be hidden.
r - The code to be executed.

enterUnitOutForAnimation

private javax.swing.JLabel enterUnitOutForAnimation(Unit unit,
                                                    Tile sourceTile)

releaseUnitOutForAnimation

private void releaseUnitOutForAnimation(Unit unit)

getUnitLabel

private javax.swing.JLabel getUnitLabel(Unit unit)
Draw the unit's image and occupation indicator in one JLabel object.

Parameters:
unit - The unit to be drawn
Returns:
A JLabel object with the unit's image.

updateMapDisplayVariables

private void updateMapDisplayVariables()

getViewMode

public ViewMode getViewMode()
Get the View Mode object

Returns:
the current view mode.

startCursorBlinking

public void startCursorBlinking()
Starts the unit-selection-cursor blinking animation.


getCursor

public TerrainCursor getCursor()

setSize

public void setSize(java.awt.Dimension size)

moveTileCursor

public void moveTileCursor(Map.Direction direction)

setSelectedTile

public void setSelectedTile(Map.Position selectedTile)
Selects the tile at the specified position, without clearing the orders of the first unit contained.

Parameters:
selectedTile - The Position of the tile to be selected.
See Also:
setSelectedTile(Map.Position, boolean)

setSelectedTile

public void setSelectedTile(Map.Position selectedTile,
                            boolean clearGoToOrders)
Selects the tile at the specified position. There are three possible cases:
  1. If there is a Colony on the Tile the Canvas.showColonyPanel(net.sf.freecol.common.model.Colony) will be invoked.
  2. If the tile contains a unit that can become active, then that unit will be set as the active unit, and clear their goto orders if clearGoToOrders is true
  3. If the two conditions above do not match, then the selectedTile will become the map focus.
If a unit is active and is located on the selected tile, then nothing (except perhaps a map reposition) will happen.

Parameters:
selectedTile - The Position of the tile to be selected.
clearGoToOrders - Use true to clear goto orders of the unit which is activated.
See Also:
getSelectedTile(), setActiveUnit(net.sf.freecol.common.model.Unit), setFocus(Map.Position)

showColonyPanel

public void showColonyPanel(Map.Position selectedTile)

restartBlinking

public void restartBlinking()

stopBlinking

public void stopBlinking()

getUnitInFront

public Unit getUnitInFront(Tile unitTile)
Gets the unit that should be displayed on the given tile.

Parameters:
unitTile - The Tile.
Returns:
The Unit or null if no unit applies.

getSelectedTile

public Map.Position getSelectedTile()
Gets the selected tile.

Returns:
The Position of that tile.
See Also:
setSelectedTile(Map.Position)

getActiveUnit

public Unit getActiveUnit()
Gets the active unit.

Returns:
The Unit.
See Also:
setActiveUnit(net.sf.freecol.common.model.Unit)

setActiveUnit

public void setActiveUnit(Unit activeUnit)
Sets the active unit. Invokes setSelectedTile(Map.Position) if the selected tile is another tile than where the activeUnit is located.

Parameters:
activeUnit - The new active unit.
See Also:
setSelectedTile(Map.Position)

getFocus

public Map.Position getFocus()
Gets the focus of the map. That is the center tile of the displayed map.

Returns:
The Position of the center tile of the displayed map
See Also:
setFocus(Map.Position)

setFocus

public void setFocus(Map.Position focus)
Sets the focus of the map.

Parameters:
focus - The Position of the center tile of the displayed map.
See Also:
getFocus()

setFocusImmediately

public void setFocusImmediately(Map.Position focus)
Sets the focus of the map and repaints the screen immediately.

Parameters:
focus - The Position of the center tile of the displayed map.
See Also:
getFocus()

setFocus

public void setFocus(int x,
                     int y)
Sets the focus of the map.

Parameters:
x - The x-coordinate of the center tile of the displayed map.
y - The x-coordinate of the center tile of the displayed map.
See Also:
getFocus()

getMessageCount

public int getMessageCount()
Gets the amount of message that are currently being displayed on this GUI.

Returns:
The amount of message that are currently being displayed on this GUI.

getMessage

public GUIMessage getMessage(int index)
Gets the message at position 'index'. The message at position 0 is the oldest message and is most likely to be removed during the next call of removeOldMessages(). The higher the index of a message, the more recently it was added.

Parameters:
index - The index of the message to return.
Returns:
The message at position 'index'.

addMessage

public void addMessage(GUIMessage message)
Adds a message to the list of messages that need to be displayed on the GUI.

Parameters:
message - The message to add.

removeOldMessages

public boolean removeOldMessages()
Removes all the message that are older than MESSAGE_AGE.

Returns:
'true' if at least one message has been removed, 'false' otherwise. This can be useful to see if it is necessary to refresh the screen.

getWidth

public int getWidth()
Returns the width of this GUI.

Returns:
The width of this GUI.

getHeight

public int getHeight()
Returns the height of this GUI.

Returns:
The height of this GUI.

display

public void display(java.awt.Graphics2D g)
Displays this GUI onto the given Graphics2D.

Parameters:
g - The Graphics2D on which to display this GUI.

getLeftColumns

private int getLeftColumns()
Returns the amount of columns that are to the left of the Tile that is displayed in the center of the Map.

Returns:
The amount of columns that are to the left of the Tile that is displayed in the center of the Map.

getLeftColumns

private int getLeftColumns(int y)
Returns the amount of columns that are to the left of the Tile with the given y-coordinate.

Parameters:
y - The y-coordinate of the Tile in question.
Returns:
The amount of columns that are to the left of the Tile with the given y-coordinate.

getRightColumns

private int getRightColumns()
Returns the amount of columns that are to the right of the Tile that is displayed in the center of the Map.

Returns:
The amount of columns that are to the right of the Tile that is displayed in the center of the Map.

getRightColumns

private int getRightColumns(int y)
Returns the amount of columns that are to the right of the Tile with the given y-coordinate.

Parameters:
y - The y-coordinate of the Tile in question.
Returns:
The amount of columns that are to the right of the Tile with the given y-coordinate.

positionMap

private void positionMap()
Position the map so that the Tile at the focus location is displayed at the center.


displayGotoPath

private void displayGotoPath(java.awt.Graphics2D g,
                             PathNode gotoPath)

getXOffset

private int getXOffset(int clipLeftX,
                       int tileY)

displayMap

private void displayMap(java.awt.Graphics2D g)
Displays the Map onto the given Graphics2D object. The Tile at location (x, y) is displayed in the center.

Parameters:
g - The Graphics2D object on which to draw the Map.

getPathImage

private java.awt.Image getPathImage(Unit u)
Gets an image to represent the path of the given Unit.

Parameters:
u - The Unit
Returns:
The Image.

getPathNextTurnImage

private java.awt.Image getPathNextTurnImage(Unit u)
Gets an image to represent the path of the given Unit.

Parameters:
u - The Unit
Returns:
The Image.

createStringImage

public java.awt.image.BufferedImage createStringImage(java.awt.Graphics2D g,
                                                      java.lang.String nameString,
                                                      java.awt.Color color,
                                                      int maxWidth,
                                                      int preferredFontSize)
Creates an image with a string of a given color and with a black border around the glyphs.

Parameters:
g - A Graphics-object for getting a Font.
nameString - The String to make an image of.
color - The Color to use when displaying the nameString.
maxWidth - The maximum width of the image. The size of the Font will be adjusted if the image gets larger than this value.
preferredFontSize - The preferred font size.
Returns:
The image that was created.

createStringImage

public java.awt.image.BufferedImage createStringImage(javax.swing.JComponent c,
                                                      java.lang.String nameString,
                                                      java.awt.Color color,
                                                      int maxWidth,
                                                      int preferredFontSize)
Creates an image with a string of a given color and with a black border around the glyphs.

Parameters:
c - A JComponent-object for getting a Font.
nameString - The String to make an image of.
color - The Color to use when displaying the nameString.
maxWidth - The maximum width of the image. The size of the Font will be adjusted if the image gets larger than this value.
preferredFontSize - The preferred font size.
Returns:
The image that was created.

createStringImage

private java.awt.image.BufferedImage createStringImage(javax.swing.JComponent c,
                                                       java.awt.Graphics g,
                                                       java.lang.String nameString,
                                                       java.awt.Color color,
                                                       int maxWidth,
                                                       int preferredFontSize)
Creates an image with a string of a given color and with a black border around the glyphs.

Parameters:
c - A JComponent-object for getting a Font.
g - A Graphics-object for getting a Font.
nameString - The String to make an image of.
color - The Color to use when displaying the nameString.
maxWidth - The maximum width of the image. The size of the Font will be adjusted if the image gets larger than this value.
preferredFontSize - The preferred font size.
Returns:
The image that was created.

createSettlementNameImage

private java.awt.image.BufferedImage createSettlementNameImage(java.awt.Graphics g,
                                                               Settlement settlement,
                                                               int maxWidth,
                                                               int preferredFontSize)

drawRoad

public void drawRoad(java.awt.Graphics2D g,
                     long seed,
                     int x1,
                     int y1,
                     int x2,
                     int y2)
Draws a road, between the given points, on the provided Graphics. When you provide the same seed you will get the same road.

Parameters:
g - The Graphics to draw the road upon.
seed - The seed of the random generator that is creating the road.
x1 - The x-component of the first coordinate.
y1 - The y-component of the first coordinate.
x2 - The x-component of the second coordinate.
y2 - The y-component of the second coordinate.

displayColonyTile

public void displayColonyTile(java.awt.Graphics2D g,
                              Map map,
                              Tile tile,
                              int x,
                              int y,
                              Colony colony)
Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates. The visualization of the Tile also includes information from the corresponding ColonyTile from the given Colony.

Parameters:
g - The Graphics2D object on which to draw the Tile.
map - The Map.
tile - The Tile to draw.
x - The x-coordinate of the location where to draw the Tile (in pixels).
y - The y-coordinate of the location where to draw the Tile (in pixels).
colony - The Colony to create the visualization of the Tile for. This object is also used to get the ColonyTile for the given Tile.

displayTerrain

public void displayTerrain(java.awt.Graphics2D g,
                           Map map,
                           Tile tile,
                           int x,
                           int y)
Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates. Draws the terrain and improvements. Doesn't draw settlements, lost city rumours, fog of war, optional values neither units.

The same as calling displayTile(g, map, tile, x, y, true);.

Parameters:
g - The Graphics2D object on which to draw the Tile.
map - The map.
tile - The Tile to draw.
x - The x-coordinate of the location where to draw the Tile (in pixels).
y - The y-coordinate of the location where to draw the Tile (in pixels).

displayTile

public void displayTile(java.awt.Graphics2D g,
                        Map map,
                        Tile tile,
                        int x,
                        int y)
Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates. Everything located on the Tile will also be drawn except for units because their image can be larger than a Tile.

The same as calling displayTile(g, map, tile, x, y, true);.

Parameters:
g - The Graphics2D object on which to draw the Tile.
map - The map.
tile - The Tile to draw.
x - The x-coordinate of the location where to draw the Tile (in pixels).
y - The y-coordinate of the location where to draw the Tile (in pixels).

displayTile

public void displayTile(java.awt.Graphics2D g,
                        Map map,
                        Tile tile,
                        int x,
                        int y,
                        boolean drawUnexploredBorders)
Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates. Everything located on the Tile will also be drawn except for units because their image can be larger than a Tile.

Parameters:
g - The Graphics2D object on which to draw the Tile.
map - The map.
tile - The Tile to draw.
x - The x-coordinate of the location where to draw the Tile (in pixels).
y - The y-coordinate of the location where to draw the Tile (in pixels).
drawUnexploredBorders - If true; draws border between explored and unexplored terrain.

displayBaseTile

private void displayBaseTile(java.awt.Graphics2D g,
                             Map map,
                             Tile tile,
                             int x,
                             int y,
                             boolean drawUnexploredBorders)
Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates. Only base terrain will be drawn.

Parameters:
g - The Graphics2D object on which to draw the Tile.
map - The map.
tile - The Tile to draw.
x - The x-coordinate of the location where to draw the Tile (in pixels).
y - The y-coordinate of the location where to draw the Tile (in pixels).
drawUnexploredBorders - If true; draws border between explored and unexplored terrain.

paintBorders

private void paintBorders(java.awt.Graphics2D g,
                          Tile tile,
                          int x,
                          int y,
                          boolean opaque)

displayTileOverlays

private void displayTileOverlays(java.awt.Graphics2D g,
                                 Map map,
                                 Tile tile,
                                 int x,
                                 int y,
                                 boolean drawUnexploredBorders,
                                 boolean withNumber)
Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates. Everything located on the Tile will also be drawn except for units because their image can be larger than a Tile.

Parameters:
g - The Graphics2D object on which to draw the Tile.
map - The map.
tile - The Tile to draw.
x - The x-coordinate of the location where to draw the Tile (in pixels).
y - The y-coordinate of the location where to draw the Tile (in pixels).
drawUnexploredBorders - If true; draws border between explored and unexplored terrain.
withNumber - indicates if the number of inhabitants should be drawn too.

displayTileItems

private void displayTileItems(java.awt.Graphics2D g,
                              Map map,
                              Tile tile,
                              int x,
                              int y)
Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates. Addtions and improvements to Tile will be drawn.

Parameters:
g - The Graphics2D object on which to draw the Tile.
map - The map.
tile - The Tile to draw.
x - The x-coordinate of the location where to draw the Tile (in pixels).
y - The y-coordinate of the location where to draw the Tile (in pixels).

drawItem

private void drawItem(java.awt.Graphics2D g,
                      Tile tile,
                      TileItem item,
                      int x,
                      int y)

displaySettlement

private void displaySettlement(java.awt.Graphics2D g,
                               Map map,
                               Tile tile,
                               int x,
                               int y,
                               boolean withNumber)
Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates. Settlements and Lost City Rumours will be shown.

Parameters:
g - The Graphics2D object on which to draw the Tile.
map - The map.
tile - The Tile to draw.
x - The x-coordinate of the location where to draw the Tile (in pixels).
y - The y-coordinate of the location where to draw the Tile (in pixels).

displayFogOfWar

private void displayFogOfWar(java.awt.Graphics2D g,
                             Map map,
                             Tile tile,
                             int x,
                             int y)
Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates. Fog of war will be drawn.

Parameters:
g - The Graphics2D object on which to draw the Tile.
map - The map.
tile - The Tile to draw.
x - The x-coordinate of the location where to draw the Tile (in pixels).
y - The y-coordinate of the location where to draw the Tile (in pixels).

displayUnexploredBorders

private void displayUnexploredBorders(java.awt.Graphics2D g,
                                      Map map,
                                      Tile tile,
                                      int x,
                                      int y)
Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates. Borders next to unexplored tiles will be drawn differently.

Parameters:
g - The Graphics2D object on which to draw the Tile.
map - The map.
tile - The Tile to draw.
x - The x-coordinate of the location where to draw the Tile (in pixels).
y - The y-coordinate of the location where to draw the Tile (in pixels).

displayOptionalValues

private void displayOptionalValues(java.awt.Graphics2D g,
                                   Map map,
                                   Tile tile,
                                   int x,
                                   int y)
Displays the given Tile onto the given Graphics2D object at the location specified by the coordinates. Show tile names, coordinates and colony values.

Parameters:
g - The Graphics2D object on which to draw the Tile.
map - The map.
tile - The Tile to draw.
x - The x-coordinate of the location where to draw the Tile (in pixels).
y - The y-coordinate of the location where to draw the Tile (in pixels).

stopGoto

public void stopGoto()
Stops any ongoing goto operation on the mapboard.


startGoto

public void startGoto()
Starts a goto operation on the mapboard.


isGotoStarted

public boolean isGotoStarted()
Checks if there is currently a goto operation on the mapboard.

Returns:
true if a goto operation is in progress.

updateGotoPathForActiveUnit

public void updateGotoPathForActiveUnit()
Sets the path of the active unit to display it.


setGotoPath

public void setGotoPath(PathNode gotoPath)
Sets the path to be drawn on the map.

Parameters:
gotoPath - The path that should be drawn on the map or null if no path should be drawn.

getGotoPath

public PathNode getGotoPath()
Gets the path to be drawn on the map.

Returns:
The path that should be drawn on the map or null if no path should be drawn.

setDisplayTileText

public void setDisplayTileText(DisplayTileTextAction.DisplayText tileTextType)
Set the type of text drawn in the tiles.

Parameters:
tileTextType - a DisplayText value

getBreakingPoint

public int getBreakingPoint(java.lang.String string)
Breaks a line between two words. The breaking point is as close to the center as possible.

Parameters:
string - The line for which we should determine a breaking point.
Returns:
The best breaking point or -1 if there are none.

getOccupationIndicatorImage

private java.awt.Image getOccupationIndicatorImage(Unit unit)

getForegroundColor

private java.awt.Color getForegroundColor(java.awt.Color background)

getStringBorderColor

private java.awt.Color getStringBorderColor(java.awt.Color color)

displayOccupationIndicator

public void displayOccupationIndicator(java.awt.Graphics g,
                                       Unit unit,
                                       int x,
                                       int y)

displayUnit

private void displayUnit(java.awt.Graphics2D g,
                         Unit unit,
                         int x,
                         int y)
Displays the given Unit onto the given Graphics2D object at the location specified by the coordinates.

Parameters:
g - The Graphics2D object on which to draw the Unit.
unit - The Unit to draw.
x - The x-coordinate of the location where to draw the Unit (in pixels). These are the coordinates of the Tile on which the Unit is located.
y - The y-coordinate of the location where to draw the Unit (in pixels). These are the coordinates of the Tile on which the Unit is located.

getUnitImagePositionInTile

private java.awt.Point getUnitImagePositionInTile(java.awt.Image unitImage,
                                                  int tileX,
                                                  int tileY)
Gets the coordinates to draw a unit in a given tile.

Parameters:
unitImage - The unit's image
tileX - The X coordinate of the tile
tileY - The Y coordinate of the tile
Returns:
The coordinates where the unit should be drawn onscreen

getUnitImagePositionInTile

private java.awt.Point getUnitImagePositionInTile(int unitImageWidth,
                                                  int unitImageHeight,
                                                  int tileX,
                                                  int tileY)
Gets the coordinates to draw a unit in a given tile.

Parameters:
unitImageWidth - The unit image's width
unitImageHeight - The unit image's height
tileX - The X coordinate of the tile
tileY - The Y coordinate of the tile
Returns:
The coordinates where the unit should be drawn onscreen

getUnitLabelPositionInTile

public java.awt.Point getUnitLabelPositionInTile(javax.swing.JLabel unitLabel,
                                                 Tile tile)
Gets the position where a unitLabel located at tile should be drawn.

Parameters:
unitLabel - The unit label with the unit's image and occupation indicator drawn.
tile - The tile where the unitLabel will be drawn over
Returns:
The position where to put the label, null if the Tile is offscreen.

getUnitLabelPositionInTile

public java.awt.Point getUnitLabelPositionInTile(javax.swing.JLabel unitLabel,
                                                 java.awt.Point tileP)
Gets the position where a unitLabel located at tile should be drawn.

Parameters:
unitLabel - The unit label with the unit's image and occupation indicator drawn.
tileP - The position of the Tile on the screen.
Returns:
The position where to put the label, null if tileP is null.

drawCursor

private void drawCursor(java.awt.Graphics2D g,
                        int x,
                        int y)

setInGame

public void setInGame(boolean inGame)
Notifies this GUI that the game has started or ended.

Parameters:
inGame - Indicates whether or not the game has started.

isInGame

public boolean isInGame()
Checks if the game has started.

Returns:
true if the game has started.
See Also:
setInGame(boolean)

onScreen

public boolean onScreen(int x,
                        int y)
Checks if the Tile/Units at the given coordinates are displayed on the screen (or, if the map is already displayed and the focus has been changed, whether they will be displayed on the screen the next time it'll be redrawn).

Parameters:
x - The x-coordinate of the Tile in question.
y - The y-coordinate of the Tile in question.
Returns:
'true' if the Tile will be drawn on the screen, 'false' otherwise.

onScreen

public boolean onScreen(Map.Position position)
Checks if the Tile/Units at the given coordinates are displayed on the screen (or, if the map is already displayed and the focus has been changed, whether they will be displayed on the screen the next time it'll be redrawn).

Parameters:
position - The position of the Tile in question.
Returns:
true if the Tile will be drawn on the screen, false otherwise.

convertToMapCoordinates

public Map.Position convertToMapCoordinates(int x,
                                            int y)
Converts the given screen coordinates to Map coordinates. It checks to see to which Tile the given pixel 'belongs'.

Parameters:
x - The x-coordinate in pixels.
y - The y-coordinate in pixels.
Returns:
The map coordinates of the Tile that is located at the given position on the screen.

isMapNearTop

public boolean isMapNearTop(int y)
Returns 'true' if the Tile is near the top.

Parameters:
y - The y-coordinate of a Tile.
Returns:
'true' if the Tile is near the top.

isMapNearBottom

public boolean isMapNearBottom(int y)
Returns 'true' if the Tile is near the bottom.

Parameters:
y - The y-coordinate of a Tile.
Returns:
'true' if the Tile is near the bottom.

isMapNearLeft

public boolean isMapNearLeft(int x,
                             int y)
Returns 'true' if the Tile is near the left.

Parameters:
x - The x-coordinate of a Tile.
y - The y-coordinate of a Tile.
Returns:
'true' if the Tile is near the left.

isMapNearRight

public boolean isMapNearRight(int x,
                              int y)
Returns 'true' if the Tile is near the right.

Parameters:
x - The x-coordinate of a Tile.
y - The y-coordinate of a Tile.
Returns:
'true' if the Tile is near the right.

getMapScale

public float getMapScale()
Get the current scale of the map.

Returns:
a float value

scaleMap

public void scaleMap(float delta)
Change the scale of the map by delta.

Parameters:
delta - a float value

getTilePosition

public java.awt.Point getTilePosition(Tile t)
Gets the position of the given Tile on the drawn map.

Parameters:
t - The Tile.
Returns:
The position of the given Tile, or null if the Tile is not drawn on the mapboard.

getTileBounds

public java.awt.Rectangle getTileBounds(Tile tile)
Calculate the bounds of the rectangle containing a Tile on the screen, and return it. If the Tile is not on-screen a maximal rectangle is returned. The bounds includes a one-tile padding area above the Tile, to include the space needed by any units in the Tile.

Parameters:
tile - The tile on the screen.
Returns:
The bounds rectangle

getTileBounds

public java.awt.Rectangle getTileBounds(int x,
                                        int y)
Calculate the bounds of the rectangle containing a Tile on the screen, and return it. If the Tile is not on-screen a maximal rectangle is returned. The bounds includes a one-tile padding area above the Tile, to include the space needed by any units in the Tile.

Parameters:
x - The x-coordinate of the Tile
y - The y-coordinate of the Tile
Returns:
The bounds rectangle

forceReposition

public void forceReposition()
Force the next screen repaint to reposition the tiles on the window.


getTileHeight

public int getTileHeight()

getTileWidth

public int getTileWidth()