01: /*
02: * MacrosProvider.java - Macros menu
03: * :tabSize=8:indentSize=8:noTabs=false:
04: * :folding=explicit:collapseFolds=1:
05: *
06: * Copyright (C) 1999, 2003 Slava Pestov
07: *
08: * This program is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU General Public License
10: * as published by the Free Software Foundation; either version 2
11: * of the License, or any later version.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: * You should have received a copy of the GNU General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: */
22:
23: package org.gjt.sp.jedit.menu;
24:
25: //{{{ Imports
26: import javax.swing.*;
27: import java.util.Collections;
28: import java.util.Vector;
29: import org.gjt.sp.jedit.*;
30:
31: //}}}
32:
33: public class MacrosProvider implements DynamicMenuProvider {
34: //{{{ updateEveryTime() method
35: public boolean updateEveryTime() {
36: return false;
37: } //}}}
38:
39: //{{{ update() method
40: public void update(JMenu menu) {
41: Vector macroVector = Macros.getMacroHierarchy();
42:
43: int count = menu.getMenuComponentCount();
44:
45: createMacrosMenu(menu, macroVector, 0);
46:
47: if (count == menu.getMenuComponentCount()) {
48: JMenuItem mi = new JMenuItem(jEdit
49: .getProperty("no-macros.label"));
50: mi.setEnabled(false);
51: menu.add(mi);
52: }
53: } //}}}
54:
55: //{{{ createMacrosMenu() method
56: private void createMacrosMenu(JMenu menu, Vector vector, int start) {
57: Vector menuItems = new Vector();
58:
59: for (int i = start; i < vector.size(); i++) {
60: Object obj = vector.elementAt(i);
61: if (obj instanceof String) {
62: menuItems.add(new EnhancedMenuItem(jEdit
63: .getProperty(obj + ".label"), (String) obj,
64: jEdit.getActionContext()));
65: } else if (obj instanceof Vector) {
66: Vector subvector = (Vector) obj;
67: String name = (String) subvector.elementAt(0);
68: JMenu submenu = new JMenu(name);
69: createMacrosMenu(submenu, subvector, 1);
70: if (submenu.getMenuComponentCount() != 0)
71: menuItems.add(submenu);
72: }
73: }
74:
75: Collections
76: .sort(menuItems, new MiscUtilities.MenuItemCompare());
77: for (int i = 0; i < menuItems.size(); i++) {
78: menu.add((JMenuItem) menuItems.get(i));
79: }
80: } //}}}
81: }
|