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