summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-07-17 17:20:38 +0200
committerSimon Rettberg2015-07-17 17:20:38 +0200
commit7844be5e4d74612e9aff44c5aab09d4f6e5d2631 (patch)
tree2605abdf19b146b22feda18a3256e3e031c677eb /dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java
parent[client] first steps in ImagePermissions page (diff)
downloadtutor-module-7844be5e4d74612e9aff44c5aab09d4f6e5d2631.tar.gz
tutor-module-7844be5e4d74612e9aff44c5aab09d4f6e5d2631.tar.xz
tutor-module-7844be5e4d74612e9aff44c5aab09d4f6e5d2631.zip
[client] Add image details window
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java27
1 files changed, 26 insertions, 1 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java
index 42fbf165..57103748 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java
@@ -33,6 +33,7 @@ public class Gui {
/**
* Center the given shell on the {@link Monitor} it is displayed on.
+ * WARNING: Seems broken on Linux, SWT only sees the primary monitor.
*
* @param shell Some shell
*/
@@ -46,6 +47,24 @@ public class Gui {
}
/**
+ * Take a shell and center it relative to another shell
+ *
+ * @param parent Parent shell, used as reference
+ * @param shellToCenter The shell that should be repositioned
+ */
+ public static void centerShellOverShell(Shell parent, Shell shellToCenter) {
+ Rectangle bounds = parent.getBounds();
+ Rectangle rect = shellToCenter.getBounds();
+ int x = bounds.x + (bounds.width - rect.width) / 2;
+ int y = bounds.y + (bounds.height - rect.height) / 2;
+ if (x < bounds.x)
+ x = bounds.x;
+ if (y < bounds.y)
+ y = bounds.y;
+ shellToCenter.setLocation(x, y);
+ }
+
+ /**
* Make sure the given shell fits the {@link Monitor} it is displayed on.
*
* @param shell Some shell
@@ -90,14 +109,18 @@ public class Gui {
* @return the {@link Monitor}
*/
public static Monitor getMonitorFromPoint(Point point, boolean defaultToPrimary) {
+ LOGGER.debug("Finding monitor for point " + point.toString());
Monitor[] monitors = display.getMonitors();
for (Monitor monitor : monitors) {
Rectangle bounds = monitor.getBounds();
+ LOGGER.debug("Checking monitor " + bounds.toString());
if (bounds.contains(point))
return monitor;
}
- if (defaultToPrimary)
+ if (defaultToPrimary) {
+ LOGGER.debug("Defaulting to promary...");
return display.getPrimaryMonitor();
+ }
return null;
}
@@ -113,6 +136,7 @@ public class Gui {
// Make sure rectangle is in bounds. This is not completely accurate
// in case there are multiple monitors that have different resolutions.
Rectangle bounds = display.getBounds();
+ LOGGER.debug("Display bounds are " + bounds.toString() + ", rect is " + rect.toString());
if (rect.x + rect.width >= bounds.x + bounds.width) {
rect.width -= (rect.x + rect.width) - (bounds.x + bounds.width);
if (rect.width < 1)
@@ -131,6 +155,7 @@ public class Gui {
rect.height -= bounds.y - rect.y;
rect.y = bounds.y;
}
+ LOGGER.debug("After correction: " + rect.toString());
// Now just use the same code as *FromPoint by using the rectangle's center
return getMonitorFromPoint(new Point(rect.x + rect.width / 2, rect.y + rect.height / 2),
defaultToPrimary);