@SuppressWarnings("restriction")
  public static void enableAppleFullscreen(JFrame window) {
    window.pack();
    window.setVisible(true);
    setAutoRequestFocus(window, true);
    if (javaVersion()
        == 7) { // work around bug in java 7 where top bar space is blank unless undecorated
      FullScreenUtilities.addFullScreenListenerTo(
          window,
          new FullScreenAdapter() {
            boolean working = false;

            @Override
            public void windowEnteredFullScreen(AppEvent.FullScreenEvent e) {
              if (working) {
                working = false;
                return;
              }
              ;
              if (!((JFrame) e.getWindow()).isUndecorated()) {
                working = true;
                Application.getApplication().requestToggleFullScreen(e.getWindow());
              }
            }

            @Override
            public void windowExitedFullScreen(AppEvent.FullScreenEvent e) {
              if (working) {
                e.getWindow().dispose();
                ((JFrame) e.getWindow()).setUndecorated(true);
                e.getWindow().pack();
                e.getWindow().setVisible(true);
                Application.getApplication().requestToggleFullScreen(e.getWindow());
                return;
              }
              ;
              if (((JFrame) e.getWindow()).isUndecorated()) {
                e.getWindow().dispose();
                ((JFrame) e.getWindow()).setUndecorated(false);
                e.getWindow().setVisible(true);
              }
            }
          });
    }
    FullScreenUtilities.setWindowCanFullScreen(window, true);
  }
 public static void toFullScreen(
     JFrame window,
     GraphicsDevice gd,
     boolean tryAppleFullscreen,
     boolean tryExclusiveFullscreen) {
   if (appleEawtAvailable()
       && tryAppleFullscreen
       && appleOSVersion() >= 7
       && // lion and above
       javaVersion() >= 7) { // java 7 and above
     System.out.println("trying to apple fullscreen");
     enableAppleFullscreen(window);
     doAppleFullscreen(window);
   } else if (appleEawtAvailable()
       && // Snow Leopard and below OR apple java 6 and below TODO: test this on SL
       tryExclusiveFullscreen
       && gd.isFullScreenSupported()) {
     if (javaVersion() >= 7) setAutoRequestFocus(window, true);
     window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     window.setUndecorated(true);
     // window.setExtendedState(JFrame.MAXIMIZED_BOTH);
     gd.setFullScreenWindow(window);
     window.toFront();
     Rectangle r = gd.getDefaultConfiguration().getBounds();
     window.setBounds(r);
     // window.pack();
   } else { // Windows and Linux TODO: test this
     window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     window.setUndecorated(true);
     window.setSize(gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight());
     window.setLocation(0, 0);
     window.setExtendedState(JFrame.MAXIMIZED_BOTH);
     window.toFront();
   }
   window.pack();
   window.setVisible(true);
 }