Source Code Cross Referenced for MenuItem.java in  » XML-UI » xmlgui » org » beryl » gui » widgets » 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 » XML UI » xmlgui » org.beryl.gui.widgets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Beryl - A web platform based on XML, XSLT and Java
003:         * This file is part of the Beryl XML GUI
004:         *
005:         * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107  USA
020:         */
021:
022:        package org.beryl.gui.widgets;
023:
024:        import java.awt.Component;
025:        import java.awt.event.ActionEvent;
026:        import java.awt.event.ActionListener;
027:        import java.awt.event.InputEvent;
028:        import java.awt.event.KeyEvent;
029:
030:        import javax.swing.JMenuItem;
031:        import javax.swing.KeyStroke;
032:
033:        import org.beryl.gui.GUIEvent;
034:        import org.beryl.gui.GUIEventListener;
035:        import org.beryl.gui.GUIException;
036:        import org.beryl.gui.ImageIconFactory;
037:        import org.beryl.gui.Widget;
038:        import org.beryl.gui.WidgetInfo;
039:
040:        public class MenuItem extends Widget {
041:            protected static WidgetInfo menuItemInfo = null;
042:            private JMenuItem menuItem = null;
043:
044:            static {
045:                menuItemInfo = new WidgetInfo(MenuItem.class, widgetInfo);
046:                menuItemInfo.addProperty("accelerator", "istring", "");
047:                menuItemInfo.addProperty("mnemonic", "istring", "");
048:                menuItemInfo.addProperty("text", "istring", "");
049:                menuItemInfo.addEvent("selected");
050:                menuItemInfo.setSupportsAnchor(false);
051:                try {
052:                    menuItemInfo.addProperty("icon", "icon", ImageIconFactory
053:                            .getIcon("broken"));
054:                } catch (Exception e) {
055:                    throw new RuntimeException(e);
056:                }
057:            };
058:
059:            public MenuItem(Widget parent, String name) throws GUIException {
060:                super (parent, name);
061:                menuItem = new JMenuItem();
062:            }
063:
064:            public void addListener(String event, final String name,
065:                    final GUIEventListener listener) throws GUIException {
066:                if ("selected".equals(event)) {
067:                    menuItem.addActionListener(new ActionListener() {
068:                        public void actionPerformed(ActionEvent e) {
069:                            listener.eventOccured(new GUIEvent(MenuItem.this ,
070:                                    name, e));
071:                        }
072:                    });
073:                } else {
074:                    super .addListener(event, name, listener);
075:                }
076:            }
077:
078:            /** 
079:             * Construct a keystroke from a string
080:             */
081:            private KeyStroke parseKeyStroke(String keyStroke)
082:                    throws GUIException {
083:                if (keyStroke == null)
084:                    return null;
085:
086:                int modifiers = 0;
087:                int index = keyStroke.indexOf('+');
088:                if (index != -1) {
089:                    for (int i = 0; i < index; i++) {
090:                        switch (Character.toUpperCase(keyStroke.charAt(i))) {
091:                        case 'A':
092:                            modifiers |= InputEvent.ALT_MASK;
093:                            break;
094:                        case 'C':
095:                            modifiers |= InputEvent.CTRL_MASK;
096:                            break;
097:                        case 'M':
098:                            modifiers |= InputEvent.META_MASK;
099:                            break;
100:                        case 'S':
101:                            modifiers |= InputEvent.SHIFT_MASK;
102:                            break;
103:                        }
104:                    }
105:                }
106:                String key = keyStroke.substring(index + 1);
107:                if (key.length() == 1) {
108:                    char ch = Character.toUpperCase(key.charAt(0));
109:                    if (modifiers == 0)
110:                        return KeyStroke.getKeyStroke(ch);
111:                    else
112:                        return KeyStroke.getKeyStroke(ch, modifiers);
113:                } else if (key.length() == 0) {
114:                    throw new GUIException("Invalid key stroke: " + keyStroke);
115:                } else {
116:                    try {
117:                        int ch = KeyEvent.class.getField("VK_".concat(key))
118:                                .getInt(null);
119:                        return KeyStroke.getKeyStroke(ch, modifiers);
120:                    } catch (Exception e) {
121:                        throw new GUIException("Invalid key stroke: "
122:                                + keyStroke);
123:                    }
124:                }
125:            }
126:
127:            public void setProperty(String name, Object value)
128:                    throws GUIException {
129:                if ("accelerator".equals(name)) {
130:                    if (value != null && !value.equals("")) {
131:                        KeyStroke stroke = parseKeyStroke((String) value);
132:                        menuItem.setAccelerator(stroke);
133:                    }
134:                } else if (name.equals("mnemonic")) {
135:                    if (((String) value).length() > 0)
136:                        menuItem.setMnemonic(((String) value).charAt(0));
137:                    else
138:                        menuItem.setMnemonic('\0');
139:                } else {
140:                    super .setProperty(name, value);
141:                }
142:            }
143:
144:            public Component getWidget() {
145:                return menuItem;
146:            }
147:
148:            public WidgetInfo getWidgetInfo() {
149:                return menuItemInfo;
150:            }
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.