Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8345261: Refactor the Dimension2D classes #1653

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@

package com.sun.glass.ui.gtk.screencast;

import com.sun.javafx.geom.Dimension;
import com.sun.javafx.geom.Rectangle;
import static com.sun.glass.ui.gtk.screencast.ScreencastHelper.SCREENCAST_DEBUG;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static com.sun.glass.ui.gtk.screencast.ScreencastHelper.SCREENCAST_DEBUG;
import com.sun.javafx.geom.Dimension2D;
import com.sun.javafx.geom.Rectangle;


/**
Expand Down Expand Up @@ -76,15 +77,15 @@ public boolean hasAllScreensWithExactMatch(List<Rectangle> bounds) {
return allowedScreensBounds.containsAll(bounds);
}

public boolean hasAllScreensOfSameSize(List<Dimension> screenSizes) {
public boolean hasAllScreensOfSameSize(List<Dimension2D> screenSizes) {
// We also need to consider duplicates, since there may be
// multiple screens of the same size.
// The token item must also have at least the same number
// of screens with that size.

List<Dimension> tokenSizes = allowedScreensBounds
List<Dimension2D> tokenSizes = allowedScreensBounds
.stream()
.map(bounds -> new Dimension(bounds.width, bounds.height))
.map(bounds -> new Dimension2D(bounds.width, bounds.height))
.collect(Collectors.toCollection(ArrayList::new));

return screenSizes.size() == screenSizes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@

package com.sun.glass.ui.gtk.screencast;

import com.sun.javafx.geom.Dimension;
import com.sun.javafx.geom.Rectangle;
import static com.sun.glass.ui.gtk.screencast.ScreencastHelper.SCREENCAST_DEBUG;
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
import static java.nio.file.StandardWatchEventKinds.OVERFLOW;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
Expand All @@ -45,11 +49,8 @@
import java.util.Properties;
import java.util.Set;

import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
import static java.nio.file.StandardWatchEventKinds.OVERFLOW;
import static com.sun.glass.ui.gtk.screencast.ScreencastHelper.SCREENCAST_DEBUG;
import com.sun.javafx.geom.Dimension2D;
import com.sun.javafx.geom.Rectangle;

/**
* Helper class for persistent storage of ScreenCast restore tokens
Expand Down Expand Up @@ -365,13 +366,10 @@ static Set<TokenItem> getTokens(List<Rectangle> affectedScreenBounds) {

// 2. Try screens of the same size but in different locations,
// screens may have been moved while the token is still valid
List<Dimension> dimensions =
List<Dimension2D> dimensions =
affectedScreenBounds
.stream()
.map(rectangle -> new Dimension(
rectangle.width,
rectangle.height
))
.map(rectangle -> new Dimension2D(rectangle.width, rectangle.height))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the largest positive integer that can be stored in a float exactly is ~16M. we are fine here.

.toList();

for (TokenItem tokenItem : allTokenItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public Point2D getEndPoint() {
*/
public void setArc(Point2D loc, Dimension2D size,
float angSt, float angExt, int closure) {
setArc(loc.x, loc.y, size.width, size.height, angSt, angExt, closure);
setArc(loc.x, loc.y, size.width(), size.height(), angSt, angExt, closure);
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@
package com.sun.javafx.geom;

/**
* The <code>Dimension2D</code> class is to encapsulate a width
* and a height dimension.
* <p>
* A 2D dimension object that contains a width and a height.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe mention that this class uses floats?

*/
public class Dimension2D {
public float width;
public float height;

public Dimension2D() { }

public Dimension2D(float w, float h) {
width = w;
height = h;
}
}
public record Dimension2D(float width, float height) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish this class was named differently to signify it's based on float...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the classes in this package are based on floats. As this is an internal class, adding a comment seems sufficient.

Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public float getCenterY() {
* @see #getFrame
*/
public void setFrame(Point2D loc, Dimension2D size) {
setFrame(loc.x, loc.y, size.width, size.height);
setFrame(loc.x, loc.y, size.width(), size.height());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Dimension2D(@NamedArg("width") double width, @NamedArg("height") double h
*
* @defaultValue 0.0
*/
private double width;
private final double width;

/**
* The width of the dimension.
Expand All @@ -66,7 +66,7 @@ public final double getWidth() {
*
* @defaultValue 0.0
*/
private double height;
private final double height;

/**
* The height of the dimension.
Expand Down