Package VASSAL.build.module.map
Class StackMetrics
java.lang.Object
VASSAL.build.AbstractBuildable
VASSAL.build.AbstractConfigurable
VASSAL.build.module.map.StackMetrics
- All Implemented Interfaces:
AutoConfigurable
,Buildable
,Configurable
,PropertyNameSource
,ValidityChecker
,Translatable
- Direct Known Subclasses:
HandMetrics
public class StackMetrics extends AbstractConfigurable
Encapsulates information on how to draw expanded and unexpanded
views of a stack
-
Nested Class Summary
Nested classes/interfaces inherited from interface VASSAL.build.AutoConfigurable
AutoConfigurable.Util
-
Field Summary
Fields Modifier and Type Field Description protected Color
blankColor
static String
BOTTOM_KEY
protected KeyStroke
bottomKey
static String
COLOR
static int
DEFAULT_EXSEP_X
static int
DEFAULT_EXSEP_Y
static int
DEFAULT_UNEXSEP_X
static int
DEFAULT_UNEXSEP_Y
protected boolean
disabled
static String
DISABLED
static String
DOWN_KEY
protected KeyStroke
downKey
static String
EXSEP_X
static String
EXSEP_Y
protected int
exSepX
protected int
exSepY
protected Map
map
protected PieceFilter
selectedVisible
static String
TOP_KEY
protected KeyStroke
topKey
static String
UNEXSEP_X
static String
UNEXSEP_Y
protected int
unexSepX
protected int
unexSepY
protected PieceFilter
unselectedVisible
static String
UP_KEY
protected KeyStroke
upKey
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
Constructors Constructor Description StackMetrics()
StackMetrics(boolean dis, int exSx, int exSy, int unexSx, int unexSy)
-
Method Summary
Modifier and Type Method Description void
addTo(Buildable b)
Adds this component to its parent.Stack
createStack(GamePiece p)
Stack
createStack(GamePiece p, boolean force)
void
draw(Stack stack, Graphics g, int x, int y, Component obs, double zoom)
Different instances of StackMetrics may render aStack
in different ways.void
draw(Stack stack, Point location, Graphics g, Map map, double zoom, Rectangle visibleRect)
Draw only those pieces in the target stack whose boundingBoxes fall within the given visibleRect This method is considerably faster than the other draw method.protected void
drawUnexpanded(GamePiece p, Graphics g, int x, int y, Component obs, double zoom)
Class<?>[]
getAllowableConfigureComponents()
Return a list of valid sub-component Classes.String[]
getAttributeDescriptions()
Return an array of Strings describing the attributes of this object.String[]
getAttributeNames()
Lists all the buildFile (XML) attribute names for this component.Class<?>[]
getAttributeTypes()
Return the Class for the buildFile (XML) attributes of this component.String
getAttributeValueString(String name)
Called by theBuildable.getBuildElement(org.w3c.dom.Document)
method to write the attributes into an XML elementVisibilityCondition
getAttributeVisibility(String name)
By default, all attributes are visibleColor
getBlankColor()
The color used to draw boxes representing counters beneath the top one in a stack.String
getConfigureName()
ConfigureName is used, in particular, by the Editor to track the names of components, and is preferred byUniqueIdManager
.static String
getConfigureTypeName()
int
getContents(Stack parent, Point[] positions, Shape[] shapes, Rectangle[] boundingBoxes, int x, int y)
Fill the argument arrays with the positions, selection bounds and bounding boxes of the pieces in the argument stackHelpFile
getHelpFile()
KeyStroke
getMoveBottomKey()
KeyStroke
getMoveDownKey()
KeyStroke
getMoveTopKey()
KeyStroke
getMoveUpKey()
boolean
isStackingEnabled()
Command
merge(GamePiece fixed, GamePiece moving)
Place a GamePiece on top of another GamePiece Create/remove stacks as necessary, even if stacking is disabled for this instanceprotected void
nextPosition(Point currentPos, Rectangle currentBounds, Point nextPos, Rectangle nextBounds, int dx, int dy)
Command
placeOrMerge(GamePiece fixed, GamePiece moving)
Merge the two pieces if stacking is enabled.Point
relativePosition(Stack parent, GamePiece c)
void
removeFrom(Buildable parent)
Remove this component from its parentvoid
setAttribute(String name, Object value)
Sets a buildFile (XML) attribute value for this component.Methods inherited from class VASSAL.build.AbstractConfigurable
add, addPropertyChangeListener, getConfigureComponents, getConfigurer, getI18nData, getI18nPrefix, getLocalizedConfigureName, remove, removePropertyChangeListener, setAllAttributesUntranslatable, setAttributeTranslatable, setConfigureName
Methods inherited from class VASSAL.build.AbstractBuildable
build, getAllDescendantComponents, getAllDescendantComponentsOf, getBuildables, getBuildComponents, getBuildElement, getComponents, getComponentsOf, getPropertyNames, validate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface VASSAL.build.Buildable
build, getBuildElement
-
Field Details
-
exSepX
protected int exSepX -
exSepY
protected int exSepY -
unexSepX
protected int unexSepX -
unexSepY
protected int unexSepY -
disabled
protected boolean disabled -
topKey
-
bottomKey
-
upKey
-
downKey
-
unselectedVisible
-
selectedVisible
-
blankColor
-
EXSEP_X
- See Also:
- Constant Field Values
-
EXSEP_Y
- See Also:
- Constant Field Values
-
UNEXSEP_X
- See Also:
- Constant Field Values
-
UNEXSEP_Y
- See Also:
- Constant Field Values
-
DISABLED
- See Also:
- Constant Field Values
-
TOP_KEY
- See Also:
- Constant Field Values
-
BOTTOM_KEY
- See Also:
- Constant Field Values
-
UP_KEY
- See Also:
- Constant Field Values
-
DOWN_KEY
- See Also:
- Constant Field Values
-
COLOR
- See Also:
- Constant Field Values
-
DEFAULT_EXSEP_X
public static int DEFAULT_EXSEP_X -
DEFAULT_EXSEP_Y
public static int DEFAULT_EXSEP_Y -
DEFAULT_UNEXSEP_X
public static int DEFAULT_UNEXSEP_X -
DEFAULT_UNEXSEP_Y
public static int DEFAULT_UNEXSEP_Y -
map
-
-
Constructor Details
-
StackMetrics
public StackMetrics() -
StackMetrics
public StackMetrics(boolean dis, int exSx, int exSy, int unexSx, int unexSy)
-
-
Method Details
-
setAttribute
Description copied from class:AbstractBuildable
Sets a buildFile (XML) attribute value for this component. Thekey
parameter will be one of those listed inAbstractBuildable.getAttributeNames()
. If thevalue
parameter is a String, it will be the value returned byAbstractBuildable.getAttributeValueString(java.lang.String)
for the samekey
. If the implementing class extendsAbstractConfigurable
, thenvalue
will be an instance of the corresponding Class listed inAbstractConfigurable.getAttributeTypes()
- Specified by:
setAttribute
in interfaceAutoConfigurable
- Specified by:
setAttribute
in interfaceTranslatable
- Specified by:
setAttribute
in classAbstractBuildable
- Parameters:
name
- the name of the attribute. Will be one of those listed inAbstractBuildable.getAttributeNames()
value
- If thevalue
parameter is a String, it will be the value returned byAbstractBuildable.getAttributeValueString(java.lang.String)
for the samekey
. If the implementing class extendsAbstractConfigurable
, thenvalue
can also be an instance of the corresponding Class listed inAbstractConfigurable.getAttributeTypes()
-
getAttributeValueString
Description copied from interface:AutoConfigurable
Called by theBuildable.getBuildElement(org.w3c.dom.Document)
method to write the attributes into an XML element- Specified by:
getAttributeValueString
in interfaceAutoConfigurable
- Specified by:
getAttributeValueString
in interfaceTranslatable
- Specified by:
getAttributeValueString
in classAbstractBuildable
- Parameters:
name
- the name of the attribute. Will be one of those listed inAbstractBuildable.getAttributeNames()
- Returns:
- a String representation of the attribute with the given name. When initializing a module, this String value will be passed to
AbstractBuildable.setAttribute(java.lang.String, java.lang.Object)
.
-
addTo
Description copied from interface:Buildable
Adds this component to its parent. In order to make Buildable objects extensible, the child is reponsible for adding itself to the parent. That way, Buildable subcomponents can be defined in an extension package without needing to modify the containing class. -
draw
Different instances of StackMetrics may render aStack
in different ways. The default algorithm is: If not expanded, all but the top visible GamePiece is drawn as a white square with size given byGamePiece.getShape()
. The separation between GamePieces is given byrelativePosition(VASSAL.counters.Stack, VASSAL.counters.GamePiece)
If expanded, all GamePieces are drawn with separation given byrelativePosition(VASSAL.counters.Stack, VASSAL.counters.GamePiece)
. GamePiece that are selected are drawn in front of other GamePieces, even those above them in the stack. -
draw
public void draw(Stack stack, Point location, Graphics g, Map map, double zoom, Rectangle visibleRect)Draw only those pieces in the target stack whose boundingBoxes fall within the given visibleRect This method is considerably faster than the other draw method.- Parameters:
stack
-g
-location
- the location of the stack in component coordinateszoom
-visibleRect
- the visible rectangle in component coordinates
-
drawUnexpanded
-
getBlankColor
The color used to draw boxes representing counters beneath the top one in a stack. A value of null indicates that the counters should be drawn fully- Returns:
-
getContents
public int getContents(Stack parent, Point[] positions, Shape[] shapes, Rectangle[] boundingBoxes, int x, int y)Fill the argument arrays with the positions, selection bounds and bounding boxes of the pieces in the argument stack- Parameters:
parent
- The parent Stackpositions
- If non-null will contain aPoint
giving the position of each piece inparent
shapes
- If non-null will contain aShape
giving the shape of for each piece inparent
boundingBoxes
- If non-null will contain aRectangle
giving the bounding box for each piece inparent
x
- the x-location of the parenty
- the y-location of the parent- Returns:
- the number of pieces processed in the stack
-
nextPosition
-
relativePosition
-
isStackingEnabled
public boolean isStackingEnabled() -
removeFrom
Description copied from interface:Configurable
Remove this component from its parent -
getConfigureName
Description copied from class:AbstractConfigurable
ConfigureName is used, in particular, by the Editor to track the names of components, and is preferred byUniqueIdManager
.- Specified by:
getConfigureName
in interfaceConfigurable
- Overrides:
getConfigureName
in classAbstractConfigurable
- Returns:
- The language-independent name of this component used for programmatic identification (including within Modules by e.g. Traits and module components)
-
getConfigureTypeName
-
getHelpFile
- Returns:
- a HelpFilte describing how to use and configure this component
-
getAllowableConfigureComponents
Description copied from interface:Configurable
Return 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 Configuration Window. -
getAttributeNames
Description copied from class:AbstractBuildable
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
- Specified by:
getAttributeNames
in classAbstractBuildable
- Returns:
- a list of all buildFile (XML) attribute names for this component
-
getAttributeDescriptions
Description copied from interface:AutoConfigurable
Return an array of Strings describing the attributes of this object. These strings are used as prompts in the Properties window for this object.- Specified by:
getAttributeDescriptions
in interfaceAutoConfigurable
- Specified by:
getAttributeDescriptions
in classAbstractConfigurable
- 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()
-
getAttributeTypes
Description copied from class:AbstractConfigurable
Return 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 ofAutoConfigurer
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()
- Specified by:
getAttributeTypes
in interfaceAutoConfigurable
- Specified by:
getAttributeTypes
in classAbstractConfigurable
-
getAttributeVisibility
Description copied from class:AbstractConfigurable
By default, all attributes are visible- Specified by:
getAttributeVisibility
in interfaceAutoConfigurable
- Overrides:
getAttributeVisibility
in classAbstractConfigurable
- Parameters:
name
- Name (key) of one of this component's attributes- Returns:
- a
VisibilityCondition
for this attribute, or null if attribute should always be visible.
-
createStack
-
createStack
-
getMoveUpKey
-
getMoveDownKey
-
getMoveTopKey
-
getMoveBottomKey
-
placeOrMerge
Merge the two pieces if stacking is enabled. If stacking is disabled, place the moving piece at the same location as the fixed piece- Parameters:
fixed
-moving
-- Returns:
- a Command that accomplishes this task
- See Also:
merge(VASSAL.counters.GamePiece, VASSAL.counters.GamePiece)
-
merge
Place a GamePiece on top of another GamePiece Create/remove stacks as necessary, even if stacking is disabled for this instance- Parameters:
moving
- the GamePiece that will be merged into the stackfixed
- the GamePiece defining the location and contents of the existing stack- Returns:
- a Command that accomplishes this task
-