/**
   * Returns a <code>Popup</code> instance from the <code>PopupMenuUI</code> that has had <code>show
   * </code> invoked on it. If the current <code>popup</code> is non-null, this will invoke <code>
   * dispose</code> of it, and then <code>show</code> the new one.
   *
   * <p>This does NOT fire any events, it is up the caller to dispatch the necessary events.
   */
  private Popup getPopup() {
    Popup oldPopup = popup;

    if (oldPopup != null) {
      oldPopup.hide();
    }
    PopupFactory popupFactory = PopupFactory.getSharedInstance();

    if (isLightWeightPopupEnabled()) {
      popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
    } else {
      popupFactory.setPopupType(PopupFactory.MEDIUM_WEIGHT_POPUP);
    }

    // adjust the location of the popup
    Point p = adjustPopupLocationToFitScreen(desiredLocationX, desiredLocationY);
    desiredLocationX = p.x;
    desiredLocationY = p.y;

    Popup newPopup = getUI().getPopup(this, desiredLocationX, desiredLocationY);

    popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
    newPopup.show();
    return newPopup;
  }
Exemple #2
0
 public static void hidePopups(Component comp) {
   if (comp != null) {
     label0:
     for (Component c = comp; c != null; c = c.getParent()) {
       if (!(c instanceof ZPopupGallery)) continue;
       do {
         if (currShownList.size() <= 0) continue label0;
         if (currShownList.getLast() == c) return;
         ZPopupGallery jpg = (ZPopupGallery) currShownList.removeLast();
         Popup popup = (Popup) popupGalleryHM.get(jpg);
         popup.hide();
         popupGalleryHM.remove(jpg);
       } while (true);
     }
   }
   Iterator iterator = popupGalleryHM.keySet().iterator();
   do {
     if (!iterator.hasNext()) break;
     ZPopupGallery gallery = (ZPopupGallery) iterator.next();
     ((Popup) popupGalleryHM.get(gallery)).hide();
     if (gallery.getActionListener() != null)
       gallery.getActionListener().actionPerformed(new ActionEvent(gallery, 1, "Hidden"));
   } while (true);
   popupGalleryHM.clear();
 }
    public void mousePressed(MouseEvent e) {
      if (e.getButton() == e.BUTTON3) {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(2);
        int index = list.locationToIndex(e.getPoint());
        GetImageFile gif = new GetImageFile(files[index]);

        JTextArea area =
            new JTextArea(
                "File: "
                    + gif.getImageString()
                    + "\n"
                    + "Score: "
                    + nf.format(scores[index])
                    + "\n"
                    + "Pairs: "
                    + nrpairs[index]);
        area.setEditable(false);
        area.setBorder(BorderFactory.createLineBorder(Color.black));
        area.setFont(new Font("times", Font.PLAIN, 12));
        PopupFactory factory = PopupFactory.getSharedInstance();
        popup =
            factory.getPopup(
                null,
                area,
                (int) e.getComponent().getLocationOnScreen().getX() + e.getX() + 25,
                (int) e.getComponent().getLocationOnScreen().getY() + e.getY());
        popup.show();
      }
    }
Exemple #4
0
 protected void showInfoPopup(String info, int x, int y) {
   JPanel content = new JPanel();
   content.add(new JLabel(info));
   content.setBorder(BorderFactory.createLineBorder(Color.BLACK));
   Point location = getLocationOnScreen();
   location.x += x + 5;
   location.y += y + 5;
   popup = PopupFactory.getSharedInstance().getPopup(this, content, location.x, location.y);
   popup.show();
 }
    public void hide(boolean dispose) {
      myPopup.hide();

      Window wnd = getWindow();
      if (wnd instanceof JWindow) {
        JRootPane rootPane = ((JWindow) wnd).getRootPane();
        if (rootPane != null) {
          ReflectionUtil.resetField(rootPane, "clientProperties");
        }
      }
    }
    void reset(Component owner, Component contents, int ownerX, int ownerY) {
      if ((owner instanceof JFrame) || (owner instanceof JDialog) || (owner instanceof JWindow)) {
        // Force the content to be added to the layered pane, otherwise
        // we'll get an exception when adding to the RootPaneContainer.
        owner = ((RootPaneContainer) owner).getLayeredPane();
      }
      super.reset(owner, contents, ownerX, ownerY);

      x = ownerX;
      y = ownerY;
      this.owner = owner;
    }
  /**
   * Sets the visibility of the popup menu.
   *
   * @param b true to make the popup visible, or false to hide it
   * @beaninfo bound: true description: Makes the popup visible
   */
  public void setVisible(boolean b) {
    if (DEBUG) {
      System.out.println("JPopupMenu.setVisible " + b);
    }

    // Is it a no-op?
    if (b == isVisible()) return;

    // if closing, first close all Submenus
    if (b == false) {

      // 4234793: This is a workaround because JPopupMenu.firePopupMenuCanceled is
      // a protected method and cannot be called from BasicPopupMenuUI directly
      // The real solution could be to make
      // firePopupMenuCanceled public and call it directly.
      Boolean doCanceled = (Boolean) getClientProperty("JPopupMenu.firePopupMenuCanceled");
      if (doCanceled != null && doCanceled == Boolean.TRUE) {
        putClientProperty("JPopupMenu.firePopupMenuCanceled", Boolean.FALSE);
        firePopupMenuCanceled();
      }
      getSelectionModel().clearSelection();

    } else {
      // This is a popup menu with MenuElement children,
      // set selection path before popping up!
      if (isPopupMenu()) {
        MenuElement me[] = new MenuElement[1];
        me[0] = this;
        MenuSelectionManager.defaultManager().setSelectedPath(me);
      }
    }

    if (b) {
      firePopupMenuWillBecomeVisible();
      popup = getPopup();
      firePropertyChange("visible", Boolean.FALSE, Boolean.TRUE);

    } else if (popup != null) {
      firePopupMenuWillBecomeInvisible();
      popup.hide();
      popup = null;
      firePropertyChange("visible", Boolean.TRUE, Boolean.FALSE);
      // 4694797: When popup menu is made invisible, selected path
      // should be cleared
      if (isPopupMenu()) {
        MenuSelectionManager.defaultManager().clearSelectedPath();
      }
    }
  }
    private static void fixPopupSize(final Popup popup, final Component contents) {
      if (!UIUtil.isUnderGTKLookAndFeel() || !(contents instanceof JPopupMenu)) return;

      for (Class<?> aClass = popup.getClass();
          aClass != null && Popup.class.isAssignableFrom(aClass);
          aClass = aClass.getSuperclass()) {
        try {
          final Method getComponent = aClass.getDeclaredMethod("getComponent");
          getComponent.setAccessible(true);
          final Object component = getComponent.invoke(popup);
          if (component instanceof JWindow) {
            ((JWindow) component).setSize(new Dimension(0, 0));
          }
          break;
        } catch (Exception ignored) {
        }
      }
    }
 public void show() {
   myPopup.show();
 }
Exemple #10
0
 public void mouseReleased(MouseEvent e) {
   if (e.isPopupTrigger()) {
     Popup popup = new Popup();
     popup.show(e.getComponent(), e.getX(), e.getY());
   }
 }
 public void mouseReleased(MouseEvent e) {
   if (e.getButton() == e.BUTTON3) {
     popup.hide();
   }
 }
Exemple #12
0
 public void hideInfo() {
   if (popup != null) popup.hide();
 }
 void _dispose() {
   super.dispose();
 }
 //
 // Popup methods
 //
 public void hide() {
   super.hide();
   recycleHeavyWeightPopup(this);
 }