Package gamedata
Class Silhouette
- java.lang.Object
-
- gamedata.Silhouette
-
- All Implemented Interfaces:
IconProvider
public class Silhouette extends java.lang.Object implements IconProvider
A stencil shape that can be used to "cut out" a marker or token. Silhouette shapes are defined using a greyscale image; white areas will be cut off while black areas will be included as part of the marker's shape. Shades of grey are correspondingly transparent and can be used to create soft edges via antialiasing.- Author:
- Chris Jennings
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_PORTRAIT
The portrait resource that will be returned as the default portrait by all silhouettes who do not specify one.static RegistrationEventSource<Expansion>
Listeners
Listeners that are informed of registration changes.
-
Constructor Summary
Constructors Constructor Description Silhouette(java.lang.String key, java.lang.String stencilResource, java.awt.image.BufferedImage stencil)
This constructor is used when a saved file contains a stencil that is not installed in this copy of Strange Eons.Silhouette(java.lang.String key, java.lang.String stencilResource, java.lang.String portraitResource, double bleedMargin)
Creates a new silhouette with unique keykey
, that will obtain a stencil image fromstencilResource
and useportraitResource
as its default portrait.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
add(java.lang.String silhouetteResource)
Adds silhouettes by parsing a silhouette definition file stored in resources.boolean
equals(java.lang.Object obj)
Returnstrue
if this silhouette andobj
have the same key.static Silhouette
get(java.lang.String key)
Returns the Silhouette with the specified key, ornull
if there is none.double
getBleedMargin()
Returns this silhouette's bleed margin, in points, or 0 if the silhouette does not include a bleed margin.java.lang.String
getDefaultPortrait()
Returns the image resource name for this silhouette's default portrait resource.javax.swing.Icon
getIcon()
Returns a small icon that can be used to represent this silhouette in an interface.java.lang.String
getKey()
Returns this silhouette's unique key.java.lang.String
getLabel()
Returns a localized description of this silhouette.static Silhouette[]
getSilhouettes()
Returns an array of all of the currently registered silhouettes.java.awt.image.BufferedImage
getStencil()
Returns the stencil image for this silhouette.int
hashCode()
static void
register(Silhouette s)
Registers a new silhouette.java.lang.String
toString()
Returns a string representation of the silhouette.static void
unregister(Silhouette s)
Unregisters a silhouette.
-
-
-
Field Detail
-
DEFAULT_PORTRAIT
public static final java.lang.String DEFAULT_PORTRAIT
The portrait resource that will be returned as the default portrait by all silhouettes who do not specify one.- See Also:
- Constant Field Values
-
Listeners
public static final RegistrationEventSource<Expansion> Listeners
Listeners that are informed of registration changes.
-
-
Constructor Detail
-
Silhouette
public Silhouette(java.lang.String key, java.lang.String stencilResource, java.lang.String portraitResource, double bleedMargin)
Creates a new silhouette with unique keykey
, that will obtain a stencil image fromstencilResource
and useportraitResource
as its default portrait.- Parameters:
key
- the unique keystencilResource
- resource file of the stencil imageportraitResource
- resource file of the portrait image; may benull
bleedMargin
- the bleed margin surrounding the silhouette, in points, or 0
-
Silhouette
public Silhouette(java.lang.String key, java.lang.String stencilResource, java.awt.image.BufferedImage stencil)
This constructor is used when a saved file contains a stencil that is not installed in this copy of Strange Eons.- Parameters:
key
-stencilResource
-stencil
-
-
-
Method Detail
-
getKey
public java.lang.String getKey()
Returns this silhouette's unique key.- Returns:
- the silhouette key
-
getLabel
public java.lang.String getLabel()
Returns a localized description of this silhouette.- Returns:
- the silhouette's description
-
getIcon
public javax.swing.Icon getIcon()
Returns a small icon that can be used to represent this silhouette in an interface.- Specified by:
getIcon
in interfaceIconProvider
- Returns:
- an icon of the silhouette shape
-
getStencil
public java.awt.image.BufferedImage getStencil()
Returns the stencil image for this silhouette. The stencil image's alpha channel defines the shape of markers created with this silhouette.- Returns:
- the stencil image for this silhouette
-
getDefaultPortrait
public java.lang.String getDefaultPortrait()
Returns the image resource name for this silhouette's default portrait resource. This is guaranteed not to benull
.- Returns:
- the silhouette's default portrait
-
getBleedMargin
public double getBleedMargin()
Returns this silhouette's bleed margin, in points, or 0 if the silhouette does not include a bleed margin.- Returns:
- the bleed margin surrounding the silhouette, in points, or 0
-
toString
public java.lang.String toString()
Returns a string representation of the silhouette. This is a cover forgetLabel()
.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the silhouette's description
-
equals
public boolean equals(java.lang.Object obj)
Returnstrue
if this silhouette andobj
have the same key.- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- the object to test- Returns:
true
ifobj
is a silhouette with the same key
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
get
public static Silhouette get(java.lang.String key)
Returns the Silhouette with the specified key, ornull
if there is none.- Parameters:
key
- the key to search for- Returns:
- the silhouette with the given key, or
null
-
getSilhouettes
public static Silhouette[] getSilhouettes()
Returns an array of all of the currently registered silhouettes.- Returns:
- a possibly empty array of all silhouettes
-
add
public static void add(java.lang.String silhouetteResource) throws java.io.IOException
Adds silhouettes by parsing a silhouette definition file stored in resources.- Parameters:
silhouetteResource
- the file to parse- Throws:
java.lang.NullPointerException
- if the resource file isnull
java.io.IOException
- if an error occurs while reading the resource fileResourceParserException
- if an error occurs while parsing the file
-
register
public static void register(Silhouette s)
Registers a new silhouette.- Parameters:
s
- the new silhouette to register- Throws:
java.lang.NullPointerException
- ifs
isnull
-
unregister
public static void unregister(Silhouette s)
Unregisters a silhouette.- Parameters:
s
- the silhouette to unregister
-
-