+
+ /**
+ * Set the given {@link JButton} as "pressed" (selected, but with more UI
+ * visibility).
+ * <p>
+ * The {@link JButton} will answer {@link JButton#isSelected()} if it is
+ * pressed.
+ *
+ * @param button
+ * the button to select/press
+ * @param pressed
+ * the new "pressed" state
+ */
+ static public void setButtonPressed(JButton button, boolean pressed) {
+ if (buttonNormal == null) {
+ JButton defButton = new JButton(" ");
+ buttonNormal = defButton.getBackground();
+ if (buttonNormal.getBlue() >= 128) {
+ buttonPressed = new Color( //
+ Math.max(buttonNormal.getRed() - 100, 0), //
+ Math.max(buttonNormal.getGreen() - 100, 0), //
+ Math.max(buttonNormal.getBlue() - 100, 0));
+ } else {
+ buttonPressed = new Color( //
+ Math.min(buttonNormal.getRed() + 100, 255), //
+ Math.min(buttonNormal.getGreen() + 100, 255), //
+ Math.min(buttonNormal.getBlue() + 100, 255));
+ }
+ }
+
+ button.setSelected(pressed);
+ button.setBackground(pressed ? buttonPressed : buttonNormal);
+ }
+
+ /**
+ * Set the given {@link Window} to full screen mode, on the desktop it
+ * currently resides on.
+ * <p>
+ * Can be cancelled by calling again with a NULL value.
+ *
+ * @param win
+ * the window to set to full screen
+ */
+ static public void setFullscreenWindow(Window win) {
+ GraphicsEnvironment env = GraphicsEnvironment
+ .getLocalGraphicsEnvironment();
+ GraphicsDevice[] screens = env.getScreenDevices();
+
+ if (win == null) {
+ for (GraphicsDevice screen : screens) {
+ if (win == null) {
+ screen.setFullScreenWindow(null);
+ }
+ }
+
+ return;
+ }
+
+ Rectangle r = win.getBounds();
+ Point center = new Point(r.x + r.width / 2, r.y + r.height / 2);
+
+ GraphicsDevice current = null;
+ for (GraphicsDevice screen : screens) {
+ GraphicsConfiguration[] confs = screen.getConfigurations();
+ for (GraphicsConfiguration conf : confs) {
+ if (conf.getBounds().contains(center)) {
+ current = screen;
+ break;
+ }
+ }
+
+ if (current != null)
+ break;
+ }
+
+ if (current == null) {
+ current = GraphicsEnvironment.getLocalGraphicsEnvironment()
+ .getDefaultScreenDevice();
+ }
+
+ current.setFullScreenWindow(win);
+ }