PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 101 lines | 69 code | 11 blank | 21 comment | 11 complexity | 4eef65adf233cce1a00a0d7e48e87fb9 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. * MacrosMenu.java - Macros menu
  3. * Copyright (C) 1999, 2000, 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.msg.MacrosChanged;
  24. import org.gjt.sp.jedit.*;
  25. public class MacrosMenu extends EnhancedMenu implements EBComponent
  26. {
  27. public MacrosMenu()
  28. {
  29. super("macros");
  30. updateMacrosMenu();
  31. }
  32. public void addNotify()
  33. {
  34. super.addNotify();
  35. EditBus.addToBus(this);
  36. }
  37. public void removeNotify()
  38. {
  39. super.removeNotify();
  40. EditBus.removeFromBus(this);
  41. }
  42. public void handleMessage(EBMessage msg)
  43. {
  44. if(msg instanceof MacrosChanged)
  45. updateMacrosMenu();
  46. }
  47. private void updateMacrosMenu()
  48. {
  49. // Because the macros menu contains normal items as
  50. // well as dynamically-generated stuff, we are careful
  51. // to only remove the dynamic crap here...
  52. for(int i = getMenuComponentCount() - 1; i >= 0; i--)
  53. {
  54. if(getMenuComponent(i) instanceof JSeparator)
  55. break;
  56. else
  57. remove(i);
  58. }
  59. int count = getMenuComponentCount();
  60. Vector macroVector = Macros.getMacroHierarchy();
  61. createMacrosMenu(this,macroVector,0);
  62. if(count == getMenuComponentCount())
  63. add(GUIUtilities.loadMenuItem("no-macros"));
  64. }
  65. private void createMacrosMenu(JMenu menu, Vector vector, int start)
  66. {
  67. for(int i = start; i < vector.size(); i++)
  68. {
  69. Object obj = vector.elementAt(i);
  70. if(obj instanceof Macros.Macro)
  71. {
  72. Macros.Macro macro = (Macros.Macro)obj;
  73. menu.add(new EnhancedMenuItem(macro.getLabel(),macro));
  74. }
  75. else if(obj instanceof Vector)
  76. {
  77. Vector subvector = (Vector)obj;
  78. String name = (String)subvector.elementAt(0);
  79. JMenu submenu = new JMenu(name);
  80. createMacrosMenu(submenu,subvector,1);
  81. if(submenu.getMenuComponentCount() == 0)
  82. {
  83. submenu.add(GUIUtilities.loadMenuItem(
  84. "no-macros"));
  85. }
  86. menu.add(submenu);
  87. }
  88. }
  89. }
  90. }