Source Code Cross Referenced for MenuBarView.java in  » Swing-Library » jgoodies-looks » com » jgoodies » looks » demo » 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 » Swing Library » jgoodies looks » com.jgoodies.looks.demo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2001-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without 
005:         * modification, are permitted provided that the following conditions are met:
006:         * 
007:         *  o Redistributions of source code must retain the above copyright notice, 
008:         *    this list of conditions and the following disclaimer. 
009:         *     
010:         *  o Redistributions in binary form must reproduce the above copyright notice, 
011:         *    this list of conditions and the following disclaimer in the documentation 
012:         *    and/or other materials provided with the distribution. 
013:         *     
014:         *  o Neither the name of JGoodies Karsten Lentzsch nor the names of 
015:         *    its contributors may be used to endorse or promote products derived 
016:         *    from this software without specific prior written permission. 
017:         *     
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
020:         * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
021:         * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
022:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
023:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
024:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
025:         * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026:         * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
027:         * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
028:         * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
029:         */
030:
031:        package com.jgoodies.looks.demo;
032:
033:        import java.awt.event.ActionListener;
034:        import java.net.URL;
035:
036:        import javax.swing.*;
037:        import javax.swing.event.ChangeEvent;
038:        import javax.swing.event.ChangeListener;
039:
040:        import com.jgoodies.looks.Options;
041:        import com.jgoodies.looks.plastic.PlasticLookAndFeel;
042:        import com.jgoodies.looks.windows.WindowsLookAndFeel;
043:
044:        /**
045:         * Builds the menu bar and pull-down menus in the Simple Looks Demo. 
046:         * Demonstrates and tests different multi-platform issues.<p>
047:         * 
048:         * This class provides a couple of factory methods that create
049:         * menu items, check box menu items, and radio button menu items.
050:         * The full JGoodies Looks Demo overrides these methods to vend
051:         * components from the JGoodies UI framework that better handle
052:         * different platforms.
053:         *
054:         * @author Karsten Lentzsch
055:         * @version $Revision: 1.5 $
056:         */
057:        public class MenuBarView {
058:
059:            private static final String HTML_TEXT = "<html><b>Bold</b>, <i>Italics</i>, <tt>Typewriter</tt></html>";
060:
061:            /**
062:             * Builds, configures, and returns the menubar. Requests HeaderStyle, 
063:             * look-specific BorderStyles, and Plastic 3D hint from Launcher.
064:             */
065:            JMenuBar buildMenuBar(Settings settings,
066:                    ActionListener helpActionListener,
067:                    ActionListener aboutActionListener) {
068:
069:                JMenuBar bar = new JMenuBar();
070:                bar.putClientProperty(Options.HEADER_STYLE_KEY, settings
071:                        .getMenuBarHeaderStyle());
072:                bar.putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY,
073:                        settings.getMenuBarPlasticBorderStyle());
074:                bar.putClientProperty(WindowsLookAndFeel.BORDER_STYLE_KEY,
075:                        settings.getMenuBarWindowsBorderStyle());
076:                bar.putClientProperty(PlasticLookAndFeel.IS_3D_KEY, settings
077:                        .getMenuBar3DHint());
078:
079:                bar.add(buildFileMenu());
080:                bar.add(buildRadioMenu());
081:                bar.add(buildCheckMenu());
082:                bar.add(buildHtmlMenu());
083:                bar.add(buildAlignmentTestMenu());
084:                bar.add(buildHelpMenu(helpActionListener, aboutActionListener));
085:                return bar;
086:            }
087:
088:            /**
089:             * Builds and returns the file menu.
090:             */
091:            private JMenu buildFileMenu() {
092:                JMenuItem item;
093:
094:                JMenu menu = createMenu("File", 'F');
095:
096:                // Build a submenu that has the noIcons hint set.
097:                JMenu submenu = createMenu("New", 'N');
098:                submenu.putClientProperty(Options.NO_ICONS_KEY, Boolean.TRUE);
099:                submenu.add(createMenuItem("Project\u2026", 'P'));
100:                submenu.add(createMenuItem("Folder\u2026", 'F'));
101:                submenu.add(createMenuItem("Document\u2026", 'D', KeyStroke
102:                        .getKeyStroke("ctrl F8")));
103:                submenu.addSeparator();
104:                submenu.add(createMenuItem("No icon hint set", 'N', KeyStroke
105:                        .getKeyStroke("ctrl F9")));
106:
107:                menu.add(submenu);
108:                menu.addSeparator();
109:                item = createMenuItem("Close", 'C', KeyStroke
110:                        .getKeyStroke("ctrl F4"));
111:                menu.add(item);
112:                item = createMenuItem("Close All", 'o', KeyStroke
113:                        .getKeyStroke("ctrl shift F4"));
114:                menu.add(item);
115:                menu.addSeparator();
116:                item = createMenuItem("Save description.txt",
117:                        readImageIcon("save_edit.gif"), 'd', KeyStroke
118:                                .getKeyStroke("ctrl S"));
119:                item.setEnabled(false);
120:                menu.add(item);
121:                item = createMenuItem("Save description.txt As\u2026",
122:                        readImageIcon("saveas_edit.gif"), 'e');
123:                menu.add(item);
124:                item = createMenuItem("Save All", 'A', KeyStroke
125:                        .getKeyStroke("ctrl shift S"));
126:                item.setEnabled(false);
127:                menu.add(item);
128:                menu.addSeparator();
129:                item = createMenuItem("Print", readImageIcon("print.gif"), 'P',
130:                        KeyStroke.getKeyStroke("ctrl P"));
131:                menu.add(item);
132:                menu.addSeparator();
133:                menu.add(createMenuItem("1 WinXPMenuItemUI.java", '1'));
134:                menu.add(createMenuItem("2 WinXPUtils.java", '2'));
135:                menu.add(createMenuItem("3 WinXPBorders.java", '3'));
136:                menu.add(createMenuItem("4 WinXPLookAndFeel.java", '4'));
137:                if (!isQuitInOSMenu()) {
138:                    menu.addSeparator();
139:                    menu.add(createMenuItem("Exit", 'E'));
140:                }
141:                return menu;
142:            }
143:
144:            /**
145:             * Builds and returns a menu with different JRadioButtonMenuItems.
146:             */
147:            private JMenu buildRadioMenu() {
148:                JRadioButtonMenuItem item;
149:
150:                JMenu menu = createMenu("Radio", 'R');
151:
152:                // Default icon
153:                ButtonGroup group1 = new ButtonGroup();
154:                item = createRadioItem(true, false);
155:                group1.add(item);
156:                menu.add(item);
157:                item = createRadioItem(true, true);
158:                group1.add(item);
159:                menu.add(item);
160:
161:                menu.addSeparator();
162:
163:                item = createRadioItem(false, false);
164:                menu.add(item);
165:                item = createRadioItem(false, true);
166:                menu.add(item);
167:
168:                menu.addSeparator();
169:
170:                // Custom icon
171:                ButtonGroup group2 = new ButtonGroup();
172:                item = createRadioItem(true, false);
173:                item.setIcon(readImageIcon("pie_mode.png"));
174:                group2.add(item);
175:                menu.add(item);
176:                item = createRadioItem(true, true);
177:                item.setIcon(readImageIcon("bar_mode.png"));
178:                group2.add(item);
179:                menu.add(item);
180:
181:                menu.addSeparator();
182:
183:                item = createRadioItem(false, false);
184:                item.setIcon(readImageIcon("alphab_sort.png"));
185:                //item.setDisabledIcon(Utils.getIcon("alphab_sort_gray.png"));
186:                menu.add(item);
187:                item = createRadioItem(false, true);
188:                item.setIcon(readImageIcon("size_sort.png"));
189:                //item.setDisabledIcon(readImageIcon("size_sort_gray.png"));
190:                menu.add(item);
191:
192:                return menu;
193:            }
194:
195:            /**
196:             * Builds and returns a menu with different JCheckBoxMenuItems.
197:             */
198:            private JMenu buildCheckMenu() {
199:                JCheckBoxMenuItem item;
200:
201:                JMenu menu = createMenu("Check", 'C');
202:
203:                // Default icon
204:                menu.add(createCheckItem(true, false));
205:                menu.add(createCheckItem(true, true));
206:                menu.addSeparator();
207:                menu.add(createCheckItem(false, false));
208:                menu.add(createCheckItem(false, true));
209:
210:                menu.addSeparator();
211:
212:                // Custom icon
213:                item = createCheckItem(true, false);
214:                item.setIcon(readImageIcon("check.gif"));
215:                item.setSelectedIcon(readImageIcon("check_selected.gif"));
216:                menu.add(item);
217:                item = createCheckItem(true, true);
218:                item.setIcon(readImageIcon("check.gif"));
219:                item.setSelectedIcon(readImageIcon("check_selected.gif"));
220:                menu.add(item);
221:
222:                menu.addSeparator();
223:
224:                item = createCheckItem(false, false);
225:                item.setIcon(readImageIcon("check.gif"));
226:                item.setSelectedIcon(readImageIcon("check_selected.gif"));
227:                menu.add(item);
228:                item = createCheckItem(false, true);
229:                item.setIcon(readImageIcon("check.gif"));
230:                item.setSelectedIcon(readImageIcon("check_selected.gif"));
231:                item
232:                        .setDisabledSelectedIcon(readImageIcon("check_disabled_selected.gif"));
233:                menu.add(item);
234:
235:                return menu;
236:            }
237:
238:            /**
239:             * Builds and returns a menu with items that use a HTML text.
240:             */
241:            private JMenu buildHtmlMenu() {
242:                JMenu menu = createMenu("Styled", 'S');
243:
244:                menu.add(createSubmenu(HTML_TEXT));
245:                menu.add(createMenuItem(HTML_TEXT));
246:                menu.addSeparator();
247:                menu.add(new JRadioButtonMenuItem(HTML_TEXT, false));
248:                menu.add(new JRadioButtonMenuItem(HTML_TEXT, true));
249:                menu.addSeparator();
250:                menu.add(new JCheckBoxMenuItem(HTML_TEXT, true));
251:                menu.add(new JCheckBoxMenuItem(HTML_TEXT, false));
252:                return menu;
253:            }
254:
255:            /**
256:             * Builds and returns a menu with items that use a HTML text.
257:             */
258:            private JMenu buildAlignmentTestMenu() {
259:                JMenu menu = createMenu("Alignment", 'A');
260:
261:                menu.add(createMenuItem("Menu item"));
262:                menu.add(createMenuItem("Menu item with icon",
263:                        readImageIcon("refresh.gif")));
264:                menu.addSeparator();
265:                JMenu submenu = createSubmenu("Submenu");
266:                menu.add(submenu);
267:
268:                submenu = createSubmenu("Submenu with icon");
269:                submenu.setIcon(readImageIcon("refresh.gif"));
270:                menu.add(submenu);
271:
272:                return menu;
273:            }
274:
275:            /**
276:             * Builds and and returns the help menu.
277:             */
278:            private JMenu buildHelpMenu(ActionListener helpActionListener,
279:                    ActionListener aboutActionListener) {
280:
281:                JMenu menu = createMenu("Help", 'H');
282:
283:                JMenuItem item;
284:                item = createMenuItem("Help Contents",
285:                        readImageIcon("help.gif"), 'H');
286:                if (helpActionListener != null) {
287:                    item.addActionListener(helpActionListener);
288:                }
289:                menu.add(item);
290:                if (!isAboutInOSMenu()) {
291:                    menu.addSeparator();
292:                    item = createMenuItem("About", 'a');
293:                    item.addActionListener(aboutActionListener);
294:                    menu.add(item);
295:                }
296:
297:                return menu;
298:            }
299:
300:            // Factory Methods ********************************************************
301:
302:            protected JMenu createMenu(String text, char mnemonic) {
303:                JMenu menu = new JMenu(text);
304:                menu.setMnemonic(mnemonic);
305:                return menu;
306:            }
307:
308:            protected JMenuItem createMenuItem(String text) {
309:                return new JMenuItem(text);
310:            }
311:
312:            protected JMenuItem createMenuItem(String text, char mnemonic) {
313:                return new JMenuItem(text, mnemonic);
314:            }
315:
316:            protected JMenuItem createMenuItem(String text, char mnemonic,
317:                    KeyStroke key) {
318:                JMenuItem menuItem = new JMenuItem(text, mnemonic);
319:                menuItem.setAccelerator(key);
320:                return menuItem;
321:            }
322:
323:            protected JMenuItem createMenuItem(String text, Icon icon) {
324:                return new JMenuItem(text, icon);
325:            }
326:
327:            protected JMenuItem createMenuItem(String text, Icon icon,
328:                    char mnemonic) {
329:                JMenuItem menuItem = new JMenuItem(text, icon);
330:                menuItem.setMnemonic(mnemonic);
331:                return menuItem;
332:            }
333:
334:            protected JMenuItem createMenuItem(String text, Icon icon,
335:                    char mnemonic, KeyStroke key) {
336:                JMenuItem menuItem = createMenuItem(text, icon, mnemonic);
337:                menuItem.setAccelerator(key);
338:                return menuItem;
339:            }
340:
341:            protected JRadioButtonMenuItem createRadioButtonMenuItem(
342:                    String text, boolean selected) {
343:                return new JRadioButtonMenuItem(text, selected);
344:            }
345:
346:            protected JCheckBoxMenuItem createCheckBoxMenuItem(String text,
347:                    boolean selected) {
348:                return new JCheckBoxMenuItem(text, selected);
349:            }
350:
351:            // Subclass will override the following methods ***************************
352:
353:            /**
354:             * Checks and answers whether the quit action has been moved to an
355:             * operating system specific menu, e.g. the OS X application menu.
356:             *  
357:             * @return true if the quit action is in an OS-specific menu
358:             */
359:            protected boolean isQuitInOSMenu() {
360:                return false;
361:            }
362:
363:            /**
364:             * Checks and answers whether the about action has been moved to an
365:             * operating system specific menu, e.g. the OS X application menu.
366:             *  
367:             * @return true if the about action is in an OS-specific menu
368:             */
369:            protected boolean isAboutInOSMenu() {
370:                return false;
371:            }
372:
373:            // Higher Level Factory Methods *****************************************
374:
375:            /**
376:             * Creates and returns a JRadioButtonMenuItem
377:             * with the given enablement and selection state.
378:             */
379:            private JRadioButtonMenuItem createRadioItem(boolean enabled,
380:                    boolean selected) {
381:                JRadioButtonMenuItem item = createRadioButtonMenuItem(
382:                        getToggleLabel(enabled, selected), selected);
383:                item.setEnabled(enabled);
384:                item.addChangeListener(new ChangeListener() {
385:                    public void stateChanged(ChangeEvent e) {
386:                        JRadioButtonMenuItem source = (JRadioButtonMenuItem) e
387:                                .getSource();
388:                        source.setText(getToggleLabel(source.isEnabled(),
389:                                source.isSelected()));
390:                    }
391:                });
392:                return item;
393:            }
394:
395:            /**
396:             * Creates and returns a JCheckBoxMenuItem
397:             * with the given enablement and selection state.
398:             */
399:            private JCheckBoxMenuItem createCheckItem(boolean enabled,
400:                    boolean selected) {
401:                JCheckBoxMenuItem item = createCheckBoxMenuItem(getToggleLabel(
402:                        enabled, selected), selected);
403:                item.setEnabled(enabled);
404:                item.addChangeListener(new ChangeListener() {
405:                    public void stateChanged(ChangeEvent e) {
406:                        JCheckBoxMenuItem source = (JCheckBoxMenuItem) e
407:                                .getSource();
408:                        source.setText(getToggleLabel(source.isEnabled(),
409:                                source.isSelected()));
410:                    }
411:                });
412:                return item;
413:            }
414:
415:            /**
416:             *  Returns an appropriate label for the given enablement and selection state.
417:             */
418:            protected String getToggleLabel(boolean enabled, boolean selected) {
419:                String prefix = enabled ? "Enabled" : "Disabled";
420:                String suffix = selected ? "Selected" : "Deselected";
421:                return prefix + " and " + suffix;
422:            }
423:
424:            // Helper Code ************************************************************
425:
426:            /**
427:             * Looks up and returns an icon for the specified filename suffix.
428:             */
429:            private ImageIcon readImageIcon(String filename) {
430:                URL url = getClass()
431:                        .getResource("resources/images/" + filename);
432:                return new ImageIcon(url);
433:            }
434:
435:            /**
436:             * Creates and returns a submenu labeled with the given text.
437:             */
438:            private JMenu createSubmenu(String text) {
439:                JMenu submenu = new JMenu(text);
440:                submenu.add(new JMenuItem("Item 1"));
441:                submenu.add(new JMenuItem("Item 2"));
442:                submenu.add(new JMenuItem("Item 3"));
443:                return submenu;
444:            }
445:
446:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.