/**
   * Inserts the given <code>command</command> at the end of the <code>popupMenu</code>.
   *
   * @param popupMenu The popup menu to add the given <code>command</code> to.
   * @param command The command to insert.
   * @param manager The command manager.
   */
  public static void insertCommandMenuItem(
      final JPopupMenu popupMenu, final Command command, final CommandManager manager) {
    Command[] commands = getCommands(popupMenu, manager, command);
    commands = sort(commands);

    final Map<String, Component> popupMenues = new HashMap<String, Component>();
    int count = popupMenu.getComponentCount();
    for (int i = 0; i < count; i++) {
      final Component component = popupMenu.getComponent(i);
      if (component instanceof JMenu) {
        popupMenues.put(component.getName(), component);
      }
    }

    popupMenu.removeAll();
    for (Command command1 : commands) {
      insertCommandMenuItem(popupMenu, command1, popupMenu.getComponentCount());
    }
    count = popupMenu.getComponentCount();
    for (int i = 0; i < count; i++) {
      final Component component = popupMenu.getComponent(i);
      if (component instanceof JMenu) {
        final String name = component.getName();
        final Object o = popupMenues.get(name);
        if (o != null) {
          popupMenu.remove(i);
          popupMenu.insert((Component) o, i);
        }
      }
    }
  }
  @Override
  public void insertSeparator(int index) {
    if (index < 0) {
      throw new IllegalArgumentException("index less than zero.");
    }

    ensurePopupMenuCreated();
    popupMenu.insert(new JPopupMenu.Separator(), index);
  }
 @Override
 public JMenuItem insert(JMenuItem mi, int pos) {
   if (pos < 0) {
     throw new IllegalArgumentException("index less than zero.");
   }
   ensurePopupMenuCreated();
   popupMenu.insert(mi, pos);
   return mi;
 }
  @Override
  public void insert(String s, int pos) {
    if (pos < 0) {
      throw new IllegalArgumentException("index less than zero.");
    }

    ensurePopupMenuCreated();
    popupMenu.insert(new JMenuItem(s), pos);
  }
  /**
   * Inserts the given <code>command</command> to the <code>popupMenu</code> at the given <code>position</code>.
   *
   * @param popupMenu The popup menu to add the given <code>command</code> to.
   * @param command The command to insert.
   * @param pos the position where to insert the <code>command</code>.
   */
  public static void insertCommandMenuItem(
      final JPopupMenu popupMenu, final Command command, final int pos) {
    final JMenuItem menuItem = command.createMenuItem();
    if (menuItem == null) {
      return;
    }

    int insertPos = pos;

    if (command.isSeparatorBefore() && insertPos > 0) {
      if (insertPos == popupMenu.getComponentCount()) {
        final Component c = popupMenu.getComponent(insertPos - 1);
        if (!(c instanceof JSeparator)) {
          popupMenu.addSeparator();
          insertPos++;
        }
      } else {
        final Component c = popupMenu.getComponent(insertPos);
        if (!(c instanceof JSeparator)) {
          popupMenu.insert(new JPopupMenu.Separator(), insertPos);
          insertPos++;
        }
      }
    }

    if (insertPos >= popupMenu.getComponentCount()) {
      popupMenu.add(menuItem);
    } else {
      popupMenu.insert(menuItem, insertPos);
    }
    insertPos++;

    if (command.isSeparatorAfter()) {
      if (insertPos == popupMenu.getComponentCount()) {
        popupMenu.addSeparator();
      } else {
        final Component c = popupMenu.getComponent(insertPos);
        if (!(c instanceof JSeparator)) {
          popupMenu.insert(new JPopupMenu.Separator(), insertPos);
        }
      }
    }
  }
  public JPopupMenu createMenu(
      JPopupMenu popupMenu,
      TableLine[] lines,
      boolean markAsSpam,
      boolean markAsNot,
      ResultPanel resultPanel) {
    JPopupMenu menu = new JPopupMenu();
    List<JLabel> labels = new ArrayList<JLabel>(5);
    for (TableLine line : lines) {
      SharedSearchResult result = (SharedSearchResult) line.getSearchResult();
      JLabel label = new JLabel(I18n.tr("Path") + ": " + result.getFileDesc().getPath());
      menu.insert(label, labels.size());
      labels.add(label);
      if (labels.size() == 5 && lines.length > labels.size()) {
        int numberOfMore = lines.length - labels.size();
        label = new JLabel(I18n.trn("... {0} more.", "... {0} more.", numberOfMore, numberOfMore));
        menu.insert(label, labels.size());
        labels.add(label);
        break;
      }
    }
    menu.addSeparator();

    // TODO: fix this hidden coupling, SharedSearchResult needs to be tied MyFilesResultPanel
    //        explicitly
    JMenuItem menuItem =
        new JMenuItem(((MySharedFilesResultPanel) resultPanel).getUnshareAction(lines.length));
    menu.add(menuItem);

    // configure label to have the same borders and margins as a menu item
    Insets margin = menuItem.getMargin();
    Insets border = menuItem.getInsets();
    for (JLabel label : labels) {
      label.setBorder(
          BorderFactory.createEmptyBorder(
              border.top, margin.left + border.left, border.bottom, margin.right + border.right));
      label.setIconTextGap(menuItem.getIconTextGap());
      // if icon is null, icon text gap value is ignored
      label.setIcon(new GUIUtils.EmptyIcon("empty", 0, 0));
    }

    return menu;
  }
    private void maybeShowPopup(MouseEvent e) {

      if (e.isPopupTrigger()) {
        popup = new JPopupMenu();
        CalendarCardPanel cc = new CalendarCardPanel(ClientContext.getEventColorTable());
        cc.addPropertyChangeListener(CalendarCardPanel.PICKED_DATE, this);
        cc.setCalendarRange(new int[] {-12, 0});
        popup.insert(cc, 0);
        popup.show(e.getComponent(), e.getX(), e.getY());
      }
    }
  /**
   * Shows the appropriate user interface that would allow the user to add the given
   * <tt>SourceUIContact</tt> to their contact list.
   *
   * @param contact the contact to add
   */
  private void addContact(SourceUIContact contact) {
    SourceContact sourceContact = (SourceContact) contact.getDescriptor();

    List<ContactDetail> details =
        sourceContact.getContactDetails(OperationSetPersistentPresence.class);
    int detailsCount = details.size();

    if (detailsCount > 1) {
      JMenuItem addContactMenu =
          TreeContactList.createAddContactMenu((SourceContact) contact.getDescriptor());

      JPopupMenu popupMenu = ((JMenu) addContactMenu).getPopupMenu();

      // Add a title label.
      JLabel infoLabel = new JLabel();
      infoLabel.setText(
          "<html><b>"
              + GuiActivator.getResources().getI18NString("service.gui.ADD_CONTACT")
              + "</b></html>");

      popupMenu.insert(infoLabel, 0);
      popupMenu.insert(new Separator(), 1);

      popupMenu.setFocusable(true);
      popupMenu.setInvoker(treeContactList);

      Point location =
          new Point(
              addContactButton.getX(), addContactButton.getY() + addContactButton.getHeight());

      SwingUtilities.convertPointToScreen(location, treeContactList);

      location.y = location.y + treeContactList.getPathBounds(treeContactList.getSelectionPath()).y;

      popupMenu.setLocation(location.x + 8, location.y - 8);
      popupMenu.setVisible(true);
    } else if (details.size() == 1) {
      TreeContactList.showAddContactDialog(details.get(0), sourceContact.getDisplayName());
    }
  }
  @Override
  public JMenuItem insert(Action a, int pos) {
    if (pos < 0) {
      throw new IllegalArgumentException("index less than zero.");
    }

    ensurePopupMenuCreated();
    JMenuItem mi = new JMenuItem(a);
    mi.setHorizontalTextPosition(JButton.TRAILING);
    mi.setVerticalTextPosition(JButton.CENTER);
    popupMenu.insert(mi, pos);
    return mi;
  }
Exemple #10
0
 public void insertSeparator(int index) {
   super.insert(new Separator(), index);
 }
Exemple #11
0
 public void insert(IMenuItem menuItem, int index) {
   super.insert((JMenuItem) menuItem, index);
 }
Exemple #12
0
 /**
  * Inserts a menu item for the specified <code>Action</code> object at a given position.
  *
  * @param a the <code>Action</code> object to insert
  * @param index specifies the position at which to insert the <code>Action</code>, where 0 is the
  *     first
  * @exception IllegalArgumentException if <code>index</code> < 0
  * @see Action
  */
 public void insert(Action a, int index) {
   JMenuItem mi = createActionComponent(a);
   mi.setAction(a);
   insert(mi, index);
 }