From bab56e6309434f571f304102c201826d6d950701 Mon Sep 17 00:00:00 2001 From: Amartya Parijat Date: Thu, 4 Sep 2025 12:17:02 +0200 Subject: [PATCH 1/2] Add OfFloat.from methods in Point/Rectangle This commit adds Rectangle.OfFloat.from and Point.OfFloat.from methods and removes the Win32DPIUtils.FloatAwareGeometryFactory class to make these methods OS-independent. It additionally adds clone methods in Point class and sub-classes and Rectangle.OfFloat::clone. --- .../org/eclipse/swt/graphics/Point.java | 35 ++++++++++++++++++- .../org/eclipse/swt/graphics/Rectangle.java | 15 ++++++++ .../eclipse/swt/internal/Win32DPIUtils.java | 22 ++---------- 3 files changed, 52 insertions(+), 20 deletions(-) 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 b1a026ca92c..96565ee2cf5 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 @@ -43,7 +43,7 @@ * @see Sample code and further information */ -public sealed class Point implements Serializable permits Point.OfFloat { +public sealed class Point implements Serializable, Cloneable permits Point.OfFloat { /** * the x coordinate of the point @@ -118,6 +118,15 @@ public String toString () { return "Point {" + x + ", " + y + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } +/** + * Creates and returns a shallow copy of this {@code Point}. + * @since 3.132 + */ +@Override +public Point clone() { + return new Point(x, y); +} + /** * Instances of this class represent {@link org.eclipse.swt.graphics.Point} * objects with the fields capable of storing more precise value in float. @@ -158,6 +167,21 @@ public void setY(float y) { this.y = Math.round(y); this.residualY = y - this.y; } + + @Override + public Point.OfFloat clone() { + return new Point.OfFloat(getX(), getY()); + } + + /** + * Creates a shallow copy of the provided point as a Point.OfFloat instance. + */ + public static Point.OfFloat from(Point point) { + if (point instanceof Point.OfFloat pointOfFloat) { + return pointOfFloat.clone(); + } + return new Point.OfFloat(point.x, point.y); + } } /** @@ -187,6 +211,11 @@ public WithMonitor(int x, int y, Monitor monitor) { this.monitor = monitor; } + private WithMonitor(float x, float y, Monitor monitor) { + super(x, y); + this.monitor = monitor; + } + /** * {@return the monitor with whose context the instance is created} */ @@ -194,6 +223,10 @@ public Monitor getMonitor() { return monitor; } + @Override + public Point.WithMonitor clone() { + return new WithMonitor(getX(), getY(), monitor); + } } } 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 935f61e9e6e..31ff39f25b0 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 @@ -459,6 +459,21 @@ public void setHeight(float height) { this.residualHeight = height - this.height; } + @Override + public Rectangle.OfFloat clone() { + return new Rectangle.OfFloat(getX(), getY(), getWidth(), getHeight()); + } + + /** + * Creates a shallow copy of the provided Rectangle as a Rectangle.OfFloat instance. + */ + public static Rectangle.OfFloat from(Rectangle rectangle) { + if (rectangle instanceof Rectangle.OfFloat rectangleOfFloat) { + return rectangleOfFloat.clone(); + } + return new Rectangle.OfFloat(rectangle.x, rectangle.y, rectangle.width, rectangle.height); + } + } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java index fb27d92d90d..0bd1badfd73 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java @@ -115,7 +115,7 @@ public static float pixelToPoint(Drawable drawable, float size, int zoom) { public static Point pixelToPoint(Point point, int zoom) { if (zoom == 100 || point == null) return point; - Point.OfFloat fPoint = FloatAwareGeometryFactory.createFrom(point); + Point.OfFloat fPoint = Point.OfFloat.from(point); float scaleFactor = DPIUtil.getScalingFactor(zoom); float scaledX = fPoint.getX() / scaleFactor; float scaledY = fPoint.getY() / scaleFactor; @@ -170,7 +170,7 @@ public static Rectangle scaleBounds (Rectangle rect, int targetZoom, int current */ private static Rectangle scaleBounds (Rectangle.OfFloat rect, int targetZoom, int currentZoom) { if (rect == null || targetZoom == currentZoom) return rect; - Rectangle.OfFloat fRect = FloatAwareGeometryFactory.createFrom(rect); + Rectangle.OfFloat fRect = Rectangle.OfFloat.from(rect); float scaleFactor = DPIUtil.getScalingFactor(targetZoom, currentZoom); float scaledX = fRect.getX() * scaleFactor; float scaledY = fRect.getY() * scaleFactor; @@ -221,7 +221,7 @@ public static float pointToPixel(Drawable drawable, float size, int zoom) { public static Point pointToPixel(Point point, int zoom) { if (zoom == 100 || point == null) return point; - Point.OfFloat fPoint = FloatAwareGeometryFactory.createFrom(point); + Point.OfFloat fPoint = Point.OfFloat.from(point); float scaleFactor = DPIUtil.getScalingFactor(zoom); float scaledX = fPoint.getX() * scaleFactor; float scaledY = fPoint.getY() * scaleFactor; @@ -330,20 +330,4 @@ public ImageData getImageData(int zoom) { return DPIUtil.scaleImageData(device, imageData, zoom, currentZoom); } } - - private class FloatAwareGeometryFactory { - static Rectangle.OfFloat createFrom(Rectangle rectangle) { - if (rectangle instanceof Rectangle.OfFloat) { - return (Rectangle.OfFloat) rectangle; - } - return new Rectangle.OfFloat(rectangle.x, rectangle.y, rectangle.width, rectangle.height); - } - - static Point.OfFloat createFrom(Point point) { - if (point instanceof Point.OfFloat) { - return (Point.OfFloat) point; - } - return new Point.OfFloat(point.x, point.y); - } - } } From 59ed1211e04bd9b3e822c2064d7a9c2913783d34 Mon Sep 17 00:00:00 2001 From: Amartya Parijat Date: Wed, 10 Sep 2025 11:46:53 +0200 Subject: [PATCH 2/2] Version Bump --- .../org.eclipse.swt.cocoa.macosx.aarch64/META-INF/MANIFEST.MF | 2 +- .../org.eclipse.swt.cocoa.macosx.x86_64/META-INF/MANIFEST.MF | 2 +- binaries/org.eclipse.swt.gtk.linux.aarch64/META-INF/MANIFEST.MF | 2 +- .../org.eclipse.swt.gtk.linux.loongarch64/META-INF/MANIFEST.MF | 2 +- binaries/org.eclipse.swt.gtk.linux.ppc64le/META-INF/MANIFEST.MF | 2 +- binaries/org.eclipse.swt.gtk.linux.riscv64/META-INF/MANIFEST.MF | 2 +- binaries/org.eclipse.swt.gtk.linux.x86_64/META-INF/MANIFEST.MF | 2 +- .../org.eclipse.swt.win32.win32.aarch64/META-INF/MANIFEST.MF | 2 +- .../org.eclipse.swt.win32.win32.x86_64/META-INF/MANIFEST.MF | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/binaries/org.eclipse.swt.cocoa.macosx.aarch64/META-INF/MANIFEST.MF b/binaries/org.eclipse.swt.cocoa.macosx.aarch64/META-INF/MANIFEST.MF index ac3a606dae0..126ecc19ba8 100644 --- a/binaries/org.eclipse.swt.cocoa.macosx.aarch64/META-INF/MANIFEST.MF +++ b/binaries/org.eclipse.swt.cocoa.macosx.aarch64/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Fragment-Host: org.eclipse.swt;bundle-version="[3.128.0,4.0.0)" Bundle-Name: %fragmentName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.swt.cocoa.macosx.aarch64; singleton:=true -Bundle-Version: 3.131.100.qualifier +Bundle-Version: 3.132.0.qualifier Bundle-ManifestVersion: 2 Bundle-Localization: fragment Export-Package: diff --git a/binaries/org.eclipse.swt.cocoa.macosx.x86_64/META-INF/MANIFEST.MF b/binaries/org.eclipse.swt.cocoa.macosx.x86_64/META-INF/MANIFEST.MF index cd516b318e0..799baef7c67 100644 --- a/binaries/org.eclipse.swt.cocoa.macosx.x86_64/META-INF/MANIFEST.MF +++ b/binaries/org.eclipse.swt.cocoa.macosx.x86_64/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Fragment-Host: org.eclipse.swt;bundle-version="[3.128.0,4.0.0)" Bundle-Name: %fragmentName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.swt.cocoa.macosx.x86_64; singleton:=true -Bundle-Version: 3.131.100.qualifier +Bundle-Version: 3.132.0.qualifier Bundle-ManifestVersion: 2 Bundle-Localization: fragment Export-Package: diff --git a/binaries/org.eclipse.swt.gtk.linux.aarch64/META-INF/MANIFEST.MF b/binaries/org.eclipse.swt.gtk.linux.aarch64/META-INF/MANIFEST.MF index 77b5072882b..e2a8a8d3661 100644 --- a/binaries/org.eclipse.swt.gtk.linux.aarch64/META-INF/MANIFEST.MF +++ b/binaries/org.eclipse.swt.gtk.linux.aarch64/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Fragment-Host: org.eclipse.swt;bundle-version="[3.128.0,4.0.0)" Bundle-Name: %fragmentName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.swt.gtk.linux.aarch64; singleton:=true -Bundle-Version: 3.131.100.qualifier +Bundle-Version: 3.132.0.qualifier Bundle-ManifestVersion: 2 Bundle-Localization: fragment Export-Package: diff --git a/binaries/org.eclipse.swt.gtk.linux.loongarch64/META-INF/MANIFEST.MF b/binaries/org.eclipse.swt.gtk.linux.loongarch64/META-INF/MANIFEST.MF index 681fcdc9a62..db1efee8c1c 100644 --- a/binaries/org.eclipse.swt.gtk.linux.loongarch64/META-INF/MANIFEST.MF +++ b/binaries/org.eclipse.swt.gtk.linux.loongarch64/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Fragment-Host: org.eclipse.swt;bundle-version="[3.128.0,4.0.0)" Bundle-Name: %fragmentName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.swt.gtk.linux.loongarch64; singleton:=true -Bundle-Version: 3.131.0.qualifier +Bundle-Version: 3.132.0.qualifier Bundle-ManifestVersion: 2 Bundle-Localization: fragment Export-Package: diff --git a/binaries/org.eclipse.swt.gtk.linux.ppc64le/META-INF/MANIFEST.MF b/binaries/org.eclipse.swt.gtk.linux.ppc64le/META-INF/MANIFEST.MF index 6d14bd58674..f6015be594d 100644 --- a/binaries/org.eclipse.swt.gtk.linux.ppc64le/META-INF/MANIFEST.MF +++ b/binaries/org.eclipse.swt.gtk.linux.ppc64le/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Fragment-Host: org.eclipse.swt;bundle-version="[3.128.0,4.0.0)" Bundle-Name: %fragmentName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.swt.gtk.linux.ppc64le;singleton:=true -Bundle-Version: 3.131.100.qualifier +Bundle-Version: 3.132.0.qualifier Bundle-ManifestVersion: 2 Bundle-Localization: fragment Export-Package: diff --git a/binaries/org.eclipse.swt.gtk.linux.riscv64/META-INF/MANIFEST.MF b/binaries/org.eclipse.swt.gtk.linux.riscv64/META-INF/MANIFEST.MF index 7fd71e115d8..76d0b4ea316 100644 --- a/binaries/org.eclipse.swt.gtk.linux.riscv64/META-INF/MANIFEST.MF +++ b/binaries/org.eclipse.swt.gtk.linux.riscv64/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Fragment-Host: org.eclipse.swt;bundle-version="[3.128.0,4.0.0)" Bundle-Name: %fragmentName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.swt.gtk.linux.riscv64; singleton:=true -Bundle-Version: 3.131.100.qualifier +Bundle-Version: 3.132.0.qualifier Bundle-ManifestVersion: 2 Bundle-Localization: fragment Export-Package: diff --git a/binaries/org.eclipse.swt.gtk.linux.x86_64/META-INF/MANIFEST.MF b/binaries/org.eclipse.swt.gtk.linux.x86_64/META-INF/MANIFEST.MF index afe6592fba2..5ce90b73997 100644 --- a/binaries/org.eclipse.swt.gtk.linux.x86_64/META-INF/MANIFEST.MF +++ b/binaries/org.eclipse.swt.gtk.linux.x86_64/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Fragment-Host: org.eclipse.swt;bundle-version="[3.128.0,4.0.0)" Bundle-Name: %fragmentName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.swt.gtk.linux.x86_64; singleton:=true -Bundle-Version: 3.131.100.qualifier +Bundle-Version: 3.132.0.qualifier Bundle-ManifestVersion: 2 Bundle-Localization: fragment Export-Package: diff --git a/binaries/org.eclipse.swt.win32.win32.aarch64/META-INF/MANIFEST.MF b/binaries/org.eclipse.swt.win32.win32.aarch64/META-INF/MANIFEST.MF index b6dc89e7117..3fd6e010835 100644 --- a/binaries/org.eclipse.swt.win32.win32.aarch64/META-INF/MANIFEST.MF +++ b/binaries/org.eclipse.swt.win32.win32.aarch64/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Fragment-Host: org.eclipse.swt;bundle-version="[3.128.0,4.0.0)" Bundle-Name: %fragmentName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.swt.win32.win32.aarch64; singleton:=true -Bundle-Version: 3.131.100.qualifier +Bundle-Version: 3.132.0.qualifier Bundle-ManifestVersion: 2 Bundle-Localization: fragment Export-Package: diff --git a/binaries/org.eclipse.swt.win32.win32.x86_64/META-INF/MANIFEST.MF b/binaries/org.eclipse.swt.win32.win32.x86_64/META-INF/MANIFEST.MF index 873ca47cd08..84f618f2b6a 100644 --- a/binaries/org.eclipse.swt.win32.win32.x86_64/META-INF/MANIFEST.MF +++ b/binaries/org.eclipse.swt.win32.win32.x86_64/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Fragment-Host: org.eclipse.swt;bundle-version="[3.128.0,4.0.0)" Bundle-Name: %fragmentName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.swt.win32.win32.x86_64; singleton:=true -Bundle-Version: 3.131.100.qualifier +Bundle-Version: 3.132.0.qualifier Bundle-ManifestVersion: 2 Bundle-Localization: fragment Export-Package: