diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/MonitorAwarePoint.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/MonitorAwarePoint.java
deleted file mode 100644
index 282acdbe07b..00000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/MonitorAwarePoint.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2025 Yatta Solutions and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Yatta Solutions - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import java.util.*;
-
-import org.eclipse.swt.widgets.*;
-
-/**
- * Instances of this class represent {@link org.eclipse.swt.graphics.Point}
- * 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.129
- * @noreference This class is not intended to be referenced by clients
- */
-public final class MonitorAwarePoint extends Point {
-
- private static final long serialVersionUID = 6077427420686999194L;
-
- private final Monitor monitor;
-
- /**
- * Constructs a new MonitorAwarePoint
- *
- * @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 MonitorAwarePoint(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;
- }
-
- @Override
- public boolean equals(Object object) {
- if (this == object) {
- return true;
- }
- if (!super.equals(object)) {
- return false;
- }
- MonitorAwarePoint other = (MonitorAwarePoint) object;
- return Objects.equals(this.monitor, other.monitor);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), monitor);
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/MonitorAwareRectangle.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/MonitorAwareRectangle.java
deleted file mode 100644
index f20d620e356..00000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/MonitorAwareRectangle.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2025 Yatta Solutions and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Yatta Solutions - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import java.util.*;
-
-import org.eclipse.swt.widgets.*;
-
-/**
- * Instances of this class represent {@link org.eclipse.swt.graphics.Rectangle}
- * 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.129
- * @noreference This class is not intended to be referenced by clients
- */
-public final class MonitorAwareRectangle extends Rectangle {
-
- private static final long serialVersionUID = 5041911840525116925L;
-
- private final Monitor monitor;
-
- /**
- * Constructs a new MonitorAwareRectangle
- *
- * @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 MonitorAwareRectangle(int x, int y, int width, int 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 boolean equals(Object object) {
- if (this == object) {
- return true;
- }
- if (!super.equals(object)) {
- return false;
- }
- MonitorAwareRectangle other = (MonitorAwareRectangle) object;
- return Objects.equals(this.monitor, other.monitor);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), monitor);
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java
index 6de7f344460..069fb4d81eb 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java
@@ -41,7 +41,7 @@
* @see Sample code and further information
*/
-public sealed class Point implements Serializable permits MonitorAwarePoint {
+public final class Point implements Serializable {
/**
* the x coordinate of the point
@@ -78,17 +78,9 @@ public Point (int x, int y) {
*/
@Override
public boolean equals (Object object) {
- if (object == null) {
- return false;
- }
- if (object == this) {
- return true;
- }
- if (object.getClass() != this.getClass()) {
- return false;
- }
- Point other = (Point) object;
- return (other.x == this.x) && (other.y == this.y);
+ if (object == this) return true;
+ if (!(object instanceof Point p)) return false;
+ return (p.x == this.x) && (p.y == this.y);
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java
index b8e78d3b8da..8c1503488d7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java
@@ -45,7 +45,7 @@
* @see Sample code and further information
*/
-public sealed class Rectangle implements Serializable permits MonitorAwareRectangle {
+public final class Rectangle implements Serializable {
/**
* the x coordinate of the rectangle
@@ -156,17 +156,9 @@ public boolean contains (Point pt) {
*/
@Override
public boolean equals(Object object) {
- if (object == null) {
- return false;
- }
- if (object == this) {
- return true;
- }
- if (object.getClass() != this.getClass()) {
- return false;
- }
- Rectangle other = (Rectangle) object;
- return (other.x == this.x) && (other.y == this.y) && (other.width == this.width) && (other.height == this.height);
+ if (object == this) return true;
+ if (!(object instanceof Rectangle r)) return false;
+ return (r.x == this.x) && (r.y == this.y) && (r.width == this.width) && (r.height == this.height);
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MultiZoomCoordinateSystemMapper.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MultiZoomCoordinateSystemMapper.java
index 2057c9305ed..72585418a03 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MultiZoomCoordinateSystemMapper.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MultiZoomCoordinateSystemMapper.java
@@ -19,6 +19,14 @@
import org.eclipse.swt.internal.*;
class MultiZoomCoordinateSystemMapper implements CoordinateSystemMapper {
+ static class WithMonitor {
+ final T geometry;
+ final Monitor monitor;
+ WithMonitor(T geometry, Monitor monitor) {
+ this.geometry = geometry;
+ this.monitor = monitor;
+ }
+ }
private final Display display;
@@ -45,42 +53,40 @@ public Rectangle map(Control from, Control to, Rectangle rectangle) {
@Override
public Point map(Control from, Control to, int x, int y) {
- Point mappedPointInPoints;
if (from == null) {
Point mappedPointInpixels = display.mapInPixels(from, to,
getPixelsFromPoint(to.getShell().getMonitor(), x, y));
- mappedPointInPoints = DPIUtil.scaleDown(mappedPointInpixels, to.getZoom());
+ return DPIUtil.scaleDown(mappedPointInpixels, to.getZoom());
} else if (to == null) {
Point mappedPointInpixels = display.mapInPixels(from, to, DPIUtil.scaleUp(new Point(x, y), from.getZoom()));
- mappedPointInPoints = getPointFromPixels(from.getShell().getMonitor(), mappedPointInpixels.x,
+ WithMonitor mappedPointInPointsWithMonitor = getPointFromPixels(from.getShell().getMonitor(), mappedPointInpixels.x,
mappedPointInpixels.y);
+ return mappedPointInPointsWithMonitor.geometry;
} else {
Point mappedPointInpixels = display.mapInPixels(from, to, DPIUtil.scaleUp(new Point(x, y), from.getZoom()));
- mappedPointInPoints = DPIUtil.scaleDown(mappedPointInpixels, to.getZoom());
+ return DPIUtil.scaleDown(mappedPointInpixels, to.getZoom());
}
- return mappedPointInPoints;
}
@Override
public Rectangle map(Control from, Control to, int x, int y, int width, int height) {
- Rectangle mappedRectangleInPoints;
if (from == null) {
Rectangle mappedRectangleInPixels = display.mapInPixels(from, to,
translateRectangleInPointsToPixels(x, y, width, height,
to.getShell().getMonitor()));
- mappedRectangleInPoints = DPIUtil.scaleDown(mappedRectangleInPixels, to.getZoom());
+ return DPIUtil.scaleDown(mappedRectangleInPixels, to.getZoom());
} else if (to == null) {
Rectangle mappedRectangleInPixels = display.mapInPixels(from, to,
DPIUtil.scaleUp(new Rectangle(x, y, width, height), from.getZoom()));
- mappedRectangleInPoints = translateRectangleInPixelsToPoints(mappedRectangleInPixels.x,
+ WithMonitor mappedRectangleInPoints = translateRectangleInPixelsToPoints(mappedRectangleInPixels.x,
mappedRectangleInPixels.y, mappedRectangleInPixels.width, mappedRectangleInPixels.height,
from.getShell().getMonitor());
+ return mappedRectangleInPoints.geometry;
} else {
Rectangle mappedRectangleInPixels = display.mapInPixels(from, to,
DPIUtil.scaleUp(new Rectangle(x, y, width, height), from.getZoom()));
- mappedRectangleInPoints = DPIUtil.scaleDown(mappedRectangleInPixels, to.getZoom());
+ return DPIUtil.scaleDown(mappedRectangleInPixels, to.getZoom());
}
- return mappedRectangleInPoints;
}
@Override
@@ -98,19 +104,20 @@ public Point translateFromDisplayCoordinates(Point point, int zoom) {
@Override
public Point translateToDisplayCoordinates(Point point, int zoom) {
- Monitor monitor = point instanceof MonitorAwarePoint monitorAwarePoint ? monitorAwarePoint.getMonitor() : null;
+ Monitor monitor = null;
return translateLocationInPointsToPixels(point.x, point.y, monitor);
}
@Override
public Rectangle translateFromDisplayCoordinates(Rectangle rect, int zoom) {
- Monitor monitor = rect instanceof MonitorAwareRectangle monitorAwareRect ? monitorAwareRect.getMonitor() : null;
- return translateRectangleInPixelsToPoints(rect.x, rect.y, rect.width, rect.height, monitor);
+ Monitor monitor = null;
+ WithMonitor value = translateRectangleInPixelsToPoints(rect.x, rect.y, rect.width, rect.height, monitor);
+ return value.geometry;
}
@Override
public Rectangle translateToDisplayCoordinates(Rectangle rect, int zoom) {
- Monitor monitor = rect instanceof MonitorAwareRectangle monitorAwareRect ? monitorAwareRect.getMonitor() : null;
+ Monitor monitor = null;
return translateRectangleInPointsToPixels(rect.x, rect.y, rect.width, rect.height, monitor);
}
@@ -133,7 +140,8 @@ private Point translateLocationInPointsToPixels(int x, int y, Monitor monitor) {
private Point translateLocationInPixelsToPoints(int x, int y) {
Monitor monitor = getContainingMonitorForPixels(x, y);
- return getPointFromPixels(monitor, x, y);
+ WithMonitor value = getPointFromPixels(monitor, x, y);
+ return value.geometry;
}
private Rectangle translateRectangleInPointsToPixels(int x, int y, int width, int height, Monitor monitor) {
@@ -145,15 +153,14 @@ private Rectangle translateRectangleInPointsToPixels(int x, int y, int width, in
return new Rectangle(topLeft.x, topLeft.y, widthInPixels, heightInPixels);
}
- private Rectangle translateRectangleInPixelsToPoints(int x, int y, int widthInPixels, int heightInPixels, Monitor monitor) {
+ private WithMonitor translateRectangleInPixelsToPoints(int x, int y, int widthInPixels, int heightInPixels, Monitor monitor) {
if (monitor == null)
monitor = getContainingMonitorForPixels(x, y, widthInPixels, heightInPixels);
int zoom = getApplicableMonitorZoom(monitor);
- Point topLeft = getPointFromPixels(monitor, x, y);
+ WithMonitor topLeft = getPointFromPixels(monitor, x, y);
int width = DPIUtil.scaleDown(widthInPixels, zoom);
int height = DPIUtil.scaleDown(heightInPixels, zoom);
- MonitorAwareRectangle rect = new MonitorAwareRectangle(topLeft.x, topLeft.y, width, height, monitor);
- return rect;
+ return new WithMonitor<>(new Rectangle(topLeft.geometry.x, topLeft.geometry.y, width, height), monitor);
}
private Monitor getValidMonitorIfApplicable(int x, int y, int width, int height, Monitor monitor) {
@@ -257,11 +264,11 @@ private Point getPixelsFromPoint(Monitor monitor, int x, int y) {
return new Point(mappedX, mappedY);
}
- private Point getPointFromPixels(Monitor monitor, int x, int y) {
+ private WithMonitor getPointFromPixels(Monitor monitor, int x, int y) {
int zoom = getApplicableMonitorZoom(monitor);
int mappedX = DPIUtil.scaleDown(x - monitor.clientX, zoom) + monitor.clientX;
int mappedY = DPIUtil.scaleDown(y - monitor.clientY, zoom) + monitor.clientY;
- return new MonitorAwarePoint(mappedX, mappedY, monitor);
+ return new WithMonitor<>(new Point(mappedX, mappedY), monitor);
}
private int getApplicableMonitorZoom(Monitor monitor) {