442115: comment popup shown on wrong screen
Change-Id: If58e10226ae86afaa7c1d976ceb0b3bdf5e54cf4
Task-Url:https://bugs.eclipse.org/bugs/show_bug.cgi?id=442115
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialog.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialog.java
index d2096ed..77bf6c1 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialog.java
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialog.java
@@ -175,7 +175,17 @@
}
public void setLocation(Point location) {
- getShell().setLocation(location);
+ Rectangle bounds = getShell().getBounds();
+ Rectangle monitorBounds = getShell().getMonitor().getClientArea();
+ // ensure the popup fits on the shell's monitor
+ bounds.x = contrain(location.x, monitorBounds.x, monitorBounds.x + monitorBounds.width - bounds.width);
+ bounds.y = contrain(location.y, monitorBounds.y, monitorBounds.y + monitorBounds.height - bounds.height);
+
+ getShell().setLocation(new Point(bounds.x, bounds.y));
+ }
+
+ private int contrain(int value, int min, int max) {
+ return Math.max(min, Math.min(max, value));
}
public void setSize(int width, int height) {