01: /*
02: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
03: *
04: * The program is provided "as is" without any warranty express or
05: * implied, including the warranty of non-infringement and the implied
06: * warranties of merchantibility and fitness for a particular purpose.
07: * IBM will not be liable for any damages suffered by you as a result
08: * of using the Program. In no event will IBM be liable for any
09: * special, indirect or consequential damages or lost profits even if
10: * IBM has been advised of the possibility of their occurrence. IBM
11: * will not be liable for any third party claims against you.
12: */
13: package com.ibm.richtext.swingdemo;
14:
15: import java.awt.Event;
16:
17: import javax.swing.JMenu;
18: import javax.swing.JMenuItem;
19: import javax.swing.JSeparator;
20: import javax.swing.KeyStroke;
21:
22: import com.ibm.richtext.demo.DocumentWindow;
23: import com.ibm.richtext.demo.EditApplication;
24: import com.ibm.richtext.demo.FileMenuManager;
25: import com.ibm.richtext.demo.MenuData;
26: import com.ibm.richtext.demo.ResourceUtils;
27:
28: final class SwingFileMenuManager extends FileMenuManager {
29:
30: private JMenu fMenu;
31:
32: public SwingFileMenuManager(JMenu menu,
33: EditApplication application, DocumentWindow document,
34: boolean supportStyledFormat, boolean supportPlainFormat) {
35:
36: super (application, document);
37:
38: fMenu = menu;
39: createItems(supportStyledFormat, supportPlainFormat);
40: fMenu = null;
41: }
42:
43: protected Object addMenuItem(String key) {
44:
45: MenuData menuData = ResourceUtils.getMenuData(key);
46: JMenuItem item = new JMenuItem(menuData.getName());
47: if (menuData.hasShortcut()) {
48: KeyStroke ks = KeyStroke.getKeyStroke(menuData
49: .getShortcutKeyCode(), Event.CTRL_MASK);
50: item.setAccelerator(ks);
51: }
52: item.addActionListener(this );
53: fMenu.add(item);
54: return item;
55: }
56:
57: protected void addSeparator() {
58:
59: fMenu.add(new JSeparator());
60: }
61: }
|