PageRenderTime 73ms CodeModel.GetById 65ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/org/gjt/sp/jedit/gui/PluginsMenu.java

#
Java | 79 lines | 49 code | 9 blank | 21 comment | 6 complexity | de38897d82c54fea0ccc5159ad450005 MD5 | raw file
 1/*
 2 * PluginsMenu.java - Plugins menu
 3 * Copyright (C) 2001 Slava Pestov
 4 *
 5 * This program is free software; you can redistribute it and/or
 6 * modify it under the terms of the GNU General Public License
 7 * as published by the Free Software Foundation; either version 2
 8 * of the License, or any later version.
 9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19
20package org.gjt.sp.jedit.gui;
21
22import javax.swing.*;
23import java.awt.event.*;
24import java.util.Vector;
25import org.gjt.sp.jedit.*;
26import org.gjt.sp.util.Log;
27
28public class PluginsMenu extends EnhancedMenu
29{
30	public PluginsMenu()
31	{
32		super("plugins");
33
34		// Query plugins for menu items
35		Vector pluginMenuItems = new Vector();
36
37		EditPlugin[] pluginArray = jEdit.getPlugins();
38		for(int i = 0; i < pluginArray.length; i++)
39		{
40			try
41			{
42				EditPlugin plugin = pluginArray[i];
43				plugin.createMenuItems(pluginMenuItems);
44			}
45			catch(Throwable t)
46			{
47				Log.log(Log.ERROR,this,"Error creating menu items"
48					+ " for plugin");
49				Log.log(Log.ERROR,this,t);
50			}
51		}
52
53		if(pluginMenuItems.isEmpty())
54		{
55			add(GUIUtilities.loadMenuItem("no-plugins"));
56			return;
57		}
58
59		// Sort them
60		MiscUtilities.quicksort(pluginMenuItems,
61			new MiscUtilities.MenuItemCompare());
62
63		JMenu menu = this;
64		for(int i = 0; i < pluginMenuItems.size(); i++)
65		{
66			// We don't want to have a 'More' menu with only one item
67			if(menu.getItemCount() >= 20 && i != pluginMenuItems.size() - 1)
68			{
69				menu.addSeparator();
70				JMenu newMenu = new JMenu(jEdit.getProperty(
71					"common.more"));
72				menu.add(newMenu);
73				menu = newMenu;
74			}
75
76			menu.add((JMenuItem)pluginMenuItems.elementAt(i));
77		}
78	}
79}