java.awt.Menu.insert()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(156)

本文整理了Java中java.awt.Menu.insert()方法的一些代码示例,展示了Menu.insert()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Menu.insert()方法的具体详情如下:
包路径:java.awt.Menu
类名称:Menu
方法名:insert

暂无

代码示例

代码示例来源:origin: com.dorkbox/SystemTray

AwtMenuItemStatus(final AwtMenu parent) {
  this.parent = parent;
  // status is ALWAYS at 0 index...
  parent._native.insert(_native, 0);
}

代码示例来源:origin: net.imagej/ij

/** Inserts one item (a non-image window) into the Window menu. */
static synchronized void insertWindowMenuItem(Window win) {
  if (ij==null || win==null)
    return;
  String title = win instanceof Frame?((Frame)win).getTitle():((Dialog)win).getTitle();
  CheckboxMenuItem item = new CheckboxMenuItem(title);
  item.addItemListener(ij);
  int index = WINDOW_MENU_ITEMS+windowMenuItems2;
  if (windowMenuItems2>=2)
    index--;
  window.insert(item, index);
  windowMenuItems2++;
  if (windowMenuItems2==1) {
    window.insertSeparator(WINDOW_MENU_ITEMS+windowMenuItems2);
    windowMenuItems2++;
  }
}

代码示例来源:origin: net.imagej/ij

/** Inserts 'item' into 'menu' in alphanumeric order. */
static void addOrdered(Menu menu, MenuItem item) {
  String label = item.getLabel();
  int start = addPluginSeparatorIfNeeded(menu);
  for (int i=start; i<menu.getItemCount(); i++) {
    if (label.compareTo(menu.getItem(i).getLabel())<0) {
      menu.insert(item, i);
      return;
    }
  }
  menu.add(item);
}

代码示例来源:origin: imagej/ImageJA

/** Inserts one item (a non-image window) into the Window menu. */
static synchronized void insertWindowMenuItem(Window win) {
  if (ij==null || win==null)
    return;
  String title = win instanceof Frame?((Frame)win).getTitle():((Dialog)win).getTitle();
  CheckboxMenuItem item = new CheckboxMenuItem(title);
  item.addItemListener(ij);
  int index = WINDOW_MENU_ITEMS+windowMenuItems2;
  if (windowMenuItems2>=2)
    index--;
  window.insert(item, index);
  windowMenuItems2++;
  if (windowMenuItems2==1) {
    window.insertSeparator(WINDOW_MENU_ITEMS+windowMenuItems2);
    windowMenuItems2++;
  }
}

代码示例来源:origin: net.imagej/ij

static void addItemSorted(Menu menu, MenuItem item, int startingIndex) {
  String itemLabel = item.getLabel();
  int count = menu.getItemCount();
  boolean inserted = false;
  for (int i=startingIndex; i<count; i++) {
    MenuItem mi = menu.getItem(i);
    String label = mi.getLabel();
    //IJ.log(i+ "  "+itemLabel+"  "+label + "  "+(itemLabel.compareTo(label)));
    if (itemLabel.compareTo(label)<0) {
      menu.insert(item, i);
      inserted = true;
      break;
    }
  }
  if (!inserted) menu.add(item);
}

代码示例来源:origin: imagej/ImageJA

/** Inserts 'item' into 'menu' in alphanumeric order. */
static void addOrdered(Menu menu, MenuItem item) {
  String label = item.getLabel();
  int start = addPluginSeparatorIfNeeded(menu);
  for (int i=start; i<menu.getItemCount(); i++) {
    if (label.compareTo(menu.getItem(i).getLabel())<0) {
      menu.insert(item, i);
      return;
    }
  }
  menu.add(item);
}

代码示例来源:origin: imagej/ImageJA

