Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ private SingleZoomCoordinateSystemMapper getSingleZoomCoordinateSystemMapper() {
@MethodSource("provideCoordinateSystemMappers")
void translatePointInNoMonitorBackAndForthShouldBeTheSame(CoordinateSystemMapper mapper) {
setupMonitors(mapper);
Point pt = createExpectedPoint(mapper, 5000, -400, monitors[0]);
MonitorAwarePoint pt = createExpectedPoint(mapper, 5000, -400, monitors[0]);
Point px = mapper.translateToDisplayCoordinates(pt, monitors[0].getZoom());
assertEquals(pt, mapper.translateFromDisplayCoordinates(px, monitors[0].getZoom()));
assertEquals(pt.getPoint(), mapper.translateFromDisplayCoordinates(px, monitors[0].getZoom()));
}

@Test
void translatePointInGapBackAndForthInSingleZoomShouldBeTheSame() {
SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper();
setupMonitors(mapper);
Point pt = new Point(1900, 400);
Point px = mapper.translateToDisplayCoordinates(pt, monitors[0].getZoom());
Point px = mapper.translateToDisplayCoordinates(new MonitorAwarePoint(pt), monitors[0].getZoom());
assertEquals(pt, mapper.translateFromDisplayCoordinates(px, monitors[0].getZoom()));
}

Expand All @@ -82,9 +82,9 @@ void translatePointInGapBackAndForthInMultiZoomShouldEndInsideTheSameMonitor() {
MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper();
setupMonitors(mapper);
Point pt = new Point(1900, 400);
Point px = mapper.translateToDisplayCoordinates(pt, monitors[0].getZoom());
Point px = mapper.translateToDisplayCoordinates(new MonitorAwarePoint(pt), monitors[0].getZoom());
Point translatedPt = mapper.translateFromDisplayCoordinates(px, monitors[0].getZoom());
Point translatedPx = mapper.translateToDisplayCoordinates(translatedPt, monitors[0].getZoom());
Point translatedPx = mapper.translateToDisplayCoordinates(new MonitorAwarePoint(translatedPt), monitors[0].getZoom());
assertEquals(new Point(translatedPt.x, translatedPt.y), translatedPx);
assertEquals(translatedPx, px);
}
Expand All @@ -93,27 +93,27 @@ void translatePointInGapBackAndForthInMultiZoomShouldEndInsideTheSameMonitor() {
@MethodSource("provideCoordinateSystemMappers")
void translateRectangleInNoMonitorBackAndForthShouldBeTheSame(CoordinateSystemMapper mapper) {
setupMonitors(mapper);
Rectangle rectInPts = createExpectedRectangle(mapper, 5000, -400, 200, 200, monitors[0]);
MonitorAwareRectangle rectInPts = createExpectedRectangle(mapper, 5000, -400, 200, 200, monitors[0]);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
assertEquals(rectInPts.getRectangle(), mapper.translateFromDisplayCoordinates(new MonitorAwareRectangle(rectInPxs), monitors[0].getZoom()));
}

@Test
void translateRectangleInGapBackAndForthInSingleZoomShouldBeTheSame() {
SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper();
setupMonitors(mapper);
Rectangle rectInPts = new Rectangle(1800, 400, 100, 100);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(new MonitorAwareRectangle(rectInPts), monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(new MonitorAwareRectangle(rectInPxs), monitors[0].getZoom()));
}

@Test
void translateRectangleInGapBackAndForthInMultiZoomShouldBeInMonitorBounds() {
MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper();
setupMonitors(mapper);
Rectangle rectInPts = new Rectangle(1800, 400, 100, 100);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
Rectangle rectInPtsTranslated = mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom());
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(new MonitorAwareRectangle(rectInPts), monitors[0].getZoom());
Rectangle rectInPtsTranslated = mapper.translateFromDisplayCoordinates(new MonitorAwareRectangle(rectInPxs), monitors[0].getZoom());
boolean isInsideMonitor = false;
for (Monitor monitor : monitors) {
if (monitor.getClientArea().intersects(rectInPtsTranslated)) {
Expand All @@ -129,45 +129,45 @@ void translateRectangleInGapPartiallyInRightBackAndForthInSingleZoomShouldBeTheS
SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper();
setupMonitors(mapper);
Rectangle rectInPts = new Rectangle(1950, 400, 150, 100);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(new MonitorAwareRectangle(rectInPts), monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(new MonitorAwareRectangle(rectInPxs), monitors[0].getZoom()));
}

@Test
void translateRectangleInGapPartiallyInRightBackAndForthInMultiZoomShouldBeInside() {
MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper();
setupMonitors(mapper);
Rectangle rectInPts = new MonitorAwareRectangle(1950, 400, 150, 100, monitors[1]);
MonitorAwareRectangle rectInPts = new MonitorAwareRectangle(1950, 400, 150, 100, monitors[1]);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
assertEquals(rectInPts.getRectangle(), mapper.translateFromDisplayCoordinates(new MonitorAwareRectangle(rectInPxs), monitors[0].getZoom()));
}

@ParameterizedTest
@MethodSource("provideCoordinateSystemMappers")
void translateRectangleInGapPartiallyInLeftBackAndForthShouldBeTheSame(CoordinateSystemMapper mapper) {
setupMonitors(mapper);
Rectangle rectInPts = createExpectedRectangle(mapper, 750, 400, 100, 100, monitors[0]);
MonitorAwareRectangle rectInPts = createExpectedRectangle(mapper, 750, 400, 100, 100, monitors[0]);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
assertEquals(rectInPts.getRectangle(), mapper.translateFromDisplayCoordinates(new MonitorAwareRectangle(rectInPxs), monitors[0].getZoom()));
}

@Test
void translateRectangleInPointsInBothMonitorsPartiallyBackAndForthInSingleZoomShouldBeTheSame() {
SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper();
setupMonitors(mapper);
Rectangle rectInPts = new Rectangle(950, 400, 1500, 100);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(new MonitorAwareRectangle(rectInPts), monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(new MonitorAwareRectangle(rectInPxs), monitors[0].getZoom()));
}

@Test
void translateRectangleInPointsInBothMonitorsPartiallyBackAndForthInMultiZoomShouldNotEndUpInGap() {
MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper();
setupMonitors(mapper);
Rectangle rectInPts = new Rectangle(950, 400, 1500, 100);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
Rectangle rectInPtsTranslated = mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom());
Rectangle rectInPxsTranslated = mapper.translateToDisplayCoordinates(rectInPtsTranslated,
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(new MonitorAwareRectangle(rectInPts), monitors[0].getZoom());
Rectangle rectInPtsTranslated = mapper.translateFromDisplayCoordinates(new MonitorAwareRectangle(rectInPxs), monitors[0].getZoom());
Rectangle rectInPxsTranslated = mapper.translateToDisplayCoordinates(new MonitorAwareRectangle(rectInPtsTranslated),
monitors[0].getZoom());
assertEquals(rectInPxs, rectInPxsTranslated);
}
Expand All @@ -182,13 +182,13 @@ void moveRectangleInPixelsInRightMonitorsPartiallyBackAndForthShouldBeTheSame()
expectedSmallRectInPxs.y = rectInPxs.y + (rectInPxs.height / 2) - 200;
expectedSmallRectInPxs.width = 400;
expectedSmallRectInPxs.height = 400;
Rectangle rectInPts = mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom());
Rectangle rectInPts = mapper.translateFromDisplayCoordinates(new MonitorAwareRectangle(rectInPxs), monitors[0].getZoom());
Rectangle smallRectInPts = new Rectangle(0, 0, 0, monitors[0].getZoom());
smallRectInPts.x = rectInPts.x + (rectInPts.width / 2) - 200;
smallRectInPts.y = rectInPts.y + (rectInPts.height / 2) - 200;
smallRectInPts.width = 400;
smallRectInPts.height = 400;
Rectangle smallRectInPxs = mapper.translateToDisplayCoordinates(smallRectInPts, monitors[0].getZoom());
Rectangle smallRectInPxs = mapper.translateToDisplayCoordinates(new MonitorAwareRectangle(smallRectInPts), monitors[0].getZoom());
assertEquals(expectedSmallRectInPxs, smallRectInPxs);
}

Expand All @@ -197,30 +197,30 @@ void moveRectangleInPixelsInRightMonitorsPartiallyBackAndForthShouldBeTheSame()
void translateRectangleInPixelsOutisdeMonitorsBackAndForthShouldBeTheSame(CoordinateSystemMapper mapper) {
setupMonitors(mapper);
Rectangle rectInPxs = new Rectangle(400, 2400, 1000, 1000);
Rectangle rectInPts = mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom());
assertEquals(rectInPxs, mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom()));
Rectangle rectInPts = mapper.translateFromDisplayCoordinates(new MonitorAwareRectangle(rectInPxs), monitors[0].getZoom());
assertEquals(rectInPxs, mapper.translateToDisplayCoordinates(new MonitorAwareRectangle(rectInPts), monitors[0].getZoom()));
}

