Package VASSAL.build.widget
Class PieceSlot
java.lang.Object
VASSAL.build.AbstractBuildable
VASSAL.build.AbstractConfigurable
VASSAL.build.Widget
VASSAL.build.widget.PieceSlot
- All Implemented Interfaces:
KeyListener
,MouseListener
,EventListener
,AutoConfigurable
,Buildable
,Configurable
,PropertyNameSource
,ValidityChecker
,Translatable
- Direct Known Subclasses:
CardSlot
public class PieceSlot extends Widget implements MouseListener, KeyListener
A Component that displays a GamePiece.
Can be added to any Widget but cannot contain any children Keyboard input on
a PieceSlot is forwarded to the
GamePiece.keyEvent(javax.swing.KeyStroke)
method for the
PieceSlot's GamePiece. Clicking on a PieceSlot initiates a drag-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
PieceSlot.Panel
Nested classes/interfaces inherited from class VASSAL.build.Widget
Widget.MyCellRenderer
Nested classes/interfaces inherited from interface VASSAL.build.AutoConfigurable
AutoConfigurable.Util
-
Field Summary
Fields Modifier and Type Field Description protected GamePiece
c
protected GamePiece
expanded
protected static Font
FONT
static String
GP_ID
protected String
gpId
protected GpIdSupport
gpidSupport
protected int
height
protected JPanel
panel
protected String
pieceDefinition
protected int
width
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 Type Method Description void
addTo(Buildable par)
Adds this component to its parent.void
build(Element e)
When building a PieceSlot, the text contents of the XML element are parsed into a String.protected void
clearExpandedPiece()
protected void
copyFrom(PieceSlot piece)
protected void
doPopup(MouseEvent e)
Class<?>[]
getAllowableConfigureComponents()
The allowable Configurable components of a Widget are the same as its parentString[]
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 attr)
Called by theBuildable.getBuildElement(org.w3c.dom.Document)
method to write the attributes into an XML elementElement
getBuildElement(Document doc)
Component
getComponent()
Configurable[]
getConfigureComponents()
String
getConfigureName()
ConfigureName is used, in particular, by the Editor to track the names of components, and is preferred byUniqueIdManager
.Configurer
getConfigurer()
static String
getConfigureTypeName()
protected GamePiece
getExpandedPiece()
Return defined GamePiece with prototypes fully expanded.String
getGpId()
HelpFile
getHelpFile()
ComponentI18nData
getI18nData()
String
getName()
GamePiece
getPiece()
Return defined GamePiece with prototypes unexpanded.String
getPieceDefinition()
Dimension
getPreferredSize()
double
getScale()
void
keyPressed(KeyEvent e)
void
keyReleased(KeyEvent e)
void
keyTyped(KeyEvent e)
void
mouseClicked(MouseEvent e)
void
mouseEntered(MouseEvent e)
void
mouseExited(MouseEvent e)
void
mousePressed(MouseEvent e)
void
mouseReleased(MouseEvent e)
void
paint(Graphics g)
void
removeFrom(Buildable parent)
Remove this component from its parentvoid
setAttribute(String name, Object value)
Sets a buildFile (XML) attribute value for this component.void
setGpId(String id)
void
setGpidSupport(GpIdSupport s)
void
setPiece(GamePiece p)
protected void
startDrag()
void
updateGpId()
Allocate a new gpid to this PieceSlot, plus to any PlaceMarker or Replace traits.void
updateGpId(GpIdSupport s)
Update the gpid for this PieceSlot, using the givenGpIdSupport
to generate the new id.void
updateGpId(GamePiece piece)
Allocate new gpid's in the given GamePieceMethods inherited from class VASSAL.build.AbstractConfigurable
add, addPropertyChangeListener, getAttributeVisibility, getI18nPrefix, getLocalizedConfigureName, remove, removePropertyChangeListener, setAllAttributesUntranslatable, setAttributeTranslatable, setConfigureName
Methods inherited from class VASSAL.build.AbstractBuildable
getAllDescendantComponents, getAllDescendantComponentsOf, getBuildables, getBuildComponents, getComponents, getComponentsOf, getPropertyNames, validate
-
Field Details
-
GP_ID
- See Also:
- Constant Field Values
-
c
-
expanded
-
pieceDefinition
-
FONT
-
panel
-
width
protected int width -
height
protected int height -
gpId
-
gpidSupport
-
-
Constructor Details
-
PieceSlot
public PieceSlot() -
PieceSlot
-
PieceSlot
-
PieceSlot
-
-
Method Details
-
getName
-
getPieceDefinition
-
getScale
public double getScale() -
copyFrom
-
setPiece
-
getExpandedPiece
Return defined GamePiece with prototypes fully expanded.- Returns:
- expanded piece
-
clearExpandedPiece
protected void clearExpandedPiece() -
getPiece
Return defined GamePiece with prototypes unexpanded.- Returns:
- unexpanded piece
-
paint
-
getPreferredSize
-
startDrag
protected void startDrag() -
doPopup
-
mousePressed
- Specified by:
mousePressed
in interfaceMouseListener
-
mouseReleased
- Specified by:
mouseReleased
in interfaceMouseListener
-
mouseClicked
- Specified by:
mouseClicked
in interfaceMouseListener
-
mouseEntered
- Specified by:
mouseEntered
in interfaceMouseListener
-
mouseExited
- Specified by:
mouseExited
in interfaceMouseListener
-
keyPressed
- Specified by:
keyPressed
in interfaceKeyListener
-
keyTyped
- Specified by:
keyTyped
in interfaceKeyListener
-
keyReleased
- Specified by:
keyReleased
in interfaceKeyListener
-
getConfigureTypeName
-
getComponent
- Specified by:
getComponent
in classWidget
- Returns:
- the Component for this widget. For efficiency, the
Component may be initialized lazily instead of being created
in the
Buildable.build(org.w3c.dom.Element)
method
-
build
When building a PieceSlot, the text contents of the XML element are parsed into a String. The String is decoded usingGameModule.decode(java.lang.String)
. The resultingCommand
should be an instance ofAddPiece
. The piece referred to in the Command becomes the piece contained in the PieceSlot -
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. -
getBuildElement
- Specified by:
getBuildElement
in interfaceBuildable
- Overrides:
getBuildElement
in classWidget
- Returns:
- an XML element from which this component can be built
-
removeFrom
Description copied from interface:Configurable
Remove this component from its parent- Specified by:
removeFrom
in interfaceConfigurable
- Overrides:
removeFrom
in classWidget
-
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)
-
getHelpFile
- Specified by:
getHelpFile
in interfaceConfigurable
- Overrides:
getHelpFile
in classWidget
- Returns:
- a HelpFilte describing how to use and configure this component
-
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
-
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()
-
getConfigureComponents
- Specified by:
getConfigureComponents
in interfaceConfigurable
- Overrides:
getConfigureComponents
in classWidget
- Returns:
- an array of Configurer objects representing the Buildable children of this Configurable object
-
getAllowableConfigureComponents
Description copied from class:Widget
The allowable Configurable components of a Widget are the same as its parent- Specified by:
getAllowableConfigureComponents
in interfaceConfigurable
- Overrides:
getAllowableConfigureComponents
in classWidget
- Returns:
- an array of Configurer objects representing all possible classes of Buildable children of this Configurable object
-
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:
attr
- 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)
.
-
getI18nData
- Specified by:
getI18nData
in interfaceTranslatable
- Overrides:
getI18nData
in classAbstractConfigurable
- Returns:
- the i18n data for this component
-
getConfigurer
Description copied from class:AbstractConfigurable
- Specified by:
getConfigurer
in interfaceConfigurable
- Overrides:
getConfigurer
in classAbstractConfigurable
- Returns:
- Configurer for this component
-
updateGpId
Update the gpid for this PieceSlot, using the givenGpIdSupport
to generate the new id. -
setGpidSupport
-
updateGpId
public void updateGpId()Allocate a new gpid to this PieceSlot, plus to any PlaceMarker or Replace traits. -
updateGpId
Allocate new gpid's in the given GamePiece- Parameters:
piece
- GamePiece
-
getGpId
-
setGpId
-