Source Code Cross Referenced for CheckboxMenuItem.java in  » Apache-Harmony-Java-SE » java-package » java » awt » 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 » Apache Harmony Java SE » java package » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package java.awt;
019:
020:        import java.awt.event.ItemEvent;
021:        import java.awt.event.ItemListener;
022:        import java.util.EventListener;
023:        import javax.accessibility.Accessible;
024:        import javax.accessibility.AccessibleAction;
025:        import javax.accessibility.AccessibleContext;
026:        import javax.accessibility.AccessibleRole;
027:        import javax.accessibility.AccessibleValue;
028:
029:        public class CheckboxMenuItem extends MenuItem implements 
030:                ItemSelectable, Accessible {
031:            private static final long serialVersionUID = 6190621106981774043L;
032:
033:            private final AWTListenerList<ItemListener> itemListeners = new AWTListenerList<ItemListener>();
034:
035:            private boolean checked;
036:
037:            protected class AccessibleAWTCheckboxMenuItem extends
038:                    AccessibleAWTMenuItem implements  AccessibleAction,
039:                    AccessibleValue {
040:                private static final long serialVersionUID = -1122642964303476L;
041:
042:                @Override
043:                public boolean doAccessibleAction(int i) {
044:                    return false; // do nothing
045:                }
046:
047:                @Override
048:                public AccessibleAction getAccessibleAction() {
049:                    return this ;
050:                }
051:
052:                @Override
053:                public int getAccessibleActionCount() {
054:                    return 0; // no accessible actions
055:                }
056:
057:                @Override
058:                public String getAccessibleActionDescription(int i) {
059:                    return null;
060:                }
061:
062:                @Override
063:                public AccessibleRole getAccessibleRole() {
064:                    return AccessibleRole.CHECK_BOX;
065:                }
066:
067:                @Override
068:                public AccessibleValue getAccessibleValue() {
069:                    return this ;
070:                }
071:
072:                @Override
073:                public Number getCurrentAccessibleValue() {
074:                    return null;
075:                }
076:
077:                @Override
078:                public Number getMaximumAccessibleValue() {
079:                    return null;
080:                }
081:
082:                @Override
083:                public Number getMinimumAccessibleValue() {
084:                    return null;
085:                }
086:
087:                @Override
088:                public boolean setCurrentAccessibleValue(Number n) {
089:                    return false;
090:                }
091:            }
092:
093:            public CheckboxMenuItem() throws HeadlessException {
094:                super ();
095:            }
096:
097:            public CheckboxMenuItem(String label) throws HeadlessException {
098:                this (label, false);
099:            }
100:
101:            public CheckboxMenuItem(String label, boolean state)
102:                    throws HeadlessException {
103:                super (label);
104:                toolkit.lockAWT();
105:                try {
106:                    checked = state;
107:                } finally {
108:                    toolkit.unlockAWT();
109:                }
110:            }
111:
112:            public boolean getState() {
113:                toolkit.lockAWT();
114:                try {
115:                    return checked;
116:                } finally {
117:                    toolkit.unlockAWT();
118:                }
119:            }
120:
121:            @Override
122:            public void addNotify() {
123:                toolkit.lockAWT();
124:                try {
125:                    super .addNotify();
126:                } finally {
127:                    toolkit.unlockAWT();
128:                }
129:            }
130:
131:            @Override
132:            public AccessibleContext getAccessibleContext() {
133:                toolkit.lockAWT();
134:                try {
135:                    return super .getAccessibleContext();
136:                } finally {
137:                    toolkit.unlockAWT();
138:                }
139:            }
140:
141:            @Override
142:            public String paramString() {
143:                /*
144:                 * The format of paramString is based on 1.5 release behavior which can
145:                 * be revealed using the following code:
146:                 * 
147:                 * CheckboxMenuItem obj = new CheckboxMenuItem("Label", true);
148:                 * System.out.println(obj.toString());
149:                 */
150:                toolkit.lockAWT();
151:                try {
152:                    return super .paramString() + (checked ? ",checked" : ""); //$NON-NLS-1$ //$NON-NLS-2$
153:                } finally {
154:                    toolkit.unlockAWT();
155:                }
156:            }
157:
158:            public Object[] getSelectedObjects() {
159:                toolkit.lockAWT();
160:                try {
161:                    return checked ? new Object[] { getLabel() } : null;
162:                } finally {
163:                    toolkit.unlockAWT();
164:                }
165:            }
166:
167:            public void setState(boolean b) {
168:                toolkit.lockAWT();
169:                try {
170:                    checked = b;
171:                } finally {
172:                    toolkit.unlockAWT();
173:                }
174:            }
175:
176:            @SuppressWarnings("unchecked")
177:            @Override
178:            public <T extends EventListener> T[] getListeners(
179:                    Class<T> listenerType) {
180:                if (ItemListener.class.isAssignableFrom(listenerType)) {
181:                    return (T[]) getItemListeners();
182:                }
183:                return super .getListeners(listenerType);
184:            }
185:
186:            public void addItemListener(ItemListener l) {
187:                itemListeners.addUserListener(l);
188:            }
189:
190:            public void removeItemListener(ItemListener l) {
191:                itemListeners.removeUserListener(l);
192:            }
193:
194:            public ItemListener[] getItemListeners() {
195:                return itemListeners.getUserListeners(new ItemListener[0]);
196:            }
197:
198:            @Override
199:            protected void processEvent(AWTEvent e) {
200:                if (toolkit.eventTypeLookup.getEventMask(e) == AWTEvent.ITEM_EVENT_MASK) {
201:                    processItemEvent((ItemEvent) e);
202:                } else {
203:                    super .processEvent(e);
204:                }
205:            }
206:
207:            protected void processItemEvent(ItemEvent e) {
208:                for (ItemListener listener : itemListeners.getUserListeners()) {
209:                    switch (e.getID()) {
210:                    case ItemEvent.ITEM_STATE_CHANGED:
211:                        listener.itemStateChanged(e);
212:                        break;
213:                    }
214:                }
215:            }
216:
217:            @Override
218:            AccessibleContext createAccessibleContext() {
219:                return new AccessibleAWTCheckboxMenuItem();
220:            }
221:
222:            @Override
223:            void itemSelected(long when, int modifiers) {
224:                checked = !checked;
225:                super .itemSelected(when, modifiers);
226:            }
227:
228:            @Override
229:            AWTEvent createEvent(long when, int modifiers) {
230:                int state = checked ? ItemEvent.SELECTED : ItemEvent.DESELECTED;
231:                return new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
232:                        getLabel(), state);
233:            }
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.