PageRenderTime 105ms CodeModel.GetById 99ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/menu/MacrosProvider.java

#
Java | 89 lines | 53 code | 10 blank | 26 comment | 9 complexity | 429129d9c0943894b43051c0bd0c90cc MD5 | raw file
 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
23package org.gjt.sp.jedit.menu;
24
25//{{{ Imports
26import javax.swing.*;
27import java.util.Collections;
28import java.util.Vector;
29import org.gjt.sp.jedit.*;
30//}}}
31
32public 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 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 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	} //}}}
89}