Class 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 class  StyleCapture.Property
      Encapsulates 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
      void apply​(java.lang.Object target)
      Applies the properties in this capture to the given object.
      static boolean canPaste()
      Returns true if the global style clipboard contains style information.
      int capture​(java.lang.Object pi)
      Captures style information from the specified object (typically a PageItem) and merges it with the existing capture.
      void clear()
      Clears the captured information, resetting this capture to an empty state.
      void copy()
      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.Property getProperty​(java.lang.String name)
      Returns a StyleCapture.Property instance representing the captured property with the given name, or null if the property has not been captured.
      boolean isStyleInCapture​(java.lang.Class<? extends Style> style)
      Returns true if the specified style has been captured.
      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.
      java.util.Iterator<StyleCapture.Property> iterator()
      Returns an iterator over the captured properties.
      static void paste​(java.lang.Object... destination)
      Applies the styles in the global style clipboard to the specified objects.
      void setProperty​(java.lang.Class<? extends Style> style, java.lang.String name, java.lang.Object value)
      Sets the value of a property.
      int size()
      Returns the number of style properties in this capture.
      java.lang.String toString()
      Returns a string containing debugging information about this capture.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • 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 a PageItem) and merges it with the existing capture.
        Parameters:
        pi - the item to capture
        Returns:
        the number of subinterfaces of the Style interface 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:
        apply in interface StyleApplicator
        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)
        Returns true if the specified style has been captured.
        Parameters:
        style - the style to test for
        Returns:
        true if 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:
        true if the style is in conflict
      • getProperty

        public StyleCapture.Property getProperty​(java.lang.String name)
        Returns a StyleCapture.Property instance representing the captured property with the given name, or null if the property has not been captured.
        Parameters:
        name - the property name, which must be non-null
        Returns:
        the value of the property, or null if 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 - the Style interface that the property belongs to
        name - the name of the property
        value - 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:
        iterator in interface java.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:
        toString in class java.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()
        Returns true if the global style clipboard contains style information.
        Returns:
        true if non-empty captures have previously been copied.