2 * (C) Copyright IBM Corp. 1998-2008. 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.swingui;
\r
15 import java.awt.Frame;
\r
16 import java.awt.Window;
\r
18 import javax.swing.JMenu;
\r
19 import javax.swing.JMenuBar;
\r
21 import com.ibm.richtext.textpanel.MTextPanel;
\r
23 import com.ibm.richtext.uiimpl.resources.FrameResources;
\r
25 import com.ibm.richtext.uiimpl.*;
\r
26 import com.ibm.richtext.uiimpl.DialogItem.DialogFactory;
\r
29 * SwingMenuBuilder provides a method for creating a set of Swing menus for interacting
\r
30 * with an MTextPanel. Future versions of this class may provide greater control
\r
31 * over the menu contents.
\r
34 public final class SwingMenuBuilder extends MenuBuilder {
\r
36 static final String COPYRIGHT =
\r
37 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
38 private static final SwingMenuBuilder INSTANCE = new SwingMenuBuilder();
\r
41 * Id for an Edit menu. The Edit menu has the following items:
\r
43 * <li><b>Undo</b> - invoke undo() on the MTextPanel</li>
\r
44 * <li><b>Redo</b> - invoke redo() on the MTextPanel</li>
\r
45 * <li><b>Cut</b> - invoke cut() on the MTextPanel</li>
\r
46 * <li><b>Copy</b> - invoke copy() on the MTextPanel</li>
\r
47 * <li><b>Paste</b> - invoke paste() on the MTextPanel</li>
\r
48 * <li><b>Clear</b> - invoke clear() on the MTextPanel</li>
\r
49 * <li><b>Select All</b> - invoke selectAll() on the MTextPanel</li>
\r
52 public static final int EDIT = MenuBuilder.EDIT;
\r
54 * Id for the point sizes menu. The menu has items that set the size of a character
\r
57 public static final int SIZE = MenuBuilder.SIZE;
\r
59 * Id for a Style menu. The Style menu has the following items:
\r
61 * <li><b>Plain</b> - remove <code>WEIGHT</code>,
\r
62 * <code>POSTURE</code>,
\r
63 * <code>UNDERLINE</code> and
\r
64 * <code>STRIKETHROUGH</code> attributes from the
\r
65 * current selection</li>
\r
66 * <li><b>Bold</b> - add <code>{WEIGHT,WEIGHT_BOLD}</code> to
\r
67 * the current selection</li>
\r
68 * <li><b>Italic</b> - add <code>{POSTURE,POSTURE_ITALIC}</code> to
\r
69 * the current selection</li>
\r
70 * <li><b>Underline</b> - add <code>{UNDERLINE,UNDERLINE_ON}</code> to
\r
71 * the current selection</li>
\r
72 * <li><b>Strikethrough</b> - add <code>{STRIKETHROUGH,STRIKETHROUGH_ON}</code>
\r
73 * to the current selection</li>
\r
74 * <li><b>Font...</b> - display a dialog allowing the user to
\r
75 * select a typeface (font family) for the current selection</li>
\r
76 * <li><b>Forecolor...</b> - display a dialog allowing the user to
\r
77 * select a foreground color for the current selection</li>
\r
78 * <li><b>Backcolor...</b> - display a dialog allowing the user to
\r
79 * select a background color for the current selection</li>
\r
82 public static final int STYLE = MenuBuilder.STYLE;
\r
84 * Id for a paragraph alignment menu. The menu has the following items:
\r
86 * <li><b>Leading</b> - give selected paragraph(s) LEADING flush</li>
\r
87 * <li><b>Center</b> - give selected paragraph(s) CENTER flush</li>
\r
88 * <li><b>Trailing</b> - give selected paragraph(s) TRAILING flush</li>
\r
89 * <li><b>Justified</b> - give selected paragraph(s) full justification</li>
\r
92 public static final int FLUSH = MenuBuilder.FLUSH;
\r
94 * Id for a menu that sets the KeyRemap
\r
95 * on an MTextPanel. The menu has the following items:
\r
97 * <li><b>Default</b> - set KeyRemap to identity remap</li>
\r
98 * <li><b>Arabic</b> - set KeyRemap to Arabic transliteration</li>
\r
99 * <li><b>Hebrew</b> - set KeyRemap to Hebrew transliteration</li>
\r
100 * <li><b>Israel Nikud</b> - set KeyRemap to Israel Nikud</li>
\r
101 * <li><b>Thai Ketmanee</b> - set KeyRemap to Thai Ketmanee</li>
\r
104 public static final int KEYMAP = MenuBuilder.KEYMAP;
\r
106 * Id for a menu that sets
\r
107 * the primary run direction for a paragraph. Run direction can be left-to-right,
\r
108 * right-to-left, or can use the default run direction from the Unicode bidi algorithm.
\r
110 public static final int BIDI = MenuBuilder.BIDI;
\r
112 * Id for a menu with an <b>About</b> item. When selected,
\r
113 * the item displays a Frame containing some
\r
114 * self-promotional text.
\r
116 public static final int ABOUT = MenuBuilder.ABOUT;
\r
118 * Return an instance of SwingMenuBuilder.
\r
121 public static SwingMenuBuilder getInstance() {
\r
126 private JMenuBar fMenuBar;
\r
128 private SwingMenuBuilder() {
\r
132 * Add a standard set of menus to the given menu bar. The menus
\r
133 * will interact with the given MTextPanel.
\r
134 * @param menuBar the MenuBar to which menus are added
\r
135 * @param textPanel the MTextPanel with which the menus interact
\r
136 * @param frame a Frame to use as the parent of any dialogs created by a
\r
137 * a menu item. If null, menu items which create dialogs will be omitted.
\r
139 public void createMenus(JMenuBar menuBar,
\r
140 MTextPanel textPanel,
\r
143 createMenus(menuBar, textPanel, frame, defaultMenus);
\r
147 * Add a set of menus to the given menu bar. The menus
\r
148 * will interact with the given MTextPanel.
\r
149 * @param menuBar the MenuBar to which menus are added
\r
150 * @param textPanel the MTextPanel with which the menus interact
\r
151 * @param frame a Frame to use as the parent of any dialogs created by a
\r
152 * a menu item. If null, menu items which create dialogs will be omitted.
\r
153 * @param menus an array of integer menu id's. Each element of the
\r
154 * array must be one of this class's menu id constants. If null,
\r
155 * the default menus are created.
\r
157 public void createMenus(JMenuBar menuBar,
\r
158 MTextPanel textPanel,
\r
162 if (menus == null) {
\r
163 menus = defaultMenus;
\r
166 synchronized (MItem.LOCK) {
\r
168 fMenuBar = menuBar;
\r
169 doCreateMenus(textPanel, frame, menus);
\r
174 protected void handleAddMenu(String key) {
\r
176 JMenu menu = new JMenu(ResourceUtils.getResourceString(key));
\r
177 fMenuBar.add(menu);
\r
178 MItem.setItemFactory(new SwingMenuFactory(menu));
\r
181 protected DialogFactory createObjectDialogFactory(final String dialogTitle,
\r
182 final String dialogMessage,
\r
184 final boolean character,
\r
185 final String[] names,
\r
186 final Object[] values) {
\r
188 final Frame dialogParent = fDialogParent;
\r
190 return new DialogFactory() {
\r
191 public Window createDialog(MTextPanel textPanel) {
\r
192 return new JObjectDialog(dialogParent,
\r
204 protected DialogFactory createNumberDialogFactory(final String dialogTitle,
\r
205 final String dialogMessage,
\r
207 final boolean character) {
\r
209 final Frame dialogParent = fDialogParent;
\r
210 // variable not used final MTextPanel textPanel = fTextPanel;
\r
212 return new DialogFactory() {
\r
213 public Window createDialog(MTextPanel fTxtPanel) {
\r
214 return new JNumberDialog(dialogParent,
\r
225 protected DialogFactory createAboutDialogFactory() {
\r
227 return new DialogFactory() {
\r
228 public Window createDialog(MTextPanel textPanel) {
\r
229 String title = ResourceUtils.getResourceString(FrameResources.ABOUT_TITLE);
\r
230 return new JMessageDialog(title, AboutText.getAboutText());
\r