Class StyleCapture
- java.lang.Object
-
- ca.cgjennings.apps.arkham.deck.item.StyleCapture
-
- All Implemented Interfaces:
StyleApplicator,java.lang.Iterable<StyleCapture.Property>
public final class StyleCapture extends java.lang.Object implements java.lang.Iterable<StyleCapture.Property>, StyleApplicator
A style capture can collect a composite of the styles of one or more items, and can optionally apply those styles to another set of items.- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStyleCapture.PropertyEncapsulates a captured style property.
-
Constructor Summary
Constructors Constructor Description StyleCapture()Creates a new, empty style capture.StyleCapture(PageItem item)Creates a new style capture whose initial state is a capture of the specified items.StyleCapture(PageItem... items)Creates a new style capture whose initial state is a capture of the specified items.StyleCapture(java.util.Collection<? extends PageItem> items)Creates a new style capture whose initial state is a capture of the specified items.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapply(java.lang.Object target)Applies the properties in this capture to the given object.static booleancanPaste()Returnstrueif the global style clipboard contains style information.intcapture(java.lang.Object pi)Captures style information from the specified object (typically aPageItem) and merges it with the existing capture.voidclear()Clears the captured information, resetting this capture to an empty state.voidcopy()Copies this style capture to the global style clipboard.java.util.Set<java.lang.Class<? extends Style>>getCapturedStyles()Returns a set of the style classes that have been captured.StyleCapture.PropertygetProperty(java.lang.String name)Returns aStyleCapture.Propertyinstance representing the captured property with the given name, ornullif the property has not been captured.booleanisStyleInCapture(java.lang.Class<? extends Style> style)Returnstrueif the specified style has been captured.booleanisStyleInConflict(java.lang.Class<? extends Style> style)As styles are captured from more than one item, if two items share a common style but the properties of that style are different, then only the most recently added item's style will be reflected.java.util.Iterator<StyleCapture.Property>iterator()Returns an iterator over the captured properties.static voidpaste(java.lang.Object... destination)Applies the styles in the global style clipboard to the specified objects.voidsetProperty(java.lang.Class<? extends Style> style, java.lang.String name, java.lang.Object value)Sets the value of a property.intsize()Returns the number of style properties in this capture.java.lang.StringtoString()Returns a string containing debugging information about this capture.
-
-
-
Constructor Detail
-
StyleCapture
public StyleCapture()
Creates a new, empty style capture.
-
StyleCapture
public StyleCapture(PageItem item)
Creates a new style capture whose initial state is a capture of the specified items.- Parameters:
item- the initial capture
-
StyleCapture
public StyleCapture(PageItem... items)
Creates a new style capture whose initial state is a capture of the specified items.- Parameters:
items- the initial capture
-
StyleCapture
public StyleCapture(java.util.Collection<? extends PageItem> items)
Creates a new style capture whose initial state is a capture of the specified items.- Parameters:
items- the initial capture
-
-
Method Detail
-
capture
public int capture(java.lang.Object pi)
Captures style information from the specified object (typically aPageItem) and merges it with the existing capture.- Parameters:
pi- the item to capture- Returns:
- the number of subinterfaces of the
Styleinterface whose properties were captured from the page item
-
apply
public void apply(java.lang.Object target)
Applies the properties in this capture to the given object. This is done by calling the setters on the page item with names and signatures that match the captured properties.- Specified by:
applyin interfaceStyleApplicator- Parameters:
target- the item to modify
-
getCapturedStyles
public java.util.Set<java.lang.Class<? extends Style>> getCapturedStyles()
Returns a set of the style classes that have been captured. For example, to test if the set contains a opacity, you could use the following code:getCapturedStyles().contains( OpacityStyle.class );
- Returns:
- an immutable set of the captured styles
-
isStyleInCapture
public boolean isStyleInCapture(java.lang.Class<? extends Style> style)
Returnstrueif the specified style has been captured.- Parameters:
style- the style to test for- Returns:
trueif any of the captured items provide this style
-
isStyleInConflict
public boolean isStyleInConflict(java.lang.Class<? extends Style> style)
As styles are captured from more than one item, if two items share a common style but the properties of that style are different, then only the most recently added item's style will be reflected. The capture is said to have a conflict for that style.- Parameters:
style- the style to check- Returns:
trueif the style is in conflict
-
getProperty
public StyleCapture.Property getProperty(java.lang.String name)
Returns aStyleCapture.Propertyinstance representing the captured property with the given name, ornullif the property has not been captured.- Parameters:
name- the property name, which must be non-null- Returns:
- the value of the property, or
nullif it has not been captured
-
setProperty
public void setProperty(java.lang.Class<? extends Style> style, java.lang.String name, java.lang.Object value)
Sets the value of a property. If the property is already defined, its value will be replaced (possibly creating a conflict for the style). This method is used primarily to define a capture that represents a set of style defaults.- Parameters:
style- theStyleinterface that the property belongs toname- the name of the propertyvalue- the property's new value (the type of this object must be appropriate for the an object with the correct type for the property that will become the propits new value- Throws:
java.lang.IllegalArgumentException- if the specified style class has no property with the specified name
-
size
public int size()
Returns the number of style properties in this capture.- Returns:
- the number of captured properties
-
iterator
public java.util.Iterator<StyleCapture.Property> iterator()
Returns an iterator over the captured properties.- Specified by:
iteratorin interfacejava.lang.Iterable<StyleCapture.Property>- Returns:
- an iterator over the properties in this capture
-
clear
public void clear()
Clears the captured information, resetting this capture to an empty state.
-
toString
public java.lang.String toString()
Returns a string containing debugging information about this capture. The returned string will include all of the captured interfaces and all of the captured properties and their values.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string describing what has been captured by this capture
-
copy
public void copy()
Copies this style capture to the global style clipboard. The properties of the captured style classes in this capture will replace the properties of the same classes in the capture.
-
paste
public static void paste(java.lang.Object... destination)
Applies the styles in the global style clipboard to the specified objects. If no styles have been copied into the global style clipboard, this method does nothing.- Parameters:
destination- the objects to apply the style clipboard styles to
-
canPaste
public static boolean canPaste()
Returnstrueif the global style clipboard contains style information.- Returns:
trueif non-empty captures have previously been copied.
-
-