Class Dimensions

  • All Implemented Interfaces:
    java.io.Serializable

    public final class Dimensions
    extends java.lang.Object
    implements java.io.Serializable
    Class representing the dimensions of an object.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int height
      The height value of the dimension.
      static java.lang.String HEIGHT_KEY
      The map key to retrieve the height value.
      int width
      The width value of the dimension.
      static java.lang.String WIDTH_KEY
      The map key to retrieve the width value.
      static Dimensions ZERO
      An empty (zero size) dimension value.
    • Constructor Summary

      Constructors 
      Constructor Description
      Dimensions​(int size)
      Construct a "square" dimensions that has the same width as height.
      Dimensions​(int widthValue, int heightValue)
      Construct a dimension with the given values.
      Dimensions​(Dictionary<java.lang.String,​?> dimensions)
      Construct new dimensions from the given dictionary.
      Dimensions​(Sequence<?> dimensions)
      Construct new dimensions from the given sequence of Number values.
      Dimensions​(Dimensions dimensions)
      Construct new dimensions from the given dimensions.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Dimensions decode​(java.lang.String value)
      Convert a string dimensions value to the object.
      boolean equals​(java.lang.Object object)  
      Dimensions expand​(int delta)
      Expand this dimensions by the given amount (positive or negative) in both width and height directions.
      Dimensions expand​(int widthDelta, int heightDelta)
      Expand this dimensions by the given amounts (positive or negative) separately in the width and height directions.
      Dimensions expand​(Insets insets)
      Expand this dimensions by the given Insets amounts in the width and height directions.
      int hashCode()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • width

        public final int width
        The width value of the dimension.
      • height

        public final int height
        The height value of the dimension.
      • WIDTH_KEY

        public static final java.lang.String WIDTH_KEY
        The map key to retrieve the width value.
        See Also:
        Constant Field Values
      • HEIGHT_KEY

        public static final java.lang.String HEIGHT_KEY
        The map key to retrieve the height value.
        See Also:
        Constant Field Values
      • ZERO

        public static final Dimensions ZERO
        An empty (zero size) dimension value.
    • Constructor Detail

      • Dimensions

        public Dimensions​(int size)
        Construct a "square" dimensions that has the same width as height.
        Parameters:
        size - The width and height of this dimension.
      • Dimensions

        public Dimensions​(int widthValue,
                          int heightValue)
        Construct a dimension with the given values.
        Parameters:
        widthValue - The width of the new dimension.
        heightValue - The height of the new dimension.
      • Dimensions

        public Dimensions​(Dimensions dimensions)
        Construct new dimensions from the given dimensions.
        Parameters:
        dimensions - The existing dimensions to copy.
        Throws:
        java.lang.IllegalArgumentException - if the given dimensions is null.
      • Dimensions

        public Dimensions​(Dictionary<java.lang.String,​?> dimensions)
        Construct new dimensions from the given dictionary.
        Parameters:
        dimensions - The dictionary to lookup the new values from.
        Throws:
        java.lang.IllegalArgumentException - if the dictionary value is null.
        See Also:
        WIDTH_KEY, HEIGHT_KEY
      • Dimensions

        public Dimensions​(Sequence<?> dimensions)
        Construct new dimensions from the given sequence of Number values.
        Parameters:
        dimensions - The sequence of dimension values in [width, height] order.
        Throws:
        java.lang.IllegalArgumentException - if the sequence value is null.
    • Method Detail

      • expand

        public Dimensions expand​(int delta)
        Expand this dimensions by the given amount (positive or negative) in both width and height directions.
        Parameters:
        delta - The amount to add to/subtract from both the width and height.
        Returns:
        The new dimensions with the changed values.
      • expand

        public Dimensions expand​(int widthDelta,
                                 int heightDelta)
        Expand this dimensions by the given amounts (positive or negative) separately in the width and height directions.
        Parameters:
        widthDelta - The amount to add to/subtract from the width.
        heightDelta - The amount to add to/subtract from the height.
        Returns:
        The new dimensions with the changed values.
      • expand

        public Dimensions expand​(Insets insets)
        Expand this dimensions by the given Insets amounts in the width and height directions.
        Parameters:
        insets - The padding amounts (width and height) to expand by.
        Returns:
        The new dimensions with the changed values.
      • equals

        public boolean equals​(java.lang.Object object)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • decode

        public static Dimensions decode​(java.lang.String value)
        Convert a string dimensions value to the object.

        The string can be in a variety of forms:

        • A JSON map like this:
          { width:nnn, height:nnn }
        • A JSON array list this:
          [ width, height ]
        • A string formatted as:
          "widthXheight"
          (where the X is case-insensitive)
        • A simple comma-separated string with two numeric values:
          "width, height"
        Parameters:
        value - The input string in one of these formats.
        Returns:
        The parsed dimensions value if possible.
        Throws:
        java.lang.IllegalArgumentException - if the input value is null, empty, or cannot be parsed in one of these forms.
        See Also:
        Dimensions(Dictionary), Dimensions(Sequence), Dimensions(int, int)