Source Code Cross Referenced for MenuBuilder.java in  » Internationalization-Localization » icu4j » com » ibm » richtext » uiimpl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Internationalization Localization » icu4j » com.ibm.richtext.uiimpl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * (C) Copyright IBM Corp. 1998-2004.  All Rights Reserved.
003:         *
004:         * The program is provided "as is" without any warranty express or
005:         * implied, including the warranty of non-infringement and the implied
006:         * warranties of merchantibility and fitness for a particular purpose.
007:         * IBM will not be liable for any damages suffered by you as a result
008:         * of using the Program. In no event will IBM be liable for any
009:         * special, indirect or consequential damages or lost profits even if
010:         * IBM has been advised of the possibility of their occurrence. IBM
011:         * will not be liable for any third party claims against you.
012:         */
013:        package com.ibm.richtext.uiimpl;
014:
015:        import java.awt.Color;
016:        import java.awt.Frame;
017:
018:        import java.text.NumberFormat;
019:
020:        import com.ibm.richtext.textlayout.attributes.TextAttribute;
021:        import com.ibm.richtext.textpanel.MTextPanel;
022:        import com.ibm.richtext.textpanel.KeyRemap;
023:
024:        import com.ibm.richtext.uiimpl.resources.FrameResources;
025:        import com.ibm.richtext.uiimpl.resources.MenuData;
026:
027:        import com.ibm.richtext.uiimpl.DialogItem.DialogFactory;
028:
029:        public abstract class MenuBuilder {
030:
031:            static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
032:
033:            public static final int EDIT = 0;
034:            public static final int SIZE = 1;
035:            public static final int STYLE = 2;
036:            public static final int FLUSH = 3;
037:            public static final int KEYMAP = 4;
038:            public static final int BIDI = 5;
039:            public static final int ABOUT = 6;
040:
041:            private Color[] colors = { Color.black, Color.white, Color.green,
042:                    Color.blue, Color.cyan, Color.gray, Color.darkGray,
043:                    Color.lightGray, Color.magenta, Color.orange, Color.pink,
044:                    Color.red, Color.yellow, null };
045:            private String[] colorNames = {
046:                    ResourceUtils.getResourceString(FrameResources.BLACK),
047:                    ResourceUtils.getResourceString(FrameResources.WHITE),
048:                    ResourceUtils.getResourceString(FrameResources.GREEN),
049:                    ResourceUtils.getResourceString(FrameResources.BLUE),
050:                    ResourceUtils.getResourceString(FrameResources.CYAN),
051:                    ResourceUtils.getResourceString(FrameResources.GRAY),
052:                    ResourceUtils.getResourceString(FrameResources.DARK_GRAY),
053:                    ResourceUtils.getResourceString(FrameResources.LIGHT_GRAY),
054:                    ResourceUtils.getResourceString(FrameResources.MAGENTA),
055:                    ResourceUtils.getResourceString(FrameResources.ORANGE),
056:                    ResourceUtils.getResourceString(FrameResources.PINK),
057:                    ResourceUtils.getResourceString(FrameResources.RED),
058:                    ResourceUtils.getResourceString(FrameResources.YELLOW),
059:                    ResourceUtils.getResourceString(FrameResources.NONE) };
060:
061:            protected int[] defaultMenus = { EDIT, SIZE, STYLE, FLUSH, KEYMAP,
062:                    BIDI, ABOUT };
063:
064:            protected MTextPanel fTextPanel;
065:            protected Frame fDialogParent;
066:
067:            protected MenuBuilder() {
068:            }
069:
070:            protected final void doCreateMenus(MTextPanel textPanel,
071:                    Frame frame, int[] menus) {
072:
073:                fTextPanel = textPanel;
074:                fDialogParent = frame;
075:
076:                for (int i = 0; i < menus.length; i++) {
077:                    switch (menus[i]) {
078:                    case EDIT:
079:                        createEditMenu();
080:                        break;
081:                    case SIZE:
082:                        createSizeMenu();
083:                        break;
084:                    case STYLE:
085:                        createStyleMenu();
086:                        break;
087:                    case FLUSH:
088:                        createFlushMenu();
089:                        break;
090:                    case KEYMAP:
091:                        createKeymapMenu();
092:                        break;
093:                    case BIDI:
094:                        createBidiMenu();
095:                        break;
096:                    case ABOUT:
097:                        createAboutMenu();
098:                        break;
099:                    default:
100:                        throw new IllegalArgumentException("Illegal menu: "
101:                                + menus[i]);
102:                    }
103:                }
104:
105:                fTextPanel = null;
106:                fDialogParent = null;
107:            }
108:
109:            protected abstract void handleAddMenu(String key);
110:
111:            protected abstract DialogFactory createObjectDialogFactory(
112:                    String dialogTitle, String dialogText, Object key,
113:                    boolean character, String[] names, Object[] values);
114:
115:            protected abstract DialogFactory createNumberDialogFactory(
116:                    String dialogTitle, String dialogText, Object key,
117:                    boolean character);
118:
119:            protected abstract DialogFactory createAboutDialogFactory();
120:
121:            private void createEditMenu() {
122:
123:                handleAddMenu(FrameResources.EDIT);
124:
125:                new CommandMenuItem.UndoRedo(ResourceUtils
126:                        .getMenuData(FrameResources.UNDO),
127:                        CommandMenuItem.UndoRedo.UNDO).setTextPanel(fTextPanel);
128:                new CommandMenuItem.UndoRedo(ResourceUtils
129:                        .getMenuData(FrameResources.REDO),
130:                        CommandMenuItem.UndoRedo.REDO).setTextPanel(fTextPanel);
131:                MItem.getItemFactory().createSeparator();
132:                new CommandMenuItem.CutCopyClear(ResourceUtils
133:                        .getMenuData(FrameResources.CUT),
134:                        CommandMenuItem.CutCopyClear.CUT)
135:                        .setTextPanel(fTextPanel);
136:                new CommandMenuItem.CutCopyClear(ResourceUtils
137:                        .getMenuData(FrameResources.COPY),
138:                        CommandMenuItem.CutCopyClear.COPY)
139:                        .setTextPanel(fTextPanel);
140:                new CommandMenuItem.Paste(ResourceUtils
141:                        .getMenuData(FrameResources.PASTE))
142:                        .setTextPanel(fTextPanel);
143:                new CommandMenuItem.CutCopyClear(ResourceUtils
144:                        .getMenuData(FrameResources.CLEAR),
145:                        CommandMenuItem.CutCopyClear.CLEAR)
146:                        .setTextPanel(fTextPanel);
147:                MItem.getItemFactory().createSeparator();
148:                new CommandMenuItem.SelectAll(ResourceUtils
149:                        .getMenuData(FrameResources.SELECT_ALL))
150:                        .setTextPanel(fTextPanel);
151:            }
152:
153:            private static final float[] DEFAULT_SIZES = { 9, 10, 12, 14, 18,
154:                    24, 36, 48, 72 };
155:
156:            private void createSizeMenu() {
157:
158:                createSizeMenu(DEFAULT_SIZES);
159:            }
160:
161:            private void createSizeMenu(float[] sizes) {
162:
163:                handleAddMenu(FrameResources.SIZE);
164:
165:                if (sizes != DEFAULT_SIZES) {
166:
167:                    sizes = (float[]) sizes.clone();
168:                    if (sizes.length == 0) {
169:                        throw new IllegalArgumentException(
170:                                "sizes array has zero length");
171:                    }
172:
173:                    float lastValue = sizes[0];
174:                    for (int i = 1; i < sizes.length; i++) {
175:                        if (sizes[i] >= lastValue) {
176:                            throw new IllegalArgumentException(
177:                                    "sizes array must be increasing");
178:                        }
179:                        lastValue = sizes[i];
180:                    }
181:                }
182:
183:                Float[] values = new Float[sizes.length];
184:                MenuData[] mData = new MenuData[sizes.length];
185:                NumberFormat fmt = NumberFormat.getNumberInstance();
186:
187:                for (int i = 0; i < sizes.length; i++) {
188:                    values[i] = new Float(sizes[i]);
189:                    mData[i] = new MenuData(fmt.format(sizes[i]));
190:                }
191:
192:                new StyleMenuItemSet(TextAttribute.SIZE, values, mData,
193:                        MenuItemSet.CHARACTER).setTextPanel(fTextPanel);
194:
195:                if (fDialogParent != null) {
196:                    String dialogTitle = ResourceUtils
197:                            .getResourceString(FrameResources.SET_SIZE_TITLE);
198:                    String dialogText = ResourceUtils
199:                            .getResourceString(FrameResources.SET_SIZE_LABEL);
200:                    DialogFactory factory = createNumberDialogFactory(
201:                            dialogTitle, dialogText, TextAttribute.SIZE,
202:                            MenuItemSet.CHARACTER);
203:
204:                    new DialogItem(ResourceUtils
205:                            .getMenuData(FrameResources.OTHER_DIALOG), factory)
206:                            .setTextPanel(fTextPanel);
207:                }
208:            }
209:
210:            private void createStyleMenu() {
211:
212:                handleAddMenu(FrameResources.STYLE);
213:
214:                Object[] keys = { TextAttribute.WEIGHT, TextAttribute.POSTURE,
215:                        TextAttribute.UNDERLINE, TextAttribute.STRIKETHROUGH,
216:                        TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT };
217:                Object[] values = { TextAttribute.WEIGHT_BOLD,
218:                        TextAttribute.POSTURE_OBLIQUE,
219:                        TextAttribute.UNDERLINE_ON,
220:                        TextAttribute.STRIKETHROUGH_ON, new Integer(1),
221:                        new Integer(-1) };
222:                MenuData[] mData = {
223:                        ResourceUtils.getMenuData(FrameResources.BOLD),
224:                        ResourceUtils.getMenuData(FrameResources.ITALIC),
225:                        ResourceUtils.getMenuData(FrameResources.UNDERLINE),
226:                        ResourceUtils.getMenuData(FrameResources.STRIKETHROUGH),
227:                        ResourceUtils.getMenuData(FrameResources.SUPERSCRIPT),
228:                        ResourceUtils.getMenuData(FrameResources.SUBSCRIPT) };
229:
230:                new SubtractStyleMenuItem(keys, ResourceUtils
231:                        .getMenuData(FrameResources.PLAIN),
232:                        MenuItemSet.CHARACTER).setTextPanel(fTextPanel);
233:
234:                for (int i = 0; i < keys.length; i++) {
235:                    new BooleanStyleMenuItem(keys[i], values[i], mData[i],
236:                            MenuItemSet.CHARACTER).setTextPanel(fTextPanel);
237:                }
238:
239:                if (fDialogParent != null) {
240:
241:                    MItem.getItemFactory().createSeparator();
242:
243:                    String[] fonts = FontList.getFontList();
244:                    String title = ResourceUtils
245:                            .getResourceString(FrameResources.SET_FONT_TITLE);
246:                    String label = ResourceUtils
247:                            .getResourceString(FrameResources.SET_FONT_LABEL);
248:
249:                    DialogFactory fontF = createObjectDialogFactory(title,
250:                            label, TextAttribute.FAMILY,
251:                            StyleMenuItemSet.CHARACTER, fonts, fonts);
252:                    new DialogItem(ResourceUtils
253:                            .getMenuData(FrameResources.FONT_DIALOG), fontF)
254:                            .setTextPanel(fTextPanel);
255:
256:                    DialogFactory foregroundF = createColorDialogFactory(true);
257:                    DialogFactory backgroundF = createColorDialogFactory(false);
258:
259:                    new DialogItem(ResourceUtils
260:                            .getMenuData(FrameResources.FORECOLOR_DIALOG),
261:                            foregroundF).setTextPanel(fTextPanel);
262:                    new DialogItem(ResourceUtils
263:                            .getMenuData(FrameResources.BACKCOLOR_DIALOG),
264:                            backgroundF).setTextPanel(fTextPanel);
265:                }
266:            }
267:
268:            private DialogFactory createColorDialogFactory(boolean foreground) {
269:
270:                String title;
271:                String message;
272:                Object key;
273:
274:                if (foreground) {
275:                    title = ResourceUtils
276:                            .getResourceString(FrameResources.SET_FOREGROUND_TITLE);
277:                    message = ResourceUtils
278:                            .getResourceString(FrameResources.SET_FOREGROUND_LABEL);
279:                    key = TextAttribute.FOREGROUND;
280:                } else {
281:                    title = ResourceUtils
282:                            .getResourceString(FrameResources.SET_BACKGROUND_TITLE);
283:                    message = ResourceUtils
284:                            .getResourceString(FrameResources.SET_BACKGROUND_LABEL);
285:                    key = TextAttribute.BACKGROUND;
286:                }
287:                return createObjectDialogFactory(title, message, key,
288:                        StyleMenuItemSet.CHARACTER, colorNames, colors);
289:            }
290:
291:            private void createFontMenu() {
292:
293:                handleAddMenu(FrameResources.FONT);
294:
295:                String[] fonts = FontList.getFontList();
296:                MenuData[] mData = new MenuData[fonts.length];
297:                for (int i = 0; i < mData.length; i++) {
298:                    mData[i] = new MenuData(fonts[i]);
299:                }
300:
301:                new StyleMenuItemSet(TextAttribute.FAMILY, fonts, mData,
302:                        StyleMenuItemSet.CHARACTER).setTextPanel(fTextPanel);
303:            }
304:
305:            private void createFlushMenu() {
306:
307:                handleAddMenu(FrameResources.FLUSH);
308:
309:                Object[] values = { TextAttribute.FLUSH_LEADING,
310:                        TextAttribute.FLUSH_CENTER,
311:                        TextAttribute.FLUSH_TRAILING,
312:                        TextAttribute.FULLY_JUSTIFIED };
313:                MenuData[] mData = {
314:                        ResourceUtils.getMenuData(FrameResources.LEADING),
315:                        ResourceUtils.getMenuData(FrameResources.CENTER),
316:                        ResourceUtils.getMenuData(FrameResources.TRAILING),
317:                        ResourceUtils.getMenuData(FrameResources.JUSTIFIED) };
318:
319:                new StyleMenuItemSet(TextAttribute.LINE_FLUSH, values, mData,
320:                        MenuItemSet.PARAGRAPH).setTextPanel(fTextPanel);
321:            }
322:
323:            private void createKeymapMenu() {
324:
325:                handleAddMenu(FrameResources.KEYMAP);
326:
327:                KeyRemap[] values = { KeyRemap.getIdentityRemap(),
328:                        KeyRemap.getArabicTransliteration(),
329:                        KeyRemap.getHebrewTransliteration(),
330:                        KeyRemap.getIsraelNikud(), KeyRemap.getThaiKetmanee() };
331:                MenuData[] mData = {
332:                        ResourceUtils.getMenuData(FrameResources.DEFAULT),
333:                        ResourceUtils.getMenuData(FrameResources.ARABIC),
334:                        ResourceUtils.getMenuData(FrameResources.HEBREW),
335:                        ResourceUtils.getMenuData(FrameResources.ISRAEL_NIKUD),
336:                        ResourceUtils.getMenuData(FrameResources.THAI_KETMANEE) };
337:
338:                new KeymapMenuItemSet(values, mData).setTextPanel(fTextPanel);
339:            }
340:
341:            private void createBidiMenu() {
342:
343:                handleAddMenu(FrameResources.BIDI);
344:
345:                Object[] values = { null, TextAttribute.RUN_DIRECTION_LTR,
346:                        TextAttribute.RUN_DIRECTION_RTL };
347:                MenuData[] mData = {
348:                        ResourceUtils
349:                                .getMenuData(FrameResources.DEFAULT_DIRECTION),
350:                        ResourceUtils.getMenuData(FrameResources.LTR_DIRECTION),
351:                        ResourceUtils.getMenuData(FrameResources.RTL_DIRECTION), };
352:
353:                new StyleMenuItemSet(TextAttribute.RUN_DIRECTION, values,
354:                        mData, MenuItemSet.PARAGRAPH).setTextPanel(fTextPanel);
355:            }
356:
357:            private void createAboutMenu() {
358:
359:                handleAddMenu(FrameResources.ABOUT_MENU);
360:
361:                new DialogItem(ResourceUtils
362:                        .getMenuData(FrameResources.ABOUT_ITEM),
363:                        createAboutDialogFactory()).setTextPanel(fTextPanel);
364:            }
365:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.