Source Code Cross Referenced for MenuUtils.java in  » Report » datavision-1.1.0 » jimm » datavision » gui » 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 » Report » datavision 1.1.0 » jimm.datavision.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package jimm.datavision.gui;
002:
003:        import jimm.datavision.PaperFormat;
004:        import jimm.util.I18N;
005:        import jimm.util.StringUtils;
006:        import java.awt.Font;
007:        import java.awt.event.*;
008:        import java.util.List;
009:        import java.util.Iterator;
010:        import javax.swing.*;
011:
012:        /**
013:         * Menu creation utilities.
014:         *
015:         * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
016:         */
017:        public class MenuUtils {
018:
019:            public static JMenu readMenu(String key) {
020:                JMenu menu = new JMenu(I18N.get(I18N.MENU_FILE_PREFIX, key));
021:                setKeys(menu, key); // Read .keys property; set mnemonic
022:                return menu;
023:            }
024:
025:            public static JMenuItem readItem(ActionListener listener,
026:                    String key, Font font) {
027:                JMenuItem item = new JMenuItem(I18N.get(I18N.MENU_FILE_PREFIX,
028:                        key));
029:                modifyItem(item, listener, key, font);
030:                return item;
031:            }
032:
033:            public static JCheckBoxMenuItem readCheckboxItem(
034:                    ActionListener listener, String key, Font font) {
035:                JCheckBoxMenuItem item = new JCheckBoxMenuItem(I18N.get(
036:                        I18N.MENU_FILE_PREFIX, key));
037:                modifyItem(item, listener, key, font);
038:                return item;
039:            }
040:
041:            protected static void modifyItem(JMenuItem item,
042:                    ActionListener listener, String key, Font font) {
043:                if (listener != null)
044:                    item.addActionListener(listener);
045:                if (font != null)
046:                    item.setFont(font);
047:
048:                String val = I18N.getNullIfMissing(I18N.MENU_FILE_PREFIX, key
049:                        + ".action");
050:                if (val != null && val.length() > 0)
051:                    item.setActionCommand(val);
052:
053:                val = I18N.getNullIfMissing(I18N.MENU_FILE_PREFIX, key
054:                        + ".enabled");
055:                if (val != null
056:                        && val.length() > 0
057:                        && ("false".equalsIgnoreCase(val) || "no"
058:                                .equalsIgnoreCase(val)))
059:                    item.setEnabled(false);
060:
061:                setKeys(item, key); // Read .keys property; set mnemonic and accel
062:            }
063:
064:            /**
065:             * Adds a single item to a menu.
066:             *
067:             * @param listener action listener for item; may be <code>null</code>
068:             * @param menu the menu
069:             * @param key the menu properties file lookup key
070:             */
071:            public static JMenuItem addToMenu(ActionListener listener,
072:                    JMenu menu, String key) {
073:                return addToMenu(listener, menu, key, null);
074:            }
075:
076:            /**
077:             * Adds a single item to a menu.
078:             *
079:             * @param listener action listener for item; may be <code>null</code>
080:             * @param menu the menu
081:             * @param key the menu properties file lookup key
082:             * @param font font; may be <code>null</code>
083:             */
084:            public static JMenuItem addToMenu(ActionListener listener,
085:                    JMenu menu, String key, Font font) {
086:                JMenuItem item = readItem(listener, key, font);
087:                menu.add(item);
088:                return item;
089:            }
090:
091:            /**
092:             * Adds a single item to a popup menu.
093:             *
094:             * @param listener action listener for item; may be <code>null</code>
095:             * @param menu the menu
096:             * @param key the menu properties file lookup key
097:             */
098:            public static JMenuItem addToMenu(ActionListener listener,
099:                    JPopupMenu menu, String key) {
100:                return addToMenu(listener, menu, key, null);
101:            }
102:
103:            /**
104:             * Adds a single item to a popup menu.
105:             *
106:             * @param listener action listener for item; may be <code>null</code>
107:             * @param menu the menu
108:             * @param key the menu properties file lookup key
109:             * @param font font; may be <code>null</code>
110:             */
111:            public static JMenuItem addToMenu(ActionListener listener,
112:                    JPopupMenu menu, String key, Font font) {
113:                JMenuItem item = readItem(listener, key, font);
114:                menu.add(item);
115:                return item;
116:            }
117:
118:            /**
119:             * Adds a single checkbox item to a menu.
120:             *
121:             * @param listener action listener for item; may be <code>null</code>
122:             * @param menu the menu
123:             * @param key the menu properties file lookup key
124:             * @param font font; may be <code>null</code>
125:             */
126:            public static JCheckBoxMenuItem addCheckboxToMenu(
127:                    ActionListener listener, JMenu menu, String key, Font font) {
128:                JCheckBoxMenuItem item = readCheckboxItem(listener, key, font);
129:                menu.add(item);
130:                return item;
131:            }
132:
133:            /**
134:             * Adds a single checkbox item to a popup menu.
135:             *
136:             * @param listener action listener for item; may be <code>null</code>
137:             * @param menu the menu
138:             * @param key the menu properties file lookup key
139:             * @param font font; may be <code>null</code>
140:             */
141:            public static JCheckBoxMenuItem addCheckboxToMenu(
142:                    ActionListener listener, JPopupMenu menu, String key,
143:                    Font font) {
144:                JCheckBoxMenuItem item = readCheckboxItem(listener, key, font);
145:                menu.add(item);
146:                return item;
147:            }
148:
149:            /**
150:             * Adds an action to a menu.
151:             *
152:             * @param menu the menu
153:             * @param action the action
154:             * @param key the menu properties file lookup key
155:             */
156:            public static JMenuItem addToMenu(JMenu menu, Action action,
157:                    String key) {
158:                JMenuItem item = menu.add(action);
159:                setKeys(item, key); // Read .keys property; set mnemonic and accel
160:                return item;
161:            }
162:
163:            protected static void setKeys(JMenuItem item, String key) {
164:                String keys = I18N.getNullIfMissing(I18N.MENU_FILE_PREFIX, key
165:                        + ".keys");
166:                if (keys == null)
167:                    return;
168:
169:                List split = StringUtils.split(keys, " ");
170:
171:                if (split.size() >= 1) { // Mnemonic key
172:                    key = (String) split.get(0);
173:                    item.setMnemonic((int) key.charAt(0));
174:                }
175:
176:                if (split.size() >= 2) { // Accelerator key
177:                    key = (String) split.get(1);
178:                    int stroke = (int) key.charAt(0);
179:                    int mask = ActionEvent.CTRL_MASK;
180:                    if ("DEL".equals(key)) {
181:                        stroke = KeyEvent.VK_DELETE;
182:                        mask = 0;
183:                    }
184:                    item.setAccelerator(KeyStroke.getKeyStroke(stroke, mask));
185:                }
186:            }
187:
188:            /**
189:             * Returns a new align menu.
190:             *
191:             * @param listener action listener for item; may be <code>null</code>
192:             * @param font font; may be <code>null</code>
193:             * @return a new menu
194:             */
195:            public static JMenu buildAlignMenu(ActionListener listener,
196:                    Font font) {
197:                JMenu menu = readMenu("Align.menu");
198:
199:                MenuUtils.addToMenu(listener, menu, "Align.menu_tops", font);
200:                MenuUtils.addToMenu(listener, menu, "Align.menu_middles", font);
201:                MenuUtils.addToMenu(listener, menu, "Align.menu_bottoms", font);
202:                MenuUtils.addToMenu(listener, menu, "Align.menu_lefts", font);
203:                MenuUtils.addToMenu(listener, menu, "Align.menu_centers", font);
204:                MenuUtils.addToMenu(listener, menu, "Align.menu_rights", font);
205:                MenuUtils.addToMenu(listener, menu, "Align.menu_snap", font);
206:
207:                return menu;
208:            }
209:
210:            /**
211:             * Returns a new size menu.
212:             *
213:             * @param listener action listener for item; may be <code>null</code>
214:             * @param font font; may be <code>null</code>
215:             * @return a new menu
216:             */
217:            public static JMenu buildSizeMenu(ActionListener listener, Font font) {
218:                JMenu menu = readMenu("Size.menu");
219:
220:                MenuUtils.addToMenu(listener, menu, "Size.menu_same_width",
221:                        font);
222:                MenuUtils.addToMenu(listener, menu, "Size.menu_same_height",
223:                        font);
224:                MenuUtils
225:                        .addToMenu(listener, menu, "Size.menu_same_size", font);
226:
227:                return menu;
228:            }
229:
230:            /**
231:             * Returns a new paper size menu.
232:             *
233:             * @param listener action button listener for item; may be <code>null</code>
234:             * @param currChoice current paper choice (its orientation and name will be
235:             * pre-selected)
236:             * @param orientationGroup a radio button group for orientations
237:             * @param nameGroup a radio button group for names
238:             * @return a new menu
239:             */
240:            public static JMenu buildPaperSizeMenu(ActionListener listener,
241:                    PaperFormat currChoice, ButtonGroup orientationGroup,
242:                    ButtonGroup nameGroup) {
243:                JMenu menu = readMenu("MenuUtils.menu_paper_size");
244:
245:                JRadioButtonMenuItem item = null;
246:
247:                // Portrait
248:                String key = "MenuUtils.menu_paper_size_portrait";
249:                String str = I18N.get(I18N.MENU_FILE_PREFIX, key);
250:                item = new JRadioButtonMenuItem(str);
251:
252:                String action = I18N.getNullIfMissing(I18N.MENU_FILE_PREFIX,
253:                        key + ".action");
254:                if (action != null && action.length() > 0)
255:                    item.setActionCommand(action);
256:
257:                orientationGroup.add(item);
258:                if (listener != null)
259:                    item.addActionListener(listener);
260:                if (currChoice.getOrientation() == PaperFormat.PORTRAIT)
261:                    item.setSelected(true);
262:                menu.add(item);
263:
264:                // Landscape
265:                key = "MenuUtils.menu_paper_size_landscape";
266:                str = I18N.get(I18N.MENU_FILE_PREFIX, key);
267:                item = new JRadioButtonMenuItem(str);
268:
269:                action = I18N.getNullIfMissing(I18N.MENU_FILE_PREFIX, key
270:                        + ".action");
271:                if (action != null && action.length() > 0)
272:                    item.setActionCommand(action);
273:
274:                orientationGroup.add(item);
275:                if (listener != null)
276:                    item.addActionListener(listener);
277:                if (currChoice.getOrientation() == PaperFormat.LANDSCAPE)
278:                    item.setSelected(true);
279:                menu.add(item);
280:
281:                menu.addSeparator();
282:
283:                // Paper sizes
284:                for (Iterator iter = PaperFormat.names(); iter.hasNext();) {
285:                    String name = (String) iter.next();
286:                    item = new JRadioButtonMenuItem(name);
287:                    nameGroup.add(item);
288:                    if (listener != null)
289:                        item.addActionListener(listener);
290:
291:                    if (name.equals(currChoice.getName()))
292:                        item.setSelected(true);
293:
294:                    menu.add(item);
295:                }
296:
297:                return menu;
298:            }
299:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.