Example #1
52
 /**
  * Show the given message in a dialog box or independent window, depending on whether the source
  * component is contained in a Frame or not.
  *
  * @param c The Controller that calls this method, or null if it is not called by a Controller.
  *     (The Controller, if any, will be notified when the error message is cleared.)
  * @param message The message to display.
  */
 public void setErrorMessage(Controller c, String message) {
   if (popup != null) clearErrorMessage();
   if (message == null) return;
   errorSource = c;
   errorMessage = message;
   Component parent = source;
   while (parent != null && !(parent instanceof Frame)) parent = parent.getParent();
   if (parent != null) popup = new Dialog((Frame) parent, "Error Message", true); // modal dialog
   else popup = new Frame("Error Message"); // independent window
   popup.setBackground(Color.white);
   popup.add(new MC(message), BorderLayout.CENTER);
   Panel buttonBar = new Panel();
   buttonBar.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 10));
   Button OK = new Button("    OK    ");
   OK.addActionListener(this);
   buttonBar.add(OK);
   popup.add(buttonBar, BorderLayout.SOUTH);
   popup.pack();
   if (parent == null) popup.setLocation(100, 80);
   else popup.setLocation(parent.getLocation().x + 50, parent.getLocation().y + 30);
   popup.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent evt) {
           popup.dispose();
         }
       });
   popup.show(); // make the dialog visible.
 }
Example #2
0
  // Constructor
  public SimpleGLCanvas(Window parent, boolean debug) {
    debugging = debug;

    animator = new Animator(this);
    parent.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            // Run this on another thread than the AWT event queue to
            // make sure the call to Animator.stop() completes before
            // exiting
            new Thread(
                    new Runnable() {
                      public void run() {
                        if (animator.isAnimating()) animator.stop();
                        System.exit(0);
                      }
                    })
                .start();
          }
        });

    addGLEventListener(this);

    // Reset timer
    resetClock();
  }
 private void installListeners() {
   if (myWindow != null) {
     myWindowListener = createWindowListener();
     myWindow.addWindowListener(myWindowListener);
     myPropertyChangeListener = createWindowPropertyChangeListener();
     myWindow.addPropertyChangeListener(myPropertyChangeListener);
   }
 }
 public Component propertiesPage(WorkbenchContext context) {
   Window window = context.getCurrentWindow();
   Component propertiesPage = (Component) this.propertiesPages.get(window);
   if (propertiesPage == null) {
     propertiesPage = this.buildPropertiesPage(this.buildLocalWorkbenchContext(context));
     this.propertiesPages.put(window, propertiesPage);
     window.addWindowListener(this.windowListener);
   }
   return propertiesPage;
 }
Example #5
0
 public static void addExitWindowListener(Window window) {
   Preconditions.checkArgument(window != null);
   window.addWindowListener(
       new WindowAdapter() {
         @Override
         public void windowClosing(WindowEvent windowEvent) {
           System.exit(1);
         }
       });
 }
 private void learnWindow(Container c) {
   if (c != null && c instanceof Window) {
     win = (Window) c;
     win.addWindowListener(winL);
     win.addComponentListener(cmpL);
     if (EventManager.DEBUG_EVENTS) {
       System.err.println(
           "DynamicAncestorAdapter added WindowListener : " + win.getClass().getName());
     }
     if (!listening && win.isShowing()) startListening();
   }
 }
