Skip to content

Commit 47abefa

Browse files
committed
Revert "Internalize MonitorAware* Classes to Parent #62"
This reverts commit 5b9f3a0.
1 parent d1b9d86 commit 47abefa

File tree

6 files changed

+144
-95
lines changed

6 files changed

+144
-95
lines changed

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/CoordinateSystemMapperTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void translateRectangleInGapPartiallyInRightBackAndForthInSingleZoomShouldBeTheS
137137
void translateRectangleInGapPartiallyInRightBackAndForthInMultiZoomShouldBeInside() {
138138
MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper();
139139
setupMonitors(mapper);
140-
Rectangle rectInPts = new Rectangle.WithMonitor(1950, 400, 150, 100, monitors[1]);
140+
Rectangle rectInPts = new MonitorAwareRectangle(1950, 400, 150, 100, monitors[1]);
141141
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
142142
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
143143
}
@@ -223,15 +223,15 @@ private Point createExpectedPoint(CoordinateSystemMapper mapper, int x, int y, M
223223
if (mapper instanceof SingleZoomCoordinateSystemMapper) {
224224
return new Point(x, y);
225225
} else {
226-
return new Point.WithMonitor(x, y, monitor);
226+
return new MonitorAwarePoint(x, y, monitor);
227227
}
228228
}
229229

