PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/gui/EnhancedMenu.java

#
Java | 68 lines | 44 code | 6 blank | 18 comment | 10 complexity | 50fa4f9b394445e553d2c8198a056ab9 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. * EnhancedMenu.java - jEdit 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.StringTokenizer;
  23. import org.gjt.sp.jedit.*;
  24. public class EnhancedMenu extends JMenu
  25. {
  26. public EnhancedMenu(String name)
  27. {
  28. String label = jEdit.getProperty(name.concat(".label"));
  29. if(label == null)
  30. label = name;
  31. char mnemonic;
  32. int index = label.indexOf('$');
  33. if(index != -1 && label.length() - index > 1)
  34. {
  35. mnemonic = Character.toLowerCase(label.charAt(index + 1));
  36. label = label.substring(0,index).concat(label.substring(++index));
  37. }
  38. else
  39. mnemonic = '\0';
  40. setText(label);
  41. if(!OperatingSystem.isMacOS())
  42. setMnemonic(mnemonic);
  43. String menuItems = jEdit.getProperty(name);
  44. if(menuItems != null)
  45. {
  46. StringTokenizer st = new StringTokenizer(menuItems);
  47. while(st.hasMoreTokens())
  48. {
  49. String menuItemName = st.nextToken();
  50. if(menuItemName.equals("-"))
  51. addSeparator();
  52. else
  53. {
  54. if(menuItemName.startsWith("%"))
  55. add(GUIUtilities.loadMenu(menuItemName.substring(1)));
  56. else
  57. add(GUIUtilities.loadMenuItem(menuItemName));
  58. }
  59. }
  60. }
  61. }
  62. }