Example #7
0
    /** Recycles the passed in <code>HeavyWeightPopup</code>. */
    private static void recycleHeavyWeightPopup(HeavyWeightPopup popup) {
      synchronized (HeavyWeightPopup.class) {
        List<HeavyWeightPopup> cache;
        Window window = SwingUtilities.getWindowAncestor(popup.getComponent());
        Map<Window, List<HeavyWeightPopup>> heavyPopupCache = getHeavyWeightPopupCache();

        if (window instanceof Popup.DefaultFrame || !window.isVisible()) {
          // If the Window isn't visible, we don't cache it as we
          // likely won't ever get a windowClosed event to clean up.
          // We also don't cache DefaultFrames as this indicates
          // there wasn't a valid Window parent, and thus we don't
          // know when to clean up.
          popup._dispose();
          return;
        } else if (heavyPopupCache.containsKey(window)) {
          cache = heavyPopupCache.get(window);
        } else {
          cache = new ArrayList<HeavyWeightPopup>();
          heavyPopupCache.put(window, cache);
          // Clean up if the Window is closed
          final Window w = window;

          w.addWindowListener(
              new WindowAdapter() {
                public void windowClosed(WindowEvent e) {
                  List<HeavyWeightPopup> popups;

                  synchronized (HeavyWeightPopup.class) {
                    Map<Window, List<HeavyWeightPopup>> heavyPopupCache2 =
                        getHeavyWeightPopupCache();

                    popups = heavyPopupCache2.remove(w);
                  }
                  if (popups != null) {
                    for (int counter = popups.size() - 1; counter >= 0; counter--) {
                      popups.get(counter)._dispose();
                    }
                  }
                }
              });
        }

        if (cache.size() < MAX_CACHE_SIZE) {
          cache.add(popup);
        } else {
          popup._dispose();
        }
      }
    }
  /**
   * Sets the Parent window.
   *
   * @param window Parent window
   */
  public void setWindow(final Window window) {
    this.window = window;

    if (window != null) {
      window.addWindowListener(
          new WindowAdapter() {

            /** {@inheritDoc} */
            @Override
            public void windowClosed(final WindowEvent e) {
              dispose();
            }
          });
    }
  }
    public void hierarchyChanged(HierarchyEvent e) {
      if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) {
        Window parentWindow = SwingUtilities.getWindowAncestor(BufferedCanvasComponent.this);
        if (lastParentWindow != parentWindow) {
          if (lastParentWindow != null)
            lastParentWindow.removeWindowListener(VisibilityHandler.this);
          if (parentWindow != null) parentWindow.addWindowListener(VisibilityHandler.this);
          lastParentWindow = parentWindow;
        }
      }

      if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
        if (isShowing()) BufferedCanvasComponent.this.shown();
        else BufferedCanvasComponent.this.hidden();
      }
    }
  /**
   * Utility method for initializing a Window for displaying a JXErrorPane. This is particularly
   * useful because the differences between JFrame and JDialog are so minor. removed.
   */
  private void initWindow(final Window w, final JXErrorPane pane) {
    w.setLayout(new BorderLayout());
    w.add(pane, BorderLayout.CENTER);
    final Action closeAction = new CloseAction(w);
    closeButton.addActionListener(closeAction);
    final ResizeWindow resizeListener = new ResizeWindow(w);
    // make sure this action listener is last (or, oddly, the first in the list)
    ActionListener[] list = detailButton.getActionListeners();
    for (ActionListener a : list) {
      detailButton.removeActionListener(a);
    }
    detailButton.addActionListener(resizeListener);
    for (ActionListener a : list) {
      detailButton.addActionListener(a);
    }

    if (w instanceof JFrame) {
      final JFrame f = (JFrame) w;
      f.getRootPane().setDefaultButton(closeButton);
      f.setResizable(true);
      f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
      f.getRootPane().registerKeyboardAction(closeAction, ks, JComponent.WHEN_IN_FOCUSED_WINDOW);
    } else if (w instanceof JDialog) {
      final JDialog d = (JDialog) w;
      d.getRootPane().setDefaultButton(closeButton);
      d.setResizable(true);
      d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
      KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
      d.getRootPane().registerKeyboardAction(closeAction, ks, JComponent.WHEN_IN_FOCUSED_WINDOW);
    }

    w.addWindowListener(
        new WindowAdapter() {
          public void windowClosed(WindowEvent e) {
            // remove the action listener
            closeButton.removeActionListener(closeAction);
            detailButton.removeActionListener(resizeListener);
            exitIfFatal();
          }
        });
    w.pack();
  }
  public void setPalette(Window newValue) {
    AbstractOSXApplication application = getApplication();
    if (palette != null) {
      palette.removeWindowListener(windowHandler);
    }

    palette = newValue;

    if (palette != null) {
      palette.addWindowListener(windowHandler);
      if (getValue(Actions.SELECTED_KEY) == Boolean.TRUE) {
        application.addPalette(palette);
        palette.setVisible(true);
      } else {
        application.removePalette(palette);
        palette.setVisible(false);
      }
    }
  }
  /** This method installs listeners for the JToolBar. */
  protected void installListeners() {
    dockingListener = createDockingListener();
    toolBar.addMouseListener(dockingListener);
    toolBar.addMouseMotionListener(dockingListener);

    propertyListener = createPropertyListener();
    toolBar.addPropertyChangeListener(propertyListener);

    toolBarContListener = createToolBarContListener();
    toolBar.addContainerListener(toolBarContListener);

    windowListener = createFrameListener();
    floatFrame.addWindowListener(windowListener);

    toolBarFocusListener = createToolBarFocusListener();
    if (toolBarFocusListener != null) {
      int count = toolBar.getComponentCount();
      for (int i = 0; i < count; i++)
        toolBar.getComponent(i).addFocusListener(toolBarFocusListener);
    }
  }
