public void setFullScreen(IdeFrameImpl frame, boolean fullScreen) {
    if (!isFullScreenSupportedInCurrentOS() || frame.isInFullScreen() == fullScreen) return;

    try {
      if (SystemInfo.isMacOSLion) {
        frame.getFrameDecorator().toggleFullScreen(fullScreen);
        return;
      }

      if (SystemInfo.isWindows) {
        GraphicsDevice device = ScreenUtil.getScreenDevice(frame.getBounds());
        if (device == null) return;
        try {
          frame.getRootPane().putClientProperty(ScreenUtil.DISPOSE_TEMPORARY, Boolean.TRUE);
          if (fullScreen) {
            frame.getRootPane().putClientProperty("oldBounds", frame.getBounds());
          }
          frame.dispose();
          frame.setUndecorated(fullScreen);
        } finally {
          if (fullScreen) {
            frame.setBounds(device.getDefaultConfiguration().getBounds());
          } else {
            Object o = frame.getRootPane().getClientProperty("oldBounds");
            if (o instanceof Rectangle) {
              frame.setBounds((Rectangle) o);
            }
          }
          frame.setVisible(true);
          frame.getRootPane().putClientProperty(ScreenUtil.DISPOSE_TEMPORARY, null);
        }
      }
    } finally {
      frame.storeFullScreenStateIfNeeded(fullScreen);
    }
  }