Package VASSAL.build.module
Class Map
- All Implemented Interfaces:
DropTargetListener
,MouseListener
,MouseMotionListener
,PropertyChangeListener
,EventListener
,AutoConfigurable
,Buildable
,Configurable
,GameComponent
,PlayerRoster.SideChangeListener
,MutablePropertiesContainer
,PropertyNameSource
,PropertySource
,ComponentDescription
,ValidityChecker
,Translatable
,Auditable
,ImageSearchTarget
,SearchTarget
,ToolBarComponent
,UniqueIdManager.Identifyable
- Direct Known Subclasses:
PrivateMap
,WidgetMap
public class Map
extends AbstractToolbarItem
implements GameComponent, MouseListener, MouseMotionListener, DropTargetListener, Configurable, UniqueIdManager.Identifyable, ToolBarComponent, MutablePropertiesContainer, PropertySource, PlayerRoster.SideChangeListener, ComponentDescription
The Map is the main component for displaying and containing
GamePiece
s during play. Pieces are displayed on
the map's Board
(s) and moved by clicking and dragging. Keyboard events are forwarded to selected pieces. Multiple
map windows are supported in a single game, with dragging between windows allowed.
To a map's Board
subcomponent(s), various forms of grid can be added: (ZonedGrid
(aka Multi-zone Grid),
HexGrid
, SquareGrid
(aka Rectangular Grid), and RegionGrid
(aka Irregular Grid). These can be used
to determine where pieces are allowed to move, and also for filling properties (e.g. LocationName, CurrentZone, CurrentBoard,
CurrentMap) to allow the module to keep track of pieces and react to their movements.
A Map may contain many different Buildable
subcomponents. Components which are addable uniquely to a Map are
contained in the VASSAL.build.module.map
package. Some of the most common Map subcomponents include
Zoomer
for Zoom Capability, CounterDetailViewer
aka Mouse-over Stack Viewer, HidePiecesButton
,
and SelectionHighlighters
.
Map also contain several critical subcomponents which are automatically added and are not configurable at the module level.
These include PieceMover
which handles dragging and dropping of pieces, KeyBufferer
which tracks which pieces
are currently "selected" and forwards key commands to them, MenuDisplayer
which listens for "right clicks" and provides
"context menu" services, and StackMetrics
which handles the "stacking" of game pieces.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Report format configurer for "modified on map"static class
Report format configurer for "created on map"static class
Autoconfigurer for map's icon used on its launch buttonstatic class
static class
static class
Report format configurer for "moved to map"static class
Report format configurer for "moved within map"static class
Autoconfigurer for mark-unmoved iconstatic class
Report format configurer for clear movement historystatic class
The (JPanel-extending) component that represents the map itselfNested classes/interfaces inherited from class VASSAL.build.AbstractToolbarItem
AbstractToolbarItem.FormattedStringConfig
Nested classes/interfaces inherited from interface VASSAL.build.AutoConfigurable
AutoConfigurable.Util
Nested classes/interfaces inherited from interface VASSAL.build.module.properties.MutablePropertiesContainer
MutablePropertiesContainer.Impl
-
Field Summary
Modifier and TypeFieldDescriptionstatic Map
static final String
protected boolean
static final String
protected Color
protected int[][]
protected int[][]
static final String
static final String
protected String
protected static boolean
protected boolean
static final String
protected String
protected static final String
protected static final String
protected static final String
protected String
static final String
protected DragGestureListener
protected int
protected int
static final String
static double
static final String
protected Dimension
static final String
protected boolean
protected NamedKeyStrokeListener
static final String
static final String
protected Highlighter
protected ArrayList
<Highlighter> static final String
static final String
protected static final UniqueIdManager
protected KeyBufferer
protected LaunchButton
Deprecated, for removal: This API element is subject to removal in a future version.use launch from the superclassprotected JLayeredPane
static final String
protected ComponentSplitter.SplitPane
Deprecated, for removal: This API element is subject to removal in a future version.static final String
protected String
protected String
static final String
static final String
static final String
static final String
static final String
static final String
protected String
protected NamedKeyStroke
protected String
protected String
protected String
protected String
static final String
protected StackMetrics
protected ArrayList
<MouseListener> static final String
static final String
static final String
protected NamedKeyStroke
protected String
protected String
static final String
protected MouseListener
static final String
static final String
static final String
static final String
protected boolean
protected BoardPicker
static final String
protected PieceMover
protected float
protected PieceCollection
static final String
static final int
static final String
static final double
The rate at which things scrollstatic final int
The width of the hot zone for triggering autoscrolling.static final String
protected Point
protected MutablePropertiesContainer
protected PropertyChangeListener
protected KeyListener[]
protected JScrollPane
static int
protected org.jdesktop.animation.timing.Animator
The animator which controls autoscrolling.static final String
protected NamedKeyStrokeListener
protected SplitPane
static final String
protected int
The horizontal component of the autoscrolling vector, -1, 0, or 1.protected int
The vertical component of the autoscrolling vector, -1, 0, or 1.protected JPanel
protected JToolBar
protected String
static final String
static final String
protected boolean
protected boolean
protected VisibilityCondition
protected Zoomer
Fields inherited from class VASSAL.build.AbstractToolbarItem
BUTTON_TEXT, CAN_DISABLE, canDisable, DISABLED_ICON, disabledIconConfig, HIDE_WHEN_DISABLED, hideWhenDisabled, launch, property, PROPERTY_GATE, propertyGate, showDisabledOptions
Fields inherited from class VASSAL.build.AbstractConfigurable
changeSupport, config, localizedName, myI18nData, name
Fields inherited from class VASSAL.build.AbstractBuildable
buildComponents, validator
Fields inherited from interface VASSAL.build.Configurable
NAME_PROPERTY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDrawComponent
(Drawable theComponent) Registers aDrawable
component to this map.void
void
In case reports use HTML and refer to any image filesvoid
Because MouseEvents are received in Component coordinates, it is inconvenient for MouseListeners on the map to have to translate to Map coordinates.void
Because MouseEvents are received in Component coordinates, it is inconvenient for MouseListeners on the map to have to translate to Map coordinates.void
addMutableProperty
(String key, MutableProperty p) Adds a new Global Property to this map.void
Adds a GamePiece to this map's list of pieces.void
Registers this Map as a child of another buildable component, usually theGameModule
.void
Deprecated, for removal: This API element is subject to removal in a future version.useupdateTitleBar()
apply
(PieceVisitorDispatcher commandFactory) Attempts to apply the providedPieceVisitorDispatcher
to all pieces on this map, until it finds one that returns a non-null Command.void
Builds the map's component hierarchy from a given XML element, or a null one is given initializes a brand new default "new map" hierarchy.void
Center the map at given map coordinates within its JScrollPane containervoid
Center the map at the given map coordinates, if the point is not already within (dx,dy) of the center.static void
Repaints the current ActiveMap (seesetActiveMap(VASSAL.build.module.Map)
) and unmarks it.protected void
Clears the map border region, if any.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.int
componentToDrawing
(int c, double os_scale) Converts an integer value from Component coordinates system to Drawing coordinates for rendering.componentToDrawing
(Point p, double os_scale) Converts a Point from Component coordinates to Drawing coordinates for rendering.componentToDrawing
(Rectangle r, double os_scale) Converts a Rectangle from Component coordinates to Drawing coordinates for rendering.int
componentToMap
(int c) Converts an integer value from swing Component coordinates to the Map's coordinate system.Converts a Point from swing Component coordinates to the Map's coordinate system.Converts a Rectangle from swing Component coordinates to the Map's coordinate system.protected Window
Creates the top-level window for this map.void
Restore the previously disabled KeyListenersvoid
dragEnter
(DropTargetDragEvent dtde) void
dragExit
(DropTargetEvent dte) void
dragOver
(DropTargetDragEvent dtde) Handles scrolling when dragging an gamepiece to the edge of the windowvoid
drawBoards
(Graphics g, int xoffset, int yoffset, double zoom, Component obs) Draw the boards of the map at the given point and zoom factor onto the given Graphics objectvoid
drawBoardsInRegion
(Graphics g, Rectangle visibleRect) For each Board overlapping the given region, update the appropriate section of the board image.void
drawBoardsInRegion
(Graphics g, Rectangle visibleRect, Component c) For each Board overlapping the given region, update the appropriate section of the board image.void
drawDrawable
(Graphics g, boolean aboveCounters) Draws all of our "Drawable" components.int
drawingToComponent
(int c, double os_scale) Converts an integer value from Drawing coordinates to swing Component coordinates.drawingToComponent
(Point p, double os_scale) Converts a Point from Drawing coordinates to swing Component coordinates.drawingToComponent
(Rectangle r, double os_scale) Converts a Rectangle from Drawing coordinates to swing Component coordinates.int
drawingToMap
(int c, double os_scale) Converts an integer value from Drawing coordinates to the Map's coordinate system.drawingToMap
(Point p, double os_scale) Converts a Point from Drawing coordinates to the Map's coordinate system.drawingToMap
(Rectangle r, double os_scale) Converts a Rectangle from Drawing coordinates to the Map's coordinate system.void
drawPieces
(Graphics g, int xOffset, int yOffset) Draws the map pieces at a given offsetvoid
drawPiecesInRegion
(Graphics g, Rectangle visibleRect) Draws all pieces visible in a rectangular area of the mapvoid
drawPiecesInRegion
(Graphics g, Rectangle visibleRect, Component c) Draws all pieces visible in a rectangular area of the mapvoid
drop
(DropTargetDropEvent dtde) We put the "drop" in drag-n-drop!void
void
Save all current Key Listeners and remove them from the map.void
Ensure that the given region (in map coordinates) is visible.findAnyPiece
(Point pt, PieceFinder finder) Use the providedPieceFinder
instance to locate any piece at the given location, regardless of whether it is visible or not.findPiece
(Point pt, PieceFinder finder) Use the providedPieceFinder
instance to locate a visible piece at the given locationfindRegion
(String name) Search on all boards for a Region (location on an Irregular Grid) with the given nameSearch on all boards for a Zone with the given nameClass<?>[]
List of subcomponents which can be added to a Map.String[]
This getAttributeDescriptions() will return the items specific to the Toolbar Button - classes extending this should add their own items as well.String[]
Lists all the buildFile (XML) attribute names for this component.Class<?>[]
This getAttributeTypes() will return the items specific to the Toolbar Button - classes extending this should add their own items as well.Classes extending AbstractToolbarItem can call this as a super() method after checking for their own keys, to avoid needing to deal with the nitty gritty of the toolbar button.getAttributeVisibility
(String name) By default, all attributes are visiblegetBoardByName
(String name) Searches our list of boards for one with the given nameint
Every map must include aBoardPicker
as one of its build components.getChangeFormat
(boolean noSuppress) The component to be added to the control window toolbarstatic String
Gets the generic name for this type of class across all instances of it.Return the name of theDeck
whose position is precisely pprotected String
getId()
Each Map must have a unique String idMake a best guess for a unique identifier for the target.Return the localized name of theDeck
whose position is precisely pGets the value of map-level global property, or a module-level one if a map-level one is not found.protected Point
getLocation
(int column, int row, double zoom) Finds the location of a board (in Map space) at a particular column and row, based on passed zoom factorgetLocation
(Board b, double zoom) Gets the location of a board in Map space, based on a passed zoom factorprotected Point2D
getLocation2D
(int column, int row, double zoom) getLocation2D
(Board b, double zoom) static Map
getMapById
(String id) Find the map that corresponds to a known unique idUtility method to return aList
of all map components (on all maps!)int
Return the apply-on-move key.Return a unique Id for the containergetMutableProperty
(String name) Find a contained Global Property (variable) by name.float
getProperty
(Object key) Gets the value of a map-level global property.Override this method to provide a list of properties to be exposed for use by expressions in the module.As aGameComponent
, Map does not have any action inherently needing to be taken for "restoring" itself for load/save and network play purposes (the locations of pieces, etc, are stored in the pieces, and are restored fromGameState
in itsGameState.getRestorePiecesCommand()
method, which creates an AddPiece command for each piece).Every map must include a singleStackMetrics
object as one of its build components, which governs the visuals of stacking of GamePieces on the mapEvery map window has a toolbar, and this method returns swing toolbar component for this map.getView()
double
getZoom()
If the map has aZoomer
(seesetZoomer(VASSAL.build.module.map.Zoomer)
), then returns the Zoomer's current zoom factor.A map may include aZoomer
as one of its build components.void
hideMap()
int
Returns the index of a piece.boolean
static boolean
boolean
boolean
boolean
boolean
boolean
isNotPieceDrag
(Transferable trans) boolean
boolean
boolean
Is this map visible to all players?Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.mapSize()
int
mapToComponent
(int c) Converts an integer value from the Map's coordinate system to Component coordinates used for interactions between swing components.Converts a Point from the Map's coordinate system to Component coordinates used for interactions between swing components.Converts a Rectangle from the Map's coordinate system to Component coordinates used for interactions between swing components.int
mapToDrawing
(int c, double os_scale) Converts an integer value from the Map's coordinate system to Drawing coordinates for rendering.mapToDrawing
(Point p, double os_scale) Converts a point from the Map's coordinate system to Drawing coordinates for rendering.mapToDrawing
(Rectangle r, double os_scale) Converts a rectangle from the Map's coordinate system to Drawing coordinates for rendering.void
Mouse events are first translated into map coordinates.void
Mouse motion events are not forwarded to LocalMouseListeners or to listeners on the stack.void
void
void
Mouse motion events are not forwarded to LocalMouseListeners or to listeners on the stackvoid
Mouse events are first translated into map coordinates.void
Mouse events are first translated into map coordinates.void
paintRegion
(Graphics g, Rectangle visibleRect) Paints a specific region of the map, denoted by a Rectangle.void
paintRegion
(Graphics g, Rectangle visibleRect, Component c) Paints a specific region of the map, denoted by a Rectangle.Place a piece at the destination point.placeOrMerge
(GamePiece p, Point pt) Move a piece to the destination point.void
MouseListeners on a map may be pushed and popped onto a stack.void
Remove the most recently pushed mouse listener only if it is the supplied listenervoid
MouseListeners on a map may be pushed and popped onto a stack.void
removeDrawComponent
(Drawable theComponent) Unregister aDrawable
component from this mapvoid
Unregisters this Map from itsBuildable
parent (usually aGameModule
), reversing the process ofaddTo(VASSAL.build.Buildable)
.void
void
Because MouseEvents are received in Component coordinates, it is inconvenient for MouseListeners on the map to have to translate to Map coordinates.Removes a new Global Property from this map.void
Removes a piece from the mapvoid
repaint()
Repaints the map.void
repaint
(boolean cf) Repaints the map.void
Repaint the given area, specified in map coordinatesprotected int
scale
(int c, double zoom) Scales an integer value to a zoom factorprotected Point
Scales a point to a zoom factorprotected Rectangle
Scales a Rectangle to a zoom factorvoid
scroll
(int dx, int dy) Scrolls the map in the containing JScrollPane.void
scrollAtEdge
(Point evtPt, int dist) Begin autoscrolling the map if the given point is within the given distance from a viewport edge.static void
setActiveMap
(Map m) Marks an ActiveMap for certain drag and drop operations, so that the map can be repainted when the operation is complete.void
setAnyMouseoverDrawn
(boolean flag) void
setAttribute
(String key, Object value) Sets a buildFile (XML) attribute value for this component.protected void
Adjusts the bounds() rectangle to account for the Board's relative position to other boards.void
setBoardPicker
(BoardPicker picker) Every map must include a singleBoardPicker
as one of its build components.void
setBoards
(Collection<Board> c) Set the boards for this map.static void
setChangeReportingEnabled
(boolean b) Global Change Reporting control - used by Global Key Commands (seeGlobalCommand
) to temporarily disable reporting while they run, if their "Suppress individual reports" option is selected.void
setDragGestureListener
(DragGestureListener dragGestureListener) This listener will be notified when a drag event is initiated, assuming that no MouseListeners are on the stack.void
setDrawingMouseOver
(boolean flag) void
void
Each Map must have a unique String id Sets our unique ID (among Maps), so that e.g. commands sent to different maps don't inadvertently get confused when we send commands to other clients.void
Registers the keyBufferer for this map (old way of scanning through components to find one is silly)void
setMapName
(String s) void
setPieceCollection
(PieceCollection pieces) void
setPieceMover
(PieceMover mover) Every map must include a singlePieceMover
component as one of its build components, which handles drag-and-drop behavior for the map.void
setPieceOpacity
(float pieceOpacity) void
setPiecesVisible
(boolean show) void
Every map must include a singleStackMetrics
as one of its build components, which governs the visuals of stacking of GamePieces on the map.void
setup
(boolean show) When a game is started, create a top-level window, if none exists.void
Common view setup code for Map and PrivateMap, which confusingly have different View classes that sharing the same namevoid
A map may include a singleZoomer
as one of its build components.boolean
If this map shows with its own special button, it does not dock into the main window.void
showMap()
void
sideChanged
(String oldSide, String newSide) Takes action when the local player has switched sides.Because MouseEvents are received in Component coordinates, it is inconvenient for MouseListeners on the map to have to translate to Map coordinates.void
Accepts the current actual center of the map as the new "preferred center" (e.g. if we scroll) Just not if suppressed after a zoom level change (we don't want zoom level changes to cause us to lose track of the user's preferred ceter point)void
Updates the title bar of the current windowMethods inherited from class VASSAL.build.AbstractToolbarItem
addPropertyGateListener, addPropertyGateListener, checkDisabled, disableIfTrue, getLaunchButton, getNameKey, getPropertyList, isShowDisabledOptions, makeLaunchButton, propertyChange, removePropertyGateListener, setButtonTextKey, setHotKeyKey, setIconKey, setLaunchButton, setNameKey, setNamePrompt, setShowDisabledOptions, setTooltipKey
Methods inherited from class VASSAL.build.AbstractConfigurable
add, addPropertyChangeListener, getConfigureComponents, getConfigureName, getConfigurer, getExpressionList, getI18nData, getI18nPrefix, getLocalizedConfigureName, getTypeName, remove, removePropertyChangeListener, setAllAttributesUntranslatable, setAttributeTranslatable, setConfigureName
Methods inherited from class VASSAL.build.AbstractBuildable
addImageNamesRecursively, buildString, getAllDescendantComponentsOf, getAncestor, getBuildables, getBuildComponents, getBuildElement, getComponents, getComponentsOf, getNonFolderAncestor, setAncestor, validate
Methods inherited from class VASSAL.search.AbstractImageFinder
getAllImageNames, getLocalImageNames
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface VASSAL.script.expression.Auditable
getComponentName, getComponentTypeName
Methods inherited from interface VASSAL.build.Buildable
add, getBuildElement, isMandatory, isMovable, isUnique
Methods inherited from interface VASSAL.build.Configurable
addPropertyChangeListener, getConfigureComponents, getConfigureName, getConfigurer, remove
Methods inherited from interface VASSAL.tools.ToolBarComponent
updateToolbarButtons
Methods inherited from interface VASSAL.i18n.Translatable
getI18nData
Methods inherited from interface VASSAL.tools.UniqueIdManager.Identifyable
getConfigureName
-
Field Details
-
changeReportingEnabled
protected static boolean changeReportingEnabled -
mapID
-
mapName
-
idMgr
-
theMap
-
drawComponents
-
layeredPane
-
scroll
-
mainWindowDock
@Deprecated(since="2020-11-05", forRemoval=true) protected ComponentSplitter.SplitPane mainWindowDockDeprecated, for removal: This API element is subject to removal in a future version. -
splitPane
-
picker
-
toolBar
-
zoom
-
metrics
-
edgeBuffer
-
bgColor
-
launchButton
Deprecated, for removal: This API element is subject to removal in a future version.use launch from the superclass -
useLaunchButton
protected boolean useLaunchButton -
useLaunchButtonEdit
protected boolean useLaunchButtonEdit -
markMovedOption
-
markUnmovedIcon
-
markUnmovedText
-
markUnmovedTooltip
-
markUnmovedHotkey
-
markUnmovedReport
-
multicaster
-
mouseListenerStack
-
boards
-
boardWidths
protected int[][] boardWidths -
boardHeights
protected int[][] boardHeights -
pieces
-
highlighter
-
highlighters
-
clearFirst
protected boolean clearFirst -
hideCounters
protected boolean hideCounters -
pieceOpacity
protected float pieceOpacity -
allowMultiple
protected boolean allowMultiple -
visibilityCondition
-
dragGestureListener
-
onlyReportChangedLocation
protected boolean onlyReportChangedLocation -
moveWithinFormat
-
moveToFormat
-
createFormat
-
changeFormat
-
moveKey
-
tooltip
-
propsContainer
-
repaintOnPropertyChange
-
pieceMover
-
keyBufferer
-
saveKeyListeners
-
showKeyListener
-
hideKeyListener
-
description
-
preferredCenter
-
NAME
- See Also:
-
DESCRIPTION
- See Also:
-
MARK_MOVED
- See Also:
-
MARK_UNMOVED_ICON
- See Also:
-
MARK_UNMOVED_TEXT
- See Also:
-
MARK_UNMOVED_TOOLTIP
- See Also:
-
MARK_UNMOVED_HOTKEY
- See Also:
-
MARK_UNMOVED_REPORT
- See Also:
-
EDGE_WIDTH
- See Also:
-
EDGE_HEIGHT
- See Also:
-
BACKGROUND_COLOR
- See Also:
-
HIGHLIGHT_COLOR
- See Also:
-
HIGHLIGHT_THICKNESS
- See Also:
-
ALLOW_MULTIPLE
- See Also:
-
USE_LAUNCH_BUTTON
- See Also:
-
BUTTON_NAME
- See Also:
-
TOOLTIP
- See Also:
-
ICON
- See Also:
-
HOTKEY
- See Also:
-
SUPPRESS_AUTO
- See Also:
-
ONLY_REPORT_CHANGED_LOCATION
- See Also:
-
MOVE_WITHIN_FORMAT
- See Also:
-
MOVE_TO_FORMAT
- See Also:
-
CREATE_FORMAT
- See Also:
-
CHANGE_FORMAT
- See Also:
-
MOVE_KEY
- See Also:
-
MOVING_STACKS_PICKUP_UNITS
- See Also:
-
SHOW_KEY
- See Also:
-
HIDE_KEY
- See Also:
-
activeMap
-
DEFAULT_EDGE_SCROLL_DELAY_PROPERTY
- See Also:
-
DEFAULT_EDGE_SCROLL_ZONE_PROPERTY
- See Also:
-
DEFAULT_EDGE_SCROLL_RATE_PROPERTY
- See Also:
-
PREFERRED_EDGE_SCROLL_DELAY
public static final int PREFERRED_EDGE_SCROLL_DELAY- See Also:
-
PREFERRED_EDGE_DELAY
- See Also:
-
PREFERRED_EDGE_SCROLL_ZONE_STANDARD_DEFAULT
public static final int PREFERRED_EDGE_SCROLL_ZONE_STANDARD_DEFAULTThe width of the hot zone for triggering autoscrolling.- See Also:
-
SCROLL_ZONE
public static int SCROLL_ZONE -
PREFERRED_SCROLL_ZONE
- See Also:
-
PREFERRED_EDGE_SCROLL_RATE_STANDARD_DEFAULT
public static final double PREFERRED_EDGE_SCROLL_RATE_STANDARD_DEFAULTThe rate at which things scroll- See Also:
-
EDGE_SCROLL_RATE
public static double EDGE_SCROLL_RATE -
PREFERRED_EDGE_SCROLL_RATE
- See Also:
-
sx
protected int sxThe horizontal component of the autoscrolling vector, -1, 0, or 1. -
sy
protected int syThe vertical component of the autoscrolling vector, -1, 0, or 1. -
dx
protected int dx -
dy
protected int dy -
scroller
protected org.jdesktop.animation.timing.Animator scrollerThe animator which controls autoscrolling. -
LOCATION
- See Also:
-
OLD_LOCATION
- See Also:
-
OLD_MAP
- See Also:
-
MAP_NAME
- See Also:
-
PIECE_NAME
- See Also:
-
MESSAGE
- See Also:
-
-
Constructor Details
-
Map
public Map()
-
-
Method Details
-
isAnyMouseoverDrawn
public boolean isAnyMouseoverDrawn() -
setAnyMouseoverDrawn
public void setAnyMouseoverDrawn(boolean flag) -
isDrawingMouseOver
public boolean isDrawingMouseOver() -
setDrawingMouseOver
public void setDrawingMouseOver(boolean flag) -
showMap
public void showMap() -
hideMap
public void hideMap() -
getComponent
Description copied from class:AbstractToolbarItem
The component to be added to the control window toolbar- Overrides:
getComponent
in classAbstractToolbarItem
- Returns:
- Map's main visual interface swing component (its JPanel)
-
isMarkMoved
public boolean isMarkMoved()- Returns:
- true if the map marks pieces as moved
-
isOnlyReportChangedLocation
public boolean isOnlyReportChangedLocation()- Returns:
- true if auto-reporting moves should only happen if location changed
-
setChangeReportingEnabled
public static void setChangeReportingEnabled(boolean b) Global Change Reporting control - used by Global Key Commands (seeGlobalCommand
) to temporarily disable reporting while they run, if their "Suppress individual reports" option is selected.- Parameters:
b
- true to turn global change reporting on, false to turn it off.
-
isChangeReportingEnabled
public static boolean isChangeReportingEnabled()- Returns:
- true if change reporting is currently enabled, false if it is presently being suppressed by a Global Key Command.
-
setAttribute
Sets a buildFile (XML) attribute value for this component.- Specified by:
setAttribute
in interfaceAutoConfigurable
- Specified by:
setAttribute
in interfaceTranslatable
- Overrides:
setAttribute
in classAbstractToolbarItem
- Parameters:
key
- the name of the attribute. Will be one of those listed ingetAttributeNames()
value
- If thevalue
parameter is a String, it will be the value returned bygetAttributeValueString(java.lang.String)
for the samekey
. Since Map extendsAbstractConfigurable
, thenvalue
can also be an instance of the corresponding Class listed ingetAttributeTypes()
.
-
getAttributeValueString
Description copied from class:AbstractToolbarItem
Classes extending AbstractToolbarItem can call this as a super() method after checking for their own keys, to avoid needing to deal with the nitty gritty of the toolbar button.- Specified by:
getAttributeValueString
in interfaceAutoConfigurable
- Specified by:
getAttributeValueString
in interfaceTranslatable
- Overrides:
getAttributeValueString
in classAbstractToolbarItem
- Parameters:
key
- the name of the attribute. Will be one of those listed ingetAttributeNames()
- Returns:
- a String representation of the XML buildFile attribute with the given name. When initializing a module,
this String value will loaded from the XML and passed to
setAttribute(java.lang.String, java.lang.Object)
. It is also frequently used for checking the current value of an attribute.
-
build
Builds the map's component hierarchy from a given XML element, or a null one is given initializes a brand new default "new map" hierarchy.- Specified by:
build
in interfaceBuildable
- Overrides:
build
in classAbstractBuildable
- Parameters:
e
- XML element to build from, or null to build the default hierarchy for a brand new Map
-
setBoardPicker
Every map must include a singleBoardPicker
as one of its build components. This will contain the map'sBoard
(or Boards), which will in turn contain any grids, zones, and location information.- Parameters:
picker
- BoardPicker to register to the map. This method unregisters any previous BoardPicker.
-
getBoardPicker
Every map must include aBoardPicker
as one of its build components. This contains the map'sBoard
(or Boards), which will in turn contain any grids, zones, and location information.- Returns:
- the BoardPicker for this map (if none exist, this method will add one and return it)
-
setZoomer
-
getZoomer
-
getZoom
public double getZoom()If the map has aZoomer
(seesetZoomer(VASSAL.build.module.map.Zoomer)
), then returns the Zoomer's current zoom factor. If no Zoomer exists, returns 1.0 as the zoom factor.- Returns:
- the current zoom factor for the map
-
setStackMetrics
Every map must include a singleStackMetrics
as one of its build components, which governs the visuals of stacking of GamePieces on the map.- Parameters:
sm
-StackMetrics
component to register
-
getStackMetrics
Every map must include a singleStackMetrics
object as one of its build components, which governs the visuals of stacking of GamePieces on the map- Returns:
- the StackMetrics for this map
-
setPieceMover
Every map must include a singlePieceMover
component as one of its build components, which handles drag-and-drop behavior for the map.- Parameters:
mover
-PieceMover
component to register
-
getPieceMover
- Returns:
- Our pieceMover
-
getToolBar
Every map window has a toolbar, and this method returns swing toolbar component for this map.- Specified by:
getToolBar
in interfaceToolBarComponent
- Returns:
- the swing toolbar component (
JToolBar
for this map's window.
-
addDrawComponent
Registers aDrawable
component to this map. Components can implement theDrawable
interface (and register themselves here) if they have a graphical component that should be drawn whenever the Map is drawn. Standard examples includeCounterDetailViewer
s (aka Mouse-over Stack Viewers),GlobalMap
s (aka Overview Maps),LOS_Thread
s,MapShader
s, and theKeyBufferer
(to show which pieces are selected). -
removeDrawComponent
-
getKeyBufferer
- Returns:
- KeyBufferer (if any) for this map.
-
setKeyBufferer
Registers the keyBufferer for this map (old way of scanning through components to find one is silly)- Parameters:
kb
- KeyBufferer
-
getDescription
- Specified by:
getDescription
in interfaceComponentDescription
- Returns:
- Map's description field
-
addTo
Registers this Map as a child of another buildable component, usually theGameModule
. Determines a unique id for this Map. Registers itself asKeyStrokeSource
. Registers itself as aGameComponent
. Registers itself as a drop target and drag source. If the map is to be removed or otherwise shutdown, it can be deregistered, reversing this process, byremoveFrom(VASSAL.build.Buildable)
- Specified by:
addTo
in interfaceBuildable
- Overrides:
addTo
in classAbstractToolbarItem
- Parameters:
b
- parent Buildable to add this component to as a subcomponent.- See Also:
-
removeFrom
Unregisters this Map from itsBuildable
parent (usually aGameModule
), reversing the process ofaddTo(VASSAL.build.Buildable)
.- Specified by:
removeFrom
in interfaceConfigurable
- Overrides:
removeFrom
in classAbstractToolbarItem
- Parameters:
b
- parentBuildable
to deregister from
-
sideChanged
Takes action when the local player has switched sides. Because Map implementsPlayerRoster.SideChangeListener
, this method will automatically be called whenever the local player switches sides.- Specified by:
sideChanged
in interfacePlayerRoster.SideChangeListener
- Parameters:
oldSide
- side the local player is switching away fromnewSide
- side the local player is switching to
-
setBoards
Set the boards for this map. Each map may contain more than oneBoard
.- Parameters:
c
- Collection of Boards to be used.
-
findBoard
-
findZone
-
findZone
-
findRegion
-
getMaxPixelsPerRangeUnit
-
getBoardByName
-
getPreferredSize
- Returns:
- Dimension for map window's "preferred size"
-
mapSize
- Returns:
- the size of the map in pixels at 100% zoom, including the edge buffer
-
isLocationRestricted
- Returns:
- true if the given point may not be a legal location. I.e., if this grid will attempt to snap it to the nearest grid location
-
snapTo
-
snapTo
-
snapTo
-
getEdgeBuffer
- Returns:
- The buffer of empty space around the boards in the Map window, in component coordinates at 100% zoom
-
mapCoordinates
Deprecated, for removal: This API element is subject to removal in a future version.Translate a point from component coordinates (i.e., x,y position on the JPanel) to map coordinates (i.e., accounting for zoom factor).- See Also:
-
mapRectangle
Deprecated, for removal: This API element is subject to removal in a future version. -
componentCoordinates
Deprecated, for removal: This API element is subject to removal in a future version.Translate a point from map coordinates to component coordinates- See Also:
-
componentRectangle
Deprecated, for removal: This API element is subject to removal in a future version. -
scale
protected int scale(int c, double zoom) Scales an integer value to a zoom factor- Parameters:
c
- value to be scaledzoom
- zoom factor- Returns:
- scaled value result
-
scale
-
scale
-
mapToDrawing
public int mapToDrawing(int c, double os_scale) Converts an integer value from the Map's coordinate system to Drawing coordinates for rendering. Takes into account the operating system's scale factor (needed to deal with HiDPI monitors) as well as the Map's zoom factor. Although Drawing coordinates may sometimes have the traditional 1-to-1 relationship with component coordinates, on HiDPI monitors it will not. Examples: Drawing a line between two points on a map (seeLOS_Thread.draw(java.awt.Graphics, VASSAL.build.module.Map)
. Drawing a piece on the map (seeStackMetrics.draw(VASSAL.counters.Stack, java.awt.Graphics, int, int, java.awt.Component, double)
.- Parameters:
c
- value in Map coordinate space to be scaledos_scale
- Operating system's scale factor, (obtained fromgetDeviceConfiguration()
.getDefaultTransform()
.getScaleX()
)- Returns:
- scaled value in Drawing coordinate space
-
mapToDrawing
Converts a point from the Map's coordinate system to Drawing coordinates for rendering. Takes into account the operating system's scale factor (needed to deal with HiDPI monitors) as well as the Map's zoom factor. Although Drawing coordinates may sometimes have the traditional 1-to-1 relationship with component coordinates, on HiDPI monitors it will not. Examples: Drawing a line between two points on a map (seeLOS_Thread.draw(java.awt.Graphics, VASSAL.build.module.Map)
. Drawing a piece on the map (seeStackMetrics.draw(VASSAL.counters.Stack, java.awt.Graphics, int, int, java.awt.Component, double)
.- Parameters:
p
- point in Map coordinates to be scaledos_scale
- Operating system's scale factor, (obtained fromgetDeviceConfiguration()
* .getDefaultTransform()
* .getScaleX()
)- Returns:
- scaled point in Drawing coordinates
-
mapToDrawing
Converts a rectangle from the Map's coordinate system to Drawing coordinates for rendering. Takes into account the operating system's scale factor (needed to deal with HiDPI monitors) as well as the Map's zoom factor. Although Drawing coordinates may sometimes have the traditional 1-to-1 relationship with component coordinates, on HiDPI monitors it will not. Examples: Drawing a line between two points on a map (seeLOS_Thread.draw(java.awt.Graphics, VASSAL.build.module.Map)
. Drawing a piece on the map (seeStackMetrics.draw(VASSAL.counters.Stack, java.awt.Graphics, int, int, java.awt.Component, double)
.- Parameters:
r
- rectangle in Map coordinates to be scaledos_scale
- Operating system's scale factor, (obtained fromgetDeviceConfiguration()
* * .getDefaultTransform()
* * .getScaleX()
)- Returns:
- scaled rectangle in Drawing coordinates
-
mapToComponent
public int mapToComponent(int c) Converts an integer value from the Map's coordinate system to Component coordinates used for interactions between swing components. Basically this scales by the map's zoom factor. Note that although drawing coordinates may sometimes have the traditional 1-to-1 relationship with component coordinates, on HiDPI monitors it will not. Examples: activating a popup menu at a piece's location on a map (see MenuDisplayer#maybePopup). Drag and drop operations (see dragGestureRecognizedPrep inPieceMover
).- Parameters:
c
- value in Map coordinate system to scale- Returns:
- scaled value in Component coordinate system
-
mapToComponent
Converts a Point from the Map's coordinate system to Component coordinates used for interactions between swing components. Basically this scales by the map's zoom factor. Note that although drawing coordinates may sometimes have the traditional 1-to-1 relationship with component coordinates, on HiDPI monitors it will not. Examples: activating a popup menu at a piece's location on a map (see MenuDisplayer#maybePopup). Drag and drop operations (see dragGestureRecognizedPrep inPieceMover
).- Parameters:
p
- Point in Map coordinates to scale- Returns:
- scaled Point in Component coordinates
-
mapToComponent
Converts a Rectangle from the Map's coordinate system to Component coordinates used for interactions between swing components. Basically this scales by the map's zoom factor. Note that although drawing coordinates may sometimes have the traditional 1-to-1 relationship with component coordinates, on HiDPI monitors it will not. Examples: activating a popup menu at a piece's location on a map (see MenuDisplayer#maybePopup). Drag and drop operations (see dragGestureRecognizedPrep inPieceMover
).- Parameters:
r
- Rectangle in Map coordinates to scale- Returns:
- scaled Rectangle in Component coordinates
-
componentToDrawing
public int componentToDrawing(int c, double os_scale) Converts an integer value from Component coordinates system to Drawing coordinates for rendering. Takes into account the operating system's scale factor (needed to deal with HiDPI monitors), which accounts entirely for the difference in these two coordinate systems. Although Drawing coordinates may sometimes have the traditional 1-to-1 relationship with Component coordinates, on HiDPI monitors it will not. Examples: seeFootprint.draw(java.awt.Graphics, int, int, java.awt.Component, double)
- checking a map component's "visible" clipping rect, and using it in the context of drawing move trails.- Parameters:
c
- value in Component coordinate space to be scaledos_scale
- Operating system's scale factor, (obtained fromgetDeviceConfiguration()
* .getDefaultTransform()
* .getScaleX()
)- Returns:
- scaled value in Drawing coordinate space
-
componentToDrawing
Converts a Point from Component coordinates to Drawing coordinates for rendering. Takes into account the operating system's scale factor (needed to deal with HiDPI monitors), which accounts entirely for the difference in these two coordinate systems. Although Drawing coordinates may sometimes have the traditional 1-to-1 relationship with Component coordinates, on HiDPI monitors it will not. Examples: seeFootprint.draw(java.awt.Graphics, int, int, java.awt.Component, double)
- checking a map component's "visible" clipping rect, and using it in the context of drawing move trails.- Parameters:
p
- Point in Component coordinate space to be scaledos_scale
- Operating system's scale factor, (obtained fromgetDeviceConfiguration()
* .getDefaultTransform()
* .getScaleX()
)- Returns:
- scaled Point in Drawing coordinate space
-
componentToDrawing
Converts a Rectangle from Component coordinates to Drawing coordinates for rendering. Takes into account the operating system's scale factor (needed to deal with HiDPI monitors), which accounts entirely for the difference in these two coordinate systems. Although Drawing coordinates may sometimes have the traditional 1-to-1 relationship with Component coordinates, on HiDPI monitors it will not. Examples: seeFootprint.draw(java.awt.Graphics, int, int, java.awt.Component, double)
- checking a map component's "visible" clipping rect, and using it in the context of drawing move trails.- Parameters:
r
- Rectangle in Component coordinate space to be scaledos_scale
- Operating system's scale factor, (obtained fromgetDeviceConfiguration()
* .getDefaultTransform()
* .getScaleX()
)- Returns:
- scaled Rectangle in Drawing coordinate space
-
componentToMap
public int componentToMap(int c) Converts an integer value from swing Component coordinates to the Map's coordinate system. Basically this scales by the inverse of the map's zoom factor. Note that although drawing coordinates may sometimes have the traditional 1-to-1 relationship with component coordinates, on HiDPI monitors it will not. Examples: Checking if the mouse is currently overlapping a game pieceKeyBufferer.mouseReleased(MouseEvent)
, CounterDetailViewer#getDisplayablePieces.- Parameters:
c
- value in Component coordinates to scale- Returns:
- scaled value in Map coordinates
-
componentToMap
Converts a Point from swing Component coordinates to the Map's coordinate system. Basically this scales by the inverse of the map's zoom factor. Note that although drawing coordinates may sometimes have the traditional 1-to-1 relationship with component coordinates, on HiDPI monitors it will not. Examples: Checking if the mouse is currently overlapping a game pieceKeyBufferer.mouseReleased(MouseEvent)
, CounterDetailViewer#getDisplayablePieces.- Parameters:
p
- Point in Component coordinates to scale- Returns:
- scaled Point in Map coordinates
-
componentToMap
Converts a Rectangle from swing Component coordinates to the Map's coordinate system. Basically this scales by the inverse of the map's zoom factor. Note that although drawing coordinates may sometimes have the traditional 1-to-1 relationship with component coordinates, on HiDPI monitors it will not. Examples: Checking if the mouse is currently overlapping a game pieceKeyBufferer.mouseReleased(MouseEvent)
, CounterDetailViewer#getDisplayablePieces.- Parameters:
r
- Rectangle in Component coordinates to scale- Returns:
- scaled Rectangle in Map coordinates
-
drawingToMap
public int drawingToMap(int c, double os_scale) Converts an integer value from Drawing coordinates to the Map's coordinate system. Takes into account the operating system's scale factor (needed to deal with HiDPI monitors) as well as the Map's zoom factor, scaling by the inverse of both of these scale factors. Although Drawing coordinates may sometimes have the traditional 1-to-1 relationship with component coordinates, on HiDPI monitors it will not.- Parameters:
c
- value in Drawing coordinate space to be scaledos_scale
- Operating system's scale factor, (obtained fromgetDeviceConfiguration()
* .getDefaultTransform()
* .getScaleX()
)- Returns:
- scaled value in Map coordinates
-
drawingToMap
Converts a Point from Drawing coordinates to the Map's coordinate system. Takes into account the operating system's scale factor (needed to deal with HiDPI monitors) as well as the Map's zoom factor, scaling by the inverse of both of these scale factors. Although Drawing coordinates may sometimes have the traditional 1-to-1 relationship with component coordinates, on HiDPI monitors it will not.- Parameters:
p
- Point in Drawing coordinate space to be scaledos_scale
- Operating system's scale factor, (obtained fromgetDeviceConfiguration()
* .getDefaultTransform()
* .getScaleX()
)- Returns:
- scaled point in Map coordinates
-
drawingToMap
Converts a Rectangle from Drawing coordinates to the Map's coordinate system. Takes into account the operating system's scale factor (needed to deal with HiDPI monitors) as well as the Map's zoom factor, scaling by the inverse of both of these scale factors. Although Drawing coordinates may sometimes have the traditional 1-to-1 relationship with component coordinates, on HiDPI monitors it will not.- Parameters:
r
- Rectangle in Drawing coordinate space to be scaledos_scale
- Operating system's scale factor, (obtained fromgetDeviceConfiguration()
* .getDefaultTransform()
* .getScaleX()
)- Returns:
- scaled Rectangle in Map coordinates
-
drawingToComponent
public int drawingToComponent(int c, double os_scale) Converts an integer value from Drawing coordinates to swing Component coordinates. Takes into account the inverse of the operating system's scale factor (needed to deal with HiDPI monitors), which accounts entirely for the difference in these two coordinate systems. Although Drawing coordinates may sometimes have the traditional 1-to-1 relationship with Component coordinates, on HiDPI monitors it will not.- Parameters:
c
- value in Drawing coordinatesos_scale
- Operating system's scale factor, (obtained fromgetDeviceConfiguration()
* .getDefaultTransform()
* .getScaleX()
)- Returns:
- scaled value in Component coordinates
-
drawingToComponent
Converts a Point from Drawing coordinates to swing Component coordinates. Takes into account the inverse of the operating system's scale factor (needed to deal with HiDPI monitors), which accounts entirely for the difference in these two coordinate systems. Although Drawing coordinates may sometimes have the traditional 1-to-1 relationship with Component coordinates, on HiDPI monitors it will not.- Parameters:
p
- Point in Drawing coordinatesos_scale
- Operating system's scale factor, (obtained fromgetDeviceConfiguration()
* .getDefaultTransform()
* .getScaleX()
)- Returns:
- scaled Point in Component coordinates
-
drawingToComponent
Converts a Rectangle from Drawing coordinates to swing Component coordinates. Takes into account the inverse of the operating system's scale factor (needed to deal with HiDPI monitors), which accounts entirely for the difference in these two coordinate systems. Although Drawing coordinates may sometimes have the traditional 1-to-1 relationship with Component coordinates, on HiDPI monitors it will not.- Parameters:
r
- Rectangle in Drawing coordinatesos_scale
- Operating system's scale factor, (obtained fromgetDeviceConfiguration()
* .getDefaultTransform()
* .getScaleX()
)- Returns:
- scaled Rectangle in Component coordinates
-
locationName
-
localizedLocationName
-
isVisibleToAll
public boolean isVisibleToAll()Is this map visible to all players?- Returns:
- true if this map either (a) isn't a
PrivateMap
or (b) does have its visible-to-all flag set
-
getDeckNameContaining
-
getDeckNameAt
-
getLocalizedDeckNameAt
-
addLocalMouseListener
Because MouseEvents are received in Component coordinates, it is inconvenient for MouseListeners on the map to have to translate to Map coordinates. MouseListeners added with this method will receive mouse events with points already translated into Map coordinates. addLocalMouseListenerFirst inserts the new listener at the start of the chain.- Parameters:
l
- MouseListener to add
-
addLocalMouseListenerFirst
Because MouseEvents are received in Component coordinates, it is inconvenient for MouseListeners on the map to have to translate to Map coordinates. MouseListeners added with this method will receive mouse events with points already translated into Map coordinates. addLocalMouseListenerFirst inserts the new listener at the start of the chain.- Parameters:
l
- MouseListener to add
-
removeLocalMouseListener
Because MouseEvents are received in Component coordinates, it is inconvenient for MouseListeners on the map to have to translate to Map coordinates. MouseListeners added with this method will receive mouse events with points already translated into Map coordinates. addLocalMouseListenerFirst inserts the new listener at the start of the chain.- Parameters:
l
- MouseListener to add
-
pushMouseListener
MouseListeners on a map may be pushed and popped onto a stack. Only the top listener on the stack receives mouse events.- Parameters:
l
- MouseListener to push onto stack.
-
popMouseListener
public void popMouseListener()MouseListeners on a map may be pushed and popped onto a stack. Only the top listener on the stack receives mouse events. The pop method removes the most recently pushed mouse listener. -
popMouseListener
Remove the most recently pushed mouse listener only if it is the supplied listener- Parameters:
l
- Listener
-
mouseEntered
- Specified by:
mouseEntered
in interfaceMouseListener
- Parameters:
e
- MouseEvent
-
mouseExited
- Specified by:
mouseExited
in interfaceMouseListener
- Parameters:
e
- MouseEvent
-
translateEvent
Because MouseEvents are received in Component coordinates, it is inconvenient for MouseListeners on the map to have to translate to Map coordinates. MouseListeners added with this method will receive mouse events with points already translated into Map coordinates. addLocalMouseListenerFirst inserts the new listener at the start of the chain.- Parameters:
e
- MouseEvent in Component coordinates- Returns:
- MouseEvent translated into Map coordinates
-
mouseClicked
Mouse events are first translated into map coordinates. Then the event is forwarded to the top MouseListener in the stack, if any, otherwise forwarded to all LocalMouseListeners- Specified by:
mouseClicked
in interfaceMouseListener
- Parameters:
e
- MouseEvent from system- See Also:
-
setActiveMap
Marks an ActiveMap for certain drag and drop operations, so that the map can be repainted when the operation is complete.- Parameters:
m
- Map to be considered active.
-
clearActiveMap
public static void clearActiveMap()Repaints the current ActiveMap (seesetActiveMap(VASSAL.build.module.Map)
) and unmarks it. -
mousePressed
Mouse events are first translated into map coordinates. Then the event is forwarded to the top MouseListener in the stack, if any, otherwise forwarded to all LocalMouseListeners- Specified by:
mousePressed
in interfaceMouseListener
- Parameters:
e
- MouseEvent from system- See Also:
-
mouseReleased
Mouse events are first translated into map coordinates. Then the event is forwarded to the top MouseListener in the stack, if any, otherwise forwarded to all LocalMouseListeners- Specified by:
mouseReleased
in interfaceMouseListener
- Parameters:
e
- MouseEvent from system- See Also:
-
enableKeyListeners
public void enableKeyListeners()Save all current Key Listeners and remove them from the map. Used by Traits that need to prevent Key Commands at certain times. -
disableKeyListeners
public void disableKeyListeners()Restore the previously disabled KeyListeners -
setDragGestureListener
This listener will be notified when a drag event is initiated, assuming that no MouseListeners are on the stack.- Parameters:
dragGestureListener
- Listener- See Also:
-
getDragGestureListener
- Returns:
- current dragGestureListener that handles normal drag events (assuming no MouseListeners are on the stack)
- See Also:
-
dragEnter
- Specified by:
dragEnter
in interfaceDropTargetListener
- Parameters:
dtde
- DropTargetDragEvent
-
isNotPieceDrag
-
dragOver
Handles scrolling when dragging an gamepiece to the edge of the window- Specified by:
dragOver
in interfaceDropTargetListener
- Parameters:
dtde
- DropTargetDragEvent
-
dropActionChanged
- Specified by:
dropActionChanged
in interfaceDropTargetListener
- Parameters:
dtde
- DropTargetDragEvent
-
dragExit
- Specified by:
dragExit
in interfaceDropTargetListener
-
drop
We put the "drop" in drag-n-drop!- Specified by:
drop
in interfaceDropTargetListener
- Parameters:
dtde
- DropTargetDragEvent
-
mouseMoved
Mouse motion events are not forwarded to LocalMouseListeners or to listeners on the stack- Specified by:
mouseMoved
in interfaceMouseMotionListener
- Parameters:
e
- MouseEvent from system
-
mouseDragged
Mouse motion events are not forwarded to LocalMouseListeners or to listeners on the stack. The map scrolls when dragging the mouse near the edge.- Specified by:
mouseDragged
in interfaceMouseMotionListener
- Parameters:
e
- MouseEvent from system
-
scrollAtEdge
Begin autoscrolling the map if the given point is within the given distance from a viewport edge.- Parameters:
evtPt
- Point to checkdist
- Distance to check
-
repaint
public void repaint(boolean cf) Repaints the map. Accepts parameter about whether to clear the display first.- Parameters:
cf
- true if display should be cleared before drawing the map
-
repaint
public void repaint()Repaints the map. -
paintRegion
-
paintRegion
-
drawBoardsInRegion
-
drawBoardsInRegion
-
drawPiecesInRegion
-
drawPiecesInRegion
-
drawPieces
Draws the map pieces at a given offset- Parameters:
g
- Target graphics objectxOffset
- x offsetyOffset
- y offset
-
drawDrawable
Draws all of our "Drawable" components. Standard examples includeCounterDetailViewer
s (aka Mouse-over Stack Viewers),GlobalMap
s (aka Overview Maps),LOS_Thread
s,MapShader
s, and theKeyBufferer
(to show which pieces are selected).- Parameters:
g
- target graphics objectaboveCounters
- true means we should draw only the drawables that go above the counters; false means we should draw only the ones that go below
-
getHighlighter
- Returns:
- Current selection highlighter
-
setHighlighter
- Parameters:
h
- selection highlighter to set active
-
addHighlighter
- Parameters:
h
- selection highlighter to add to our list
-
removeHighlighter
- Parameters:
h
- selection highlighter to remove from our list
-
getHighlighters
- Returns:
- an Iterator for all of our highlighters
-
getBoards
- Returns:
- a Collection of all
Board
s on the Map
-
getBoardCount
public int getBoardCount()- Returns:
- number of Boards on this map
-
boundingBoxOf
-
selectionBoundsOf
-
positionOf
-
getPieces
- Returns:
- an array of all GamePieces on the map, subject to visibility, and sorted in order of visual layers. This is a read-only copy. Altering the array does not alter the pieces on the map.
-
getAllPieces
- Returns:
- an array of all GamePieces on the map, regardless of visibility, and sorted in order of visual layer. This is a read-only copy. Altering the array does not alter the pieces on the map.
-
setPieceCollection
- Parameters:
pieces
- Sets the PieceCollection for this map (usually a LayeredPieceCollection a/k/a "Game Piece Layer Control"), which keeps the pieces/stacks/decks sorted by visual layer, and within each layer by back-to-front draw order
-
getPieceCollection
- Returns:
- piece collection for this map (a/k/a its LayeredPieceCollection or "Game Piece Layer Control"), which maintains a list of all the pieces/stacks/decks on the map sorted by visual layer, and within each layer by back-to-front draw order
-
clearMapBorder
Clears the map border region, if any. If theclearFirst
flag is set, wipe the map image too.- Parameters:
g
- target graphics object
-
setBoardBoundaries
protected void setBoardBoundaries()Adjusts the bounds() rectangle to account for the Board's relative position to other boards. In other words, if Board A is N pixels wide and Board B is to the right of Board A, then the origin of Board B will be adjusted N pixels to the right. -
getLocation
-
getLocation
Finds the location of a board (in Map space) at a particular column and row, based on passed zoom factor- Parameters:
column
- number of board to findrow
- number of board to findzoom
- zoom factor to use- Returns:
- location of the board in Map space
-
getLocation2D
-
getLocation2D
-
drawBoards
Draw the boards of the map at the given point and zoom factor onto the given Graphics object- Parameters:
g
- target Graphics objectxoffset
- x offset to draw atyoffset
- y offset to draw atzoom
- zoom factor for drawing the boardsobs
- observer Component
-
repaint
Repaint the given area, specified in map coordinates- Parameters:
r
- Rectangle specifying region to repaint in map coordinates
-
setPiecesVisible
-
isPiecesVisible
public boolean isPiecesVisible()- Returns:
- true if
GamePiece
s should be drawn when painting the map
-
getPieceOpacity
public float getPieceOpacity()- Returns:
- current pieceOpacity for drawing
-
setPieceOpacity
public void setPieceOpacity(float pieceOpacity) - Parameters:
pieceOpacity
- sets opacity for piece drawing, 0 to 1.0
-
getProperty
Gets the value of a map-level global property. If a "Global Property" entry is not found at the map level, then module-level properties are checked, which includes identification information for the local player.- Specified by:
getProperty
in interfacePropertySource
- Parameters:
key
- identifies the global property to be returned- Returns:
- value of designated global property
-
getLocalizedProperty
Gets the value of map-level global property, or a module-level one if a map-level one is not found. The localized aspect presently only applies to permanent module-level objects which can be localized (e.g. player sides)- Specified by:
getLocalizedProperty
in interfacePropertySource
- Parameters:
key
- Name of the property to get the value of- Returns:
- Localized/translated name of the named property, if one is available, otherwise returns the non-localized name
-
getPropertyNames
Description copied from class:AbstractBuildable
Override this method to provide a list of properties to be exposed for use by expressions in the module.- Specified by:
getPropertyNames
in interfacePropertyNameSource
- Overrides:
getPropertyNames
in classAbstractBuildable
- Returns:
- Default implementation of PropertyNameSource - No properties exposed
-
getMoveKey
Return the apply-on-move key. It may be named, so just return the allocated KeyStroke.- Returns:
- apply-on-move keystroke
-
createParentFrame
Creates the top-level window for this map. Could be a JDialog or a JFrame depending on whether we are set to use a single window or have our own window.- Returns:
- the top-level window containing this map
-
isFirstMap
public boolean isFirstMap() -
shouldDockIntoMainWindow
public boolean shouldDockIntoMainWindow()If this map shows with its own special button, it does not dock into the main window. Likewise if we have no combined window setting. Otherwise the *first* non-button-launched map we find will be the one we dock.- Returns:
- whether this map should dock into the main window
-
setup
public void setup(boolean show) When a game is started, create a top-level window, if none exists. When a game is ended, remove all boards from the map.- Specified by:
setup
in interfaceGameComponent
- Overrides:
setup
in classAbstractToolbarItem
- Parameters:
show
- true if a game is starting, false if a game is ending- See Also:
-
getRestoreCommand
As aGameComponent
, Map does not have any action inherently needing to be taken for "restoring" itself for load/save and network play purposes (the locations of pieces, etc, are stored in the pieces, and are restored fromGameState
in itsGameState.getRestorePiecesCommand()
method, which creates an AddPiece command for each piece). Map's interest in GameComponent is entirely for game start/stop purposes (seesetup(boolean)
, above).- Specified by:
getRestoreCommand
in interfaceGameComponent
- Overrides:
getRestoreCommand
in classAbstractToolbarItem
- Returns:
- null since no restore command needed.
-
appendToTitle
Deprecated, for removal: This API element is subject to removal in a future version.useupdateTitleBar()
- Parameters:
s
- String to append to title
-
updateTitleBar
public void updateTitleBar()Updates the title bar of the current window -
getDefaultWindowTitle
- Returns:
- The correct current default window title
-
findPiece
Use the providedPieceFinder
instance to locate a visible piece at the given location- Parameters:
pt
- Point at which to find visible piecesfinder
- PieceFinder to use- Returns:
- a visible piece at the given location, or null if none.
-
findAnyPiece
Use the providedPieceFinder
instance to locate any piece at the given location, regardless of whether it is visible or not.- Parameters:
pt
- Point at which to find piecesfinder
- PieceFinder to use- Returns:
- a piece at the given location, regardless of visibility, or null if none.
-
placeAt
-
apply
Attempts to apply the providedPieceVisitorDispatcher
to all pieces on this map, until it finds one that returns a non-null Command.- Parameters:
commandFactory
- The PieceVisitorDispatcher to apply- Returns:
- the first non-null
Command
returned bycommandFactory
-
placeOrMerge
Move a piece to the destination point. If a piece is at the point (i.e. has a location exactly equal to it), merge into aStack
with the piece by forwarding toStackMetrics.merge(VASSAL.counters.GamePiece, VASSAL.counters.GamePiece)
. Otherwise, place by forwarding to placeAt()- Parameters:
p
- GamePiece to place/mergept
- Point location on the map to place/merge the piece.- Returns:
- a
Command
that will duplicate this action on other clients - See Also:
-
addPiece
Adds a GamePiece to this map's list of pieces. Removes the piece from its parent Stack and from its current map, if different from this map.- Parameters:
p
- Game Piece to add
-
indexOf
Returns the index of a piece. When painting the map, pieces are drawn in order of index Return -1 if the piece is not on this map- Parameters:
s
- GamePiece to find the index of- Returns:
- index of the piece on the map, or -1 if the piece is not on this map
-
removePiece
Removes a piece from the map- Parameters:
p
- GamePiece to remove from map
-
updateCenter
public void updateCenter()Accepts the current actual center of the map as the new "preferred center" (e.g. if we scroll) Just not if suppressed after a zoom level change (we don't want zoom level changes to cause us to lose track of the user's preferred ceter point) -
getPreferredCenter
- Returns:
- last location the player has requested to be the center of the map (eg by manually clicking or scrolling)
-
centerAt
Center the map at given map coordinates within its JScrollPane container- Parameters:
p
- Point to center
-
centerAt
Center the map at the given map coordinates, if the point is not already within (dx,dy) of the center.- Parameters:
p
- point to centerdx
- x tolerance for nearness to centerdy
- y tolerance for nearness to center
-
getVisibleRect
- Returns:
- the current visible rect of our map
-
getCenter
- Returns:
- the point our map's view is currently centered on
-
ensureVisible
Ensure that the given region (in map coordinates) is visible. Uses player preference to determine how sensitive to be about when to re-center.- Parameters:
r
- Rectangle demarking region to ensure is visible
-
scroll
public void scroll(int dx, int dy) Scrolls the map in the containing JScrollPane.- Parameters:
dx
- number of pixels to scroll horizontallydy
- number of pixels to scroll vertically
-
getConfigureTypeName
Gets the generic name for this type of class across all instances of it. Appears in the Editor window in [..] as e.g. [Map], [Prototype], etc.- Returns:
- The generic name for this kind of component, i.e. the part appearing [In Brackets] in the Editor's
ConfigureTree
.
-
getMapName
- Returns:
- the name of this map, for internal purposes
-
getLocalizedMapName
- Returns:
- the localized name of this map, for display purposes
-
setMapName
- Parameters:
s
- Sets the name of the map.
-
getHelpFile
- Specified by:
getHelpFile
in interfaceConfigurable
- Returns:
- a HelpFile describing how to use and configure this component
-
getAttributeDescriptions
Description copied from class:AbstractToolbarItem
This getAttributeDescriptions() will return the items specific to the Toolbar Button - classes extending this should add their own items as well. If the "nameKey" is blank, then no "name" configure entry will be generated. Extending classes can use ArrayUtils.addAll(super.getAttributeDescriptions(), key1, ..., keyN), or supply their own order from scratch.- Specified by:
getAttributeDescriptions
in interfaceAutoConfigurable
- Overrides:
getAttributeDescriptions
in classAbstractToolbarItem
- Returns:
- an array of Strings describing the buildFile (XML) attributes of this component. These strings are used as prompts in the
Properties window for this object, when the component is configured in the Editor. The order of descriptions should
be the same as the order of names in
AbstractBuildable.getAttributeNames()
- See Also:
-
getAttributeNames
Lists all the buildFile (XML) attribute names for this component. If this component is ALSO anAbstractConfigurable
, then this list of attributes determines the appropriate attribute order forAbstractConfigurable.getAttributeDescriptions()
andAbstractConfigurable.getAttributeTypes()
.- Specified by:
getAttributeNames
in interfaceAutoConfigurable
- Overrides:
getAttributeNames
in classAbstractToolbarItem
- Returns:
- a list of all buildFile (XML) attribute names for this component
- See Also:
-
getAttributeTypes
Description copied from class:AbstractToolbarItem
This getAttributeTypes() will return the items specific to the Toolbar Button - classes extending this should add their own items as well. If the "nameKey" is blank, then no "name" configure entry will be generated. Extending classes can use ArrayUtils.addAll(super.getAttributeTypes(), key1, ..., keyN), or supply their own order from scratch.- Specified by:
getAttributeTypes
in interfaceAutoConfigurable
- Overrides:
getAttributeTypes
in classAbstractToolbarItem
- Returns:
- the Class for the buildFile (XML) attributes of this component. Valid classes include: String, Integer, Double, Boolean, Image,
Color, and KeyStroke, along with any class for which a Configurer exists in VASSAL.configure. The class determines, among other things,
which type of
AutoConfigurer
will be used to configure the attribute when the object is configured in the Editor. The order of classes should be the same as the order of names inAbstractBuildable.getAttributeNames()
- See Also:
-
getCreateFormat
- Returns:
- "created on map" format string
-
getChangeFormat
- Returns:
- "changed on map" format string
-
getChangeFormat
- Returns:
- "changed on map" format string
-
getMoveToFormat
- Returns:
- "moved to map" format string
-
getMoveWithinFormat
- Returns:
- "moved within map" format string
-
getAllowableConfigureComponents
List of subcomponents which can be added to a Map.- Specified by:
getAllowableConfigureComponents
in interfaceConfigurable
- Returns:
- a list of valid sub-component Classes. If a Class
appears in this list, then instances of that class may be added
to this component from the Editor's
ConfigureTree
window by right-clicking on the component and selecting the appropriate "Add" option. - See Also:
-
getAttributeVisibility
Description copied from class:AbstractConfigurable
By default, all attributes are visible- Specified by:
getAttributeVisibility
in interfaceAutoConfigurable
- Overrides:
getAttributeVisibility
in classAbstractToolbarItem
- Parameters:
name
- Name (key) of one of this component's attributes- Returns:
- Visibility condition for the corresponding component
-
setId
Each Map must have a unique String id Sets our unique ID (among Maps), so that e.g. commands sent to different maps don't inadvertently get confused when we send commands to other clients.- Specified by:
setId
in interfaceUniqueIdManager.Identifyable
- Parameters:
id
- Sets our unique ID
-
getId
Each Map must have a unique String id- Specified by:
getId
in interfaceUniqueIdManager.Identifyable
- Returns:
- the id for this map
-
getMapById
-
getMapList
-
getMutableProperty
Find a contained Global Property (variable) by name. Does NOT search at the Module level.- Specified by:
getMutableProperty
in interfaceMutablePropertiesContainer
- Parameters:
name
- Name of Global Property to find- Returns:
- Mutable property corresponding to the name given
-
addMutableProperty
Adds a new Global Property to this map.- Specified by:
addMutableProperty
in interfaceMutablePropertiesContainer
- Parameters:
key
- Name of the new propertyp
- The property object to add
-
removeMutableProperty
Removes a new Global Property from this map.- Specified by:
removeMutableProperty
in interfaceMutablePropertiesContainer
- Parameters:
key
- Name of the property to be removed- Returns:
- the object just removed
-
getMutablePropertiesContainerId
Description copied from interface:MutablePropertiesContainer
Return a unique Id for the container- Specified by:
getMutablePropertiesContainerId
in interfaceMutablePropertiesContainer
- Returns:
- The container ID for map-level Global Properties on this object (just uses the map name)
-
getIdentifier
Make a best guess for a unique identifier for the target. UseUniqueIdManager.Identifyable.getConfigureName()
if non-null, otherwise useUniqueIdManager.Identifyable.getId()
- Returns:
- Unique Identifier
-
setUpView
public void setUpView()Common view setup code for Map and PrivateMap, which confusingly have different View classes that sharing the same name -
getView
- Returns:
- the Swing component representing the map
-
getLayeredPane
- Returns:
- the JLayeredPane holding map insets
-
getFormattedStringList
- Specified by:
getFormattedStringList
in interfaceSearchTarget
- Overrides:
getFormattedStringList
in classAbstractConfigurable
- Returns:
- a list of any Message Format strings referenced in the Configurable, if any (for search)
-
getMenuTextList
- Specified by:
getMenuTextList
in interfaceSearchTarget
- Overrides:
getMenuTextList
in classAbstractToolbarItem
- Returns:
- a list of any Menu/Button/Tooltip Text strings referenced in the Configurable, if any (for search)
-
getNamedKeyStrokeList
- Specified by:
getNamedKeyStrokeList
in interfaceSearchTarget
- Overrides:
getNamedKeyStrokeList
in classAbstractToolbarItem
- Returns:
- a list of any Named KeyStrokes referenced in the Configurable, if any (for search)
-
addLocalImageNames
In case reports use HTML and refer to any image files- Specified by:
addLocalImageNames
in interfaceImageSearchTarget
- Overrides:
addLocalImageNames
in classAbstractToolbarItem
- Parameters:
s
- Collection to add image names to
-