Package swingtree.layout
Class Size
java.lang.Object
swingtree.layout.Size
An immutable value object that represents a size in the form of a 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
IconDeclaration
s.
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 TypeMethodDescriptionboolean
int
hashCode()
boolean
Allows you to check if the height value of thisSize
instance is both specified (non-negative) and also positive.boolean
Allows you to check if the width value of thisSize
instance is both specified (non-negative) and also positive.height()
The height of thisSize
instance 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.static Size
of
(double width, double height) A factory method that creates aSize
instance from a width and height.static Size
of
(float width, float height) A factory method that creates aSize
instance from a width and height.static Size
round()
scale
(double scaleFactor) Scales the width and height of thisSize
instance by the given factor.toString()
static Size
unknown()
Exposes theUNKNOWN
size instance, which is a null object that represents an unknown size.width()
The width of thisSize
instance 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 updatedSize
instance with the given height.withWidth
(double width) Creates an updatedSize
instance with the given width.
-
Method Details
-
unknown
Exposes theUNKNOWN
size 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
Size
instance that represents an unknown size.
-
of
A factory method that creates aSize
instance from a width and height. If the width or height is negative, the returned size will be theUNKNOWN
size 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
Size
instance that represents the given width and height.
-
of
A factory method that creates aSize
instance from a width and height. If the width or height is negative, the returned size will be theUNKNOWN
size 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
Size
instance that represents the given width and height.
-
of
-
width
The width of thisSize
instance 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
Size
instance orOptional.empty()
if unknown.
-
height
The height of thisSize
instance 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
Size
instance orOptional.empty()
if unknown.
-
hasPositiveWidth
public boolean hasPositiveWidth()Allows you to check if the width value of thisSize
instance 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 thisSize
instance is both specified (non-negative) and also positive.- Returns:
- True if the height is both specified and positive, false otherwise.
-
withWidth
Creates an updatedSize
instance 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
Size
instance with the given width.
-
withHeight
Creates an updatedSize
instance 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
Size
instance with the given height.
-
toDimension
-
scale
Scales the width and height of thisSize
instance 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
Size
instance with the scaled width and height.
-
round
Rounds the float based width and height of thisSize
to the nearest integer value and returns these as a newSize
.- Returns:
- A
Size
objects whose width and height values does not have fractions.
-
toString
-
equals
-
hashCode
public int hashCode()
-