PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 0ms 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
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
  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. package org.gjt.sp.jedit.gui;
  20. import javax.swing.*;
  21. import java.awt.event.*;
  22. import java.util.Vector;
  23. import org.gjt.sp.jedit.*;
  24. import org.gjt.sp.util.Log;
  25. public class PluginsMenu extends EnhancedMenu
  26. {
  27. public PluginsMenu()
  28. {
  29. super("plugins");
  30. // Query plugins for menu items
  31. Vector pluginMenuItems = new Vector();
  32. EditPlugin[] pluginArray = jEdit.getPlugins();
  33. for(int i = 0; i < pluginArray.length; i++)
  34. {
  35. try
  36. {
  37. EditPlugin plugin = pluginArray[i];
  38. plugin.createMenuItems(pluginMenuItems);
  39. }
  40. catch(Throwable t)
  41. {
  42. Log.log(Log.ERROR,this,"Error creating menu items"
  43. + " for plugin");
  44. Log.log(Log.ERROR,this,t);
  45. }
  46. }
  47. if(pluginMenuItems.isEmpty())
  48. {
  49. add(GUIUtilities.loadMenuItem("no-plugins"));
  50. return;
  51. }
  52. // Sort them
  53. MiscUtilities.quicksort(pluginMenuItems,
  54. new MiscUtilities.MenuItemCompare());
  55. JMenu menu = this;
  56. for(int i = 0; i < pluginMenuItems.size(); i++)
  57. {
  58. // We don't want to have a 'More' menu with only one item
  59. if(menu.getItemCount() >= 20 && i != pluginMenuItems.size() - 1)
  60. {
  61. menu.addSeparator();
  62. JMenu newMenu = new JMenu(jEdit.getProperty(
  63. "common.more"));
  64. menu.add(newMenu);
  65. menu = newMenu;
  66. }
  67. menu.add((JMenuItem)pluginMenuItems.elementAt(i));
  68. }
  69. }
  70. }