/** Removes the menu represented by the node */
  private void removeVisualMenu(RADMenuItemComponent comp) {
    Object o = getBeanInstance();
    Object m = comp.getBeanInstance();
    Object dto = getDesignTimeMenus(getFormManager()).getDesignTime(o);
    Object dtm = getDesignTimeMenus(getFormManager()).getDesignTime(m);

    switch (getMenuItemType()) {
      case T_MENUBAR:
        ((MenuBar) o).remove((Menu) m);
        ((JMenuBar) dto).remove((JMenu) dtm);
        ((JMenuBar) dto).validate();
        break;
      case T_MENU:
        if (comp.getMenuItemType() == T_SEPARATOR) {
          ((Menu) o).remove(subComponents.indexOf(comp));
          ((JMenu) dto).remove(subComponents.indexOf(comp));
        } else {
          ((Menu) o).remove((MenuItem) m);
          ((JMenu) dto).remove((JMenuItem) dtm);
        }
        break;
      case T_POPUPMENU:
        if (comp.getMenuItemType() == T_SEPARATOR) {
          ((Menu) o).remove(subComponents.indexOf(comp));
          // PENDING - dont know how to get reference to JPopupMenu.Separator
          // so it is not supported by getDesignTimeMenu () !!
          // ((JPopupMenu)dto).remove((JPopupMenu.Separator)dtm);
        } else {
          ((Menu) o).remove((MenuItem) m);
          ((JPopupMenu) dto).remove((JMenuItem) dtm);
        }
        break;
      case T_JMENUBAR:
        ((JMenuBar) o).remove((JMenu) m);
        ((JMenuBar) o).validate();
        break;
      case T_JMENU:
        if (comp.getMenuItemType() == T_JSEPARATOR) {
          ((JMenu) o).remove(subComponents.indexOf(comp));
        } else {
          ((JMenu) o).remove((JMenuItem) m);
        }
        break;
      case T_JPOPUPMENU:
        if (comp.getMenuItemType() == T_JSEPARATOR) {
          // XXX(-tdt) ((JPopupMenu)o).remove((JPopupMenu.Separator)m);
          ((JPopupMenu) o).remove(subComponents.indexOf(comp));
        } else {
          ((JPopupMenu) o).remove((JMenuItem) m);
        }
        break;
    }
  }
  private void addToRecent(String s) {

    for (int i = 0; i < iMaxRecent; i++) {
      if (s.equals(sRecent[i])) {
        return;
      }
    }

    if (sRecent[iRecent] != null) {
      mRecent.remove(iRecent);
    }

    sRecent[iRecent] = s;

    if (s.length() > 43) {
      s = s.substring(0, 40) + "...";
    }

    JMenuItem item = new JMenuItem(s);

    item.setActionCommand("#" + iRecent);
    item.addActionListener(this);
    mRecent.insert(item, iRecent);

    iRecent = (iRecent + 1) % iMaxRecent;
  }
Esempio n. 3
0
  /**
   * Returns a menu with items that control this track.
   *
   * @param trackerPanel the tracker panel
   * @return a menu
   */
  public JMenu getMenu(TrackerPanel trackerPanel) {
    if (inspectorItem == null) {
      // create the model inspector item
      inspectorItem = new JMenuItem();
      inspectorItem.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              positionInspector();
              getInspector().setVisible(true);
            }
          });
      // create the useDefaultRefFrameItem item
      useDefaultRefFrameItem = new JCheckBoxMenuItem();
      useDefaultRefFrameItem.setSelected(!useDefaultReferenceFrame);
      useDefaultRefFrameItem.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              setUseDefaultReferenceFrame(!useDefaultRefFrameItem.isSelected());
              if (ParticleModel.this.trackerPanel.getCoords() instanceof ReferenceFrame) {
                lastValidFrame = -1;
                refreshSteps();
              }
            }
          });
    }
    inspectorItem.setText(
        TrackerRes.getString("ParticleModel.MenuItem.InspectModel")); // $NON-NLS-1$
    useDefaultRefFrameItem.setText(
        TrackerRes.getString("ParticleModel.MenuItem.UseDefaultReferenceFrame")); // $NON-NLS-1$
    // assemble the menu
    JMenu menu = super.getMenu(trackerPanel);

    // remove unwanted menu items and separators
    menu.remove(autotrackItem);
    menu.remove(deleteStepItem);
    menu.remove(clearStepsItem);
    menu.remove(lockedItem);
    menu.remove(autoAdvanceItem);
    menu.remove(markByDefaultItem);
    menu.insert(inspectorItem, 0);
    if (menu.getItemCount() > 1) menu.insertSeparator(1);

    //		// find visible item and insert useDefaultRefFrameItem after it
    //		for (int i=0; i<menu.getMenuComponentCount(); i++) {
    //			if (menu.getMenuComponent(i)==visibleItem) {
    //				menu.insert(useDefaultRefFrameItem, i+1);
    //				break;
    //			}
    //		}

    // eliminate any double separators
    Object prevItem = inspectorItem;
    int n = menu.getItemCount();
    for (int j = 1; j < n; j++) {
      Object item = menu.getItem(j);
      if (item == null && prevItem == null) { // found extra separator
        menu.remove(j - 1);
        j = j - 1;
        n = n - 1;
      }
      prevItem = item;
    }
    return menu;
  }