Source Code Cross Referenced for WingMenuItem.java in  » Web-Framework » wingS » com » javujavu » javux » wings » 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 » Web Framework » wingS » com.javujavu.javux.wings 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *	Javu WingS - Lightweight Java Component Set
003:         *	Copyright (c) 2005-2007 Krzysztof A. Sadlocha
004:         *	e-mail: ksadlocha@programics.com
005:         *
006:         *	This library is free software; you can redistribute it and/or
007:         *	modify it under the terms of the GNU Lesser General Public
008:         *	License as published by the Free Software Foundation; either
009:         *	version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *	This library is distributed in the hope that it will be useful,
012:         *	but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *	Lesser General Public License for more details.
015:         *
016:         *	You should have received a copy of the GNU Lesser General Public
017:         *	License along with this library; if not, write to the Free Software
018:         *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         */
020:
021:        package com.javujavu.javux.wings;
022:
023:        import java.awt.AWTEventMulticaster;
024:        import java.awt.ItemSelectable;
025:        import java.awt.Rectangle;
026:        import java.awt.event.ActionEvent;
027:        import java.awt.event.ActionListener;
028:        import java.awt.event.ItemEvent;
029:        import java.awt.event.ItemListener;
030:        import java.awt.event.KeyEvent;
031:
032:        /**
033:         * <code>WingMenuItem</code> implements an item in a menu.
034:         * It can be used as a simple menu item, checkbox menu item,
035:         * radio button menu item and menu separator.
036:         * <br>
037:         * <br>
038:         * <b>This class is thread safe.</b>
039:         **/
040:        public class WingMenuItem implements  ItemSelectable, Shortcut,
041:                WingConst {
042:            protected/*final*/int kind;
043:            protected/*final*/WingMenu menu;
044:
045:            protected ActionListener actionListener;
046:            protected ItemListener itemListener;
047:            protected Object label;
048:            protected boolean enabled;
049:            protected boolean selected;
050:            protected Object tooltip;
051:            protected Object userData;
052:            protected MenuRadioGroup group;
053:            protected WingMenu owner;
054:            protected int shortcutCode;
055:            protected int shortcutModifiers;
056:            protected Rectangle bounds;
057:
058:            public WingMenuItem(Object label) {
059:                this (label, WingMenu.NORMAL);
060:            }
061:
062:            public WingMenuItem(Object label, int kind) {
063:                this (label, kind, KeyEvent.VK_UNDEFINED, 0);
064:            }
065:
066:            public WingMenuItem(Object label, int kind, int shortcutCode,
067:                    int shortcutModifiers) {
068:                this (label, kind, shortcutCode, shortcutModifiers, null);
069:            }
070:
071:            protected WingMenuItem(Object label, int kind, int shortcutCode,
072:                    int shortcutModifiers, WingMenu menu) {
073:                this .label = label;
074:                this .kind = kind;
075:                this .shortcutCode = shortcutCode;
076:                this .shortcutModifiers = shortcutModifiers;
077:                this .menu = menu;
078:                selected = false;
079:                enabled = true;
080:                bounds = new Rectangle();
081:            }
082:
083:            public void addActionListener(ActionListener l) {
084:                actionListener = AWTEventMulticaster.add(actionListener, l);
085:            }
086:
087:            public void removeActionListener(ActionListener l) {
088:                actionListener = AWTEventMulticaster.remove(actionListener, l);
089:            }
090:
091:            public void addItemListener(ItemListener l) {
092:                itemListener = AWTEventMulticaster.add(itemListener, l);
093:            }
094:
095:            public void removeItemListener(ItemListener l) {
096:                itemListener = AWTEventMulticaster.remove(itemListener, l);
097:            }
098:
099:            public Object[] getSelectedObjects() {
100:                if (selected) {
101:                    Object[] items = { label };
102:                    return items;
103:                }
104:                return null;
105:            }
106:
107:            public boolean isSelected() {
108:                return selected;
109:            }
110:
111:            public void setSelected(boolean selected) {
112:                if (this .selected == selected)
113:                    return;
114:                this .selected = selected;
115:                MenuRadioGroup group = this .group;
116:                if (group != null)
117:                    group.setSelected(this , selected);
118:                repaint();
119:            }
120:
121:            public void setTooltip(Object tooltip) {
122:                this .tooltip = tooltip;
123:            }
124:
125:            public void setEnabled(boolean enabled) {
126:                this .enabled = enabled;
127:                repaint();
128:            }
129:
130:            public void setLabel(Object label) {
131:                this .label = label;
132:                WingMenu owner = this .owner;
133:                if (owner != null)
134:                    owner.revalidateAndRepaint();
135:            }
136:
137:            public Object getLabel() {
138:                return label;
139:            }
140:
141:            public WingMenu getSubMenu() {
142:                return menu;
143:            }
144:
145:            public int getKind() {
146:                return kind;
147:            }
148:
149:            public WingMenu getOwner() {
150:                return owner;
151:            }
152:
153:            public Object getUserData() {
154:                return userData;
155:            }
156:
157:            public void setUserData(Object userData) {
158:                this .userData = userData;
159:            }
160:
161:            private void repaint() {
162:                WingMenu owner = this .owner;
163:                if (owner != null) {
164:                    owner.repaintVisible(bounds.x, bounds.y, bounds.width,
165:                            bounds.height);
166:                }
167:            }
168:
169:            protected void fireAction() {
170:                if (kind == SEPARATOR || kind == MENU)
171:                    return;
172:
173:                Object item = this .label;
174:                WingMenu owner = this .owner;
175:
176:                if (kind == CHECKBOX || kind == RADIO) {
177:                    boolean oldsel = selected;
178:                    setSelected((group == null) ? !selected : true);
179:
180:                    if (oldsel == selected)
181:                        return;
182:
183:                    ItemListener l2 = itemListener;
184:                    ItemEvent e2 = new ItemEvent(this ,
185:                            ItemEvent.ITEM_STATE_CHANGED, item,
186:                            (selected) ? ItemEvent.SELECTED
187:                                    : ItemEvent.DESELECTED);
188:                    if (l2 != null)
189:                        l2.itemStateChanged(e2);
190:                    if (owner != null) {
191:                        owner.wingProcessItemEvent(e2);
192:                    }
193:                }
194:                ActionListener l = actionListener;
195:                ActionEvent e = new ActionEvent(this ,
196:                        ActionEvent.ACTION_PERFORMED, (item != null) ? item
197:                                .toString() : null);
198:                if (l != null)
199:                    l.actionPerformed(e);
200:                if (owner != null)
201:                    owner.wingProcessActionEvent(e);
202:            }
203:
204:            public int getShortcutCode() {
205:                return shortcutCode;
206:            }
207:
208:            public int getShortcutModifiers() {
209:                return shortcutModifiers;
210:            }
211:
212:            public void processShortcut(KeyEvent e) {
213:                WingMenu owner = this .owner;
214:                if (enabled && owner != null) {
215:                    owner.itemShortcut(this , e);
216:                }
217:            }
218:
219:            public String getShortcutText() {
220:                if (shortcutCode == KeyEvent.VK_UNDEFINED)
221:                    return null;
222:                StringBuffer s = new StringBuffer();
223:                if ((shortcutModifiers & KeyEvent.CTRL_MASK) != 0)
224:                    s.append("Ctrl+");
225:                if ((shortcutModifiers & KeyEvent.ALT_MASK) != 0)
226:                    s.append("Alt+");
227:                if ((shortcutModifiers & KeyEvent.SHIFT_MASK) != 0)
228:                    s.append("Shift+");
229:                s.append(KeyEvent.getKeyText(shortcutCode));
230:                return s.toString();
231:            }
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.