@ParameterizedTest
@MethodSource("provideCoordinateSystemMappers")
void translateRectangleInPixelsInBothMonitorsBackAndForthShouldBeTheSame(CoordinateSystemMapper mapper) {
setupMonitors(mapper);
Rectangle rectInPxs = new Rectangle(1500, 400, 502, 500);
Rectangle rectInPts = mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom());
assertEquals(rectInPxs, mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom()));
Rectangle rectInPts = mapper.translateFromDisplayCoordinates(new MonitorAwareRectangle(rectInPxs), monitors[0].getZoom());
assertEquals(rectInPxs, mapper.translateToDisplayCoordinates(new MonitorAwareRectangle(rectInPts), monitors[0].getZoom()));
}

private Point createExpectedPoint(CoordinateSystemMapper mapper, int x, int y, Monitor monitor) {
private MonitorAwarePoint createExpectedPoint(CoordinateSystemMapper mapper, int x, int y, Monitor monitor) {
if (mapper instanceof SingleZoomCoordinateSystemMapper) {
return new Point(x, y);
return new MonitorAwarePoint(new Point(x, y));
} else {
return new MonitorAwarePoint(x, y, monitor);
}
}

private Rectangle createExpectedRectangle(CoordinateSystemMapper mapper, int x, int y, int width, int height, Monitor monitor) {
private MonitorAwareRectangle createExpectedRectangle(CoordinateSystemMapper mapper, int x, int y, int width, int height, Monitor monitor) {
if (mapper instanceof SingleZoomCoordinateSystemMapper) {
return new Rectangle(x, y, width, height);
return new MonitorAwareRectangle(new Rectangle(x, y, width, height));
} else {
return new MonitorAwareRectangle(x, y, width, height, monitor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*******************************************************************************/
package org.eclipse.swt.graphics;

import java.util.*;

import org.eclipse.swt.widgets.*;

/**
Expand All @@ -26,10 +24,8 @@
* @since 3.129
* @noreference This class is not intended to be referenced by clients
*/
public final class MonitorAwarePoint extends Point {

private static final long serialVersionUID = 6077427420686999194L;

public final class MonitorAwarePoint {
private final Point point;
private final Monitor monitor;

/**
Expand All @@ -40,7 +36,15 @@ public final class MonitorAwarePoint extends Point {
* @param monitor the monitor with whose context the point is created
*/
public MonitorAwarePoint(int x, int y, Monitor monitor) {
super(x, y);
this(new Point(x, y), monitor);
}

public MonitorAwarePoint(Point point) {
this(point, null);
}

public MonitorAwarePoint(Point point, Monitor monitor) {
this.point = point;
this.monitor = monitor;
}

Expand All @@ -51,21 +55,10 @@ public Monitor getMonitor() {
return monitor;
}

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (!super.equals(object)) {
return false;
}
MonitorAwarePoint other = (MonitorAwarePoint) object;
return Objects.equals(this.monitor, other.monitor);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), monitor);
/**
* {@return the monitor with whose context the instance is created}
*/
public Point getPoint() {
return point;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*******************************************************************************/
package org.eclipse.swt.graphics;

import java.util.*;

import org.eclipse.swt.widgets.*;

/**
Expand All @@ -26,10 +24,8 @@
* @since 3.129
* @noreference This class is not intended to be referenced by clients
*/
public final class MonitorAwareRectangle extends Rectangle {

private static final long serialVersionUID = 5041911840525116925L;

public final class MonitorAwareRectangle {
private final Rectangle rect;
private final Monitor monitor;

/**
Expand All @@ -42,32 +38,29 @@ public final class MonitorAwareRectangle extends Rectangle {
* @param monitor the monitor with whose context the rectangle is created
*/
public MonitorAwareRectangle(int x, int y, int width, int height, Monitor monitor) {
super(x, y, width, height);
this(new Rectangle(x, y, width, height), monitor);
}

public MonitorAwareRectangle(Rectangle rect) {
this(rect, null);
}

public MonitorAwareRectangle(Rectangle rect, Monitor monitor) {
this.rect = rect;
this.monitor = monitor;
}

/**
* {@return the monitor with whose context the instance is created}
*/
public Monitor getMonitor() {
return monitor;
public Rectangle getRectangle() {
return rect;
}

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (!super.equals(object)) {
return false;
}
MonitorAwareRectangle other = (MonitorAwareRectangle) object;
return Objects.equals(this.monitor, other.monitor);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), monitor);
/**
* {@return the monitor with whose context the instance is created}
*/
public Monitor getMonitor() {
return monitor;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
*/

public sealed class Point implements Serializable permits MonitorAwarePoint {
public final class Point implements Serializable {

/**
* the x coordinate of the point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
*/

public sealed class Rectangle implements Serializable permits MonitorAwareRectangle {
public final class Rectangle implements Serializable {

/**
* the x coordinate of the rectangle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4009,7 +4009,7 @@ void subclass () {
public Point toControl (int x, int y) {
checkWidget ();
int zoom = getZoom();
Point displayPointInPixels = getDisplay().translateToDisplayCoordinates(new Point(x, y), zoom);
Point displayPointInPixels = getDisplay().translateToDisplayCoordinates(new MonitorAwarePoint(new Point(x, y)), zoom);
final Point controlPointInPixels = toControlInPixels(displayPointInPixels.x, displayPointInPixels.y);
return DPIUtil.scaleDown(controlPointInPixels, zoom);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@

interface CoordinateSystemMapper {

Rectangle map(Control from, Control to, Rectangle rectangle);
MonitorAwareRectangle map(Control from, Control to, Rectangle rectangle);

Rectangle map(Control from, Control to, int x, int y, int width, int height);
MonitorAwareRectangle map(Control from, Control to, int x, int y, int width, int height);

Point map(Control from, Control to, Point point);
MonitorAwarePoint map(Control from, Control to, Point point);

Point map(Control from, Control to, int x, int y);
MonitorAwarePoint map(Control from, Control to, int x, int y);

Rectangle mapMonitorBounds(Rectangle rectangle, int zoom);

Point translateFromDisplayCoordinates(Point point, int zoom);

Point translateToDisplayCoordinates(Point point, int zoom);
Point translateToDisplayCoordinates(MonitorAwarePoint point, int zoom);

Rectangle translateFromDisplayCoordinates(Rectangle rect, int zoom);
Rectangle translateFromDisplayCoordinates(MonitorAwareRectangle rect, int zoom);

Rectangle translateToDisplayCoordinates(Rectangle rect, int zoom);
Rectangle translateToDisplayCoordinates(MonitorAwareRectangle rect, int zoom);

void setCursorLocation(int x, int y);

Expand Down
Loading