1 22 23 package org.gjt.sp.jedit.menu; 24 25 import javax.swing.*; 27 import java.util.Collections ; 28 import java.util.Vector ; 29 import org.gjt.sp.jedit.*; 30 32 public class MacrosProvider implements DynamicMenuProvider 33 { 34 public boolean updateEveryTime() 36 { 37 return false; 38 } 40 public void update(JMenu menu) 42 { 43 Vector macroVector = Macros.getMacroHierarchy(); 44 45 int count = menu.getMenuComponentCount(); 46 47 createMacrosMenu(menu,macroVector,0); 48 49 if(count == menu.getMenuComponentCount()) 50 { 51 JMenuItem mi = new JMenuItem(jEdit.getProperty( 52 "no-macros.label")); 53 mi.setEnabled(false); 54 menu.add(mi); 55 } 56 } 58 private void createMacrosMenu(JMenu menu, Vector vector, int start) 60 { 61 Vector menuItems = new Vector (); 62 63 for(int i = start; i < vector.size(); i++) 64 { 65 Object obj = vector.elementAt(i); 66 if(obj instanceof String ) 67 { 68 menuItems.add(new EnhancedMenuItem( 69 jEdit.getProperty(obj + ".label"), 70 (String )obj,jEdit.getActionContext())); 71 } 72 else if(obj instanceof Vector ) 73 { 74 Vector subvector = (Vector )obj; 75 String name = (String )subvector.elementAt(0); 76 JMenu submenu = new JMenu(name); 77 createMacrosMenu(submenu,subvector,1); 78 if(submenu.getMenuComponentCount() != 0) 79 menuItems.add(submenu); 80 } 81 } 82 83 Collections.sort(menuItems,new MiscUtilities.MenuItemCompare()); 84 for(int i = 0; i < menuItems.size(); i++) 85 { 86 menu.add((JMenuItem)menuItems.get(i)); 87 } 88 } } 90 | Popular Tags |