summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/util/GuiOrganizer.java
diff options
context:
space:
mode:
authorJonathan Bauer2014-09-18 13:44:08 +0200
committerJonathan Bauer2014-09-18 13:44:08 +0200
commitb819dffd8a2e46c900f50c9f873c0603a83e8c79 (patch)
tree59cfcc46dcd54935a637fa77ebf0d5a7f5acab81 /dozentenmodul/src/main/java/util/GuiOrganizer.java
parentRevert "[client] center GUIs in the primary display only" (diff)
downloadtutor-module-b819dffd8a2e46c900f50c9f873c0603a83e8c79.tar.gz
tutor-module-b819dffd8a2e46c900f50c9f873c0603a83e8c79.tar.xz
tutor-module-b819dffd8a2e46c900f50c9f873c0603a83e8c79.zip
[client] moved main function to App.java & refined Config stuff
Diffstat (limited to 'dozentenmodul/src/main/java/util/GuiOrganizer.java')
-rw-r--r--dozentenmodul/src/main/java/util/GuiOrganizer.java61
1 files changed, 54 insertions, 7 deletions
diff --git a/dozentenmodul/src/main/java/util/GuiOrganizer.java b/dozentenmodul/src/main/java/util/GuiOrganizer.java
index 5d6b2de8..55cc2030 100644
--- a/dozentenmodul/src/main/java/util/GuiOrganizer.java
+++ b/dozentenmodul/src/main/java/util/GuiOrganizer.java
@@ -1,19 +1,66 @@
package util;
-import java.awt.Dimension;
-import java.awt.Toolkit;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.HeadlessException;
+import java.awt.Rectangle;
import java.awt.Window;
+
+import javax.swing.JOptionPane;
+
+/**
+ * An abstract class to organize the GUI.
+ * Currently only provide a method for centering Window-objects.
+ */
public abstract class GuiOrganizer {
- /* receive GUI, set it to center of the screen */
+ /**
+ * The rectangle representing the bounds of the primary display
+ */
+ private static Rectangle rect = null;
+
+ /**
+ * Gets the bounds of the primary display using
+ * AWT's GraphicsEnvironment class.
+ */
+ private static boolean getDisplayBounds() {
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ GraphicsDevice gd = null;
+ try {
+ gd = ge.getDefaultScreenDevice();
+ } catch (HeadlessException he) {
+ he.printStackTrace();
+ JOptionPane.showMessageDialog(null, "Konnte kein Display ermittelt werden.",
+ "Fehler", JOptionPane.ERROR_MESSAGE);
+ return false;
+ }
+
+ GraphicsConfiguration gc = gd.getDefaultConfiguration();
+ rect = gc.getBounds();
+
+ if (rect == null) {
+ JOptionPane.showMessageDialog(null, "Konnte die Resolution des Bildschirms nicht ermitteln!",
+ "Fehler", JOptionPane.ERROR_MESSAGE);
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Centers the given Window within the bounds of the display
+ * @param gui The Window object to be centered.
+ */
public static void centerGUI(Window gui) {
- Dimension dm = Toolkit.getDefaultToolkit().getScreenSize();
- double width = dm.getWidth();
- double height = dm.getHeight();
+
+ if (rect == null) getDisplayBounds();
+
+ double width = rect.getWidth();
+ double height = rect.getHeight();
double xPosition = (width / 2 - gui.getWidth() / 2);
double yPosition = (height / 2 - gui.getHeight() / 2);
gui.setLocation((int) xPosition, (int) yPosition);
}
-
}