コード例 #1
0
  /**
   * 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);
        }
      }
    }
  }
コード例 #2
0
  /** Sets the visibility of the column with the specified name. */
  public void setColumnVisible(String name, boolean visible) {
    // Get column and set visibility.
    TableColumnExt column = getColumnExt(name);
    column.setVisible(visible);

    // Get column title.
    String columnTitle = column.getTitle();

    // Find checkbox menu item with matching title.
    JCheckBoxMenuItem matchingItem = null;
    int itemCount = headerPopup.getComponentCount();
    for (int i = 0; i < itemCount; i++) {
      Component menuComponent = headerPopup.getComponent(i);
      if (menuComponent instanceof JCheckBoxMenuItem) {
        JCheckBoxMenuItem item = (JCheckBoxMenuItem) menuComponent;
        String itemTitle = item.getText();
        if (itemTitle.equals(columnTitle)) {
          matchingItem = item;
          break;
        }
      }
    }

    // Select matching menu item.
    if (matchingItem != null) {
      matchingItem.setSelected(visible);
    }
  }
コード例 #3
0
 /**
  * Finds the insert position of the given <code>command</command> within the <code>popupMenu</code>.
  *
  * @param popupMenu The popup menu.
  * @param command The command to insert.
  * @param manager The command manager.
  */
 public static int findMenuInsertPosition(
     final JPopupMenu popupMenu, final Command command, final CommandManager manager) {
   int pbi = popupMenu.getComponentCount();
   String placeBefore = command.getPlaceBefore();
   if (placeBefore != null) {
     pbi = UIUtils.findMenuItemPosition(popupMenu, placeBefore);
   }
   int pai = -1;
   String placeAfter = command.getPlaceAfter();
   if (placeAfter != null) {
     pai = UIUtils.findMenuItemPosition(popupMenu, placeAfter) + 1;
   }
   final int componentCount = popupMenu.getComponentCount();
   for (int i = 0; i < componentCount; i++) {
     final Component component = popupMenu.getComponent(i);
     if (!(component instanceof JMenuItem)) {
       continue;
     }
     final JMenuItem item = (JMenuItem) component;
     final String name = item.getName();
     final Command menuCommand = manager.getCommand(name);
     if (menuCommand == null) {
       continue;
     }
     placeBefore = menuCommand.getPlaceBefore();
     if (command.getCommandID().equals(placeBefore)) {
       if (pbi > i) {
         pbi = i + 1;
       }
     }
     placeAfter = menuCommand.getPlaceAfter();
     if (command.getCommandID().equals(placeAfter)) {
       if (pai < i) {
         pai = i;
       }
     }
   }
   int insertPos = -1;
   if (pbi >= pai) {
     insertPos = pai;
   }
   if (insertPos == -1) {
     insertPos = popupMenu.getComponentCount();
   }
   return insertPos;
 }
コード例 #4
0
ファイル: InviteLabel.java プロジェクト: wudigithub1/client
 /**
  * {@inheritDoc}
  *
  * @param e Mouse event
  */
 @Override
 public void mouseClicked(final MouseEvent e) {
   super.mouseClicked(e);
   popuplateMenu();
   if (menu.getComponentCount() > 0) {
     menu.show(this, e.getX(), e.getY());
   }
 }
コード例 #5
0
  /**
   * 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);
        }
      }
    }
  }
コード例 #6
0
 /*
  * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
  */
 @Override
 public void mouseClicked(MouseEvent e) {
   if (e.isPopupTrigger() && !Model.getModelManagementHelper().isReadOnly(getTarget())) {
     JPopupMenu popup = getPopupMenu();
     if (popup.getComponentCount() > 0) {
       initActions();
       LOG.info("Showing popup at " + e.getX() + "," + e.getY());
       getPopupMenu().show(this, e.getX(), e.getY());
     }
     e.consume();
   }
 }
