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

# · Java · 67 lines · 43 code · 6 blank · 18 comment · 10 complexity · 43bb0b979ea349da523ca940254f3e9c MD5 · raw file

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