- java.lang.Object
-
- javafx.scene.layout.BackgroundSize
-
public final class BackgroundSize extends Object
Defines the size of the area that a BackgroundImage should fill relative to the Region it is styling. There are several properties whose values take precedence over the others. In particular there are 4 key properties,width,height,contain, andcover. Both width and height are independent of each other, however both interact with contain and cover.From the CSS Specification,
coveris defined to:Scale the image, while preserving its intrinsic aspect ratio (if any), to the smallest size such that both its width and its height can completely cover the background positioning area.
containis defined to:Scale the image, while preserving its intrinsic aspect ratio (if any), to the largest size such that both its width and its height can fit inside the background positioning area.
And width and height both specify (in absolute values or percentages) the size to use. These two properties only apply if both cover and contain are false. If both cover and contain are true, thencoverwill be used.The width and height may also be set to
AUTO, indicating that the area should be sized so as to use the image's intrinsic size, or if it cannot be determined, 100%.- Since:
- JavaFX 8.0
-
-
Field Summary
Fields Modifier and Type Field Description static doubleAUTOFrom the CSS Specification: An "auto" value for one dimension is resolved by using the image's intrinsic ratio and the size of the other dimension, or failing that, using the image's intrinsic size, or failing that, treating it as 100%.static BackgroundSizeDEFAULTThe default BackgroundSize used by BackgroundImages when an explicit size is not defined.
-
Constructor Summary
Constructors Constructor Description BackgroundSize(double width, double height, boolean widthAsPercentage, boolean heightAsPercentage, boolean contain, boolean cover)Create a new BackgroundSize.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)Indicates whether some other object is "equal to" this one.doublegetHeight()The height of the area within the Region where the associated BackgroundImage should render.doublegetWidth()The width of the area within the Region where the associated BackgroundImage should render.inthashCode()Returns a hash code value for the object.booleanisContain()If true, scale the image, while preserving its intrinsic aspect ratio (if any), to the largest size such that both its width and its height can fit inside the background positioning area.booleanisCover()If true, scale the image, while preserving its intrinsic aspect ratio (if any), to the smallest size such that both its width and its height can completely cover the background positioning area.booleanisHeightAsPercentage()Specifies whether the value contained inheightshould be interpreted as a percentage or as a normal value.booleanisWidthAsPercentage()Specifies whether the value contained inwidthshould be interpreted as a percentage or as a normal value.
-
-
-
Field Detail
-
AUTO
public static final double AUTO
From the CSS Specification:An "auto" value for one dimension is resolved by using the image's intrinsic ratio and the size of the other dimension, or failing that, using the image's intrinsic size, or failing that, treating it as 100%.
When set to AUTO, the values for widthAsPercentage and heightAsPercentage are ignored.If both values are "auto" then the intrinsic width and/or height of the image should be used, if any, the missing dimension (if any) behaving as "auto" as described above. If the image has neither an intrinsic width nor an intrinsic height, its size is determined as for "contain".
- See Also:
- Constant Field Values
-
DEFAULT
public static final BackgroundSize DEFAULT
The default BackgroundSize used by BackgroundImages when an explicit size is not defined. By default, the BackgroundSize is AUTO, AUTO for the width and height, and is neither cover nor contain.
-
-
Constructor Detail
-
BackgroundSize
public BackgroundSize(double width, double height, boolean widthAsPercentage, boolean heightAsPercentage, boolean contain, boolean cover)Create a new BackgroundSize.- Parameters:
width- The width. Cannot be less than 0, except for the value of AUTO.height- The height. Cannot be less than 0, except for the value of AUTO.widthAsPercentage- Whether the width is to be interpreted as a percentageheightAsPercentage- Whether the height is to be interpreted as a percentagecontain- Whether the image should be sized to fit within the Region maximallycover- Whether the image should be sized to "cover" the Region
-
-
Method Detail
-
getWidth
public final double getWidth()
The width of the area within the Region where the associated BackgroundImage should render. If set to AUTO, thenwidthAsPercentageis ignored. This value has no meaning if eithercontainorcoverare specified. This value cannot be negative, except when set to the value of AUTO.- Returns:
- the width of the area within the Region where the associated BackgroundImage should render
-
getHeight
public final double getHeight()
The height of the area within the Region where the associated BackgroundImage should render. If set to AUTO, thenheightAsPercentageis ignored. This value has no meaning if eithercontainorcoverare specified. This value cannot be negative, except when set to the value of AUTO.- Returns:
- the height of the area within the Region where the associated BackgroundImage should render
-
isWidthAsPercentage
public final boolean isWidthAsPercentage()
Specifies whether the value contained inwidthshould be interpreted as a percentage or as a normal value.- Returns:
- true if width should be interpreted as a percentage
-
isHeightAsPercentage
public final boolean isHeightAsPercentage()
Specifies whether the value contained inheightshould be interpreted as a percentage or as a normal value.- Returns:
- true if height should be interpreted as a percentage
-
isContain
public final boolean isContain()
If true, scale the image, while preserving its intrinsic aspect ratio (if any), to the largest size such that both its width and its height can fit inside the background positioning area.- Returns:
- true if the image can fit inside the background positioning area
-
isCover
public final boolean isCover()
If true, scale the image, while preserving its intrinsic aspect ratio (if any), to the smallest size such that both its width and its height can completely cover the background positioning area.- Returns:
- true if image can completely cover the background positioning area
-
equals
public boolean equals(Object o)
Indicates whether some other object is "equal to" this one.The
equalsmethod implements an equivalence relation on non-null object references:- It is reflexive: for any non-null reference value
x,x.equals(x)should returntrue. - It is symmetric: for any non-null reference values
xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any non-null reference values
x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue. - It is consistent: for any non-null reference values
xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse, provided no information used inequalscomparisons on the objects is modified. - For any non-null reference value
x,x.equals(null)should returnfalse.
The
equalsmethod for classObjectimplements the most discriminating possible equivalence relation on objects; that is, for any non-null reference valuesxandy, this method returnstrueif and only ifxandyrefer to the same object (x == yhas the valuetrue).Note that it is generally necessary to override the
hashCodemethod whenever this method is overridden, so as to maintain the general contract for thehashCodemethod, which states that equal objects must have equal hash codes.- Overrides:
equalsin classObject- Parameters:
o- the reference object with which to compare.- Returns:
trueif this object is the same as the obj argument;falseotherwise.- See Also:
Object.hashCode(),HashMap
- It is reflexive: for any non-null reference value
-
hashCode
public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided byHashMap.The general contract of
hashCodeis:- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
hashCodemethod must consistently return the same integer, provided no information used inequalscomparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals(Object)method, then calling thehashCodemethod on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal
according to the
Object.equals(java.lang.Object)method, then calling thehashCodemethod on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by class
Objectdoes return distinct integers for distinct objects. (The hashCode may or may not be implemented as some function of an object's memory address at some point in time.)- Overrides:
hashCodein classObject- Returns:
- a hash code value for this object.
- See Also:
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
-
-