PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms 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
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. * 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. package org.gjt.sp.jedit.menu;
  23. //{{{ Imports
  24. import javax.swing.*;
  25. import java.util.Collections;
  26. import java.util.Vector;
  27. import org.gjt.sp.jedit.*;
  28. //}}}
  29. public class MacrosProvider implements DynamicMenuProvider
  30. {
  31. //{{{ updateEveryTime() method
  32. public boolean updateEveryTime()
  33. {
  34. return false;
  35. } //}}}
  36. //{{{ update() method
  37. public void update(JMenu menu)
  38. {
  39. Vector macroVector = Macros.getMacroHierarchy();
  40. int count = menu.getMenuComponentCount();
  41. createMacrosMenu(menu,macroVector,0);
  42. if(count == menu.getMenuComponentCount())
  43. {
  44. JMenuItem mi = new JMenuItem(jEdit.getProperty(
  45. "no-macros.label"));
  46. mi.setEnabled(false);
  47. menu.add(mi);
  48. }
  49. } //}}}
  50. //{{{ createMacrosMenu() method
  51. private void createMacrosMenu(JMenu menu, Vector vector, int start)
  52. {
  53. Vector menuItems = new Vector();
  54. for(int i = start; i < vector.size(); i++)
  55. {
  56. Object obj = vector.elementAt(i);
  57. if(obj instanceof String)
  58. {
  59. menuItems.add(new EnhancedMenuItem(
  60. jEdit.getProperty(obj + ".label"),
  61. (String)obj,jEdit.getActionContext()));
  62. }
  63. else if(obj instanceof Vector)
  64. {
  65. Vector subvector = (Vector)obj;
  66. String name = (String)subvector.elementAt(0);
  67. JMenu submenu = new JMenu(name);
  68. createMacrosMenu(submenu,subvector,1);
  69. if(submenu.getMenuComponentCount() != 0)
  70. menuItems.add(submenu);
  71. }
  72. }
  73. Collections.sort(menuItems,new MiscUtilities.MenuItemCompare());
  74. for(int i = 0; i < menuItems.size(); i++)
  75. {
  76. menu.add((JMenuItem)menuItems.get(i));
  77. }
  78. } //}}}
  79. }