Class Insets

  • All Implemented Interfaces:
    java.io.Serializable

    public final class Insets
    extends java.lang.Object
    implements java.io.Serializable
    Class representing the insets of an object, also called "padding" (or in some classes, "margin").
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int bottom
      Value for the bottom inset (or below the object).
      static java.lang.String BOTTOM_KEY
      Map key name for the "bottom" value.
      int left
      Value for the left inset (or to the left of the object).
      static java.lang.String LEFT_KEY
      Map key name for the "left" value.
      static Insets NONE
      Insets whose top, left, bottom, and right values are all zero.
      int right
      Value for the right inset (or to the right of the object).
      static java.lang.String RIGHT_KEY
      Map key name for the "right" value.
      int top
      Value for the top inset (or above the object).
      static java.lang.String TOP_KEY
      Map key name for the "top" value.
    • Constructor Summary

      Constructors 
      Constructor Description
      Insets​(int inset)
      Construct insets with all the same value.
      Insets​(int height, int width)
      Construct an Insets value given the total height and width values to produce.
      Insets​(int topV, int leftV, int bottomV, int rightV)
      Construct with different values for each side.
      Insets​(java.lang.Number inset)
      Construct insets with all the same integer value.
      Insets​(Dictionary<java.lang.String,​?> insets)
      Construct a new set of insets given a dictionary with the values to use.
      Insets​(Sequence<?> insets)
      Construct a new set of insets given a sequence of values to use.
      Insets​(Dimensions size)
      Construct an Insets value given the total dimensions of the value to produce.
      Insets​(Insets insets)
      Copy an insets structure to a new one with the same values.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Insets decode​(java.lang.String value)
      Decode a possible Insets value.
      boolean equals​(java.lang.Object object)  
      static Insets fromObject​(java.lang.Object source)
      Convert any of our supported object sources into a Insets object.
      static Insets fromObject​(java.lang.Object source, java.lang.String message)
      Convert any of our supported object sources into a Insets object.
      int getHeight()  
      Dimensions getSize()
      Return the total size of this insets value as a single Dimensions value.
      int getWidth()  
      int hashCode()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • top

        public final int top
        Value for the top inset (or above the object).
      • left

        public final int left
        Value for the left inset (or to the left of the object).
      • bottom

        public final int bottom
        Value for the bottom inset (or below the object).
      • right

        public final int right
        Value for the right inset (or to the right of the object).
      • TOP_KEY

        public static final java.lang.String TOP_KEY
        Map key name for the "top" value.
        See Also:
        Constant Field Values
      • LEFT_KEY

        public static final java.lang.String LEFT_KEY
        Map key name for the "left" value.
        See Also:
        Constant Field Values
      • BOTTOM_KEY

        public static final java.lang.String BOTTOM_KEY
        Map key name for the "bottom" value.
        See Also:
        Constant Field Values
      • RIGHT_KEY

        public static final java.lang.String RIGHT_KEY
        Map key name for the "right" value.
        See Also:
        Constant Field Values
      • NONE

        public static final Insets NONE
        Insets whose top, left, bottom, and right values are all zero.
    • Constructor Detail

      • Insets

        public Insets​(int inset)
        Construct insets with all the same value.
        Parameters:
        inset - The pixel inset to use on all four sides.
      • Insets

        public Insets​(java.lang.Number inset)
        Construct insets with all the same integer value.
        Parameters:
        inset - The pixel value for all the insets (truncated to an integer).
      • Insets

        public Insets​(int topV,
                      int leftV,
                      int bottomV,
                      int rightV)
        Construct with different values for each side.
        Parameters:
        topV - The top inset value.
        leftV - The left inset value.
        bottomV - The bottom inset value.
        rightV - The right inset value.
      • Insets

        public Insets​(int height,
                      int width)
        Construct an Insets value given the total height and width values to produce.

        This will assign half the height to each of the top and bottom, and half the width each to the left and right.

        Any excess (for odd values) will be assigned to the bottom and right respectively.

        Parameters:
        height - The total height to assign to this Insets value.
        width - The total width to assign.
        See Also:
        getHeight(), getWidth()
      • Insets

        public Insets​(Dimensions size)
        Construct an Insets value given the total dimensions of the value to produce.

        This will assign half the dimensions height to each of the top and bottom, and half the dimensions width each to the left and right.

        Any excess (for odd values) will be assigned to the right and bottom respectively.

        Parameters:
        size - The total size (height and width) to assign.
        See Also:
        getSize()
      • Insets

        public Insets​(Insets insets)
        Copy an insets structure to a new one with the same values.
        Parameters:
        insets - The existing insets to copy (must not be null).
        Throws:
        java.lang.IllegalArgumentException - if the input is null.
      • Insets

        public Insets​(Dictionary<java.lang.String,​?> insets)
        Construct a new set of insets given a dictionary with the values to use.
        Parameters:
        insets - The dictionary of values to use.
        Throws:
        java.lang.IllegalArgumentException - if the input is null.
      • Insets

        public Insets​(Sequence<?> insets)
        Construct a new set of insets given a sequence of values to use.
        Parameters:
        insets - The sequence of values to use in the order of [top, left, bottom, right].
        Throws:
        java.lang.IllegalArgumentException - if the input is null.
    • Method Detail

      • getWidth

        public int getWidth()
        Returns:
        The total width of this Insets (that is, the left + right values).
      • getHeight

        public int getHeight()
        Returns:
        The total height of this Insets (that is, the top + bottom 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
      • fromObject

        public static Insets fromObject​(java.lang.Object source)
        Convert any of our supported object sources into a Insets object.
        Parameters:
        source - Any supported object (Integer, Number, String, etc.).
        Returns:
        The constructed Insets object.
        Throws:
        java.lang.IllegalArgumentException - if the source if null or we can't figure out how to convert.
      • fromObject

        public static Insets fromObject​(java.lang.Object source,
                                        java.lang.String message)
        Convert any of our supported object sources into a Insets object.
        Parameters:
        source - Any supported object (Integer, Number, String, etc.).
        message - Description of the setting we are converting (eg, "margin", "padding", etc.).
        Returns:
        The constructed Insets object.
        Throws:
        java.lang.IllegalArgumentException - if the source if null or we can't figure out how to convert.
      • decode

        public static Insets decode​(java.lang.String value)
        Decode a possible Insets value. The value can be in one of the following forms:
        • { "top": nnn, "left": nnn, "bottom": nnn, "right": nnn }
        • [ top, left, bottom, right ]
        • top[,;] left[,;] bottom[,;] right
        • nnnn
        Parameters:
        value - The string value of the Insets to decode.
        Returns:
        The parsed Insets value.
        Throws:
        java.lang.IllegalArgumentException - if the input is not in one of these formats.
        See Also:
        Insets(Dictionary), Insets(Sequence), Insets(int, int, int, int), Insets(int)