]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/awtui/AwtMenuBuilder.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / awtui / AwtMenuBuilder.java
1 /*\r
2  * (C) Copyright IBM Corp. 1998-2004.  All Rights Reserved.\r
3  *\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
12  */\r
13 package com.ibm.richtext.awtui;\r
14 \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
19 \r
20 import com.ibm.richtext.textpanel.MTextPanel;\r
21 \r
22 import com.ibm.richtext.uiimpl.resources.FrameResources;\r
23 \r
24 import com.ibm.richtext.uiimpl.*;\r
25 import com.ibm.richtext.uiimpl.DialogItem.DialogFactory;\r
26 \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
29 // for now.\r
30 \r
31 /**\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
35  * @see MTextPanel\r
36  */\r
37 public final class AwtMenuBuilder extends MenuBuilder {\r
38     \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
42     \r
43     /**\r
44      * Id for an Edit menu.  The Edit menu has the following items:\r
45      * <ul>\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
53      * </ul>\r
54      */\r
55     public static final int EDIT = MenuBuilder.EDIT;\r
56     /**\r
57      * Id for the point sizes menu.  The menu has items that set the size of a character\r
58      * in a typeface.\r
59      */\r
60     public static final int SIZE = MenuBuilder.SIZE;\r
61     /**\r
62      * Id for a Style menu.  The Style menu has the following items:\r
63      * <ul>\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
83      * </ul>\r
84      */\r
85     public static final int STYLE = MenuBuilder.STYLE;\r
86     /**\r
87      * Id for a paragraph alignment menu.  The menu has the following items:\r
88      * <ul>\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
93      * </ul>\r
94      */\r
95     public static final int FLUSH = MenuBuilder.FLUSH;\r
96     /**\r
97      * Id for a menu that sets the KeyRemap\r
98      * on an MTextPanel.  The menu has the following items:\r
99      * <ul>\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
105      * </ul>\r
106      */\r
107     public static final int KEYMAP = MenuBuilder.KEYMAP;\r
108     /**\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
112      */\r
113     public static final int BIDI = MenuBuilder.BIDI;\r
114     /**\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
118      */\r
119     public static final int ABOUT = MenuBuilder.ABOUT;\r
120     \r
121     /**\r
122      * Return an instance of AwtMenuBuilder.\r
123      */\r
124     public static AwtMenuBuilder getInstance() {\r
125         \r
126         return INSTANCE;\r
127     }\r
128     \r
129     private MenuBar fMenuBar;\r
130     \r
131     private AwtMenuBuilder() {\r
132     }\r
133     \r
134     /**\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
141      */\r
142     public void createMenus(MenuBar menuBar, \r
143                             MTextPanel textPanel,\r
144                             Frame frame) {\r
145         \r
146         createMenus(menuBar, textPanel, frame, defaultMenus);\r
147     }\r
148     \r
149     /**\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
159      */\r
160     public void createMenus(MenuBar menuBar, \r
161                             MTextPanel textPanel,\r
162                             Frame frame,\r
163                             int[] menus) {\r
164         \r
165         if (menus == null) {\r
166             menus = defaultMenus;\r
167         }\r
168         \r
169         synchronized (MItem.LOCK) {\r
170             \r
171             fMenuBar = menuBar;\r
172             doCreateMenus(textPanel, frame, menus);\r
173             fMenuBar = null;\r
174         }\r
175     }\r
176     \r
177     protected void handleAddMenu(String key) {\r
178         \r
179         Menu menu = new Menu(ResourceUtils.getResourceString(key));\r
180         fMenuBar.add(menu);\r
181         MItem.setItemFactory(new AwtMenuFactory(menu));\r
182     }\r
183 \r
184     protected DialogFactory createObjectDialogFactory(final String dialogTitle,\r
185                                                       final String dialogMessage,\r
186                                                       final Object key,\r
187                                                       final boolean character,\r
188                                                       final String[] names,\r
189                                                       final Object[] values) {\r
190         \r
191         final Frame dialogParent = fDialogParent;\r
192 \r
193         return new DialogFactory() {    \r
194             public Window createDialog(MTextPanel textPanel) {\r
195                 return new ObjectDialog(dialogParent,\r
196                                         dialogTitle,\r
197                                         dialogMessage,\r
198                                         textPanel,\r
199                                         key,\r
200                                         character,\r
201                                         names,\r
202                                         values);\r
203             }\r
204         };\r
205     }\r
206     \r
207     protected DialogFactory createNumberDialogFactory(final String dialogTitle,\r
208                                                       final String dialogMessage,\r
209                                                       final Object key,\r
210                                                       final boolean character) {\r
211         \r
212         final Frame dialogParent = fDialogParent;\r
213             \r
214         return new DialogFactory() {\r
215             public Window createDialog(MTextPanel textPanel) {\r
216                 return new NumberDialog(dialogParent,\r
217                                         dialogTitle,\r
218                                         dialogMessage,\r
219                                         textPanel,\r
220                                         key,\r
221                                         character,\r
222                                         1);\r
223             }\r
224         };\r
225     }    \r
226     \r
227     protected DialogFactory createAboutDialogFactory() {\r
228         \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
233             }\r
234         };\r
235     }\r
236 }