Class StackMetrics

All Implemented Interfaces:
AutoConfigurable, Buildable, Configurable, PropertyNameSource, ValidityChecker, Translatable, Auditable, ImageSearchTarget, SearchTarget
Direct Known Subclasses:
HandMetrics

public class StackMetrics extends AbstractConfigurable
StackMetrics provides the [Stacking options] component of a Map. It encapsulates information on how to draw expanded and unexpanded views of a stack.
  • Field Details

  • Constructor Details

    • StackMetrics

      public StackMetrics()
    • StackMetrics

      public StackMetrics(boolean dis, int exSx, int exSy, int unexSx, int unexSy)
  • Method Details

    • setAttribute

      public void setAttribute(String name, Object value)
      Description copied from class: AbstractBuildable
      Sets a buildFile (XML) attribute value for this component. The key parameter will be one of those listed in AbstractBuildable.getAttributeNames(). If the value parameter is a String, it will be the value returned by AbstractBuildable.getAttributeValueString(String) for the same key. If the implementing class extends AbstractConfigurable, then value will be an instance of the corresponding Class listed in AbstractConfigurable.getAttributeTypes()
      Specified by:
      setAttribute in interface AutoConfigurable
      Specified by:
      setAttribute in interface Translatable
      Specified by:
      setAttribute in class AbstractBuildable
      Parameters:
      name - the name of the attribute. Will be one of those listed in AbstractBuildable.getAttributeNames()
      value - If the value parameter is a String, it will be the value returned by AbstractBuildable.getAttributeValueString(String) for the same key. If the implementing class extends AbstractConfigurable, then value can also be an instance of the corresponding Class listed in AbstractConfigurable.getAttributeTypes()
    • getAttributeValueString

      public String getAttributeValueString(String name)
      Description copied from interface: AutoConfigurable
      Called by the Buildable.getBuildElement(Document) method to write the attributes into an XML element
      Specified by:
      getAttributeValueString in interface AutoConfigurable
      Specified by:
      getAttributeValueString in interface Translatable
      Specified by:
      getAttributeValueString in class AbstractBuildable
      Parameters:
      name - the name of the attribute. Will be one of those listed in AbstractBuildable.getAttributeNames()
      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 AbstractBuildable.setAttribute(String, Object). It is also frequently used for checking the current value of an attribute.
    • addTo

      public void addTo(Buildable b)
      Description copied from interface: Buildable
      Adds this component to its parent. In order to make Buildable objects extensible, the child is responsible for adding itself to the parent. That way, Buildable subcomponents can be defined in an extension package without needing to modify the containing class.
      Parameters:
      b - parent Buildable to add this component to as a subcomponent.
    • draw

      public void draw(Stack stack, Graphics g, int x, int y, Component obs, double zoom)
      Different instances of StackMetrics may render a Stack 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 by GamePiece.getShape(). The separation between GamePieces is given by relativePosition(Stack, GamePiece) If expanded, all GamePieces are drawn with separation given by relativePosition(Stack, 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 -
      location - the location of the stack in component coordinates
      g -
      zoom -
      visibleRect - the visible rectangle in component coordinates
    • drawUnexpanded

      protected void drawUnexpanded(GamePiece p, Graphics g, int x, int y, Component obs, double zoom)
      Draw a GamePiece that is not the top piece in an unexpanded Stack Default implementation is a white square with a black border
    • getBlankColor

      public Color 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 Stack
      positions - If non-null will contain a Point giving the position of each piece in parent
      shapes - If non-null will contain a Shape giving the shape of for each piece in parent
      boundingBoxes - If non-null will contain a Rectangle giving the bounding box for each piece in parent
      x - the x-location of the parent
      y - the y-location of the parent
      Returns:
      the number of pieces processed in the stack
    • nextPosition

      protected void nextPosition(Point currentPos, Rectangle currentBounds, Point nextPos, Rectangle nextBounds, int dx, int dy)
    • relativePosition

      public Point relativePosition(Stack parent, GamePiece c)
    • isStackingEnabled

      public boolean isStackingEnabled()
    • removeFrom

      public void removeFrom(Buildable parent)
      Description copied from interface: Configurable
      Remove this component from its parent
    • getConfigureName

      public String getConfigureName()
      Description copied from class: AbstractConfigurable
      ConfigureName is used, in particular, by the Editor to track the names of components, and is preferred by UniqueIdManager.
      Specified by:
      getConfigureName in interface Configurable
      Overrides:
      getConfigureName in class AbstractConfigurable
      Returns:
      The language-independent name of this component used for programmatic identification (including within Modules by e.g. Traits and module components)
    • getConfigureTypeName

      public static String getConfigureTypeName()
    • getHelpFile

      public HelpFile getHelpFile()
      Returns:
      a HelpFile describing how to use and configure * this component
    • getAllowableConfigureComponents

      public Class<?>[] getAllowableConfigureComponents()
      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.
    • getAttributeNames

      public String[] getAttributeNames()
      Description copied from class: AbstractBuildable
      Lists all the buildFile (XML) attribute names for this component. If this component is ALSO an AbstractConfigurable, then this list of attributes determines the appropriate attribute order for AbstractConfigurable.getAttributeDescriptions() and AbstractConfigurable.getAttributeTypes().
      Specified by:
      getAttributeNames in interface AutoConfigurable
      Specified by:
      getAttributeNames in class AbstractBuildable
      Returns:
      a list of all buildFile (XML) attribute names for this component
    • getAttributeDescriptions

      public String[] 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 interface AutoConfigurable
      Specified by:
      getAttributeDescriptions in class AbstractConfigurable
      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

      public Class<?>[] getAttributeTypes()
      Description copied from interface: AutoConfigurable
      Return the Class for the attributes of this object. Valid classes are: String, Integer, Double, Boolean, Image, File, Color, and KeyStroke
      Specified by:
      getAttributeTypes in interface AutoConfigurable
      Specified by:
      getAttributeTypes in class AbstractConfigurable
      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 in AbstractBuildable.getAttributeNames()
    • getAttributeVisibility

      public VisibilityCondition getAttributeVisibility(String name)
      Description copied from class: AbstractConfigurable
      By default, all attributes are visible
      Specified by:
      getAttributeVisibility in interface AutoConfigurable
      Overrides:
      getAttributeVisibility in class AbstractConfigurable
      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

      public Stack createStack(GamePiece p)
    • createStack

      public Stack createStack(GamePiece p, boolean force)
    • getMoveUpKey

      public KeyStroke getMoveUpKey()
    • getMoveDownKey

      public KeyStroke getMoveDownKey()
    • getMoveTopKey

      public KeyStroke getMoveTopKey()
    • getMoveBottomKey

      public KeyStroke getMoveBottomKey()
    • placeOrMerge

      public Command placeOrMerge(GamePiece fixed, GamePiece moving)
      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

      public 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 instance
      Parameters:
      fixed - the GamePiece defining the location and contents of the existing stack
      moving - the GamePiece that will be merged into the stack
      Returns:
      a Command that accomplishes this task
    • isMandatory

      public boolean isMandatory()
      Description copied from interface: Buildable
      Is this component a reqired component within its parent?
      Returns:
      true if component is mandatory
    • isUnique

      public boolean isUnique()
      Description copied from interface: Buildable
      Does this component need to be unique within it's parent?
      Returns: