Package swingtree.layout
Class Size
java.lang.Object
swingtree.layout.Size
An immutable value object that represents a size in the form of float based width and height or lack thereof.
This is used to represent the size and layout dimensions of components in the SwingTree style API,
as well as the size of icons as part of
IconDeclarations.
See UIForAnySwing.withStyle(Styler),
ComponentStyleDelegate.image(swingtree.api.Configurator) and
ImageConf.size(int, int) for examples of where and how this class is used.-
Method Summary
Modifier and TypeMethodDescriptionbooleaninthashCode()booleanAllows you to check if the height value of thisSizeinstance is both specified (non-negative) and also positive.booleanAllows you to check if the width value of thisSizeinstance is both specified (non-negative) and also positive.height()The height of thisSizeinstance may not be specified, in which case this method returnsOptional.empty()and the thing that this configuration is applied to should resort to its default height.minus(double size) Creates an updatedSizeinstance where the width and height are decreased by the given amount.minus(double width, double height) Creates an updatedSizeinstance where the width and height are decreased by the given amount.Creates an updatedSizeinstance where the width and height are decreased by the width and height of the given size.static Sizeof(double width, double height) A factory method that creates aSizeinstance from a width and height.static Sizeof(float width, float height) A factory method that creates aSizeinstance from a width and height.static Sizeplus(double size) Creates an updatedSizeinstance where the width and height are increased by the given amount.plus(double width, double height) Creates an updatedSizeinstance where the width and height are increased by the given amount.Creates an updatedSizeinstance where the width and height are increased by the width and height of the given size.round()scale(double scaleFactor) Scales the width and height of thisSizeinstance by the given factor.toString()static Sizeunknown()Exposes theUNKNOWNsize instance, which is a null object that represents an unknown size.width()The width of thisSizeinstance may not be specified, in which case this method returnsOptional.empty()and the thing that this configuration is applied to should resort to its default width.withHeight(double height) Creates an updatedSizeinstance with the given height.withWidth(double width) Creates an updatedSizeinstance with the given width.
-
Method Details
-
unknown
Exposes theUNKNOWNsize instance, which is a null object that represents an unknown size. It uses -1 for both width and height and will returnOptional.empty()for both width and height.- Returns:
- A
Sizeinstance that represents an unknown size.
-
of
A factory method that creates aSizeinstance from a width and height. If the width and height is negative, the returned size will be theUNKNOWNsize constant with a width or height of -1.- Parameters:
width- The width of the size in the form of a float.height- The height of the size in the form of a float.- Returns:
- A
Sizeinstance that represents the given width and height.
-
of
A factory method that creates aSizeinstance from a width and height. If the width or height is negative, the returned size will be theUNKNOWNsize constant with a width or height of -1.- Parameters:
width- The width of the size in the form of a double.height- The height of the size in the form of a double.- Returns:
- A
Sizeinstance that represents the given width and height.
-
of
-
width
The width of thisSizeinstance may not be specified, in which case this method returnsOptional.empty()and the thing that this configuration is applied to should resort to its default width.- Returns:
- The width of this
Sizeinstance orOptional.empty()if unknown.
-
height
The height of thisSizeinstance may not be specified, in which case this method returnsOptional.empty()and the thing that this configuration is applied to should resort to its default height.- Returns:
- The height of this
Sizeinstance orOptional.empty()if unknown.
-
hasPositiveWidth
public boolean hasPositiveWidth()Allows you to check if the width value of thisSizeinstance is both specified (non-negative) and also positive.- Returns:
- True if the width is both specified and positive, false otherwise.
-
hasPositiveHeight
public boolean hasPositiveHeight()Allows you to check if the height value of thisSizeinstance is both specified (non-negative) and also positive.- Returns:
- True if the height is both specified and positive, false otherwise.
-
withWidth
Creates an updatedSizeinstance with the given width. If the width is negative, the width of the returned size will be -1.- Parameters:
width- The width of the size to create.- Returns:
- A new
Sizeinstance with the given width.
-
withHeight
Creates an updatedSizeinstance with the given height. If the height is negative, the height of the returned size will be -1.- Parameters:
height- The height of the size to create.- Returns:
- A new
Sizeinstance with the given height.
-
plus
Creates an updatedSizeinstance where the width and height are increased by the given amount. A dimension of -1 will remain -1.- Parameters:
size- The size to add to this size.- Returns:
- A new
Sizeinstance with the added size.
-
plus
Creates an updatedSizeinstance where the width and height are increased by the given amount. A dimension of -1 will remain -1.- Parameters:
width- The width to add to this size.height- The height to add to this size.- Returns:
- A new
Sizeinstance with the added size.
-
plus
Creates an updatedSizeinstance where the width and height are increased by the width and height of the given size. A dimension of -1 will remain -1.- Parameters:
size- The size to add to this size.- Returns:
- A new
Sizeinstance with the added size.
-
minus
Creates an updatedSizeinstance where the width and height are decreased by the given amount. A dimension of -1 will remain -1.- Parameters:
size- The size to subtract from this size.- Returns:
- A new
Sizeinstance with the subtracted size.
-
minus
Creates an updatedSizeinstance where the width and height are decreased by the given amount. A dimension of -1 will remain -1.- Parameters:
width- The width to subtract from this size.height- The height to subtract from this size.- Returns:
- A new
Sizeinstance with the subtracted size.
-
minus
Creates an updatedSizeinstance where the width and height are decreased by the width and height of the given size. A dimension of -1 will remain -1.- Parameters:
size- The size to subtract from this size.- Returns:
- A new
Sizeinstance with the subtracted size.
-
toDimension
-
scale
Scales the width and height of thisSizeinstance by the given factor. If the width or height not specified (i.e. negative), they will remain negative. A negative scale factor will result in a negative width and height.- Parameters:
scaleFactor- The factor to scale the width and height by.- Returns:
- A new
Sizeinstance with the scaled width and height.
-
round
Rounds the float based width and height of thisSizeto the nearest integer value and returns these as a newSize.- Returns:
- A
Sizeobjects whose width and height values does not have fractions.
-
toString
-
equals
-
hashCode
public int hashCode()
-