KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > menu > MacrosProvider


1 /*
2  * MacrosProvider.java - Macros menu
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 1999, 2003 Slava Pestov
7  *
8  * This program is free software; you can redistribute it and/or
9  * 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 JavaDoc;
28 import java.util.Vector JavaDoc;
29 import org.gjt.sp.jedit.*;
30 //}}}
31

32 public class MacrosProvider implements DynamicMenuProvider
33 {
34     //{{{ updateEveryTime() method
35
public boolean updateEveryTime()
36     {
37         return false;
38     } //}}}
39

40     //{{{ update() method
41
public void update(JMenu menu)
42     {
43         Vector JavaDoc 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     } //}}}
57

58     //{{{ createMacrosMenu() method
59
private void createMacrosMenu(JMenu menu, Vector JavaDoc vector, int start)
60     {
61         Vector JavaDoc menuItems = new Vector JavaDoc();
62
63         for(int i = start; i < vector.size(); i++)
64         {
65             Object JavaDoc obj = vector.elementAt(i);
66             if(obj instanceof String JavaDoc)
67             {
68                 menuItems.add(new EnhancedMenuItem(
69                     jEdit.getProperty(obj + ".label"),
70                     (String JavaDoc)obj,jEdit.getActionContext()));
71             }
72             else if(obj instanceof Vector JavaDoc)
73             {
74                 Vector JavaDoc subvector = (Vector JavaDoc)obj;
75                 String JavaDoc name = (String JavaDoc)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     } //}}}
89
}
90
Popular Tags