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

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

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

暂无

代码示例

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

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

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

  1. /** Inserts one item (a non-image window) into the Window menu. */
  2. static synchronized void insertWindowMenuItem(Window win) {
  3. if (ij==null || win==null)
  4. return;
  5. String title = win instanceof Frame?((Frame)win).getTitle():((Dialog)win).getTitle();
  6. CheckboxMenuItem item = new CheckboxMenuItem(title);
  7. item.addItemListener(ij);
  8. int index = WINDOW_MENU_ITEMS+windowMenuItems2;
  9. if (windowMenuItems2>=2)
  10. index--;
  11. window.insert(item, index);
  12. windowMenuItems2++;
  13. if (windowMenuItems2==1) {
  14. window.insertSeparator(WINDOW_MENU_ITEMS+windowMenuItems2);
  15. windowMenuItems2++;
  16. }
  17. }

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

  1. /** Inserts 'item' into 'menu' in alphanumeric order. */
  2. static void addOrdered(Menu menu, MenuItem item) {
  3. String label = item.getLabel();
  4. int start = addPluginSeparatorIfNeeded(menu);
  5. for (int i=start; i<menu.getItemCount(); i++) {
  6. if (label.compareTo(menu.getItem(i).getLabel())<0) {
  7. menu.insert(item, i);
  8. return;
  9. }
  10. }
  11. menu.add(item);
  12. }

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

  1. /** Inserts one item (a non-image window) into the Window menu. */
  2. static synchronized void insertWindowMenuItem(Window win) {
  3. if (ij==null || win==null)
  4. return;
  5. String title = win instanceof Frame?((Frame)win).getTitle():((Dialog)win).getTitle();
  6. CheckboxMenuItem item = new CheckboxMenuItem(title);
  7. item.addItemListener(ij);
  8. int index = WINDOW_MENU_ITEMS+windowMenuItems2;
  9. if (windowMenuItems2>=2)
  10. index--;
  11. window.insert(item, index);
  12. windowMenuItems2++;
  13. if (windowMenuItems2==1) {
  14. window.insertSeparator(WINDOW_MENU_ITEMS+windowMenuItems2);
  15. windowMenuItems2++;
  16. }
  17. }

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

  1. static void addItemSorted(Menu menu, MenuItem item, int startingIndex) {
  2. String itemLabel = item.getLabel();
  3. int count = menu.getItemCount();
  4. boolean inserted = false;
  5. for (int i=startingIndex; i<count; i++) {
  6. MenuItem mi = menu.getItem(i);
  7. String label = mi.getLabel();
  8. //IJ.log(i+ " "+itemLabel+" "+label + " "+(itemLabel.compareTo(label)));
  9. if (itemLabel.compareTo(label)<0) {
  10. menu.insert(item, i);
  11. inserted = true;
  12. break;
  13. }
  14. }
  15. if (!inserted) menu.add(item);
  16. }

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

  1. /** Inserts 'item' into 'menu' in alphanumeric order. */
  2. static void addOrdered(Menu menu, MenuItem item) {
  3. String label = item.getLabel();
  4. int start = addPluginSeparatorIfNeeded(menu);
  5. for (int i=start; i<menu.getItemCount(); i++) {
  6. if (label.compareTo(menu.getItem(i).getLabel())<0) {
  7. menu.insert(item, i);
  8. return;
  9. }
  10. }
  11. menu.add(item);
  12. }

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

  1. static void addItemSorted(Menu menu, MenuItem item, int startingIndex) {
  2. String itemLabel = item.getLabel();
  3. int count = menu.getItemCount();
  4. boolean inserted = false;
  5. for (int i=startingIndex; i<count; i++) {
  6. MenuItem mi = menu.getItem(i);
  7. String label = mi.getLabel();
  8. //IJ.log(i+ " "+itemLabel+" "+label + " "+(itemLabel.compareTo(label)));
  9. if (itemLabel.compareTo(label)<0) {
  10. menu.insert(item, i);
  11. inserted = true;
  12. break;
  13. }
  14. }
  15. if (!inserted) menu.add(item);
  16. }

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

  1. /** Registers this ImageJ 1.x plugin. */
  2. public static void registerMenuItem() {
  3. // inject Help>Switch to Modern Mode
  4. @SuppressWarnings("unchecked")
  5. final Hashtable<String, String> commands = Menus.getCommands();
  6. if (commands != null && !commands.containsKey(MENU_LABEL)) {
  7. ActionListener ij1 = IJ.getInstance();
  8. if (ij1 != null) {
  9. final Menu helpMenu = Menus.getMenuBar().getHelpMenu();
  10. final MenuItem item = new MenuItem(MENU_LABEL);
  11. item.addActionListener(ij1);
  12. int index = helpMenu.getItemCount();
  13. while (index > 0) {
  14. final String label = helpMenu.getItem(index - 1).getLabel();
  15. if (label.equals("-") || label.startsWith("Update") || label.endsWith("Wiki")) {
  16. index--;
  17. } else {
  18. break;
  19. }
  20. }
  21. helpMenu.insert(item, index);
  22. }
  23. commands.put(MENU_LABEL, SwitchToModernMode.class.getName());
  24. }
  25. }
  26. }

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

  1. @SuppressWarnings("unchecked")
  2. static void overrideCommands() {
  3. final Hashtable<String, String> commands = Menus.getCommands();
  4. if (!commands.containsKey("Install PlugIn...")) {
  5. commands.put("Install PlugIn...", "fiji.PlugInInstaller");
  6. if (IJ.getInstance() != null) {
  7. final Menu plugins = FijiTools.getMenu("Plugins");
  8. if (plugins != null)
  9. for (int i = 0; i < plugins.getItemCount(); i++)
  10. if (plugins.getItem(i).getLabel().equals("-")) {
  11. plugins.insert("Install PlugIn...", i);
  12. plugins.getItem(i).addActionListener(
  13. IJ.getInstance());
  14. break;
  15. }
  16. }
  17. }
  18. commands.put("Compile and Run...", "fiji.Compile_and_Run");
  19. // make sure "Edit>Options>Memory & Threads runs Fiji's plugin
  20. commands.put("Memory & Threads...", "fiji.Memory");
  21. // redirect Bio-Formats's "Update LOCI Plugins" to use the ImageJ updater
  22. Prefs.set("bioformats.upgradeCheck", false);
  23. if (commands.containsKey("Update LOCI Plugins")) {
  24. commands.put("Update LOCI Plugins", "fiji.updater.Updater(\"update\")");
  25. }
  26. }

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

  1. /** Adds a file path to the beginning of the File/Open Recent submenu. */
  2. public static synchronized void addOpenRecentItem(String path) {
  3. if (ij==null) return;
  4. int count = openRecentMenu.getItemCount();
  5. for (int i=0; i<count; ) {
  6. if (openRecentMenu.getItem(i).getLabel().equals(path)) {
  7. openRecentMenu.remove(i);
  8. count--;
  9. } else
  10. i++;
  11. }
  12. if (count==MAX_OPEN_RECENT_ITEMS)
  13. openRecentMenu.remove(MAX_OPEN_RECENT_ITEMS-1);
  14. MenuItem item = new MenuItem(path);
  15. openRecentMenu.insert(item, 0);
  16. item.addActionListener(ij);
  17. }

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

  1. /** Adds a file path to the beginning of the File/Open Recent submenu. */
  2. public static synchronized void addOpenRecentItem(String path) {
  3. if (ij==null) return;
  4. int count = openRecentMenu.getItemCount();
  5. for (int i=0; i<count; ) {
  6. if (openRecentMenu.getItem(i).getLabel().equals(path)) {
  7. openRecentMenu.remove(i);
  8. count--;
  9. } else
  10. i++;
  11. }
  12. if (count==MAX_OPEN_RECENT_ITEMS)
  13. openRecentMenu.remove(MAX_OPEN_RECENT_ITEMS-1);
  14. MenuItem item = new MenuItem(path);
  15. openRecentMenu.insert(item, 0);
  16. item.addActionListener(ij);
  17. }

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

  1. public void updateRecentMenu(final String path) {
  2. final Menu menu = Menus.getOpenRecentMenu();
  3. if (menu == null) return;
  4. final int n = menu.getItemCount();
  5. int index = -1;
  6. for (int i = 0; i < n; i++) {
  7. if (menu.getItem(i).getLabel().equals(path)) {
  8. index = i;
  9. break;
  10. }
  11. }
  12. // Move to most recent
  13. if (index > 0) {
  14. final MenuItem item = menu.getItem(index);
  15. menu.remove(index);
  16. menu.insert(item, 0);
  17. }
  18. // not found, so replace oldest
  19. else if (index < 0) {
  20. final int count = menu.getItemCount();
  21. if (count >= Menus.MAX_OPEN_RECENT_ITEMS) {
  22. menu.remove(count - 1);
  23. }
  24. final MenuItem item = new MenuItem(path);
  25. final ImageJ instance = IJ.getInstance();
  26. if (instance != null) item.addActionListener(instance);
  27. menu.insert(item, 0);
  28. }
  29. // if index was 0, already at the head so do nothing
  30. }

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

  1. /** Open the file and move the path to top of the submenu. */
  2. public void run() {
  3. Opener o = new Opener();
  4. o.open(path);
  5. Menu menu = Menus.getOpenRecentMenu();
  6. int n = menu.getItemCount();
  7. int index = 0;
  8. for (int i=0; i<n; i++) {
  9. if (menu.getItem(i).getLabel().equals(path)) {
  10. index = i;
  11. break;
  12. }
  13. }
  14. if (index>0) {
  15. MenuItem item = menu.getItem(index);
  16. menu.remove(index);
  17. menu.insert(item, 0);
  18. }
  19. }

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

  1. private void nullShortcut(final IJ1Helper ij1Helper, final String menuLabel,
  2. final String subMenuLabel, final String itemLabel)
  3. {
  4. final MenuBar menuBar = ij1Helper.getMenuBar();
  5. for (int m = 0; m < menuBar.getMenuCount(); m++) {
  6. final Menu menu = menuBar.getMenu(m);
  7. if (!menuLabel.equals(menu.getLabel())) continue;
  8. for (int s = 0; s < menu.getItemCount(); s++) {
  9. final MenuItem ms = menu.getItem(s);
  10. if (!(ms instanceof Menu)) continue;
  11. final Menu subMenu = (Menu) ms;
  12. if (!subMenuLabel.equals(subMenu.getLabel())) continue;
  13. for (int i = 0; i < subMenu.getItemCount(); i++) {
  14. final MenuItem mi = subMenu.getItem(i);
  15. if (!itemLabel.equals(mi.getLabel())) continue;
  16. subMenu.remove(i);
  17. mi.deleteShortcut();
  18. subMenu.insert(mi, i);
  19. }
  20. }
  21. }
  22. }
  23. }

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

  1. /** Open the file and move the path to top of the submenu. */
  2. public void run() {
  3. Opener o = new Opener();
  4. o.open(path);
  5. Menu menu = Menus.getOpenRecentMenu();
  6. int n = menu.getItemCount();
  7. int index = 0;
  8. for (int i=0; i<n; i++) {
  9. if (menu.getItem(i).getLabel().equals(path)) {
  10. index = i;
  11. break;
  12. }
  13. }
  14. if (index>0) {
  15. MenuItem item = menu.getItem(index);
  16. menu.remove(index);
  17. menu.insert(item, 0);
  18. }
  19. }

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

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

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

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

相关文章