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;
  }
Exemple #2
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;
  }