Class Labeler

All Implemented Interfaces:
PropertyNameSource, PropertySource, EditablePiece, GamePiece, PropertyExporter, StateMergeable, TranslatablePiece, PersistentPropertyContainer, Auditable, ImageSearchTarget, SearchTarget, RecursionLimiter.Loopable

public class Labeler extends Decorator implements TranslatablePiece, RecursionLimiter.Loopable
d/b/a "Text Label" Displays a text label, with content specified by the user at runtime.
  • Field Details

    • ID

      public static final String ID
      See Also:
    • textBg

      protected Color textBg
    • textFg

      protected Color textFg
    • imagePainter

      @Deprecated(since="2021-12-01", forRemoval=true) protected ScaledImagePainter imagePainter
      Deprecated, for removal: This API element is subject to removal in a future version.
    • rotateDegrees

      protected int rotateDegrees
    • propertyName

      protected String propertyName
    • description

      protected String description
    • alwaysUseFormat

      protected boolean alwaysUseFormat
    • lastRect

      @Deprecated(since="2021-03-14", forRemoval=true) protected Rectangle lastRect
      Deprecated, for removal: This API element is subject to removal in a future version.
    • lastShape

      @Deprecated(since="2021-03-14", forRemoval=true) protected Area lastShape
      Deprecated, for removal: This API element is subject to removal in a future version.
  • Constructor Details

    • Labeler

      public Labeler()
    • Labeler

      public Labeler(String s, GamePiece d)
  • Method Details

    • getLabelKey

      public NamedKeyStroke getLabelKey()
    • canChange

      public boolean canChange()
      Can this Label be changed?
    • mySetType

      public void mySetType(String type)
      Description copied from interface: EditablePiece
      Sets the information for this piece. See Decorator.myGetType()
      Specified by:
      mySetType in interface EditablePiece
      Parameters:
      type - a serialized configuration string to set the "type information" of this piece, which is information that doesn't change during the course of a single game (e.g. Image Files, Context Menu strings, etc). Typically ready to be processed e.g. by SequenceEncoder.decode()
    • clean

      protected String clean(String s)
    • getLocalizedProperty

      public Object getLocalizedProperty(Object key)
      Description copied from class: Decorator
      Returns a localized translation of the specified property value, if available. Otherwise returns the non-localized version. See Decorator.getProperty(java.lang.Object).
      Specified by:
      getLocalizedProperty in interface PropertySource
      Overrides:
      getLocalizedProperty in class Decorator
      Parameters:
      key - String key of property to be returned
      Returns:
      Object containing localized text of the specified property, if available, otherwise non-localized value
    • getProperty

      public Object getProperty(Object key)
      Description copied from class: Decorator
      Properties can be associated with a piece -- many may be game-specific, but others are standard, such as the LocationName property exposed by BasicPiece -- and can be read through this interface. The properties may or may not need to be encoded in the piece's Decorator.getState() method. Properties include the value of e.g. Marker Traits, DynamicProperty Traits, and so forth. Furthermore they include the values of any visible "Global Property" in a Vassal module, whether at the module level, map level, or zone level -- but these "higher level" properties, coming from "outside the piece", CANNOT be written to by the Decorator.setProperty(java.lang.Object, java.lang.Object) method even though they can be read by this method -- in this sense the two methods are NOT perfect mirrors.

      Within a Trait/Decorator, default behavior is to process some requests directly (e.g. requests for our "inner" or "outer" link), process our *part* of certain other requests (e.g. request for our game state information we supply state information for this trait and then append any information obtained from passing the same request inward), and then for any other requests that we cannot process we simply pass the request to the next trait/member inward.

      When using this interface a piece's own properties are preferred to those of "Global Properties", and those in turn are searched Zone-first then Map, then Module.

      This method implements the PropertySource interface, which allows Global Properties to be read by other types of object than GamePieces.
      Specified by:
      getProperty in interface GamePiece
      Specified by:
      getProperty in interface PropertySource
      Overrides:
      getProperty in class Decorator
      Parameters:
      key - String key of property to be returned
      Returns:
      Object containing new value of the specified property
    • myGetType

      public String myGetType()
      Description copied from class: Decorator
      The "type information" of a piece or trait is information that does not change during the course of a game. Image file names, context menu strings, etc., all should be reflected in the type. The type information is returned serialized string form, ready to be decoded by a SequenceEncoder#decode.
      Specified by:
      myGetType in class Decorator
      Returns:
      the type information of this trait alone
      See Also:
    • myGetState

      public String myGetState()
      Description copied from class: Decorator
      The "state information" is "game state" information that can change during the course of a game. State information is saved when the game is saved and is transferred between players on the server. For example, the relative order of pieces in a stack is state information, but whether the stack is expanded is not.
      Specified by:
      myGetState in class Decorator
      Returns:
      the game state information of this trait alone
      See Also:
    • mySetState

      public void mySetState(String s)
      Description copied from class: Decorator
      Sets the state of this-trait-only (inverse of Decorator.myGetState()). The "state information" is information that can change during the course of a game. State information is saved when the game is saved and is transferred between players on the server. For example, the relative order of pieces in a stack is state information, but whether the stack is expanded is not.
      Specified by:
      mySetState in class Decorator
      Parameters:
      s - New state information serialized in string form, ready to be passed to a SequenceEncoder#decode.
    • getName

      public String getName()
      Description copied from interface: GamePiece
      The plain English name for this piece
      Specified by:
      getName in interface GamePiece
    • getLocalizedName

      public String getLocalizedName()
      Description copied from interface: GamePiece
      And the translated name for this piece
      Specified by:
      getLocalizedName in interface GamePiece
      Overrides:
      getLocalizedName in class Decorator
      Returns:
      the translated name for this piece. Most pieces do not have translatable elements, so just return the standard name
    • getActualDescription

      public String getActualDescription()
    • draw

      public void draw(Graphics g, int x, int y, Component obs, double zoom)
      Description copied from interface: GamePiece
      Draw this GamePiece
      Specified by:
      draw in interface GamePiece
      Parameters:
      g - target Graphics object
      x - x-location of the center of the piece
      y - y-location of the center of the piece
      obs - the Component on which this piece is being drawn
      zoom - the scaling factor.
    • updateCachedImage

      protected void updateCachedImage()
    • setLabel

      public void setLabel(String s)
    • setBackground

      public void setBackground(Color textBg)
    • setForeground

      public void setForeground(Color textFg)
    • getLabel

      public String getLabel()
    • getLocalizedLabel

      public String getLocalizedLabel()
    • boundingBox

      public Rectangle boundingBox()
      Specified by:
      boundingBox in interface GamePiece
      Returns:
      The area which this GamePiece occupies when drawn at the point (0,0)
    • getShape

      public Shape getShape()
      Return the Shape of the counter by adding the shape of this label to the shape of all inner traits. Minimize generation of new Area objects.
      Specified by:
      getShape in interface GamePiece
      Returns:
      The shape of the piece from the user's viewpoint. This defines the area in which the user must click to select or move the piece, for example. Like GamePiece.boundingBox(), it assumes the position is (0,0) -- which to be clear is normally aligned with the CENTER of the piece image -- and must be translated to the actual location where the piece is being drawn. For most ordinary pieces, the shape returned here will simply be equivalent to the bounding box, but see NonRectangular.
    • myGetKeyCommands

      public KeyCommand[] myGetKeyCommands()
      Specified by:
      myGetKeyCommands in class Decorator
      Returns:
      the key commands for this trait alone
      See Also:
    • myKeyEvent

      public Command myKeyEvent(KeyStroke stroke)
      Description copied from class: Decorator
      The response of this trait alone to the given KeyStroke or the virtual keystroke of a NamedKeyStroke. NamedKeyStrokes are allocated a unique internal KeyStroke when they are first used in a module, and that KeyStroke is passed up and down the decorator stack to represent them (see NamedKeyStroke.getKeyStroke()).
      Specified by:
      myKeyEvent in class Decorator
      Parameters:
      stroke - KeyStroke to apply (to apply a Named Keystroke send NamedKeyStroke.getKeyStroke()
      Returns:
      Generated Command to reproduce any changes just made to to the game state, or null if no effect
      See Also:
    • getDescription

      public String getDescription()
      Description copied from interface: EditablePiece
      A plain-English description of this type of trait/piece - includes data from fields where appropriate
      Specified by:
      getDescription in interface EditablePiece
    • getBaseDescription

      public String getBaseDescription()
      Description copied from interface: EditablePiece
      Support for a basic-name-only description introduced later, so this default retrofits it from the full description if an explicit one is not defined.
      Specified by:
      getBaseDescription in interface EditablePiece
      Returns:
      name of trait/piece type, w/o additional data
    • getDescriptionField

      public String getDescriptionField()
      Description copied from class: Decorator
      If Decorator contains a description *field*, returns the current contents of it.
      Overrides:
      getDescriptionField in class Decorator
      Returns:
      contents of "description" field, if it exists.
    • getHelpFile

      public HelpFile getHelpFile()
      Specified by:
      getHelpFile in interface EditablePiece
      Returns:
      the help file for this trait
    • getEditor

      public PieceEditor getEditor()
      Specified by:
      getEditor in interface EditablePiece
      Overrides:
      getEditor in class Decorator
      Returns:
      the configurer for this trait - the dialog which allows the editing the piece's type information. Default configurer is a SimplePieceEditor, but many traits will want to provide custom versions.
    • testEquals

      public boolean testEquals(Object o)
      Description copied from class: Decorator
      Test if this Decorator's Class, Type and State are equal to another trait. Implementations of this method should compare the individual values of the fields that make up the Decorators Type and State. Implementations should NOT compare the values returned by myGetType() or myGetState(). This method is intended to be used by Unit Tests to verify that a trait is unchanged after going through a process such as serialization/deserialization.
      Overrides:
      testEquals in class Decorator
      Parameters:
      o - Object to compare this Decorator to
      Returns:
      true if the Class, type and state all match
    • getPropertyNames

      public List<String> getPropertyNames()
      Return Property names exposed by this trait
      Specified by:
      getPropertyNames in interface PropertyNameSource
      Overrides:
      getPropertyNames in class Decorator
      Returns:
      List of property names "exposed" by this piece -- that are available to other Traits and components to read. Default behavior for a Trait is not to expose any properties, but Traits which should expose some (e.g. DynamicProperty or Marker) would provide an array of the property names here.
    • getI18nData

      public PieceI18nData getI18nData()
      Description copied from class: Decorator
      Return Internationalization (I18n) data for this piece
      Specified by:
      getI18nData in interface TranslatablePiece
      Overrides:
      getI18nData in class Decorator
      Returns:
      I18n data, used to hold translations of strings
    • drawLabel

      @Deprecated(since="2020-08-27", forRemoval=true) public static void drawLabel(Graphics g, String text, int x, int y, int hAlign, int vAlign, Color fgColor, Color bgColor)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • drawLabel

      @Deprecated(since="2020-08-27", forRemoval=true) public static void drawLabel(Graphics g, String text, int x, int y, Font f, int hAlign, int vAlign, Color fgColor, Color bgColor, Color borderColor)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getPropertyList

      public List<String> getPropertyList()
      Description copied from class: Decorator
      Specified by:
      getPropertyList in interface SearchTarget
      Overrides:
      getPropertyList in class Decorator
      Returns:
      a list of any Property Names referenced in the Decorator, if any (for search)
    • getNamedKeyStrokeList

      public List<NamedKeyStroke> getNamedKeyStrokeList()
      Description copied from class: Decorator
      Specified by:
      getNamedKeyStrokeList in interface SearchTarget
      Overrides:
      getNamedKeyStrokeList in class Decorator
      Returns:
      a list of any Named KeyStrokes referenced in the Decorator, if any (for search)
    • getMenuTextList

      public List<String> getMenuTextList()
      Description copied from class: Decorator
      Specified by:
      getMenuTextList in interface SearchTarget
      Overrides:
      getMenuTextList in class Decorator
      Returns:
      a list of any Menu Text strings referenced in the Decorator, if any (for search)
    • getFormattedStringList

      public List<String> getFormattedStringList()
      Description copied from class: Decorator
      Specified by:
      getFormattedStringList in interface SearchTarget
      Overrides:
      getFormattedStringList in class Decorator
      Returns:
      a list of any Message Format strings referenced in the Decorator, if any (for search)
    • addLocalImageNames

      public void addLocalImageNames(Collection<String> s)
      In case our labels refer to any image files
      Specified by:
      addLocalImageNames in interface ImageSearchTarget
      Overrides:
      addLocalImageNames in class AbstractImageFinder
      Parameters:
      s - Collection to add image names to