コード例 #7
0
        @Override
        public void mouseClicked(MouseEvent e) {
          if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
            controller.goToSegmentAtLocation(getCaretPosition());
          }
          if (e.isPopupTrigger() || e.getButton() == MouseEvent.BUTTON3) {
            PopupMenuConstructorInfo[] cons;
            synchronized (popupConstructors) {
              /** Copy constructors - for disable blocking in the procesing time. */
              cons =
                  popupConstructors.toArray(new PopupMenuConstructorInfo[popupConstructors.size()]);
            }

            // where is the mouse
            int mousepos = viewToModel(e.getPoint());
            boolean isInActiveTranslation =
                mousepos >= getOmDocument().getTranslationStart()
                    && mousepos <= getOmDocument().getTranslationEnd();
            boolean isInActiveEntry;
            int ae = controller.displayedEntryIndex;
            SegmentBuilder sb = controller.m_docSegList[ae];
            if (sb.isActive()) {
              isInActiveEntry =
                  mousepos >= sb.getStartPosition() && mousepos <= sb.getEndPosition();
            } else {
              isInActiveEntry = false;
            }

            JPopupMenu popup = new JPopupMenu();
            for (PopupMenuConstructorInfo c : cons) {
              // call each constructor
              c.constructor.addItems(
                  popup,
                  EditorTextArea3.this,
                  mousepos,
                  isInActiveEntry,
                  isInActiveTranslation,
                  sb);
            }

            DockingUI.removeUnusedMenuSeparators(popup);

            if (popup.getComponentCount() > 0) {
              popup.show(
                  EditorTextArea3.this, (int) e.getPoint().getX(), (int) e.getPoint().getY());
            }
          }
        }
コード例 #8
0
 /*
  * @see java.awt.event.MouseListener#mouseReleased(
  *      java.awt.event.MouseEvent)
  */
 @Override
 public void mouseReleased(MouseEvent e) {
   if (e.isPopupTrigger() && !Model.getModelManagementHelper().isReadOnly(getTarget())) {
     Point point = e.getPoint();
     int index = locationToIndex(point);
     JPopupMenu popup = getPopupMenu();
     Object model = getModel();
     if (model instanceof UMLModelElementListModel) {
       ((UMLModelElementListModel) model).buildPopup(popup, index);
     }
     if (popup.getComponentCount() > 0) {
       initActions();
       LOG.info("Showing popup at " + e.getX() + "," + e.getY());
       popup.show(this, e.getX(), e.getY());
     }
     e.consume();
   }
 }
コード例 #9
0
 private static Command[] getCommands(
     final JPopupMenu popupMenu, final CommandManager manager, final Command command) {
   final List<Command> commands = new ArrayList<Command>();
   final int count = popupMenu.getComponentCount();
   for (int i = 0; i < count; i++) {
     final Component component = popupMenu.getComponent(i);
     if (!(component instanceof JMenuItem)) {
       continue;
     }
     final JMenuItem item = (JMenuItem) component;
     final String name = item.getName();
     final Command menuCommand = manager.getCommand(name);
     if (menuCommand != null) {
       commands.add(menuCommand);
     }
   }
   commands.add(command);
   return commands.toArray(new Command[commands.size()]);
 }
コード例 #10
0
  private void maybeIbpShowPopup(MouseEvent e) {
    if (e.isPopupTrigger() && ibpTb.isEnabled()) {
      currentPoint = new Point(e.getX(), e.getY());
      curCol = ibpTb.columnAtPoint(currentPoint);
      curRow = ibpTb.rowAtPoint(currentPoint);

      if (curRow < 0 || curRow >= ibpTb.getRowCount()) {
        return;
      }
      // translate table index to model index
      int mcol = ibpTb.getColumn(ibpTb.getColumnName(curCol)).getModelIndex();

      // .. create popup menu...
      JPopupMenu contextMenu = createIbpContextMenu(curRow, mcol);

      // ... and show it
      if (contextMenu != null && contextMenu.getComponentCount() > 0) {
        contextMenu.show(ibpTb, currentPoint.x, currentPoint.y);
      }
    }
  }
コード例 #11
0
ファイル: WorkspaceTree.java プロジェクト: wstarcev/RText
  /**
   * Displays the popup menu at the specified location.
   *
   * @param p The location at which to display the popup.
   */
  private void displayPopupMenu(Point p) {

    Object selectedNode = null;

    // Select the tree node at the mouse position.
    TreePath path = getPathForLocation(p.x, p.y);
    if (path != null) {
      setSelectionPath(path);
      scrollPathToVisible(path);
      selectedNode = getSelectionPath().getLastPathComponent();
    } else {
      clearSelection();
      selectedNode = model.getRoot();
    }

    // Configure and display it!
    configurePopupMenu(selectedNode);
    if (popup.getComponentCount() != 0) {
      popup.show(this, p.x, p.y);
    }
  }
コード例 #12
0
 @Override
 public int getMenuComponentCount() {
   return (popupMenu == null) ? 0 : popupMenu.getComponentCount();
 }