public final class MapViewer
extends java.lang.Object
Canvas
.
In addition, the graphical state of the map (focus, active unit..)
is currently handled by this class.Modifier and Type | Class and Description |
---|---|
private static class |
MapViewer.BorderType |
private static class |
MapViewer.TextSpecification |
Modifier and Type | Field and Description |
---|---|
private Unit |
activeUnit |
private boolean |
alignedBottom |
private boolean |
alignedLeft |
private boolean |
alignedRight |
private boolean |
alignedTop |
private java.util.EnumMap<Direction,java.awt.geom.Point2D.Float> |
borderPoints |
private java.awt.Stroke |
borderStroke |
private int |
bottomRow |
private int |
bottomRows |
private int |
bottomRowY |
private java.util.EnumMap<Direction,java.awt.geom.Point2D.Float> |
controlPoints |
private PathNode |
currentPath
A path to be displayed on the map.
|
private TerrainCursor |
cursor |
private Tile |
focus |
private FreeColClient |
freeColClient |
private PathNode |
gotoPath
A path for a current goto order.
|
private boolean |
gotoStarted |
private java.awt.Stroke |
gridStroke |
private SwingGUI |
gui |
private int |
halfHeight |
private int |
halfWidth |
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 |
private static float |
MAP_SCALE_MAX |
private static float |
MAP_SCALE_MIN |
private static float |
MAP_SCALE_STEP |
private static int |
MAX_OTHER_UNITS |
private static int |
OTHER_UNITS_OFFSET_X |
private static int |
OTHER_UNITS_OFFSET_Y |
private static int |
OTHER_UNITS_WIDTH |
private int |
rightColumn |
private int |
rightSpace |
private Tile |
selectedTile |
private java.awt.Dimension |
size |
private int |
tileHeight |
private int |
tileWidth |
private int |
topRow |
private int |
topRows |
private int |
topRowY |
private int |
topSpace |
private TileViewer |
tv |
private static int |
UNIT_OFFSET |
private java.util.Map<Unit,java.lang.Integer> |
unitsOutForAnimation |
private java.util.Map<Unit,javax.swing.JLabel> |
unitsOutForAnimationLabels |
private int |
viewMode
The view mode in use.
|
Constructor and Description |
---|
MapViewer(FreeColClient freeColClient)
The constructor to use.
|
Modifier and Type | Method and Description |
---|---|
(package private) java.awt.Rectangle |
calculateTileBounds(Tile tile)
Calculate the bounds of the rectangle containing a Tile on the
screen, and return it.
|
(package private) java.awt.Point |
calculateTilePosition(Tile t)
Gets the position of the given
Tile
on the drawn map. |
private java.awt.Point |
calculateUnitImagePositionInTile(java.awt.image.BufferedImage unitImage)
Gets the coordinates to draw a unit in a given tile.
|
(package private) java.awt.Point |
calculateUnitLabelPositionInTile(int labelWidth,
int labelHeight,
java.awt.Point tileP)
Gets the position where a unitLabel located at tile should be drawn.
|
(package private) void |
centerActiveUnit()
Centers the map on the selected unit.
|
(package private) void |
changeViewMode(int newViewMode)
Change the view mode to a new one.
|
(package private) Tile |
convertToMapTile(int x,
int y)
Converts the given screen coordinates to Map coordinates.
|
private static java.awt.image.BufferedImage |
createCapitalLabel(int extent,
int padding,
java.awt.Color backgroundColor)
Draws the pentagram indicating a native capital.
|
private static java.awt.image.BufferedImage |
createLabel(java.awt.Graphics2D g,
MapViewer.TextSpecification[] textSpecs,
java.awt.Color backgroundColor)
Creates an BufferedImage that shows the given text centred on a
translucent rounded rectangle with the given color.
|
private static java.awt.image.BufferedImage |
createLabel(java.awt.Graphics2D g,
java.lang.String text,
java.awt.Font font,
java.awt.Color backgroundColor)
Creates an BufferedImage that shows the given text centred on a
translucent rounded rectangle with the given color.
|
private static java.awt.image.BufferedImage |
createReligiousMissionLabel(int extent,
int padding,
java.awt.Color backgroundColor,
boolean expertMissionary)
Draws a cross indicating a religious mission is present in the
native village.
|
private javax.swing.JLabel |
createUnitLabel(Unit unit)
Draw the unit's image and occupation indicator in one JLabel object.
|
(package private) void |
decreaseMapScale() |
private void |
displayCursor(java.awt.Graphics2D g) |
(package private) void |
displayMap(java.awt.Graphics2D g)
Displays the Map.
|
private void |
displayPath(java.awt.Graphics2D g,
PathNode path)
Display a path.
|
private void |
displaySettlementLabels(java.awt.Graphics2D g,
Settlement settlement,
Player player,
int colonyLabels,
java.awt.Font font,
java.awt.Font italicFont,
java.awt.Font productionFont) |
private void |
displayTerritorialBorders(java.awt.Graphics2D g,
Tile tile,
MapViewer.BorderType type,
boolean opaque)
Draws the borders of a territory on the given Tile.
|
private void |
displayUnit(java.awt.Graphics2D g,
Unit unit)
Displays the given Unit onto the given Graphics2D object at the
location specified by the coordinates.
|
private javax.swing.JLabel |
enterUnitOutForAnimation(Unit unit,
Tile sourceTile) |
(package private) void |
executeWithUnitOutForAnimation(Unit unit,
Tile sourceTile,
OutForAnimationCallback r)
Run some code with the given unit made invisible.
|
private Unit |
findUnitInFront(Tile unitTile)
Gets the unit that should be displayed on the given tile.
|
(package private) void |
forceReposition()
Force the next screen repaint to reposition the tiles on the window.
|
(package private) Unit |
getActiveUnit()
Gets the active unit.
|
(package private) Tile |
getFocus()
Gets the focus of the map.
|
(package private) PathNode |
getGotoPath()
Gets the path to be drawn on the map.
|
(package private) ImageLibrary |
getImageLibrary()
Gets the contained
ImageLibrary . |
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.
|
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.
|
(package private) Tile |
getSelectedTile()
Gets the selected tile.
|
(package private) int |
getTileWidth() |
(package private) int |
getViewMode()
Get the view mode.
|
(package private) void |
increaseMapScale() |
(package private) boolean |
isAtMaxMapScale() |
(package private) boolean |
isAtMinMapScale() |
(package private) boolean |
isGotoStarted()
Checks if there is currently a goto operation on the mapboard.
|
private boolean |
isMapNearBottom(int y)
Is a y-coordinate near the bottom?
|
private boolean |
isMapNearLeft(int x,
int y)
Is an x,y coordinate near the left?
|
private boolean |
isMapNearRight(int x,
int y)
Is an x,y coordinate near the right?
|
private boolean |
isMapNearTop(int y)
Is a y-coordinate near the top?
|
private boolean |
isOutForAnimation(Unit unit)
Returns true if the given Unit is being animated.
|
private boolean |
isTileVisible(Tile tile) |
(package private) boolean |
onScreen(Tile tileToCheck)
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 |
positionMap(Tile pos)
Position the map so that the supplied tile is displayed at the center.
|
private void |
releaseUnitOutForAnimation(Unit unit) |
private void |
repositionMapIfNeeded() |
(package private) void |
resetMapScale()
Reset the scale of the map to the default.
|
(package private) void |
restartBlinking() |
(package private) boolean |
scrollMap(Direction direction)
Scroll the map in the given direction.
|
(package private) boolean |
setActiveUnit(Unit activeUnit)
Sets the active unit.
|
(package private) void |
setCurrentPath(PathNode path)
Set the current active unit path.
|
(package private) void |
setFocus(Tile focus)
Sets the focus of the map.
|
(package private) void |
setGotoPath(PathNode gotoPath)
Sets the path to be drawn on the map.
|
private void |
setImageLibraryAndUpdateData(ImageLibrary lib)
Sets the ImageLibrary and calculates various items that depend
on tile size.
|
(package private) int |
setOffsetFocus(Tile tile)
Sets the focus of the map but offset to the left or right so
that the focus position can still be visible when a popup is
raised.
|
(package private) boolean |
setSelectedTile(Tile newTile)
Selects the tile at the specified position.
|
(package private) void |
setSize(java.awt.Dimension size) |
(package private) void |
startCursorBlinking()
Starts the unit-selection-cursor blinking animation.
|
(package private) void |
startGoto()
Starts a goto operation on the mapboard.
|
(package private) void |
stopBlinking() |
(package private) void |
stopGoto()
Stops any ongoing goto operation on the mapboard.
|
(package private) void |
toggleViewMode()
Toggle the current view mode.
|
(package private) void |
updateCurrentPathForActiveUnit()
Sets the path of the active unit to display it.
|
private void |
updateMapDisplayVariables() |
private static final java.util.logging.Logger logger
private final FreeColClient freeColClient
private final SwingGUI gui
private java.awt.Dimension size
private ImageLibrary lib
private final TileViewer tv
private TerrainCursor cursor
private Tile selectedTile
private Tile focus
private Unit activeUnit
private int viewMode
private PathNode currentPath
private PathNode gotoPath
private boolean gotoStarted
private int tileHeight
private int tileWidth
private int halfHeight
private int halfWidth
private int topSpace
private int topRows
private int bottomRows
private int leftSpace
private int rightSpace
private int bottomRow
private int topRow
private int bottomRowY
private int topRowY
private int leftColumn
private int rightColumn
private int leftColumnX
private boolean alignedTop
private boolean alignedBottom
private boolean alignedLeft
private boolean alignedRight
private static final float MAP_SCALE_MIN
private static final float MAP_SCALE_MAX
private static final float MAP_SCALE_STEP
private static final int UNIT_OFFSET
private static final int OTHER_UNITS_OFFSET_X
private static final int OTHER_UNITS_OFFSET_Y
private static final int OTHER_UNITS_WIDTH
private static final int MAX_OTHER_UNITS
private final java.util.Map<Unit,java.lang.Integer> unitsOutForAnimation
private final java.util.Map<Unit,javax.swing.JLabel> unitsOutForAnimationLabels
private final java.util.EnumMap<Direction,java.awt.geom.Point2D.Float> borderPoints
private final java.util.EnumMap<Direction,java.awt.geom.Point2D.Float> controlPoints
private java.awt.Stroke borderStroke
private java.awt.Stroke gridStroke
MapViewer(FreeColClient freeColClient)
freeColClient
- The FreeColClient
for the game.ImageLibrary getImageLibrary()
ImageLibrary
.int getViewMode()
void toggleViewMode()
void changeViewMode(int newViewMode)
newViewMode
- The new view mode.void centerActiveUnit()
Tile convertToMapTile(int x, int y)
x
- The x-coordinate in pixels.y
- The y-coordinate in pixels.void executeWithUnitOutForAnimation(Unit unit, Tile sourceTile, OutForAnimationCallback r)
unit
- The Unit
to be hidden.sourceTile
- The source Tile
.r
- The code to be executed.private javax.swing.JLabel enterUnitOutForAnimation(Unit unit, Tile sourceTile)
private void releaseUnitOutForAnimation(Unit unit)
private boolean isOutForAnimation(Unit unit)
unit
- an Unit
boolean
private javax.swing.JLabel createUnitLabel(Unit unit)
unit
- The unit to be drawnjava.awt.Rectangle calculateTileBounds(Tile tile)
tile
- The Tile
on the screen.Rectangle
.java.awt.Point calculateTilePosition(Tile t)
Tile
on the drawn map.t
- The Tile
to check.Tile
, or
null
if the Tile
is not drawn on
the mapboard.int getTileWidth()
java.awt.Point calculateUnitLabelPositionInTile(int labelWidth, int labelHeight, java.awt.Point tileP)
labelWidth
- The width of the unit label.labelHeight
- The width of the unit label.tileP
- The position of the Tile on the screen.boolean onScreen(Tile tileToCheck)
tileToCheck
- The position of the Tile in question.void startCursorBlinking()
void stopBlinking()
void restartBlinking()
Tile getFocus()
setFocus(Tile)
void setFocus(Tile focus)
focus
- The Position
of the center tile of the
displayed map.getFocus()
int setOffsetFocus(Tile tile)
tile
- The Tile
to display.getFocus()
void forceReposition()
private void repositionMapIfNeeded()
private void positionMap(Tile pos)
pos
- The Tile
to center at.boolean scrollMap(Direction direction)
direction
- The Direction
to scroll in.private boolean isMapNearBottom(int y)
y
- The y-coordinate.private boolean isMapNearLeft(int x, int y)
x
- The x-coordinate.y
- The y-coordinate.private boolean isMapNearRight(int x, int y)
x
- The x-coordinate.y
- The y-coordinate.private int getLeftColumns()
private int getLeftColumns(int y)
y
- The y-coordinate of the Tile in question.private int getRightColumns()
private int getRightColumns(int y)
y
- The y-coordinate of the Tile in question.private boolean isMapNearTop(int y)
y
- The y-coordinate.private boolean isTileVisible(Tile tile)
Tile getSelectedTile()
Tile
selected.boolean setSelectedTile(Tile newTile)
selectedTile
will become the map focus.
newTile
- The Tile
, the tile to be selectedgetSelectedTile()
,
setActiveUnit(net.sf.freecol.common.model.Unit)
,
setFocus(Tile)
private Unit findUnitInFront(Tile unitTile)
unitTile
- The Tile
to check.Unit
to display or null if none found.Unit getActiveUnit()
Unit
.setActiveUnit(net.sf.freecol.common.model.Unit)
boolean setActiveUnit(Unit activeUnit)
activeUnit
- The new active Unit
.boolean isGotoStarted()
void startGoto()
void stopGoto()
PathNode getGotoPath()
null
if no path should be drawn.void setGotoPath(PathNode gotoPath)
gotoPath
- The path that should be drawn on the map
or null
if no path should be drawn.void updateCurrentPathForActiveUnit()
void setCurrentPath(PathNode path)
path
- The current PathNode
.void setSize(java.awt.Dimension size)
void resetMapScale()
boolean isAtMaxMapScale()
boolean isAtMinMapScale()
void increaseMapScale()
void decreaseMapScale()
private void updateMapDisplayVariables()
private void setImageLibraryAndUpdateData(ImageLibrary lib)
lib
- an ImageLibrary
valuevoid displayMap(java.awt.Graphics2D g)
g
- The Graphics2D object on which to draw the Map.private void displaySettlementLabels(java.awt.Graphics2D g, Settlement settlement, Player player, int colonyLabels, java.awt.Font font, java.awt.Font italicFont, java.awt.Font productionFont)
private static java.awt.image.BufferedImage createCapitalLabel(int extent, int padding, java.awt.Color backgroundColor)
private static java.awt.image.BufferedImage createLabel(java.awt.Graphics2D g, java.lang.String text, java.awt.Font font, java.awt.Color backgroundColor)
g
- a Graphics2D
text
- a String
font
- a Font
backgroundColor
- a Color
BufferedImage
private static java.awt.image.BufferedImage createLabel(java.awt.Graphics2D g, MapViewer.TextSpecification[] textSpecs, java.awt.Color backgroundColor)
g
- a Graphics2D
textSpecs
- a TextSpecification
arraybackgroundColor
- a Color
BufferedImage
private static java.awt.image.BufferedImage createReligiousMissionLabel(int extent, int padding, java.awt.Color backgroundColor, boolean expertMissionary)
private void displayPath(java.awt.Graphics2D g, PathNode path)
g
- The Graphics2D
to display on.path
- The PathNode
to display.private void displayUnit(java.awt.Graphics2D g, Unit unit)
g
- The Graphics2D object on which to draw the Unit.unit
- The Unit to draw.private java.awt.Point calculateUnitImagePositionInTile(java.awt.image.BufferedImage unitImage)
unitImage
- The unit's imageprivate void displayCursor(java.awt.Graphics2D g)
private void displayTerritorialBorders(java.awt.Graphics2D g, Tile tile, MapViewer.BorderType type, boolean opaque)
g
- a Graphics2D
tile
- a Tile
type
- a BorderType
opaque
- a boolean