Example #13
0
  /**
   * Listens to a JDialog to save and restore windows bounds automatically.
   *
   * <p>{@code setVisible(false)} and {@code dispose()} must not be used to close the window.
   * Instead, dispatch a window closing event.
   *
   * <PRE>
   * dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
   * </PRE>
   *
   * and the dialog must be set to dispose on close
   *
   * <PRE>
   * setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
   * </PRE>
   *
   * @param w {@code Window} to listen to
   * @param prefNode String identifier to preference node to save and restore from
   * @param key the key to save and restore from
   */
  private static void addBoundsListener(final Window w, final String prefNode, final String key) {
    String bounds = Preferences.userRoot().node(prefNode).get(key, null);

    if (bounds != null) { // restore to previous size and position

      if (w instanceof JDialog) {
        if (((JDialog) w).isResizable()) {
          w.setBounds(decodeRectangle(bounds));
        } else {
          w.setLocation(decodeRectangle(bounds).getLocation());
        }
      } else {
        w.setBounds(decodeRectangle(bounds));
      }

      Window owner = w.getOwner();

      if (owner != null) {
        w.setLocationRelativeTo(owner);
      }
    }

    /* listen for a window closing event and deal with it */
    w.addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(WindowEvent evt) {
            // save position and size
            Preferences p = Preferences.userRoot().node(prefNode);

            p.put(key, encodeRectangle(w.getBounds()));
            w.removeWindowListener(this); // make GC easy
          }
        });

    if (w instanceof JDialog) {
      addEscapeListener((JDialog) w);
    }
  }
    public WindowMenuItem(final Window window, String title) {
      super(title, window.isVisible());
      addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              // window.pack();
              window.setVisible(!window.isVisible());
            }
          });

      window.addWindowListener(
          new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
              WindowMenuItem.this.setSelected(false);
            }

            public void windowOpened(WindowEvent e) {
              WindowMenuItem.this.setSelected(USE_SYSTEM_UI);
            }
          });
    }
Example #15
0
 /**
  * _more_
  *
  * @return _more_
  */
 private boolean windowOk() {
   getContents();
   if (contents == null) {
     return false;
   }
   if (shouldMakeDialog()) {
     if (dialog == null) {
       dialog = new JDialog((Frame) null, getWindowTitle(), false);
       LogUtil.registerWindow(dialog);
       GuiUtils.packDialog(dialog, contents);
       dialog.setLocation(100, 100);
       window = dialog;
     }
   } else {
     if (frame == null) {
       frame = new JFrame(getWindowTitle());
       if (menuBar != null) {
         GuiUtils.decorateFrame(frame, menuBar);
       }
       LogUtil.registerWindow(frame);
       frame.getContentPane().add(contents);
       frame.pack();
       Msg.translateTree(frame);
       frame.setLocation(100, 100);
       window = frame;
     }
   }
   if (window != null) {
     window.addWindowListener(
         new WindowAdapter() {
           public void windowClosing(WindowEvent e) {
             windowIsClosing();
           }
         });
   }
   return window != null;
 }
Example #16
0
 protected void initListeners(Window parent) {
   // add listeners
   addMouseListener(
       new MouseAdapter() {
         @Override
         public void mouseReleased(MouseEvent e) {
           exit();
         }
       });
   parent.addWindowListener(
       new WindowAdapter() {
         @Override
         public void windowClosed(WindowEvent e) {
           exit();
         }
       });
   parent.addComponentListener(
       new ComponentAdapter() {
         @Override
         public void componentMoved(ComponentEvent e) {
           FloatableDialog.this.refreshLocation();
         }
       });
 }
