Skip to content

Commit

Permalink
8341372: BackgroundPosition, BorderImage, BorderStroke, CornerRadii s…
Browse files Browse the repository at this point in the history
…hould be final

Reviewed-by: angorya, jhendrikx, kcr
  • Loading branch information
Michael Strauß committed Oct 17, 2024
1 parent c4b1e1c commit 77482de
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public final class Background implements Interpolatable<Background> {
* @interpolationType <a href="../../animation/Interpolatable.html#pairwise">pairwise</a>
*/
public final List<BackgroundFill> getFills() { return fills; }
final List<BackgroundFill> fills;
private final List<BackgroundFill> fills;

/**
* The list of BackgroundImages which together define the image portion
Expand All @@ -155,7 +155,7 @@ public final class Background implements Interpolatable<Background> {
* @interpolationType <a href="../../animation/Interpolatable.html#pairwise">pairwise</a>
*/
public final List<BackgroundImage> getImages() { return images; }
final List<BackgroundImage> images;
private final List<BackgroundImage> images;

/**
* The outsets of this Background. This represents the largest
Expand All @@ -169,7 +169,7 @@ public final class Background implements Interpolatable<Background> {
* @interpolationType the intermediate value is derived from {@link #getFills() fills}
*/
public final Insets getOutsets() { return outsets; }
final Insets outsets;
private final Insets outsets;

/**
* Gets whether the background is empty. It is empty if there are no fills or images.
Expand All @@ -185,18 +185,17 @@ public final boolean isEmpty() {
private final boolean hasOpaqueFill;

/**
* Package-private immutable fields referring to the opaque insets
* of this Background.
* The opaque insets of this Background.
*/
private final double opaqueFillTop, opaqueFillRight, opaqueFillBottom, opaqueFillLeft;
final boolean hasPercentageBasedOpaqueFills;
private final boolean hasPercentageBasedOpaqueFills;

/**
* True if there are any fills that are in some way based on the size of the region.
* For example, if a CornerRadii on the fill is percentage based in either or both
* dimensions.
*/
final boolean hasPercentageBasedFills;
private final boolean hasPercentageBasedFills;

/**
* The cached hash code computation for the Background. One very big
Expand Down Expand Up @@ -314,7 +313,7 @@ private Background(List<BackgroundFill> fills, List<BackgroundImage> images, int
// The common case is to NOT have percent based radii
final boolean b = fill.getRadii().hasPercentBasedRadii;
hasPercentFillRadii |= b;
if (fill.fill.isOpaque()) {
if (fill.getFill().isOpaque()) {
opaqueFill = true;
if (b) {
hasPercentOpaqueInsets = true;
Expand Down Expand Up @@ -452,7 +451,7 @@ private void computeOpaqueInsets(double width, double height, boolean firstTime,
final double fillBottom = fillInsets.getBottom();
final double fillLeft = fillInsets.getLeft();

if (fill.fill.isOpaque()) {
if (fill.getFill().isOpaque()) {
// Some possible configurations:
// (a) rect1 is completely contained by rect2
// (b) rect2 is completely contained by rect1
Expand Down Expand Up @@ -532,7 +531,7 @@ private void computeOpaqueInsets(double width, double height, boolean firstTime,
if (bi.opaque == null) {
// If the image is not yet loaded, just skip it
// Note: Unit test wants this to be com.sun.javafx.tk.PlatformImage, not com.sun.prism.Image
final com.sun.javafx.tk.PlatformImage platformImage = acc.getImageProperty(bi.image).get();
final com.sun.javafx.tk.PlatformImage platformImage = acc.getImageProperty(bi.getImage()).get();
if (platformImage == null) continue;

// The image has been loaded, so update the opaque flag
Expand All @@ -547,9 +546,9 @@ private void computeOpaqueInsets(double width, double height, boolean firstTime,
// and we know whether it is opaque or not. Of course, we only care about processing
// opaque images.
if (bi.opaque) {
if (bi.size.cover ||
(bi.size.height == BackgroundSize.AUTO && bi.size.width == BackgroundSize.AUTO &&
bi.size.widthAsPercentage && bi.size.heightAsPercentage)) {
if (bi.size.isCover() ||
(bi.size.getHeight() == BackgroundSize.AUTO && bi.size.getWidth() == BackgroundSize.AUTO &&
bi.size.isWidthAsPercentage() && bi.size.isHeightAsPercentage())) {
// If the size mode is "cover" or AUTO, AUTO, and percentage based, then we're done -- we can simply
// accumulate insets of "0"
opaqueRegionTop = Double.isNaN(opaqueRegionTop) ? 0 : Math.min(0, opaqueRegionTop);
Expand Down Expand Up @@ -585,16 +584,16 @@ private void computeOpaqueInsets(double width, double height, boolean firstTime,

// We know that one or the other dimension is not filled, so we have to compute the right
// width / height. This is basically a big copy/paste from NGRegion! Blah!
final double w = bi.size.widthAsPercentage ? bi.size.width * width : bi.size.width;
final double h = bi.size.heightAsPercentage ? bi.size.height * height : bi.size.height;
final double imgUnscaledWidth = bi.image.getWidth();
final double imgUnscaledHeight = bi.image.getHeight();
final double w = bi.size.isWidthAsPercentage() ? bi.size.getWidth() * width : bi.size.getWidth();
final double h = bi.size.isHeightAsPercentage() ? bi.size.getHeight() * height : bi.size.getHeight();
final double imgUnscaledWidth = bi.getImage().getWidth();
final double imgUnscaledHeight = bi.getImage().getHeight();

// Now figure out the width and height of each tile to be drawn. The actual image
// dimensions may be one thing, but we need to figure out what the size of the image
// in the destination is going to be.
final double tileWidth, tileHeight;
if (bi.size.contain) {
if (bi.size.isContain()) {
// In the case of "contain", we compute the destination size based on the largest
// possible scale such that the aspect ratio is maintained, yet one side of the
// region is completely filled.
Expand All @@ -603,7 +602,7 @@ private void computeOpaqueInsets(double width, double height, boolean firstTime,
final double scale = Math.min(scaleX, scaleY);
tileWidth = Math.ceil(scale * imgUnscaledWidth);
tileHeight = Math.ceil(scale * imgUnscaledHeight);
} else if (bi.size.width >= 0 && bi.size.height >= 0) {
} else if (bi.size.getWidth() >= 0 && bi.size.getHeight() >= 0) {
// The width and height have been expressly defined. Note that AUTO is -1,
// and all other negative values are disallowed, so by checking >= 0, we
// are essentially saying "if neither is AUTO"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class BackgroundFill implements Interpolatable<BackgroundFill> {
* @interpolationType see {@link Paint}
*/
public final Paint getFill() { return fill; }
final Paint fill;
private final Paint fill;

/**
* The Radii to use for representing the four radii of the
Expand All @@ -65,7 +65,7 @@ public final class BackgroundFill implements Interpolatable<BackgroundFill> {
* @interpolationType <a href="../../animation/Interpolatable.html#default">default</a>
*/
public final CornerRadii getRadii() { return radii; }
final CornerRadii radii;
private final CornerRadii radii;

/**
* The Insets to use for this fill. Each inset indicates at what
Expand All @@ -78,7 +78,7 @@ public final class BackgroundFill implements Interpolatable<BackgroundFill> {
* @interpolationType <a href="../../animation/Interpolatable.html#default">default</a>
*/
public final Insets getInsets() { return insets; }
final Insets insets;
private final Insets insets;

/**
* A cached hash for improved performance on subsequent hash or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public final class BackgroundImage implements Interpolatable<BackgroundImage> {
* @interpolationType <a href="../../animation/Interpolatable.html#discrete">discrete</a>
*/
public final Image getImage() { return image; }
final Image image;
private final Image image;

/**
* Indicates in what manner (if at all) the background image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* the Region's right edge.
* @since JavaFX 8.0
*/
public class BackgroundPosition implements Interpolatable<BackgroundPosition> {
public final class BackgroundPosition implements Interpolatable<BackgroundPosition> {
/**
* The default BackgroundPosition for any BackgroundImage. The default
* is to have no insets and to be defined as 0% and 0%. That is, the
Expand All @@ -76,7 +76,7 @@ public class BackgroundPosition implements Interpolatable<BackgroundPosition> {
* @interpolationType <a href="../../animation/Interpolatable.html#discrete">discrete</a>
*/
public final Side getHorizontalSide() { return horizontalSide; }
final Side horizontalSide;
private final Side horizontalSide;

/**
* The side along the vertical axis to which the BackgroundImage is
Expand All @@ -85,7 +85,7 @@ public class BackgroundPosition implements Interpolatable<BackgroundPosition> {
* @interpolationType <a href="../../animation/Interpolatable.html#discrete">discrete</a>
*/
public final Side getVerticalSide() { return verticalSide; }
final Side verticalSide;
private final Side verticalSide;

/**
* The value indicating the position of the BackgroundImage relative
Expand All @@ -102,7 +102,7 @@ public class BackgroundPosition implements Interpolatable<BackgroundPosition> {
* otherwise <a href="../../animation/Interpolatable.html#linear">linear</a>
*/
public final double getHorizontalPosition() { return horizontalPosition; }
final double horizontalPosition;
private final double horizontalPosition;

/**
* The value indicating the position of the BackgroundImage relative
Expand All @@ -118,7 +118,7 @@ public class BackgroundPosition implements Interpolatable<BackgroundPosition> {
* otherwise <a href="../../animation/Interpolatable.html#linear">linear</a>
*/
public final double getVerticalPosition() { return verticalPosition; }
final double verticalPosition;
private final double verticalPosition;

/**
* Specifies whether the {@link #getHorizontalPosition() horizontalPosition} should
Expand All @@ -128,7 +128,7 @@ public class BackgroundPosition implements Interpolatable<BackgroundPosition> {
* @interpolationType <a href="../../animation/Interpolatable.html#discrete">discrete</a>
*/
public final boolean isHorizontalAsPercentage() { return horizontalAsPercentage; }
final boolean horizontalAsPercentage;
private final boolean horizontalAsPercentage;

/**
* Specifies whether the {@link #getVerticalPosition() verticalPosition} should
Expand All @@ -138,7 +138,7 @@ public class BackgroundPosition implements Interpolatable<BackgroundPosition> {
* @interpolationType <a href="../../animation/Interpolatable.html#discrete">discrete</a>
*/
public final boolean isVerticalAsPercentage() { return verticalAsPercentage; }
final boolean verticalAsPercentage;
private final boolean verticalAsPercentage;

/**
* A cached has code value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public final class BackgroundSize implements Interpolatable<BackgroundSize> {
* <a href="../../animation/Interpolatable.html#linear">linear</a>
*/
public final double getWidth() { return width; }
final double width;
private final double width;

/**
* The height of the area within the Region where the associated BackgroundImage should
Expand All @@ -112,7 +112,7 @@ public final class BackgroundSize implements Interpolatable<BackgroundSize> {
* <a href="../../animation/Interpolatable.html#linear">linear</a>
*/
public final double getHeight() { return height; }
final double height;
private final double height;

/**
* Specifies whether the value contained in {@code width} should be interpreted
Expand All @@ -122,7 +122,7 @@ public final class BackgroundSize implements Interpolatable<BackgroundSize> {
* @interpolationType <a href="../../animation/Interpolatable.html#discrete">discrete</a>
*/
public final boolean isWidthAsPercentage() { return widthAsPercentage; }
final boolean widthAsPercentage;
private final boolean widthAsPercentage;

/**
* Specifies whether the value contained in {@code height} should be interpreted
Expand All @@ -132,7 +132,7 @@ public final class BackgroundSize implements Interpolatable<BackgroundSize> {
* @interpolationType <a href="../../animation/Interpolatable.html#discrete">discrete</a>
*/
public final boolean isHeightAsPercentage() { return heightAsPercentage; }
final boolean heightAsPercentage;
private final boolean heightAsPercentage;

/**
* If true, scale the image, while preserving its intrinsic aspect ratio (if any), to the
Expand All @@ -143,7 +143,7 @@ public final class BackgroundSize implements Interpolatable<BackgroundSize> {
* @interpolationType <a href="../../animation/Interpolatable.html#discrete">discrete</a>
*/
public final boolean isContain() { return contain; }
final boolean contain;
private final boolean contain;

/**
* If true, scale the image, while preserving its intrinsic aspect ratio (if any), to the
Expand All @@ -154,7 +154,7 @@ public final class BackgroundSize implements Interpolatable<BackgroundSize> {
* @interpolationType <a href="../../animation/Interpolatable.html#discrete">discrete</a>
*/
public final boolean isCover() { return cover; }
final boolean cover;
private final boolean cover;

/**
* A cached hash code value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public final class Border implements Interpolatable<Border> {
* @interpolationType <a href="../../animation/Interpolatable.html#pairwise">pairwise</a>
*/
public final List<BorderStroke> getStrokes() { return strokes; }
final List<BorderStroke> strokes;
private final List<BorderStroke> strokes;

/**
* The list of BorderImages which together define the images to use
Expand All @@ -189,7 +189,7 @@ public final class Border implements Interpolatable<Border> {
* @interpolationType <a href="../../animation/Interpolatable.html#pairwise">pairwise</a>
*/
public final List<BorderImage> getImages() { return images; }
final List<BorderImage> images;
private final List<BorderImage> images;

/**
* The outsets of the border define the outer-most edge of the border to be drawn.
Expand All @@ -198,7 +198,7 @@ public final class Border implements Interpolatable<Border> {
* border to be drawn
*/
public final Insets getOutsets() { return outsets; }
final Insets outsets;
private final Insets outsets;

/**
* The insets define the distance from the edge of the Region to the inner-most edge
Expand All @@ -208,7 +208,7 @@ public final class Border implements Interpolatable<Border> {
* inner-most edge of the border
*/
public final Insets getInsets() { return insets; }
final Insets insets;
private final Insets insets;

/**
* Gets whether the Border is empty. It is empty if there are no strokes or images.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* When applied to a Region with a defined shape, a BorderImage is ignored.
* @since JavaFX 8.0
*/
public class BorderImage implements Interpolatable<BorderImage> {
public final class BorderImage implements Interpolatable<BorderImage> {
/**
* The image to be used. This will never be null. If this
* image fails to load, then the entire BorderImage will
Expand All @@ -61,7 +61,7 @@ public class BorderImage implements Interpolatable<BorderImage> {
* @interpolationType <a href="../../animation/Interpolatable.html#discrete">discrete</a>
*/
public final Image getImage() { return image; }
final Image image;
private final Image image;

/**
* Indicates in what manner (if at all) the border image
Expand All @@ -73,7 +73,7 @@ public class BorderImage implements Interpolatable<BorderImage> {
* @interpolationType <a href="../../animation/Interpolatable.html#discrete">discrete</a>
*/
public final BorderRepeat getRepeatX() { return repeatX; }
final BorderRepeat repeatX;
private final BorderRepeat repeatX;

/**
* Indicates in what manner (if at all) the border image
Expand All @@ -85,7 +85,7 @@ public class BorderImage implements Interpolatable<BorderImage> {
* @interpolationType <a href="../../animation/Interpolatable.html#discrete">discrete</a>
*/
public final BorderRepeat getRepeatY() { return repeatY; }
final BorderRepeat repeatY;
private final BorderRepeat repeatY;

/**
* The widths of the border on each side. These can be defined
Expand All @@ -97,7 +97,7 @@ public class BorderImage implements Interpolatable<BorderImage> {
* @interpolationType <a href="../../animation/Interpolatable.html#default">default</a>
*/
public final BorderWidths getWidths() { return widths; }
final BorderWidths widths;
private final BorderWidths widths;

/**
* Defines the slices of the image. JavaFX uses a 4-slice scheme where
Expand All @@ -119,7 +119,7 @@ public class BorderImage implements Interpolatable<BorderImage> {
* @see <a href="http://www.w3.org/TR/css3-background/#the-border-image-slice">border-image-slice</a>
*/
public final BorderWidths getSlices() { return slices; }
final BorderWidths slices;
private final BorderWidths slices;

/**
* Specifies whether or not the center patch (as defined by the left, right, top, and bottom slices)
Expand All @@ -129,7 +129,7 @@ public class BorderImage implements Interpolatable<BorderImage> {
* @interpolationType <a href="../../animation/Interpolatable.html#discrete">discrete</a>
*/
public final boolean isFilled() { return filled; }
final boolean filled;
private final boolean filled;

/**
* The insets of the BorderImage define where the border should be positioned
Expand All @@ -139,7 +139,7 @@ public class BorderImage implements Interpolatable<BorderImage> {
* @interpolationType <a href="../../animation/Interpolatable.html#default">default</a>
*/
public final Insets getInsets() { return insets; }
final Insets insets;
private final Insets insets;

// These two are used by Border to compute the insets and outsets of the border
final Insets innerEdge;
Expand Down
Loading

0 comments on commit 77482de

Please sign in to comment.