Exemplo n.º 1
0
 public void show() {
   if (!myRequestFocus) {
     myDialog.setFocusableWindowState(false);
   }
   myDialog.setVisible(true);
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           myDialog.setFocusableWindowState(true);
         }
       });
 }
Exemplo n.º 2
0
  public SheetMessage(
      final Window owner,
      final String title,
      final String message,
      final Icon icon,
      final String[] buttons,
      final DialogWrapper.DoNotAskOption doNotAskOption,
      final String defaultButton,
      final String focusedButton) {
    myWindow =
        new JDialog(owner, "This should not be shown", Dialog.ModalityType.APPLICATION_MODAL);
    myWindow.getRootPane().putClientProperty("apple.awt.draggableWindowBackground", Boolean.FALSE);

    myWindow.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowActivated(WindowEvent e) {
            super.windowActivated(e);
          }
        });

    myParent = owner;

    myWindow.setUndecorated(true);
    myWindow.setBackground(Gray.TRANSPARENT);
    myController =
        new SheetController(
            this, title, message, icon, buttons, defaultButton, doNotAskOption, focusedButton);

    imageHeight = 0;
    registerMoveResizeHandler();
    myWindow.setFocusable(true);
    myWindow.setFocusableWindowState(true);
    if (SystemInfo.isJavaVersionAtLeast("1.7")) {
      myWindow.setSize(myController.SHEET_NC_WIDTH, 0);

      setWindowOpacity(0.0f);

      myWindow.addComponentListener(
          new ComponentAdapter() {
            @Override
            public void componentShown(ComponentEvent e) {
              super.componentShown(e);
              setWindowOpacity(1.0f);
              myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT);
            }
          });
    } else {
      myWindow.setModal(true);
      myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT);
      setPositionRelativeToParent();
    }
    startAnimation(true);
    restoreFullscreenButton = couldBeInFullScreen();
    if (restoreFullscreenButton) {
      FullScreenUtilities.setWindowCanFullScreen(myParent, false);
    }

    LaterInvocator.enterModal(myWindow);
    myWindow.setVisible(true);
    LaterInvocator.leaveModal(myWindow);
  }
  public SheetMessage(
      final Window owner,
      final String title,
      final String message,
      final Icon icon,
      final String[] buttons,
      final DialogWrapper.DoNotAskOption doNotAskOption,
      final String defaultButton,
      final String focusedButton) {
    final Window activeWindow =
        KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
    final Component recentFocusOwner =
        activeWindow == null ? null : activeWindow.getMostRecentFocusOwner();
    WeakReference<Component> beforeShowFocusOwner = new WeakReference<Component>(recentFocusOwner);

    maximizeIfNeeded(owner);

    myWindow =
        new JDialog(owner, "This should not be shown", Dialog.ModalityType.APPLICATION_MODAL);
    myWindow.getRootPane().putClientProperty("apple.awt.draggableWindowBackground", Boolean.FALSE);

    myWindow.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowActivated(@NotNull WindowEvent e) {
            super.windowActivated(e);
          }
        });

    myParent = owner;

    myWindow.setUndecorated(true);
    myWindow.setBackground(Gray.TRANSPARENT);
    myController =
        new SheetController(
            this, title, message, icon, buttons, defaultButton, doNotAskOption, focusedButton);

    imageHeight = 0;
    registerMoveResizeHandler();
    myWindow.setFocusable(true);
    myWindow.setFocusableWindowState(true);
    if (SystemInfo.isJavaVersionAtLeast("1.7")) {
      myWindow.setSize(myController.SHEET_NC_WIDTH, 0);

      setWindowOpacity(0.0f);

      myWindow.addComponentListener(
          new ComponentAdapter() {
            @Override
            public void componentShown(@NotNull ComponentEvent e) {
              super.componentShown(e);
              setWindowOpacity(1.0f);
              myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT);
            }
          });
    } else {
      myWindow.setModal(true);
      myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT);
      setPositionRelativeToParent();
    }
    startAnimation(true);
    restoreFullScreenButton = couldBeInFullScreen();
    if (restoreFullScreenButton) {
      FullScreenUtilities.setWindowCanFullScreen(myParent, false);
    }

    LaterInvocator.enterModal(myWindow);
    myWindow.setVisible(true);
    LaterInvocator.leaveModal(myWindow);

    Component focusCandidate = beforeShowFocusOwner.get();

    if (focusCandidate == null) {
      focusCandidate =
          IdeFocusManager.getGlobalInstance()
              .getLastFocusedFor(IdeFocusManager.getGlobalInstance().getLastFocusedFrame());
    }

    // focusCandidate is null if a welcome screen is closed and ide frame is not opened.
    // this is ok. We set focus correctly on our frame activation.
    if (focusCandidate != null) {
      focusCandidate.requestFocus();
    }
  }