Source Code Cross Referenced for AccessibleJComponent_MultithreadedTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » 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 » javax package » javax.swing 
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:         * @author Alexander T. Simbirtsev
019:         * @version $Revision$
020:         * Created on 07.10.2004
021:
022:         */package javax.swing;
023:
024:        import java.awt.event.FocusEvent;
025:        import java.awt.event.FocusListener;
026:        import java.lang.reflect.InvocationTargetException;
027:        import javax.accessibility.AccessibleContext;
028:        import javax.accessibility.AccessibleState;
029:
030:        public class AccessibleJComponent_MultithreadedTest extends
031:                BasicSwingTestCase {
032:            protected JComponent panel;
033:
034:            protected JFrame frame;
035:
036:            protected JComponent.AccessibleJComponent aContext;
037:
038:            protected class ConcreteFocusListener implements  FocusListener {
039:                public boolean state = false;
040:
041:                public void focusGained(final FocusEvent arg0) {
042:                    state = true;
043:                }
044:
045:                public void focusLost(final FocusEvent arg0) {
046:                    state = true;
047:                }
048:            };
049:
050:            protected class SynchronizedPropertyListener extends
051:                    PropertyChangeController {
052:                private static final long serialVersionUID = 1L;
053:
054:                public final Object lock = new Object();
055:            }
056:
057:            /*
058:             * @see TestCase#setUp()
059:             */
060:            @Override
061:            protected void setUp() throws Exception {
062:                super .setUp();
063:                frame = new JFrame();
064:                panel = new JPanel();
065:                aContext = (JComponent.AccessibleJComponent) panel
066:                        .getAccessibleContext();
067:            }
068:
069:            @Override
070:            protected void tearDown() throws Exception {
071:                panel = null;
072:                aContext = null;
073:                if (frame != null) {
074:                    frame.dispose();
075:                    frame = null;
076:                }
077:                super .tearDown();
078:            }
079:
080:            protected void waitListener(
081:                    final SynchronizedPropertyListener listener) {
082:                synchronized (listener.lock) {
083:                    if (!listener.isChanged()) {
084:                        try {
085:                            listener.lock.wait(1000);
086:                        } catch (InterruptedException e) {
087:                            fail(e.getMessage());
088:                        }
089:                    }
090:                }
091:            }
092:
093:            /*
094:             * Class under test for void removePropertyChangeListener(PropertyChangeListener)
095:             */
096:            @SuppressWarnings("deprecation")
097:            public void testRemovePropertyChangeListenerPropertyChangeListener()
098:                    throws InterruptedException, InvocationTargetException {
099:                SynchronizedPropertyListener listener1 = new SynchronizedPropertyListener();
100:                SynchronizedPropertyListener listener2 = new SynchronizedPropertyListener();
101:                aContext.addPropertyChangeListener(listener1);
102:                JComponent button1 = new JPanel();
103:                JComponent button2 = new JPanel();
104:                panel.add(button1);
105:                waitListener(listener1);
106:                listener1.checkLastPropertyFired(aContext,
107:                        AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, null,
108:                        button1.getAccessibleContext());
109:                listener1.reset();
110:                aContext.addPropertyChangeListener(listener2);
111:                aContext.removePropertyChangeListener(listener1);
112:                panel.add(button2);
113:                waitListener(listener2);
114:                assertFalse(listener1.isChanged());
115:                listener2.checkLastPropertyFired(aContext,
116:                        AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, null,
117:                        button2.getAccessibleContext());
118:                listener1.reset();
119:                listener2.reset();
120:                ConcreteFocusListener focusListener = new ConcreteFocusListener();
121:                AccessibleContext bContext = button1.getAccessibleContext();
122:                bContext.addPropertyChangeListener(listener1);
123:                frame.getContentPane().add(panel);
124:                panel.add(button2);
125:                button1.addFocusListener(focusListener);
126:                listener1.reset();
127:                frame.pack();
128:                frame.show();
129:                SwingWaitTestCase.requestFocusInWindowForComponent(button1);
130:                listener1.checkLastPropertyFired(
131:                        button1.getAccessibleContext(),
132:                        AccessibleContext.ACCESSIBLE_STATE_PROPERTY, null,
133:                        AccessibleState.FOCUSED);
134:                listener1.reset();
135:                bContext.removePropertyChangeListener(listener1);
136:                SwingWaitTestCase.requestFocusInWindowForComponent(button2);
137:                assertFalse(listener1.isChanged());
138:            }
139:
140:            /*
141:             * Class under test for void addPropertyChangeListener(PropertyChangeListener)
142:             */
143:            @SuppressWarnings("deprecation")
144:            public void testAddPropertyChangeListenerPropertyChangeListener()
145:                    throws InterruptedException, InvocationTargetException {
146:                ConcreteFocusListener focusListener = new ConcreteFocusListener();
147:                SynchronizedPropertyListener listener = new SynchronizedPropertyListener();
148:                aContext.addPropertyChangeListener(listener);
149:                JComponent button1 = new JPanel();
150:                JComponent button2 = new JPanel();
151:                JComponent button3 = new JPanel();
152:                panel.add(button1);
153:                waitListener(listener);
154:                listener.checkLastPropertyFired(aContext,
155:                        AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, null,
156:                        button1.getAccessibleContext());
157:                listener.reset();
158:                panel.add(button2);
159:                waitListener(listener);
160:                listener.checkLastPropertyFired(aContext,
161:                        AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, null,
162:                        button2.getAccessibleContext());
163:                listener.reset();
164:                panel.remove(button1);
165:                waitListener(listener);
166:                listener.checkLastPropertyFired(aContext,
167:                        AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, button1
168:                                .getAccessibleContext(), null);
169:                listener.reset();
170:                panel.add(button1);
171:                AccessibleContext bContext = button1.getAccessibleContext();
172:                bContext.addPropertyChangeListener(listener);
173:                frame.getContentPane().add(panel);
174:                panel.add(button2);
175:                button1.addFocusListener(focusListener);
176:                listener.reset();
177:                frame.pack();
178:                frame.show();
179:                SwingWaitTestCase.requestFocusInWindowForComponent(button1);
180:                listener.checkLastPropertyFired(button1.getAccessibleContext(),
181:                        AccessibleContext.ACCESSIBLE_STATE_PROPERTY, null,
182:                        AccessibleState.FOCUSED);
183:                listener.reset();
184:                SwingWaitTestCase.requestFocusInWindowForComponent(button2);
185:                listener.checkLastPropertyFired(button1.getAccessibleContext(),
186:                        AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
187:                        AccessibleState.FOCUSED, null);
188:                listener.reset();
189:                panel.add(button3);
190:                waitListener(listener);
191:                listener.checkLastPropertyFired(aContext,
192:                        AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, null,
193:                        button3.getAccessibleContext());
194:                listener.reset();
195:                panel.remove(button2);
196:                waitListener(listener);
197:                listener.checkLastPropertyFired(aContext,
198:                        AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, button2
199:                                .getAccessibleContext(), null);
200:                listener.reset();
201:                SwingWaitTestCase.requestFocusInWindowForComponent(button1);
202:                listener.checkLastPropertyFired(button1.getAccessibleContext(),
203:                        AccessibleContext.ACCESSIBLE_STATE_PROPERTY, null,
204:                        AccessibleState.FOCUSED);
205:            }
206:
207:            /*
208:             * Class under test for AccessibleStateSet getAccessibleStateSet()
209:             */
210:            @SuppressWarnings("deprecation")
211:            public void testGetAccessibleStateSet()
212:                    throws InterruptedException, InvocationTargetException {
213:                assertTrue("Enabled", aContext.getAccessibleStateSet()
214:                        .contains(AccessibleState.ENABLED));
215:                assertFalse("Focused", aContext.getAccessibleStateSet()
216:                        .contains(AccessibleState.FOCUSED));
217:                assertTrue("Focusable", aContext.getAccessibleStateSet()
218:                        .contains(AccessibleState.FOCUSABLE));
219:                assertTrue("Visible", aContext.getAccessibleStateSet()
220:                        .contains(AccessibleState.VISIBLE));
221:                assertFalse("Showing", aContext.getAccessibleStateSet()
222:                        .contains(AccessibleState.SHOWING));
223:                assertTrue("Opaque", aContext.getAccessibleStateSet().contains(
224:                        AccessibleState.OPAQUE));
225:                assertEquals("Number of states", 4, aContext
226:                        .getAccessibleStateSet().toArray().length);
227:                frame.getContentPane().add(panel);
228:                frame.pack();
229:                frame.show();
230:                SwingWaitTestCase.requestFocusInWindowForComponent(panel);
231:                assertTrue("Enabled", aContext.getAccessibleStateSet()
232:                        .contains(AccessibleState.ENABLED));
233:                assertTrue("Focused", aContext.getAccessibleStateSet()
234:                        .contains(AccessibleState.FOCUSED));
235:                assertTrue("Focusable", aContext.getAccessibleStateSet()
236:                        .contains(AccessibleState.FOCUSABLE));
237:                assertTrue("Visible", aContext.getAccessibleStateSet()
238:                        .contains(AccessibleState.VISIBLE));
239:                assertTrue("Showing", aContext.getAccessibleStateSet()
240:                        .contains(AccessibleState.SHOWING));
241:                assertTrue("Opaque", aContext.getAccessibleStateSet().contains(
242:                        AccessibleState.OPAQUE));
243:                assertEquals("Number of states", 6, aContext
244:                        .getAccessibleStateSet().toArray().length);
245:                panel.setVisible(false);
246:                panel.setOpaque(false);
247:                panel.setEnabled(false);
248:                JButton button = new JButton();
249:                frame.getContentPane().add(button);
250:                SwingWaitTestCase.requestFocusInWindowForComponent(button);
251:                assertFalse("Enabled", aContext.getAccessibleStateSet()
252:                        .contains(AccessibleState.ENABLED));
253:                assertFalse("Focused", aContext.getAccessibleStateSet()
254:                        .contains(AccessibleState.FOCUSED));
255:                assertTrue("Focusable", aContext.getAccessibleStateSet()
256:                        .contains(AccessibleState.FOCUSABLE));
257:                assertFalse("Visible", aContext.getAccessibleStateSet()
258:                        .contains(AccessibleState.VISIBLE));
259:                assertFalse("Showing", aContext.getAccessibleStateSet()
260:                        .contains(AccessibleState.SHOWING));
261:                assertFalse("Opaque", aContext.getAccessibleStateSet()
262:                        .contains(AccessibleState.OPAQUE));
263:                assertEquals("Number of states", 1, aContext
264:                        .getAccessibleStateSet().toArray().length);
265:            }
266:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.