Example #17
0
  /** Installs the sheet on the owner. This method is invoked just before the JSheet is shown. */
  protected void installSheet() {
    if (!isNativeSheetSupported() && !isInstalled && isExperimentalSheet()) {
      Window owner = getOwner();
      if (owner != null) {
        owner.addWindowListener(windowEventHandler);
      }
      isInstalled = true;
    } else {
      Window owner = getOwner();
      if (owner != null) {

        // Determine the location for the sheet and its owner while
        // the sheet will be visible.
        // In case we have to shift the owner to fully display the
        // dialog, we remember the shift back position.
        Point ownerLoc = owner.getLocation();
        Point sheetLoc;
        if (isShowAsSheet()) {
          if (owner instanceof JFrame) {
            sheetLoc =
                new Point(
                    ownerLoc.x + (owner.getWidth() - getWidth()) / 2,
                    ownerLoc.y
                        + owner.getInsets().top
                        + ((JFrame) owner).getRootPane().getContentPane().getY());
          } else if (owner instanceof JDialog) {
            sheetLoc =
                new Point(
                    ownerLoc.x + (owner.getWidth() - getWidth()) / 2,
                    ownerLoc.y
                        + owner.getInsets().top
                        + ((JDialog) owner).getRootPane().getContentPane().getY());
          } else {
            sheetLoc =
                new Point(
                    ownerLoc.x + (owner.getWidth() - getWidth()) / 2,
                    ownerLoc.y + owner.getInsets().top);
          }

          if (sheetLoc.x < 0) {
            owner.setLocation(ownerLoc.x - sheetLoc.x, ownerLoc.y);
            sheetLoc.x = 0;
            shiftBackLocation = ownerLoc;
            oldLocation = owner.getLocation();
          } else {
            shiftBackLocation = null;
            oldLocation = ownerLoc;
          }
        } else {
          sheetLoc =
              new Point(
                  ownerLoc.x + (owner.getWidth() - getWidth()) / 2,
                  ownerLoc.y + (owner.getHeight() - getHeight()) / 2);
        }
        setLocation(sheetLoc);

        oldFocusOwner = owner.getFocusOwner();

        // Note: We mustn't change the windows focusable state because
        // this also affects the focusable state of the JSheet.
        // owner.setFocusableWindowState(false);
        owner.setEnabled(false);
        // ((JFrame) owner).setResizable(false);
        if (isShowAsSheet()) {
          owner.addComponentListener(ownerMovementHandler);
        } else {
          if (owner instanceof Frame) {
            setTitle(((Frame) owner).getTitle());
          }
        }
      }
      isInstalled = true;
    }
  }
