From 64c206bf4ba6e8dbf3ab174a9ffa467d88150cc5 Mon Sep 17 00:00:00 2001 From: Amartya Parijat Date: Tue, 27 May 2025 15:57:30 +0200 Subject: [PATCH 1/2] Improve API for cloning/creating rectangles This commit contributes to providing better interfaces and APIs for cloning/creating rectangles, including the proper consideration of subclasses like the monitor-aware implementation of Rectangle. Contributes to https://github.com/eclipse-platform/eclipse.platform.swt/issues/62 and https://github.com/eclipse-platform/eclipse.platform.swt/issues/128 --- .../swt/graphics/MonitorAwareRectangle.java | 5 +++ .../org/eclipse/swt/graphics/Rectangle.java | 42 ++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) 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 index c71ea94a389..ea0597621c3 100644 --- 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 @@ -61,4 +61,9 @@ public int hashCode() { return super.hashCode(); } + @Override + public MonitorAwareRectangle clone() { + return new MonitorAwareRectangle(x, y, width, height, 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 e8060493d7e..b50cb13e6ac 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 sealed class Rectangle implements Serializable, Cloneable permits MonitorAwareRectangle { /** * the x coordinate of the rectangle @@ -356,4 +356,44 @@ public Rectangle union (Rectangle rect) { return new Rectangle (left, top, right - left, bottom - top); } +/** + * Creates a new {@code Rectangle} using the specified top-left point and + * dimensions. + *

+ * If the provided {@code Point} instance carries additional contextual + * information, an extended {@code Rectangle} type may be returned to preserve + * that context. Otherwise, a standard {@code Rectangle} is returned. + *

+ * + * @param topLeft the top-left corner of the rectangle + * @param width the width of the rectangle + * @param height the height of the rectangle + * @return a new {@code Rectangle} instance appropriate for the given point and + * dimensions + * @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()); + } + return new Rectangle(topLeft.x, topLeft.y, width, height); +} + +/** + * Creates and returns a copy of this {@code Rectangle}. + *

+ * This method performs a shallow copy of the rectangle's fields: {@code x}, + * {@code y}, {@code width}, and {@code height}. It does not copy any + * subclass-specific fields, so subclasses should override this method if + * additional fields exist. + *

+ * + * @return a new {@code Rectangle} instance with the same position and size as + * this one + * @since 3.131 + */ +@Override +public Rectangle clone() { + return new Rectangle(x, y, width, height); +} } From 128175ba124a8d072a2f50aed42fb7e0c5dd5d00 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Mon, 16 Jun 2025 11:06:06 +0200 Subject: [PATCH 2/2] Bump minor version of SWT host/fragments for API addition in 4.37 stream --- .../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 +- bundles/org.eclipse.swt/META-INF/MANIFEST.MF | 2 +- bundles/org.eclipse.swt/pom.xml | 2 +- 11 files changed, 11 insertions(+), 11 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 d7f858f9fc7..26c863aecd8 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.130.100.qualifier +Bundle-Version: 3.131.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 5a17d4680de..37c4c27a312 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.130.100.qualifier +Bundle-Version: 3.131.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 777a307ca74..ab66886914a 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.130.100.qualifier +Bundle-Version: 3.131.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 f2ce3e713bf..681fcdc9a62 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.130.0.qualifier +Bundle-Version: 3.131.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 b88e2ba4d31..043a0153a2d 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.130.100.qualifier +Bundle-Version: 3.131.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 2702b8f7455..5c8fa217e53 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.130.100.qualifier +Bundle-Version: 3.131.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 748d9b14608..688a94b7de3 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.130.100.qualifier +Bundle-Version: 3.131.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 b7689042cf1..4804132b9d1 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.130.100.qualifier +Bundle-Version: 3.131.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 e9aeafceb95..7855c496bee 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.130.100.qualifier +Bundle-Version: 3.131.0.qualifier Bundle-ManifestVersion: 2 Bundle-Localization: fragment Export-Package: diff --git a/bundles/org.eclipse.swt/META-INF/MANIFEST.MF b/bundles/org.eclipse.swt/META-INF/MANIFEST.MF index a84fd767e96..cb862cd26f4 100644 --- a/bundles/org.eclipse.swt/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.swt/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.swt; singleton:=true -Bundle-Version: 3.130.100.qualifier +Bundle-Version: 3.131.0.qualifier Bundle-ManifestVersion: 2 Bundle-Localization: plugin DynamicImport-Package: org.eclipse.swt.accessibility2 diff --git a/bundles/org.eclipse.swt/pom.xml b/bundles/org.eclipse.swt/pom.xml index 29756220efb..22e847bb8ff 100644 --- a/bundles/org.eclipse.swt/pom.xml +++ b/bundles/org.eclipse.swt/pom.xml @@ -20,7 +20,7 @@ ../../ org.eclipse.swt - 3.130.100-SNAPSHOT + 3.131.0-SNAPSHOT eclipse-plugin