/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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- /*
- * PluginsMenu.java - Plugins menu
- * Copyright (C) 2001 Slava Pestov
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- package org.gjt.sp.jedit.gui;
- import javax.swing.*;
- import java.awt.event.*;
- import java.util.Vector;
- import org.gjt.sp.jedit.*;
- import org.gjt.sp.util.Log;
- public class PluginsMenu extends EnhancedMenu
- {
- public PluginsMenu()
- {
- super("plugins");
- // Query plugins for menu items
- Vector pluginMenuItems = new Vector();
- EditPlugin[] pluginArray = jEdit.getPlugins();
- for(int i = 0; i < pluginArray.length; i++)
- {
- try
- {
- EditPlugin plugin = pluginArray[i];
- plugin.createMenuItems(pluginMenuItems);
- }
- catch(Throwable t)
- {
- Log.log(Log.ERROR,this,"Error creating menu items"
- + " for plugin");
- Log.log(Log.ERROR,this,t);
- }
- }
- if(pluginMenuItems.isEmpty())
- {
- add(GUIUtilities.loadMenuItem("no-plugins"));
- return;
- }
- // Sort them
- MiscUtilities.quicksort(pluginMenuItems,
- new MiscUtilities.MenuItemCompare());
- JMenu menu = this;
- for(int i = 0; i < pluginMenuItems.size(); i++)
- {
- // We don't want to have a 'More' menu with only one item
- if(menu.getItemCount() >= 20 && i != pluginMenuItems.size() - 1)
- {
- menu.addSeparator();
- JMenu newMenu = new JMenu(jEdit.getProperty(
- "common.more"));
- menu.add(newMenu);
- menu = newMenu;
- }
- menu.add((JMenuItem)pluginMenuItems.elementAt(i));
- }
- }
- }