Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.mylyn.reviews.ui.tests/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialogTest.java41
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialog.java10
2 files changed, 48 insertions, 3 deletions
diff --git a/org.eclipse.mylyn.reviews.ui.tests/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialogTest.java b/org.eclipse.mylyn.reviews.ui.tests/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialogTest.java
index a6b924f06..09d82e58b 100644
--- a/org.eclipse.mylyn.reviews.ui.tests/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialogTest.java
+++ b/org.eclipse.mylyn.reviews.ui.tests/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialogTest.java
@@ -49,6 +49,7 @@ import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -67,6 +68,8 @@ import com.google.common.collect.Iterables;
public class CommentPopupDialogTest extends TestCase {
+ private static final int MAX_WIDTH = 500;
+
private final static String USER_ID = "1";
private final static String USER_NAME = "Test User";
@@ -434,6 +437,44 @@ public class CommentPopupDialogTest extends TestCase {
}
/**
+ * Tests that setting the height based on the y-coordinate of the mouse works for one or more monitors
+ */
+ @Test
+ public void testSetHeightBasedOnMouse() {
+ commentPopupDialog = spy(createPopupWithXComments(100, true));
+
+ // Monitor is the primary display
+ Rectangle monitorArea = new Rectangle(0, 0, 1680, 1050);
+ doReturn(monitorArea).when(commentPopupDialog).getMonitorArea();
+ commentPopupDialog.setHeightBasedOnMouse(500);
+ assertEquals(534, commentPopupDialog.getShell().getSize().y);
+
+ // Monitor to the left and below the top of primary display
+ monitorArea = new Rectangle(-1920, 480, 1920, 1080);
+ doReturn(monitorArea).when(commentPopupDialog).getMonitorArea();
+ commentPopupDialog.setHeightBasedOnMouse(500);
+ assertEquals(1044, commentPopupDialog.getShell().getSize().y);
+
+ // Monitor to the right and below the top of primary display
+ monitorArea = new Rectangle(1680, 480, 1920, 1080);
+ doReturn(monitorArea).when(commentPopupDialog).getMonitorArea();
+ commentPopupDialog.setHeightBasedOnMouse(500);
+ assertEquals(1044, commentPopupDialog.getShell().getSize().y);
+
+ // Monitor to the left above the top of primary display
+ monitorArea = new Rectangle(-1920, -420, 1920, 1080);
+ doReturn(monitorArea).when(commentPopupDialog).getMonitorArea();
+ commentPopupDialog.setHeightBasedOnMouse(500);
+ assertEquals(144, commentPopupDialog.getShell().getSize().y);
+
+ // Monitor to the right above the top of primary display
+ monitorArea = new Rectangle(1680, -420, 1920, 1080);
+ doReturn(monitorArea).when(commentPopupDialog).getMonitorArea();
+ commentPopupDialog.setHeightBasedOnMouse(500);
+ assertEquals(144, commentPopupDialog.getShell().getSize().y);
+ }
+
+ /**
* Returns a comment from the dialog depending on the ordering from the top of the comment list
*
* @param commentNumber
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 f31940976..d6332f9b6 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
@@ -283,6 +283,10 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList
return getShell().getBounds();
}
+ public Rectangle getMonitorArea() {
+ return getShell().getMonitor().getClientArea();
+ }
+
public Rectangle computeTrim() {
return getShell().computeTrim(0, 0, 0, 0);
}
@@ -299,7 +303,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList
*/
public void setLocation(Point location) {
Rectangle bounds = getShell().getBounds();
- Rectangle monitorBounds = getShell().getMonitor().getClientArea();
+ Rectangle monitorBounds = getMonitorArea();
// ensure the popup fits on the shell's monitor
bounds.x = constrain(location.x, monitorBounds.x, monitorBounds.x + monitorBounds.width - bounds.width);
bounds.y = constrain(location.y, monitorBounds.y, monitorBounds.y + monitorBounds.height - bounds.height);
@@ -319,7 +323,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList
Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
scrolledComposite.setMinSize(size);
- int height = constrain(size.y, MIN_HEIGHT, getShell().getMonitor().getClientArea().height);
+ int height = constrain(size.y, MIN_HEIGHT, getMonitorArea().height);
getShell().setSize(size.x, height);
scrolledComposite.setSize(size.x, height);
setLocation(new Point(bounds.x, bounds.y));
@@ -340,7 +344,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList
}
public void setHeightBasedOnMouse(int mouseY) {
- int mouseYFromBottom = getShell().getMonitor().getClientArea().height - mouseY;
+ int mouseYFromBottom = getMonitorArea().height + getMonitorArea().y - mouseY; // Coordinates are based on the primary monitor
recomputeSize();
setSize(MAX_WIDTH, constrain(mouseYFromBottom - ICON_BUFFER, MIN_HEIGHT, getShell().getSize().y));
}

Back to the top