static void addItemSorted(Menu menu, MenuItem item, int startingIndex) {
  String itemLabel = item.getLabel();
  int count = menu.getItemCount();
  boolean inserted = false;
  for (int i=startingIndex; i<count; i++) {
    MenuItem mi = menu.getItem(i);
    String label = mi.getLabel();
    //IJ.log(i+ "  "+itemLabel+"  "+label + "  "+(itemLabel.compareTo(label)));
    if (itemLabel.compareTo(label)<0) {
      menu.insert(item, i);
      inserted = true;
      break;
    }
  }
  if (!inserted) menu.add(item);
}

代码示例来源:origin: net.imagej/imagej-legacy

/** Registers this ImageJ 1.x plugin. */
  public static void registerMenuItem() {
    // inject Help>Switch to Modern Mode
    @SuppressWarnings("unchecked")
    final Hashtable<String, String> commands = Menus.getCommands();
    if (commands != null && !commands.containsKey(MENU_LABEL)) {
      ActionListener ij1 = IJ.getInstance();
      if (ij1 != null) {
        final Menu helpMenu = Menus.getMenuBar().getHelpMenu();
        final MenuItem item = new MenuItem(MENU_LABEL);
        item.addActionListener(ij1);
        int index = helpMenu.getItemCount();
        while (index > 0) {
          final String label = helpMenu.getItem(index - 1).getLabel();
          if (label.equals("-") || label.startsWith("Update") || label.endsWith("Wiki")) {
            index--;
          } else {
            break;
          }
        }
        helpMenu.insert(item, index);
      }

      commands.put(MENU_LABEL, SwitchToModernMode.class.getName());
    }
  }
}

代码示例来源:origin: sc.fiji/fiji-compat

@SuppressWarnings("unchecked")
static void overrideCommands() {
  final Hashtable<String, String> commands = Menus.getCommands();
  if (!commands.containsKey("Install PlugIn...")) {
    commands.put("Install PlugIn...", "fiji.PlugInInstaller");
    if (IJ.getInstance() != null) {
      final Menu plugins = FijiTools.getMenu("Plugins");
      if (plugins != null)
        for (int i = 0; i < plugins.getItemCount(); i++)
          if (plugins.getItem(i).getLabel().equals("-")) {
            plugins.insert("Install PlugIn...", i);
            plugins.getItem(i).addActionListener(
                IJ.getInstance());
            break;
          }
    }
  }
  commands.put("Compile and Run...", "fiji.Compile_and_Run");
  // make sure "Edit>Options>Memory & Threads runs Fiji's plugin
  commands.put("Memory & Threads...", "fiji.Memory");
  // redirect Bio-Formats's "Update LOCI Plugins" to use the ImageJ updater
  Prefs.set("bioformats.upgradeCheck", false);
  if (commands.containsKey("Update LOCI Plugins")) {
    commands.put("Update LOCI Plugins", "fiji.updater.Updater(\"update\")");
  }
}

代码示例来源:origin: net.imagej/ij

/** Adds a file path to the beginning of the File/Open Recent submenu. */
public static synchronized void addOpenRecentItem(String path) {
  if (ij==null) return;
  int count = openRecentMenu.getItemCount();
  for (int i=0; i<count; ) {
    if (openRecentMenu.getItem(i).getLabel().equals(path)) {
      openRecentMenu.remove(i);
      count--;
    } else
      i++;
  }
  if (count==MAX_OPEN_RECENT_ITEMS)
    openRecentMenu.remove(MAX_OPEN_RECENT_ITEMS-1);
  MenuItem item = new MenuItem(path);
  openRecentMenu.insert(item, 0);
  item.addActionListener(ij);
}

代码示例来源:origin: imagej/ImageJA