230230
private Rectangle createExpectedRectangle(CoordinateSystemMapper mapper, int x, int y, int width, int height, Monitor monitor) {
231231
if (mapper instanceof SingleZoomCoordinateSystemMapper) {
232232
return new Rectangle(x, y, width, height);
233233
} else {
234-
return new Rectangle.WithMonitor(x, y, width, height, monitor);
234+
return new MonitorAwareRectangle(x, y, width, height, monitor);
235235
}
236236
}
237237

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Yatta Solutions and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Yatta Solutions - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.swt.graphics;
15+
16+
import org.eclipse.swt.widgets.*;
17+
18+
/**
19+
* Instances of this class represent {@link org.eclipse.swt.graphics.Point}
20+
* objects along with the context of the monitor in relation to which they are
21+
* placed on the display. The monitor awareness makes it easy to scale and
22+
* translate the points between pixels and points.
23+
*
24+
* @since 3.129
25+
* @noreference This class is not intended to be referenced by clients
26+
*/
27+
public final class MonitorAwarePoint extends Point {
28+
29+
private static final long serialVersionUID = 6077427420686999194L;
30+
31+
private final Monitor monitor;
32+
33+
/**
34+
* Constructs a new MonitorAwarePoint
35+
*
36+
* @param x the x coordinate of the point
37+
* @param y the y coordinate of the point
38+
* @param monitor the monitor with whose context the point is created
39+
*/
40+
public MonitorAwarePoint(int x, int y, Monitor monitor) {
41+
super(x, y);
42+
this.monitor = monitor;
43+
}
44+
45+
/**
46+
* {@return the monitor with whose context the instance is created}
47+
*/
48+
public Monitor getMonitor() {
49+
return monitor;
50+
}
51+
52+
@Override
53+
public boolean equals(Object object) {
54+
return super.equals(object);
55+
}
56+
57+
@Override
58+
public int hashCode() {
59+
return super.hashCode();
60+
}
61+
62+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Yatta Solutions and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Yatta Solutions - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.swt.graphics;
15+
16+
import org.eclipse.swt.widgets.*;
17+
18+
/**
19+
* Instances of this class represent {@link org.eclipse.swt.graphics.Rectangle}
20+
* objects along with the context of the monitor in relation to which they are
21+
* placed on the display. The monitor awareness makes it easy to scale and
22+
* translate the rectangles between pixels and points.
23+
*
24+
* @since 3.129
25+
* @noreference This class is not intended to be referenced by clients
26+
*/
27+
public final class MonitorAwareRectangle extends Rectangle {
28+
29+
private static final long serialVersionUID = 5041911840525116925L;
30+
31+
private final Monitor monitor;
32+
33+
/**
34+
* Constructs a new MonitorAwareRectangle
35+
*
36+
* @param x the x coordinate of the top left corner of the rectangle
37+
* @param y the y coordinate of the top left corner of the rectangle
38+
* @param width the width of the rectangle
39+
* @param height the height of the rectangle
40+
* @param monitor the monitor with whose context the rectangle is created
41+
*/
42+
public MonitorAwareRectangle(int x, int y, int width, int height, Monitor monitor) {
43+
super(x, y, width, height);
44+
this.monitor = monitor;
45+
}
46+
47+
/**
48+
* {@return the monitor with whose context the instance is created}
49+
*/
50+
public Monitor getMonitor() {
51+
return monitor;
52+
}
53+
54+
@Override
55+
public boolean equals(Object object) {
56+
return super.equals(object);
57+
}
58+
59+
@Override
60+
public int hashCode() {
61+
return super.hashCode();
62+
}
63+
64+
@Override
65+
public MonitorAwareRectangle clone() {
66+
return new MonitorAwareRectangle(x, y, width, height, monitor);
67+
}
68+
69+
}

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
import java.io.*;
1818

19-
import org.eclipse.swt.widgets.*;
20-
2119
/**
2220
* Instances of this class represent places on the (x, y)
2321
* coordinate plane.
@@ -43,7 +41,7 @@
4341
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
4442
*/
4543

46-
public sealed class Point implements Serializable permits Point.WithMonitor {
44+
public sealed class Point implements Serializable permits MonitorAwarePoint {
4745

4846
/**
4947
* the x coordinate of the point
@@ -118,41 +116,5 @@ public String toString () {
118116
return "Point {" + x + ", " + y + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
119117
}
120118

121-
/**
122-
* Instances of this class represent {@link org.eclipse.swt.graphics.Point}
123-
* objects along with the context of the monitor in relation to which they are
124-
* placed on the display. The monitor awareness makes it easy to scale and
125-
* translate the points between pixels and points.
126-
*
127-
* @since 3.131
128-
* @noreference This class is not intended to be referenced by clients
129-
*/
130-
public static final class WithMonitor extends Point {
131-
132-
private static final long serialVersionUID = 6077427420686999194L;
133-
134-
private final Monitor monitor;
135-
136-
/**
137-
* Constructs a new Point.WithMonitor
138-
*
139-
* @param x the x coordinate of the point
140-
* @param y the y coordinate of the point
141-
* @param monitor the monitor with whose context the point is created
142-
*/
143-
public WithMonitor(int x, int y, Monitor monitor) {
144-
super(x, y);
145-
this.monitor = monitor;
146-
}
147-
148-
/**
149-
* {@return the monitor with whose context the instance is created}
150-
*/
151-
public Monitor getMonitor() {
152-
return monitor;
153-
}
154-
155-
}
156-
157119
}
158120

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

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.io.*;
1818

1919
import org.eclipse.swt.*;
20-
import org.eclipse.swt.widgets.*;
2120

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

49-
public sealed class Rectangle implements Serializable, Cloneable permits Rectangle.WithMonitor {
48+
public sealed class Rectangle implements Serializable, Cloneable permits MonitorAwareRectangle {
5049

5150
/**
5251
* the x coordinate of the rectangle
@@ -374,8 +373,8 @@ public Rectangle union (Rectangle rect) {
374373
* @since 3.131
375374
*/
376375
public static Rectangle of(Point topLeft, int width, int height) {
377-
if (topLeft instanceof Point.WithMonitor monitorAwareTopLeft) {
378-
return new Rectangle.WithMonitor(topLeft.x, topLeft.y, width, height, monitorAwareTopLeft.getMonitor());
376+
if (topLeft instanceof MonitorAwarePoint monitorAwareTopLeft) {
377+
return new MonitorAwareRectangle(topLeft.x, topLeft.y, width, height, monitorAwareTopLeft.getMonitor());
379378
}
380379
return new Rectangle(topLeft.x, topLeft.y, width, height);
381380
}
@@ -397,47 +396,4 @@ public static Rectangle of(Point topLeft, int width, int height) {
397396
public Rectangle clone() {
398397
return new Rectangle(x, y, width, height);
399398
}
400-
401-
/**
402-
* Instances of this class represent {@link org.eclipse.swt.graphics.Rectangle}
403-
* objects along with the context of the monitor in relation to which they are
404-
* placed on the display. The monitor awareness makes it easy to scale and
405-
* translate the rectangles between pixels and points.
406-
*
407-
* @since 3.131
408-
* @noreference This class is not intended to be referenced by clients
409-
*/
410-
public static final class WithMonitor extends Rectangle {
411-
412-
private static final long serialVersionUID = 5041911840525116925L;
413-
414-
private final Monitor monitor;
415-
416-
/**
417-
* Constructs a new Rectangle.WithMonitor
418-
*
419-
* @param x the x coordinate of the top left corner of the rectangle
420-
* @param y the y coordinate of the top left corner of the rectangle
421-
* @param width the width of the rectangle
422-
* @param height the height of the rectangle
423-
* @param monitor the monitor with whose context the rectangle is created
424-
*/
425-
public WithMonitor(int x, int y, int width, int height, Monitor monitor) {
426-
super(x, y, width, height);
427-
this.monitor = monitor;
428-
}
429-
430-
/**
431-
* {@return the monitor with whose context the instance is created}
432-
*/
433-
public Monitor getMonitor() {
434-
return monitor;
435-
}
436-
437-
@Override
438-
public Rectangle.WithMonitor clone() {
439-
return new Rectangle.WithMonitor(x, y, width, height, monitor);
440-
}
441-
442-
}
443399
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MultiZoomCoordinateSystemMapper.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,19 @@ public Point translateFromDisplayCoordinates(Point point, int zoom) {
9898

9999
@Override
100100
public Point translateToDisplayCoordinates(Point point, int zoom) {
101-
Monitor monitor = point instanceof Point.WithMonitor pointWithMonitor ? pointWithMonitor.getMonitor() : null;
101+
Monitor monitor = point instanceof MonitorAwarePoint monitorAwarePoint ? monitorAwarePoint.getMonitor() : null;
102102
return translateLocationInPointsToPixels(point.x, point.y, monitor);
103103
}
104104

105105
@Override
106106
public Rectangle translateFromDisplayCoordinates(Rectangle rect, int zoom) {
107-
Monitor monitor = rect instanceof Rectangle.WithMonitor rectWithMonitor ? rectWithMonitor.getMonitor() : null;
107+
Monitor monitor = rect instanceof MonitorAwareRectangle monitorAwareRect ? monitorAwareRect.getMonitor() : null;
108108
return translateRectangleInPixelsToPoints(rect.x, rect.y, rect.width, rect.height, monitor);
109109
}
110110

111111
@Override
112112
public Rectangle translateToDisplayCoordinates(Rectangle rect, int zoom) {
113-
Monitor monitor = rect instanceof Rectangle.WithMonitor rectWithMonitor ? rectWithMonitor.getMonitor() : null;
113+
Monitor monitor = rect instanceof MonitorAwareRectangle monitorAwareRect ? monitorAwareRect.getMonitor() : null;
114114
return translateRectangleInPointsToPixels(rect.x, rect.y, rect.width, rect.height, monitor);
115115
}
116116

@@ -152,7 +152,7 @@ private Rectangle translateRectangleInPixelsToPoints(int x, int y, int widthInPi
152152
Point topLeft = getPointFromPixels(monitor, x, y);
153153
int width = DPIUtil.scaleDown(widthInPixels, zoom);
154154
int height = DPIUtil.scaleDown(heightInPixels, zoom);
155-
Rectangle.WithMonitor rect = new Rectangle.WithMonitor(topLeft.x, topLeft.y, width, height, monitor);
155+
MonitorAwareRectangle rect = new MonitorAwareRectangle(topLeft.x, topLeft.y, width, height, monitor);
156156
return rect;
157157
}
158158

@@ -264,7 +264,7 @@ private Point getPointFromPixels(Monitor monitor, int x, int y) {
264264
int zoom = getApplicableMonitorZoom(monitor);
265265
int mappedX = DPIUtil.scaleDown(x - monitor.clientX, zoom) + monitor.clientX;
266266
int mappedY = DPIUtil.scaleDown(y - monitor.clientY, zoom) + monitor.clientY;
267-
return new Point.WithMonitor(mappedX, mappedY, monitor);
267+
return new MonitorAwarePoint(mappedX, mappedY, monitor);
268268
}
269269

270270
private int getApplicableMonitorZoom(Monitor monitor) {
@@ -273,7 +273,7 @@ private int getApplicableMonitorZoom(Monitor monitor) {
273273

274274
@Override
275275
public Rectangle getContainingMonitorBoundsInPixels(Point point) {
276-
Monitor monitor = point instanceof Point.WithMonitor monitorAwarePoint ? monitorAwarePoint.getMonitor()
276+
Monitor monitor = point instanceof MonitorAwarePoint monitorAwarePoint ? monitorAwarePoint.getMonitor()
277277
: getContainingMonitorForPoints(point.x, point.y);
278278
return getMonitorClientAreaInPixels(monitor);
279279
}

0 commit comments

Comments
 (0)