Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c5f86dd

Browse files
committedMay 30, 2025·
Better API for handling MonitorAware Coordinates
This commit contributes to providing better interfaces and APIs for handling MontiorAware Rectangles and Points with Abstraction. contributes to #62 and #128
1 parent 925a294 commit c5f86dd

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed
 

‎bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/MonitorAwareRectangle.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @since 3.129
2525
* @noreference This class is not intended to be referenced by clients
2626
*/
27-
public final class MonitorAwareRectangle extends Rectangle {
27+
public final class MonitorAwareRectangle extends Rectangle implements Cloneable {
2828

2929
private static final long serialVersionUID = 5041911840525116925L;
3030

@@ -61,4 +61,14 @@ public int hashCode() {
6161
return super.hashCode();
6262
}
6363

64+
@Override
65+
public Rectangle clone() {
66+
return new MonitorAwareRectangle(x, y, width, height, monitor);
67+
}
68+
69+
@Override
70+
public Rectangle cloneWith(int dx, int dy, int dWidth, int dHeight) {
71+
return new MonitorAwareRectangle(x + dx, y + dy, width + dWidth, height + dHeight, monitor);
72+
}
73+
6474
}

‎bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
4646
*/
4747

48-
public sealed class Rectangle implements Serializable permits MonitorAwareRectangle {
48+
public sealed class Rectangle implements Serializable, Cloneable permits MonitorAwareRectangle {
4949

5050
/**
5151
* the x coordinate of the rectangle
@@ -356,4 +356,29 @@ public Rectangle union (Rectangle rect) {
356356
return new Rectangle (left, top, right - left, bottom - top);
357357
}
358358

359+
/**
360+
* @since 3.130
361+
*/
362+
public static Rectangle of(Point topLeft, int width, int height) {
363+
if(topLeft instanceof MonitorAwarePoint monitorAwareTopLeft) {
364+
return new MonitorAwareRectangle(topLeft.x, topLeft.y, width, height, monitorAwareTopLeft.getMonitor());
365+
}
366+
return new Rectangle(topLeft.x, topLeft.y, width, height);
367+
}
368+
369+
/**
370+
* @since 3.130
371+
*/
372+
@Override
373+
public Rectangle clone() {
374+
return new Rectangle(x, y, width, height);
375+
}
376+
377+
/**
378+
* @since 3.130
379+
*/
380+
public Rectangle cloneWith(int dx, int dy, int dWidth, int dHeight) {
381+
return new Rectangle(x + dx, y + dy, width + dWidth, height + dHeight);
382+
}
383+
359384
}

0 commit comments

Comments
 (0)
Please sign in to comment.