Source Code Cross Referenced for JInternalFrame_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 Vadim L. Bogdanov
019:         * @version $Revision$
020:         */package javax.swing;
021:
022:        import java.awt.BorderLayout;
023:        import java.awt.Component;
024:        import java.awt.Container;
025:        import java.beans.PropertyVetoException;
026:        import java.lang.reflect.InvocationTargetException;
027:        import java.util.Comparator;
028:
029:        /**
030:         * Tests for JInternalFrame class that cannot be run in Event Dispatch Thread.
031:         * These are test of focus subsystem mainly.
032:         *
033:         * These tests cannot be run on Event Dispatch Thread because we cannot
034:         * request focus on some component synchronously (auxiliary
035:         * function requestFocusForComponent() cannot be synchronous).
036:         *
037:         */
038:        public class JInternalFrame_MultithreadedTest extends
039:                BasicSwingTestCase {
040:            private JInternalFrame frame;
041:
042:            // is used in tests where frame.isShowing() must be true
043:            private JFrame rootFrame;
044:
045:            /*
046:             * @see TestCase#setUp()
047:             */
048:            @Override
049:            protected void setUp() throws Exception {
050:                super .setUp();
051:                frame = new JInternalFrame();
052:            }
053:
054:            /*
055:             * @see TestCase#tearDown()
056:             */
057:            @Override
058:            protected void tearDown() throws Exception {
059:                if (rootFrame != null) {
060:                    rootFrame.dispose();
061:                    rootFrame = null;
062:                }
063:                super .tearDown();
064:            }
065:
066:            /**
067:             * Constructor for JInternalFrameTest.
068:             * @param name
069:             */
070:            public JInternalFrame_MultithreadedTest(final String name) {
071:                super (name);
072:            }
073:
074:            /*
075:             * Class under test for void restoreSubcomponentFocus()
076:             */
077:            public void testRestoreSubcomponentFocus()
078:                    throws InterruptedException, InvocationTargetException {
079:                final Component comp1 = new JPanel();
080:                final Component comp2 = new JPanel();
081:                final Component comp3 = new JPanel();
082:                frame.getContentPane().add(comp1, BorderLayout.NORTH);
083:                frame.getContentPane().add(comp2, BorderLayout.SOUTH);
084:                frame.getContentPane().add(comp3, BorderLayout.CENTER);
085:                createAndShowRootFrame();
086:                setSelectedFrame(frame, true);
087:                SwingWaitTestCase.requestFocusInWindowForComponent(comp2);
088:                setSelectedFrame(frame, false);
089:                setSelectedFrame(frame, true);
090:                assertTrue("focus is restored", frame.getFocusOwner() == comp2);
091:            }
092:
093:            /*
094:             * Creates and shows rootFrame. This method is used when JInternalFrame
095:             * need to be selected (isSelected() == true) for testing purposes.
096:             */
097:            protected void createAndShowRootFrame() {
098:                frame.setSize(70, 100);
099:                rootFrame = new JFrame();
100:                JDesktopPane desktop = new JDesktopPane();
101:                rootFrame.setContentPane(desktop);
102:                rootFrame.getContentPane().add(frame);
103:                rootFrame.setSize(100, 200);
104:                frame.setVisible(true);
105:                rootFrame.setVisible(true);
106:                SwingWaitTestCase.isRealized(rootFrame);
107:            }
108:
109:            /*
110:             * Thread safe function to make the internal frame selected
111:             * or deselected
112:             */
113:            protected void setSelectedFrame(final JInternalFrame frame,
114:                    final boolean selected) {
115:                try {
116:                    SwingUtilities.invokeAndWait(new Runnable() {
117:                        public void run() {
118:                            try {
119:                                frame.setSelected(selected);
120:                            } catch (PropertyVetoException e) {
121:                            }
122:                        }
123:                    });
124:                } catch (Exception e) {
125:                    assertFalse("exception", true);
126:                }
127:            }
128:
129:            /*
130:             * Class under test for Component getMostRecentFocusOwner()
131:             */
132:            public void testGetMostRecentFocusOwner()
133:                    throws PropertyVetoException, InterruptedException,
134:                    InvocationTargetException {
135:                final Component initial = new JPanel(); // initial focus component
136:                final Component def = new JPanel(); // default focus component
137:                final Component some = new JPanel(); // some another component
138:                frame.getContentPane().add(initial, BorderLayout.NORTH);
139:                frame.getContentPane().add(def, BorderLayout.SOUTH);
140:                frame.getContentPane().add(some, BorderLayout.CENTER);
141:                assertNull("null by default", frame.getMostRecentFocusOwner());
142:                class MyFocusTraversalPolicy extends
143:                        SortingFocusTraversalPolicy {
144:                    Component initial;
145:
146:                    Component def;
147:
148:                    public MyFocusTraversalPolicy() {
149:                        setComparator(new Comparator<Object>() {
150:                            public int compare(final Object arg0,
151:                                    final Object arg1) {
152:                                return System.identityHashCode(arg0)
153:                                        - System.identityHashCode(arg1);
154:                            }
155:                        });
156:                    }
157:
158:                    @Override
159:                    public Component getInitialComponent(
160:                            final javax.swing.JInternalFrame frame) {
161:                        return initial;
162:                    }
163:
164:                    @Override
165:                    public Component getDefaultComponent(
166:                            final Container focusCycleRoot) {
167:                        return def;
168:                    }
169:                }
170:                MyFocusTraversalPolicy traversal = new MyFocusTraversalPolicy();
171:                traversal.def = def;
172:                frame.setFocusTraversalPolicy(traversal);
173:                if (BasicSwingTestCase.isHarmony()) {
174:                    assertSame("== def (JRockit fails)", def, frame
175:                            .getMostRecentFocusOwner());
176:                }
177:                // no one component had ever the focus, initial is returned
178:                traversal.initial = initial;
179:                createAndShowRootFrame();
180:                assertTrue("== initial",
181:                        frame.getMostRecentFocusOwner() == initial);
182:                // request focus for 'some' component, this component must be returned by
183:                // getMostRecentFocusOwner()
184:                setSelectedFrame(frame, true);
185:                SwingWaitTestCase.requestFocusInWindowForComponent(some);
186:                setSelectedFrame(frame, false);
187:                assertTrue("== some", frame.getMostRecentFocusOwner() == some);
188:                // frame is selected, returns the same component as getFocusOwner()
189:                setSelectedFrame(frame, true);
190:                SwingWaitTestCase.requestFocusInWindowForComponent(def);
191:                assertTrue("== getFocusOwner()", frame
192:                        .getMostRecentFocusOwner() == frame.getFocusOwner());
193:            }
194:
195:            /*
196:             * Class under test for Component getFocusOwner()
197:             */
198:            public void testGetFocusOwner() throws InterruptedException,
199:                    InvocationTargetException {
200:                final Component comp1 = new JPanel();
201:                final Component comp2 = new JPanel();
202:                final Component comp3 = new JPanel();
203:                frame.getContentPane().add(comp1, BorderLayout.NORTH);
204:                frame.getContentPane().add(comp2, BorderLayout.SOUTH);
205:                frame.getContentPane().add(comp3, BorderLayout.CENTER);
206:                assertNull("== null", frame.getFocusOwner());
207:                createAndShowRootFrame();
208:                // frame is selected, comp2 has focus
209:                setSelectedFrame(frame, true);
210:                SwingWaitTestCase.requestFocusInWindowForComponent(comp2);
211:                assertSame("== comp2", comp2, frame.getFocusOwner());
212:                // frame is not selected
213:                setSelectedFrame(frame, false);
214:                assertNull("== null", frame.getFocusOwner());
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.