Skip to content
Merged
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 @@ -100,11 +100,11 @@ public void testCorrectScaleUpUsingDifferentSetBoundsMethod() {

button.setBounds(new Rectangle(0, 47, 200, 47));
assertEquals("Control::setBounds(Rectangle) doesn't scale up correctly",
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());
new Rectangle(0, 82, 350, 82), button.getBoundsInPixels());

button.setBounds(0, 47, 200, 47);
assertEquals("Control::setBounds(int, int, int, int) doesn't scale up correctly",
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());
new Rectangle(0, 82, 350, 82), button.getBoundsInPixels());
}

record FontComparison(int originalFontHeight, int currentFontHeight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void translateRectangleInGapPartiallyInRightBackAndForthInSingleZoomShouldBeTheS
void translateRectangleInGapPartiallyInRightBackAndForthInMultiZoomShouldBeInside() {
MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper();
setupMonitors(mapper);
Rectangle rectInPts = new MonitorAwareRectangle(1950, 400, 150, 100, monitors[1]);
Rectangle rectInPts = new Rectangle.WithMonitor(1950, 400, 150, 100, monitors[1]);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
}
Expand Down Expand Up @@ -223,15 +223,15 @@ private Point createExpectedPoint(CoordinateSystemMapper mapper, int x, int y, M
if (mapper instanceof SingleZoomCoordinateSystemMapper) {
return new Point(x, y);
} else {
return new MonitorAwarePoint(x, y, monitor);
return new Point.WithMonitor(x, y, monitor);
}
}

private Rectangle createExpectedRectangle(CoordinateSystemMapper mapper, int x, int y, int width, int height, Monitor monitor) {
if (mapper instanceof SingleZoomCoordinateSystemMapper) {
return new Rectangle(x, y, width, height);
} else {
return new MonitorAwareRectangle(x, y, width, height, monitor);
return new Rectangle.WithMonitor(x, y, width, height, monitor);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
*
* @since 3.129
* @noreference This class is not intended to be referenced by clients
* @deprecated
*/
@Deprecated(forRemoval = true, since = "2025-09")
public final class MonitorAwarePoint extends Point {

private static final long serialVersionUID = 6077427420686999194L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
*
* @since 3.129
* @noreference This class is not intended to be referenced by clients
* @deprecated
*/
@Deprecated(forRemoval = true, since = "2025-09")
public final class MonitorAwareRectangle extends Rectangle {

private static final long serialVersionUID = 5041911840525116925L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import java.io.*;

import org.eclipse.swt.widgets.*;

/**
* Instances of this class represent places on the (x, y)
* coordinate plane.
Expand All @@ -41,7 +43,8 @@
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
*/

public sealed class Point implements Serializable permits MonitorAwarePoint {
@SuppressWarnings("removal")
public sealed class Point implements Serializable permits MonitorAwarePoint, Point.OfFloat {

/**
* the x coordinate of the point
Expand Down Expand Up @@ -116,5 +119,82 @@ public String toString () {
return "Point {" + x + ", " + y + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

/**
* Instances of this class represent {@link org.eclipse.swt.graphics.Point}
* objects with the fields capable of storing more precise value in float.
*
* @since 3.131
* @noreference This class is not intended to be referenced by clients
*/
public static sealed class OfFloat extends Point permits Point.WithMonitor {

private static final long serialVersionUID = -1862062276431597053L;

public float residualX, residualY;

public OfFloat(int x, int y) {
super(x, y);
}

public OfFloat(float x, float y) {
super(Math.round(x), Math.round(y));
this.residualX = x - this.x;
this.residualY = y - this.y;
}

public float getX() {
return x + residualX;
}

public float getY() {
return y + residualY;
}

public void setX(float x) {
this.x = Math.round(x);
this.residualX = x - this.x;
}

public void setY(float y) {
this.y = Math.round(y);
this.residualY = y - this.y;
}
}

/**
* Instances of this class represent {@link org.eclipse.swt.graphics.Point.OfFloat}
* objects along with the context of the monitor in relation to which they are
* placed on the display. The monitor awareness makes it easy to scale and
* translate the points between pixels and points.
*
* @since 3.131
* @noreference This class is not intended to be referenced by clients
*/
public static final class WithMonitor extends Point.OfFloat {

private static final long serialVersionUID = 6077427420686999194L;

private final Monitor monitor;

/**
* Constructs a new Point.WithMonitor
*
* @param x the x coordinate of the point
* @param y the y coordinate of the point
* @param monitor the monitor with whose context the point is created
*/
public WithMonitor(int x, int y, Monitor monitor) {
super(x, y);
this.monitor = monitor;
}

/**
* {@return the monitor with whose context the instance is created}
*/
public Monitor getMonitor() {
return monitor;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.*;

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

/**
* Instances of this class represent rectangular areas in an
Expand Down Expand Up @@ -45,7 +46,8 @@
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
*/

public sealed class Rectangle implements Serializable, Cloneable permits MonitorAwareRectangle {
@SuppressWarnings("removal")
public sealed class Rectangle implements Serializable, Cloneable permits MonitorAwareRectangle, Rectangle.OfFloat {

/**
* the x coordinate of the rectangle
Expand Down Expand Up @@ -373,8 +375,8 @@ public Rectangle union (Rectangle rect) {
* @since 3.131
*/
public static Rectangle of(Point topLeft, int width, int height) {
if (topLeft instanceof MonitorAwarePoint monitorAwareTopLeft) {
return new MonitorAwareRectangle(topLeft.x, topLeft.y, width, height, monitorAwareTopLeft.getMonitor());
if (topLeft instanceof Point.WithMonitor monitorAwareTopLeft) {
return new Rectangle.WithMonitor(monitorAwareTopLeft.getX(), monitorAwareTopLeft.getY(), width, height, monitorAwareTopLeft.getMonitor());
}
return new Rectangle(topLeft.x, topLeft.y, width, height);
}
Expand All @@ -396,4 +398,115 @@ public static Rectangle of(Point topLeft, int width, int height) {
public Rectangle clone() {
return new Rectangle(x, y, width, height);
}

/**
* Instances of this class represent {@link org.eclipse.swt.graphics.Rectangle}
* objects which supports values of Float type for it's fields
*
* @since 3.131
* @noreference This class is not intended to be referenced by clients
*/
public static sealed class OfFloat extends Rectangle permits Rectangle.WithMonitor {

private static final long serialVersionUID = -3006999002677468391L;

private float residualX, residualY, residualWidth, residualHeight;

public OfFloat(int x, int y, int width, int height) {
super(x, y, width, height);
}

public OfFloat(float x, float y, float width, float height) {
super(Math.round(x), Math.round(y), Math.round(width), Math.round(height));
this.residualX = x - this.x;
this.residualY = y - this.y;
this.residualWidth = width - this.width;
this.residualHeight = height - this.height;
}

public float getX() {
return x + residualX;
}

public float getY() {
return y + residualY;
}

public float getWidth() {
return width + residualWidth;
}

public float getHeight() {
return height + residualHeight;
}

public void setX(float x) {
this.x = Math.round(x);
this.residualX = x - this.x;
}

public void setY(float y) {
this.y = Math.round(y);
this.residualY = y - this.y;
}

public void setWidth(float width) {
this.width = Math.round(width);
this.residualWidth = width - this.width;
}

public void setHeight(float height) {
this.height = Math.round(height);
this.residualHeight = height - this.height;
}

}

/**
* Instances of this class represent {@link org.eclipse.swt.graphics.Rectangle.OfFloat}
* objects along with the context of the monitor in relation to which they are
* placed on the display. The monitor awareness makes it easy to scale and
* translate the rectangles between pixels and points.
*
* @since 3.131
* @noreference This class is not intended to be referenced by clients
*/
public static final class WithMonitor extends Rectangle.OfFloat {

private static final long serialVersionUID = 5041911840525116925L;

private final Monitor monitor;

/**
* Constructs a new Rectangle.WithMonitor
*
* @param x the x coordinate of the top left corner of the rectangle
* @param y the y coordinate of the top left corner of the rectangle
* @param width the width of the rectangle
* @param height the height of the rectangle
* @param monitor the monitor with whose context the rectangle is created
*/
public WithMonitor(int x, int y, int width, int height, Monitor monitor) {
super(x, y, width, height);
this.monitor = monitor;
}

private WithMonitor(float x, float y, float width, float height, Monitor monitor) {
super(x, y, width, height);
this.monitor = monitor;
}

/**
* {@return the monitor with whose context the instance is created}
*/
public Monitor getMonitor() {
return monitor;
}

@Override
public Rectangle.WithMonitor clone() {
return new Rectangle.WithMonitor(getX(), getY(), getWidth(), getHeight(), monitor);
}

}
}
Loading
Loading