Skip to content

Better API for handling MonitorAware Coordinates #2186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ public int hashCode() {
return super.hashCode();
}

@Override
public MonitorAwareRectangle clone() {
return new MonitorAwareRectangle(x, y, width, height, monitor);
}

}
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 sealed class Rectangle implements Serializable, Cloneable permits MonitorAwareRectangle {

/**
* the x coordinate of the rectangle
Expand Down Expand Up @@ -356,4 +356,39 @@ 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.
* <p>
* 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.
* </p>
*
* @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}.
* <p>
* 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.
* </p>
*
* @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);
}
}
Loading