summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/util
diff options
context:
space:
mode:
authorSimon Rettberg2015-05-29 17:56:36 +0200
committerSimon Rettberg2015-05-29 17:56:36 +0200
commit605857a1ef614964d73ea83e0561d1bfb06e611b (patch)
treeae968412f038b1a53d07bf83ab8f7fdf808750d1 /dozentenmodul/src/main/java/util
parent[server] Added some TODOs (diff)
downloadtutor-module-605857a1ef614964d73ea83e0561d1bfb06e611b.tar.gz
tutor-module-605857a1ef614964d73ea83e0561d1bfb06e611b.tar.xz
tutor-module-605857a1ef614964d73ea83e0561d1bfb06e611b.zip
[client] Compiles again, but is broken....
Diffstat (limited to 'dozentenmodul/src/main/java/util')
-rw-r--r--dozentenmodul/src/main/java/util/GuiManager.java70
-rw-r--r--dozentenmodul/src/main/java/util/MessageType.java23
2 files changed, 61 insertions, 32 deletions
diff --git a/dozentenmodul/src/main/java/util/GuiManager.java b/dozentenmodul/src/main/java/util/GuiManager.java
index 9fa2814f..67671fcb 100644
--- a/dozentenmodul/src/main/java/util/GuiManager.java
+++ b/dozentenmodul/src/main/java/util/GuiManager.java
@@ -10,7 +10,6 @@ import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Rectangle;
-import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
@@ -80,8 +79,7 @@ public abstract class GuiManager {
// size management
mainWindow.setBounds(0, 0, 785, 430);
- mainWindow.setLocation(
- (int) (rect.getWidth() / 2 - mainWindow.getWidth() / 2),
+ mainWindow.setLocation((int) (rect.getWidth() / 2 - mainWindow.getWidth() / 2),
(int) (rect.getHeight() / 2 - mainWindow.getHeight() / 2));
try {
@@ -99,7 +97,7 @@ public abstract class GuiManager {
* Public function to show the given frame, replacing the current frame
*
* @param newFrame
- * the new frame to show
+ * the new frame to show
*/
public static void show(JInternalFrame newFrame) {
// first remove the current component
@@ -131,8 +129,7 @@ public abstract class GuiManager {
}
// TODO else case
- mainWindow.setTitle(newFrame.getTitle() != null ? newFrame.getTitle()
- : "bwLehrpool Suite");
+ mainWindow.setTitle(newFrame.getTitle() != null ? newFrame.getTitle() : "bwLehrpool Suite");
mainWindow.getContentPane().add(currentFrame, BorderLayout.CENTER);
mainWindow.setBounds((int) mainWindow.getLocationOnScreen().getX(),
(int) mainWindow.getLocationOnScreen().getY(), currentFrame.getWidth(),
@@ -145,17 +142,16 @@ public abstract class GuiManager {
* Public function to show the given frame, replacing the current frame
*
* @param newFrame
- * the new frame to show
+ * the new frame to show
* @param center
- * true if the main window is to be centered, false otherwise
+ * true if the main window is to be centered, false otherwise
*/
public static void show(JInternalFrame newFrame, boolean center) {
show(newFrame);
if (center) {
double xCenter = (rect.getWidth() / 2 - newFrame.getWidth() / 2);
double yCenter = (rect.getHeight() / 2 - newFrame.getHeight() / 2);
- mainWindow.setBounds((int) xCenter, (int) yCenter, newFrame.getWidth(),
- newFrame.getHeight());
+ mainWindow.setBounds((int) xCenter, (int) yCenter, newFrame.getWidth(), newFrame.getHeight());
}
}
@@ -164,18 +160,15 @@ public abstract class GuiManager {
* main window
*
* @param popup
- * The component to open as popup. Note this must be a JFrame.
+ * The component to open as popup. Note this must be a JFrame.
*/
public static void openPopup(Component popup) {
if (!(popup instanceof JFrame)) {
- LOGGER.error("Popup classes need to be JFrame, given a: "
- + popup.getClass().getName());
+ LOGGER.error("Popup classes need to be JFrame, given a: " + popup.getClass().getName());
return;
}
- int xPopup = (int) (mainWindow.getX() + (mainWindow.getWidth() / 2) - (popup
- .getWidth() / 2));
- int yPopup = (int) (mainWindow.getY() + (mainWindow.getHeight() / 2) - (popup
- .getHeight() / 2));
+ int xPopup = (int) (mainWindow.getX() + (mainWindow.getWidth() / 2) - (popup.getWidth() / 2));
+ int yPopup = (int) (mainWindow.getY() + (mainWindow.getHeight() / 2) - (popup.getHeight() / 2));
((JFrame) popup).setLocation(xPopup, yPopup);
((JFrame) popup).setVisible(true);
}
@@ -213,7 +206,8 @@ public abstract class GuiManager {
}
/**
- * Private function to determine whether the currentFrame has a 'HELP_MESSAGE'
+ * Private function to determine whether the currentFrame has a
+ * 'HELP_MESSAGE'
* defined and to add it to the menu bar if found one.
*
* @return true if setting the help button to the menu bar worked, false
@@ -225,16 +219,14 @@ public abstract class GuiManager {
// "Hilfe"
final String helpMessage;
try {
- helpMessage = (String) (currentFrame.getClass().getDeclaredField(
- "HELP_MESSAGE").get(currentFrame));
+ helpMessage = (String) (currentFrame.getClass().getDeclaredField("HELP_MESSAGE").get(currentFrame));
} catch (NoSuchFieldException e) {
// only this case if interesting for us,
// since we now we don't have a help message to show
return false;
- } catch (IllegalArgumentException | IllegalAccessException
- | SecurityException e) {
- LOGGER.error("Failed to check for 'HELP_MESSAGE' variable in '"
- + currentFrame.getClass() + "' class, see trace: " + e);
+ } catch (IllegalArgumentException | IllegalAccessException | SecurityException e) {
+ LOGGER.error("Failed to check for 'HELP_MESSAGE' variable in '" + currentFrame.getClass()
+ + "' class, see trace: " + e);
return false;
}
// print it for debugging purposes
@@ -243,9 +235,8 @@ public abstract class GuiManager {
mnNewMenu_Info.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
- JOptionPane.showMessageDialog(currentFrame,
- helpMessage != null ? helpMessage : "No help message.",
- "Hilfe zu dieser Oberfläche", JOptionPane.INFORMATION_MESSAGE);
+ JOptionPane.showMessageDialog(currentFrame, helpMessage != null ? helpMessage
+ : "No help message.", "Hilfe zu dieser Oberfläche", JOptionPane.INFORMATION_MESSAGE);
}
});
mainWindow.getJMenuBar().add(mnNewMenu_Info);
@@ -263,8 +254,7 @@ public abstract class GuiManager {
gd = ge.getDefaultScreenDevice();
} catch (HeadlessException he) {
he.printStackTrace();
- JOptionPane.showMessageDialog(null,
- "Konnte kein Display ermittelt werden.", "Fehler",
+ JOptionPane.showMessageDialog(null, "Konnte kein Display ermittelt werden.", "Fehler",
JOptionPane.ERROR_MESSAGE);
return false;
}
@@ -273,12 +263,28 @@ public abstract class GuiManager {
rect = gc.getBounds();
if (rect == null) {
- JOptionPane.showMessageDialog(null,
- "Konnte die Resolution des Bildschirms nicht ermitteln!", "Fehler",
- JOptionPane.ERROR_MESSAGE);
+ JOptionPane.showMessageDialog(null, "Konnte die Resolution des Bildschirms nicht ermitteln!",
+ "Fehler", JOptionPane.ERROR_MESSAGE);
return false;
} else {
return true;
}
}
+
+ /**
+ * Generic helper to show a message box to the user, and optionally log the message to the log file.
+ *
+ * @param message Message to display. Can be multi line.
+ * @param messageType Type of message (warning, information)
+ * @param logger Logger instance to log to. Can be null.
+ * @param exception Exception related to this message. Can be null.
+ */
+ public static void showMessageBox(String message, MessageType messageType, Logger logger,
+ Throwable exception) {
+ if (logger != null)
+ logger.log(messageType.logPriority, message, exception);
+ if (exception != null)
+ message += "\n\n" + exception.getClass().getSimpleName();
+ JOptionPane.showMessageDialog(mainWindow, message, messageType.title, messageType.optionPaneId);
+ }
}
diff --git a/dozentenmodul/src/main/java/util/MessageType.java b/dozentenmodul/src/main/java/util/MessageType.java
new file mode 100644
index 00000000..294e28d6
--- /dev/null
+++ b/dozentenmodul/src/main/java/util/MessageType.java
@@ -0,0 +1,23 @@
+package util;
+
+import javax.swing.JOptionPane;
+
+import org.apache.log4j.Priority;
+
+@SuppressWarnings("deprecation")
+public enum MessageType {
+ DEBUG(JOptionPane.INFORMATION_MESSAGE, "Debug", Priority.DEBUG),
+ INFO(JOptionPane.INFORMATION_MESSAGE, "Hinweis", Priority.INFO),
+ WARNING(JOptionPane.WARNING_MESSAGE, "Warnung", Priority.WARN),
+ ERROR(JOptionPane.ERROR_MESSAGE, "Fehler", Priority.ERROR);
+
+ public final String title;
+ public final int optionPaneId;
+ public final Priority logPriority;
+
+ private MessageType(int paneId, String title, Priority prio) {
+ this.title = title;
+ this.optionPaneId = paneId;
+ this.logPriority = prio;
+ }
+}