# Class Padding

java.lang.Object
uk.ac.starlink.ttools.plot2.Padding

@Equality public class Padding extends Object
Defines user preferences for padding a rectangular area. This resembles `Insets`, except that each member may be null, to indicate that the user has no preference. And it's immutable.

Since:
  9 Dec 2016
Author:
  Mark Taylor

## Constructor Summary

Constructors
Constructor
Description
`Padding()`
Constructs an empty padding object (no preferences).
`Padding(Integer top, Integer left, Integer bottom, Integer right)`
Constructs a padding object with preferences for all dimensions.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`equals(Object o)`
`Integer`
`getBottom()`
Returns the required bottom margin.
`Integer`
`getLeft()`
Returns the required left margin.
`Integer`
`getRight()`
Returns the required right margin.
`Integer`
`getTop()`
Returns the required top margin.
`int`
`hashCode()`
`boolean`
`isDefinite()`
Returns true if all the members of this padding object are non-null.
`Insets`
`overrideInsets(Insets insets)`
Applies the requirements specified by this object to an existing Insets object.
`static Insets`
`padInsets(Padding padding, Insets insets)`
Returns a non-null insets object based on a supplied Insets which will be modified by the state of a supplied Padding.
`Insets`
`toDefiniteInsets()`
Returns the insets object corresponding to this padding object if all the members are non-null, and null otherwise.

### Methods inherited from class Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### Padding

public Padding()
Constructs an empty padding object (no preferences).

### Padding

public Padding(Integer top, Integer left, Integer bottom, Integer right)
Constructs a padding object with preferences for all dimensions. Any of the arguments may be null.

Parameters:
  `top` - required top margin in pixels, or null
  `left` - required left margin in pixels, or null
  `bottom` - required bottom margin in pixels, or null
  `right` - required right margin in pixels, or null

## Method Details

### getTop

public Integer getTop()
Returns the required top margin.

Returns:
  top margin in pixels, or null for no preference

### getLeft

public Integer getLeft()
Returns the required left margin.

Returns:
  left margin in pixels, or null for no preference

### getBottom

public Integer getBottom()
Returns the required bottom margin.

Returns:
  bottom margin in pixels, or null for no preference

### getRight

public Integer getRight()
Returns the required right margin.

Returns:
  right margin in pixels, or null for no preference

### overrideInsets

public Insets overrideInsets(Insets insets)
Applies the requirements specified by this object to an existing Insets object. The members of the returned insets object are those of this object where they are non-null, and those of the supplied insets otherwise.

Parameters:
  `insets` - input insets object, not null
Returns:
  new insets object with values taken from this padding where available

### isDefinite

public boolean isDefinite()
Returns true if all the members of this padding object are non-null.

Returns:
  true iff all margins have definite values

### toDefiniteInsets

public Insets toDefiniteInsets()
Returns the insets object corresponding to this padding object if all the members are non-null, and null otherwise.

Returns:
  insets if `isDefinite()`, otherwise null

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### equals

public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

### padInsets

public static Insets padInsets(Padding padding, Insets insets)
Returns a non-null insets object based on a supplied Insets which will be modified by the state of a supplied Padding.

This convenience method calls `overrideInsets(Insets)` if `padding` is non-null, otherwise it returns the input `insets`.

Parameters:
  `padding` - padding to override insets value, may be null
  `insets` - default insets, not null
Returns:
  effective insets