Skip to content

Commit 426e876

Browse files
committed
Restore MonitorAwarePoint and MonitorAwareRectangle
They are deprecated for removal
1 parent 9462fe7 commit 426e876

File tree

4 files changed

+214
-2
lines changed

4 files changed

+214
-2
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
* @deprecated
27+
*/
28+
@Deprecated(forRemoval = true, since = "2025-09")
29+
public final class MonitorAwarePoint extends Point {
30+
31+
private static final long serialVersionUID = 7516155847004716654L;
32+
33+
public float residualX, residualY;
34+
35+
private final Monitor monitor;
36+
37+
public MonitorAwarePoint(int x, int y) {
38+
this(x, y, null);
39+
}
40+
41+
public MonitorAwarePoint(float x, float y, Monitor monitor) {
42+
super(Math.round(x), Math.round(y));
43+
this.residualX = x - this.x;
44+
this.residualY = y - this.y;
45+
this.monitor = monitor;
46+
}
47+
48+
49+
/**
50+
* Constructs a new MonitorAwarePoint
51+
*
52+
* @param x the x coordinate of the point
53+
* @param y the y coordinate of the point
54+
* @param monitor the monitor with whose context the point is created
55+
*/
56+
public MonitorAwarePoint(int x, int y, Monitor monitor) {
57+
super(x, y);
58+
this.monitor = monitor;
59+
}
60+
61+
/**
62+
* {@return the monitor with whose context the instance is created}
63+
*/
64+
public Monitor getMonitor() {
65+
return monitor;
66+
}
67+
68+
@Override
69+
public boolean equals(Object object) {
70+
return super.equals(object);
71+
}
72+
73+
@Override
74+
public int hashCode() {
75+
return super.hashCode();
76+
}
77+
78+
public float getX() {
79+
return x + residualX;
80+
}
81+
82+
public float getY() {
83+
return y + residualY;
84+
}
85+
86+
public void setX(float x) {
87+
this.x = Math.round(x);
88+
this.residualX = x - this.x;
89+
}
90+
91+
public void setY(float y) {
92+
this.y = Math.round(y);
93+
this.residualY = y - this.y;
94+
}
95+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
* @deprecated
27+
*/
28+
@Deprecated(forRemoval = true, since = "2025-09")
29+
public final class MonitorAwareRectangle extends Rectangle {
30+
31+
private static final long serialVersionUID = -54807918875027527L;
32+
33+
private float residualX, residualY, residualWidth, residualHeight;
34+
35+
private final Monitor monitor;
36+
37+
public MonitorAwareRectangle(int x, int y, int width, int height) {
38+
this(x, y, width, height, null);
39+
}
40+
41+
public MonitorAwareRectangle(float x, float y, float width, float height) {
42+
this(x, y, width, height, null);
43+
}
44+
45+
public MonitorAwareRectangle(int x, int y, int width, int height, Monitor monitor) {
46+
super(x, y, width, height);
47+
this.monitor = monitor;
48+
}
49+
50+
MonitorAwareRectangle(float x, float y, float width, float height, Monitor monitor) {
51+
super(Math.round(x), Math.round(y), Math.round(width), Math.round(height));
52+
this.residualX = x - this.x;
53+
this.residualY = y - this.y;
54+
this.residualWidth = width - this.width;
55+
this.residualHeight = height - this.height;
56+
this.monitor = monitor;
57+
}
58+
59+
/**
60+
* {@return the monitor with whose context the instance is created}
61+
*/
62+
public Monitor getMonitor() {
63+
return monitor;
64+
}
65+
66+
@Override
67+
public boolean equals(Object object) {
68+
return super.equals(object);
69+
}
70+
71+
@Override
72+
public int hashCode() {
73+
return super.hashCode();
74+
}
75+
76+
@Override
77+
public MonitorAwareRectangle clone() {
78+
return new MonitorAwareRectangle(getX(), getY(), getWidth(), getHeight(), monitor);
79+
}
80+
81+
public float getX() {
82+
return x + residualX;
83+
}
84+
85+
public float getY() {
86+
return y + residualY;
87+
}
88+
89+
public float getWidth() {
90+
return width + residualWidth;
91+
}
92+
93+
public float getHeight() {
94+
return height + residualHeight;
95+
}
96+
97+
public void setX(float x) {
98+
this.x = Math.round(x);
99+
this.residualX = x - this.x;
100+
}
101+
102+
public void setY(float y) {
103+
this.y = Math.round(y);
104+
this.residualY = y - this.y;
105+
}
106+
107+
public void setWidth(float width) {
108+
this.width = Math.round(width);
109+
this.residualWidth = width - this.width;
110+
}
111+
112+
public void setHeight(float height) {
113+
this.height = Math.round(height);
114+
this.residualHeight = height - this.height;
115+
}
116+
117+
}

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

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

46-
public sealed class Point implements Serializable permits Point.OfFloat {
46+
public sealed class Point implements Serializable permits MonitorAwarePoint, Point.OfFloat {
4747

4848
/**
4949
* the x coordinate of the point

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

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

49-
public sealed class Rectangle implements Serializable, Cloneable permits Rectangle.OfFloat {
49+
public sealed class Rectangle implements Serializable, Cloneable permits MonitorAwareRectangle, Rectangle.OfFloat {
5050

5151
/**
5252
* the x coordinate of the rectangle

0 commit comments

Comments
 (0)