2 * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
\r
4 * The program is provided "as is" without any warranty express or
\r
5 * implied, including the warranty of non-infringement and the implied
\r
6 * warranties of merchantibility and fitness for a particular purpose.
\r
7 * IBM will not be liable for any damages suffered by you as a result
\r
8 * of using the Program. In no event will IBM be liable for any
\r
9 * special, indirect or consequential damages or lost profits even if
\r
10 * IBM has been advised of the possibility of their occurrence. IBM
\r
11 * will not be liable for any third party claims against you.
\r
13 package com.ibm.richtext.awtui;
\r
15 import java.awt.Frame;
\r
16 import java.awt.Menu;
\r
17 import java.awt.MenuBar;
\r
18 import java.awt.Window;
\r
20 import com.ibm.richtext.textpanel.MTextPanel;
\r
22 import com.ibm.richtext.uiimpl.resources.FrameResources;
\r
24 import com.ibm.richtext.uiimpl.*;
\r
25 import com.ibm.richtext.uiimpl.DialogItem.DialogFactory;
\r
27 // TO DO: Don't hard-code menu configurations. Instead, specify them with
\r
28 // strings somehow. This is an improvement over what we had, and it'll do
\r
32 * AwtMenuBuilder creates a set of AWT menus for interacting
\r
33 * with an MTextPanel. Future versions of this class may allow
\r
34 * clients to control the menu contents.
\r
37 public final class AwtMenuBuilder extends MenuBuilder {
\r
39 static final String COPYRIGHT =
\r
40 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
41 private static final AwtMenuBuilder INSTANCE = new AwtMenuBuilder();
\r
44 * Id for an Edit menu. The Edit menu has the following items:
\r
46 * <li><b>Undo</b> - invoke undo() on the MTextPanel</li>
\r
47 * <li><b>Redo</b> - invoke redo() on the MTextPanel</li>
\r
48 * <li><b>Cut</b> - invoke cut() on the MTextPanel</li>
\r
49 * <li><b>Copy</b> - invoke copy() on the MTextPanel</li>
\r
50 * <li><b>Paste</b> - invoke paste() on the MTextPanel</li>
\r
51 * <li><b>Clear</b> - invoke clear() on the MTextPanel</li>
\r
52 * <li><b>Select All</b> - invoke selectAll() on the MTextPanel</li>
\r
55 public static final int EDIT = MenuBuilder.EDIT;
\r
57 * Id for the point sizes menu. The menu has items that set the size of a character
\r
60 public static final int SIZE = MenuBuilder.SIZE;
\r
62 * Id for a Style menu. The Style menu has the following items:
\r
64 * <li><b>Plain</b> - remove <code>WEIGHT</code>,
\r
65 * <code>POSTURE</code>,
\r
66 * <code>UNDERLINE</code> and
\r
67 * <code>STRIKETHROUGH</code> attributes from the
\r
68 * current selection</li>
\r
69 * <li><b>Bold</b> - add <code>{WEIGHT,WEIGHT_BOLD}</code> to
\r
70 * the current selection</li>
\r
71 * <li><b>Italic</b> - add <code>{POSTURE,POSTURE_ITALIC}</code> to
\r
72 * the current selection</li>
\r
73 * <li><b>Underline</b> - add <code>{UNDERLINE,UNDERLINE_ON}</code> to
\r
74 * the current selection</li>
\r
75 * <li><b>Strikethrough</b> - add <code>{STRIKETHROUGH,STRIKETHROUGH_ON}</code>
\r
76 * to the current selection</li>
\r
77 * <li><b>Font...</b> - display a dialog allowing the user to
\r
78 * select a typeface (font family) for the current selection</li>
\r
79 * <li><b>Forecolor...</b> - display a dialog allowing the user to
\r
80 * select a foreground color for the current selection</li>
\r
81 * <li><b>Backcolor...</b> - display a dialog allowing the user to
\r
82 * select a background color for the current selection</li>
\r
85 public static final int STYLE = MenuBuilder.STYLE;
\r
87 * Id for a paragraph alignment menu. The menu has the following items:
\r
89 * <li><b>Leading</b> - give selected paragraph(s) LEADING flush</li>
\r
90 * <li><b>Center</b> - give selected paragraph(s) CENTER flush</li>
\r
91 * <li><b>Trailing</b> - give selected paragraph(s) TRAILING flush</li>
\r
92 * <li><b>Justified</b> - give selected paragraph(s) full justification</li>
\r
95 public static final int FLUSH = MenuBuilder.FLUSH;
\r
97 * Id for a menu that sets the KeyRemap
\r
98 * on an MTextPanel. The menu has the following items:
\r
100 * <li><b>Default</b> - set KeyRemap to identity remap</li>
\r
101 * <li><b>Arabic</b> - set KeyRemap to Arabic transliteration</li>
\r
102 * <li><b>Hebrew</b> - set KeyRemap to Hebrew transliteration</li>
\r
103 * <li><b>Israel Nikud</b> - set KeyRemap to Israel Nikud</li>
\r
104 * <li><b>Thai Ketmanee</b> - set KeyRemap to Thai Ketmanee</li>
\r
107 public static final int KEYMAP = MenuBuilder.KEYMAP;
\r
109 * Id for a menu that sets
\r
110 * the primary run direction for a paragraph. Run direction can be left-to-right,
\r
111 * right-to-left, or can use the default run direction from the Unicode bidi algorithm.
\r
113 public static final int BIDI = MenuBuilder.BIDI;
\r
115 * Id for a menu with an <b>About</b> item. When selected,
\r
116 * the item displays a Frame containing some
\r
117 * self-promotional text.
\r
119 public static final int ABOUT = MenuBuilder.ABOUT;
\r
122 * Return an instance of AwtMenuBuilder.
\r
124 public static AwtMenuBuilder getInstance() {
\r
129 private MenuBar fMenuBar;
\r
131 private AwtMenuBuilder() {
\r
135 * Add a standard set of menus to the given menu bar. The menus
\r
136 * will interact with the given MTextPanel.
\r
137 * @param menuBar the MenuBar to which menus are added
\r
138 * @param textPanel the MTextPanel with which the menus interact
\r
139 * @param frame a Frame to use as the parent of any dialogs created by a
\r
140 * a menu item. If null, menu items which create dialogs will be omitted.
\r
142 public void createMenus(MenuBar menuBar,
\r
143 MTextPanel textPanel,
\r
146 createMenus(menuBar, textPanel, frame, defaultMenus);
\r
150 * Add a set of menus to the given menu bar. The menus
\r
151 * will interact with the given MTextPanel.
\r
152 * @param menuBar the MenuBar to which menus are added
\r
153 * @param textPanel the MTextPanel with which the menus interact
\r
154 * @param frame a Frame to use as the parent of any dialogs created by a
\r
155 * a menu item. If null, menu items which create dialogs will be omitted.
\r
156 * @param menus an array of integer menu id's. Each element of the
\r
157 * array must be one of this class's menu id constants. If null,
\r
158 * the default menus are created.
\r
160 public void createMenus(MenuBar menuBar,
\r
161 MTextPanel textPanel,
\r
165 if (menus == null) {
\r
166 menus = defaultMenus;
\r
169 synchronized (MItem.LOCK) {
\r
171 fMenuBar = menuBar;
\r
172 doCreateMenus(textPanel, frame, menus);
\r
177 protected void handleAddMenu(String key) {
\r
179 Menu menu = new Menu(ResourceUtils.getResourceString(key));
\r
180 fMenuBar.add(menu);
\r
181 MItem.setItemFactory(new AwtMenuFactory(menu));
\r
184 protected DialogFactory createObjectDialogFactory(final String dialogTitle,
\r
185 final String dialogMessage,
\r
187 final boolean character,
\r
188 final String[] names,
\r
189 final Object[] values) {
\r
191 final Frame dialogParent = fDialogParent;
\r
193 return new DialogFactory() {
\r
194 public Window createDialog(MTextPanel textPanel) {
\r
195 return new ObjectDialog(dialogParent,
\r
207 protected DialogFactory createNumberDialogFactory(final String dialogTitle,
\r
208 final String dialogMessage,
\r
210 final boolean character) {
\r
212 final Frame dialogParent = fDialogParent;
\r
214 return new DialogFactory() {
\r
215 public Window createDialog(MTextPanel textPanel) {
\r
216 return new NumberDialog(dialogParent,
\r
227 protected DialogFactory createAboutDialogFactory() {
\r
229 return new DialogFactory() {
\r
230 public Window createDialog(MTextPanel textPanel) {
\r
231 String title = ResourceUtils.getResourceString(FrameResources.ABOUT_TITLE);
\r
232 return new MessageDialog(title, AboutText.getAboutText());
\r