Example #18
0
  /**
   * Create a frame for this DockPanel. The frame will either be a JFrame or a JDialog depending on
   * the isDialog flag.
   */
  public void createFrame() {

    if (isDialog) {
      frame =
          new JDialog(app.getFrame(), false) {
            private static final long serialVersionUID = 1L;

            // Send window closing event when dialog is set invisible.
            // This allows a dock panel view to close properly.
            @Override
            public void setVisible(boolean isVisible) {
              if (!isVisible && frame != null) {
                windowClosing(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
              }
              super.setVisible(isVisible);
            }
          };
    } else {
      frame = new JFrame(getPlainTitle());
      // needs the higher res as used by Windows 7 for the Toolbar
      ((JFrame) frame).setIconImage(app.getInternalImage("geogebra64.png"));
    }

    frame.addWindowListener(this);

    frame.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentResized(ComponentEvent event) {
            setFrameBounds(event.getComponent().getBounds());
          }

          @Override
          public void componentMoved(ComponentEvent event) {
            setFrameBounds(event.getComponent().getBounds());
          }
        });

    if (isDialog) {
      (((JDialog) frame).getContentPane()).add(this);
    } else {
      (((JFrame) frame).getContentPane()).add(this);
      menubar = loadMenuBar();
      if (menubar != null) {
        ((JFrame) frame).setJMenuBar(menubar);
      }
    }

    // TODO multimonitor supported?
    Rectangle screenSize =
        GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();

    // Use the previous dimension of this view
    Rectangle windowBounds = getFrameBounds();

    // resize window if necessary
    if (windowBounds.width > screenSize.width) windowBounds.width = screenSize.width - 50;
    if (windowBounds.height > screenSize.height) windowBounds.height = windowBounds.height - 50;

    // center window if necessary
    if (isNewDialog) {
      // frame.pack();
      frame.setSize(windowBounds.getSize());
      frame.setLocationRelativeTo(app.getMainComponent());
      isNewDialog = false;
    } else if (windowBounds.x + windowBounds.width > screenSize.width
        || windowBounds.y + windowBounds.height > screenSize.height) {
      frame.setLocationRelativeTo(null);

    } else {
      frame.setLocation(windowBounds.getLocation());
    }
    setOpenInFrame(true);

    frame.setSize(windowBounds.getSize());
    frame.setVisible(true);

    // make titlebar visible if necessary
    updatePanel();

    frame.repaint();
  }
  public void show(Component owner, int aScreenX, int aScreenY, final boolean considerForcedXY) {
    if (ApplicationManagerEx.getApplicationEx() != null
        && ApplicationManager.getApplication().isHeadlessEnvironment()) return;
    if (isDisposed()) {
      throw new IllegalStateException(
          "Popup was already disposed. Recreate a new instance to show again");
    }

    assert ApplicationManager.getApplication().isDispatchThread();

    addActivity();

    final boolean shouldShow = beforeShow();
    if (!shouldShow) {
      removeActivity();
      return;
    }

    prepareToShow();

    if (myInStack) {
      myFocusTrackback = new FocusTrackback(this, owner, true);
      myFocusTrackback.setMustBeShown(true);
    }

    Dimension sizeToSet = null;

    if (myDimensionServiceKey != null) {
      sizeToSet = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject);
    }

    if (myForcedSize != null) {
      sizeToSet = myForcedSize;
    }

    if (myMinSize == null) {
      myMinSize = myContent.getMinimumSize();
    }

    if (sizeToSet == null) {
      sizeToSet = myContent.getPreferredSize();
    }

    if (sizeToSet != null) {
      sizeToSet.width = Math.max(sizeToSet.width, myMinSize.width);
      sizeToSet.height = Math.max(sizeToSet.height, myMinSize.height);

      myContent.setSize(sizeToSet);
      myContent.setPreferredSize(sizeToSet);
    }

    Point xy = new Point(aScreenX, aScreenY);
    boolean adjustXY = true;
    if (myDimensionServiceKey != null) {
      final Point storedLocation =
          DimensionService.getInstance().getLocation(myDimensionServiceKey, myProject);
      if (storedLocation != null) {
        xy = storedLocation;
        adjustXY = false;
      }
    }

    if (adjustXY) {
      final Insets insets = myContent.getInsets();
      if (insets != null) {
        xy.x -= insets.left;
        xy.y -= insets.top;
      }
    }

    if (considerForcedXY && myForcedLocation != null) {
      xy = myForcedLocation;
    }

    if (myLocateByContent) {
      final Dimension captionSize = myHeaderPanel.getPreferredSize();
      xy.y -= captionSize.height;
    }

    Rectangle targetBounds = new Rectangle(xy, myContent.getPreferredSize());
    Insets insets = myPopupBorder.getBorderInsets(myContent);
    if (insets != null) {
      targetBounds.x += insets.left;
      targetBounds.y += insets.top;
    }

    Rectangle original = new Rectangle(targetBounds);
    if (myLocateWithinScreen) {
      ScreenUtil.moveRectangleToFitTheScreen(targetBounds);
    }

    if (myMouseOutCanceller != null) {
      myMouseOutCanceller.myEverEntered = targetBounds.equals(original);
    }

    myOwner = IdeFrameImpl.findNearestModalComponent(owner);
    if (myOwner == null) {
      myOwner = owner;
    }

    myRequestorComponent = owner;

    boolean forcedDialog = (SystemInfo.isMac && !(myOwner instanceof IdeFrame)) || myMayBeParent;

    PopupComponent.Factory factory = getFactory(myForcedHeavyweight || myResizable, forcedDialog);
    myNativePopup = factory.isNativePopup();
    myPopup = factory.getPopup(myOwner, myContent, targetBounds.x, targetBounds.y);

    if (myResizable) {
      final JRootPane root = myContent.getRootPane();
      final IdeGlassPaneImpl glass = new IdeGlassPaneImpl(root);
      root.setGlassPane(glass);

      final ResizeComponentListener resizeListener = new ResizeComponentListener(this, glass);
      glass.addMousePreprocessor(resizeListener, this);
      glass.addMouseMotionPreprocessor(resizeListener, this);
    }

    if (myCaption != null && myMovable) {
      final MoveComponentListener moveListener =
          new MoveComponentListener(myCaption) {
            public void mousePressed(final MouseEvent e) {
              super.mousePressed(e);
              if (e.isConsumed()) return;

              if (UIUtil.isCloseClick(e)) {
                if (myCaption.isWithinPanel(e)) {
                  cancel();
                }
              }
            }
          };
      ListenerUtil.addMouseListener(myCaption, moveListener);
      ListenerUtil.addMouseMotionListener(myCaption, moveListener);
      final MyContentPanel saved = myContent;
      Disposer.register(
          this,
          new Disposable() {
            public void dispose() {
              ListenerUtil.removeMouseListener(saved, moveListener);
              ListenerUtil.removeMouseMotionListener(saved, moveListener);
            }
          });
    }

    for (JBPopupListener listener : myListeners) {
      listener.beforeShown(new LightweightWindowEvent(this));
    }

    myPopup.setRequestFocus(myRequestFocus);
    myPopup.show();

    final Window window = SwingUtilities.getWindowAncestor(myContent);

    myWindowListener = new MyWindowListener();
    window.addWindowListener(myWindowListener);

    if (myFocusable) {
      window.setFocusableWindowState(true);
      window.setFocusable(true);
    }

    myWindow = updateMaskAndAlpha(window);

    if (myWindow instanceof JWindow) {
      ((JWindow) myWindow).getRootPane().putClientProperty(KEY, this);
    }

    if (myWindow != null) {
      // dialogwrapper-based popups do this internally through peer,
      // for other popups like jdialog-based we should exclude them manually, but
      // we still have to be able to use IdeFrame as parent
      if (!myMayBeParent && !(myWindow instanceof Frame)) {
        WindowManager.getInstance().doNotSuggestAsParent(myWindow);
      }
    }

    final Runnable afterShow =
        new Runnable() {
          public void run() {
            if (myPreferredFocusedComponent != null && myInStack && myFocusable) {
              myFocusTrackback.registerFocusComponent(myPreferredFocusedComponent);
            }

            removeActivity();

            afterShow();
          }
        };

    if (myRequestFocus) {
      getFocusManager()
          .requestFocus(
              new FocusCommand() {
                @Override
                public ActionCallback run() {
                  if (isDisposed()) {
                    removeActivity();
                    return new ActionCallback.Done();
                  }

                  _requestFocus();

                  final ActionCallback result = new ActionCallback();

                  final Runnable afterShowRunnable =
                      new Runnable() {
                        @Override
                        public void run() {
                          afterShow.run();
                          result.setDone();
                        }
                      };
                  if (myNativePopup) {
                    final FocusRequestor furtherRequestor = getFocusManager().getFurtherRequestor();
                    SwingUtilities.invokeLater(
                        new Runnable() {
                          @Override
                          public void run() {
                            if (isDisposed()) {
                              result.setRejected();
                              return;
                            }

                            furtherRequestor
                                .requestFocus(
                                    new FocusCommand() {
                                      @Override
                                      public ActionCallback run() {
                                        if (isDisposed()) {
                                          return new ActionCallback.Rejected();
                                        }

                                        _requestFocus();

                                        afterShowRunnable.run();

                                        return new ActionCallback.Done();
                                      }
                                    },
                                    true)
                                .notify(result)
                                .doWhenProcessed(
                                    new Runnable() {
                                      @Override
                                      public void run() {
                                        removeActivity();
                                      }
                                    });
                          }
                        });
                  } else {
                    afterShowRunnable.run();
                  }

                  return result;
                }
              },
              true)
          .doWhenRejected(
              new Runnable() {
                @Override
                public void run() {
                  afterShow.run();
                }
              });
    } else {
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              if (isDisposed()) {
                removeActivity();
                return;
              }

              afterShow.run();
            }
          });
    }
  }
 /** Add a listener for window events. */
 void addWindowListener(Window w) {
   w.addWindowListener(this);
 }