/** Adds a file path to the beginning of the File/Open Recent submenu. */
public static synchronized void addOpenRecentItem(String path) {
  if (ij==null) return;
  int count = openRecentMenu.getItemCount();
  for (int i=0; i<count; ) {
    if (openRecentMenu.getItem(i).getLabel().equals(path)) {
      openRecentMenu.remove(i);
      count--;
    } else
      i++;
  }
  if (count==MAX_OPEN_RECENT_ITEMS)
    openRecentMenu.remove(MAX_OPEN_RECENT_ITEMS-1);
  MenuItem item = new MenuItem(path);
  openRecentMenu.insert(item, 0);
  item.addActionListener(ij);
}

代码示例来源:origin: net.imagej/imagej-legacy

public void updateRecentMenu(final String path) {
  final Menu menu = Menus.getOpenRecentMenu();
  if (menu == null) return;
  final int n = menu.getItemCount();
  int index = -1;
  for (int i = 0; i < n; i++) {
    if (menu.getItem(i).getLabel().equals(path)) {
      index = i;
      break;
    }
  }
  // Move to most recent
  if (index > 0) {
    final MenuItem item = menu.getItem(index);
    menu.remove(index);
    menu.insert(item, 0);
  }
  // not found, so replace oldest
  else if (index < 0) {
    final int count = menu.getItemCount();
    if (count >= Menus.MAX_OPEN_RECENT_ITEMS) {
      menu.remove(count - 1);
    }
    final MenuItem item = new MenuItem(path);
    final ImageJ instance = IJ.getInstance();
    if (instance != null) item.addActionListener(instance);
    menu.insert(item, 0);
  }
  // if index was 0, already at the head so do nothing
}

代码示例来源:origin: net.imagej/ij

/** Open the file and move the path to top of the submenu. */
public void run() {
  Opener o = new Opener();
  o.open(path);
  Menu menu = Menus.getOpenRecentMenu();
  int n = menu.getItemCount();
  int index = 0;
  for (int i=0; i<n; i++) {
    if (menu.getItem(i).getLabel().equals(path)) {
      index = i;
      break;
    }
  }
  if (index>0) {
    MenuItem item = menu.getItem(index);
    menu.remove(index);
    menu.insert(item, 0);
  }
}

代码示例来源:origin: net.imagej/imagej-legacy

private void nullShortcut(final IJ1Helper ij1Helper, final String menuLabel,
    final String subMenuLabel, final String itemLabel)
  {
    final MenuBar menuBar = ij1Helper.getMenuBar();
    for (int m = 0; m < menuBar.getMenuCount(); m++) {
      final Menu menu = menuBar.getMenu(m);
      if (!menuLabel.equals(menu.getLabel())) continue;
      for (int s = 0; s < menu.getItemCount(); s++) {
        final MenuItem ms = menu.getItem(s);
        if (!(ms instanceof Menu)) continue;
        final Menu subMenu = (Menu) ms;
        if (!subMenuLabel.equals(subMenu.getLabel())) continue;
        for (int i = 0; i < subMenu.getItemCount(); i++) {
          final MenuItem mi = subMenu.getItem(i);
          if (!itemLabel.equals(mi.getLabel())) continue;
          subMenu.remove(i);
          mi.deleteShortcut();
          subMenu.insert(mi, i);
        }
      }
    }
  }
}

代码示例来源:origin: imagej/ImageJA

/** Open the file and move the path to top of the submenu. */
public void run() {
  Opener o = new Opener();
  o.open(path);
  Menu menu = Menus.getOpenRecentMenu();
  int n = menu.getItemCount();
  int index = 0;
  for (int i=0; i<n; i++) {
    if (menu.getItem(i).getLabel().equals(path)) {
      index = i;
      break;
    }
  }
  if (index>0) {
    MenuItem item = menu.getItem(index);
    menu.remove(index);
    menu.insert(item, 0);
  }
}

代码示例来源:origin: net.imagej/imagej-legacy

menu.insert(item, getIndex(menu, label));
item.addActionListener(ij1);
return item;

代码示例来源:origin: net.imagej/imagej-legacy

parent.insert(menu, getIndex(parent, menu.getLabel()));

相关文章