Source Code Cross Referenced for SwingUtilitiesRTest.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 16.12.2004
021:
022:         */package javax.swing;
023:
024:        import java.awt.Component;
025:        import java.awt.Dimension;
026:        import java.awt.FontMetrics;
027:        import java.awt.Frame;
028:        import java.awt.Rectangle;
029:        import java.awt.event.InputEvent;
030:        import java.awt.event.MouseEvent;
031:
032:        public class SwingUtilitiesRTest extends SwingTestCase {
033:            public void testLayoutCompoundLabel() {
034:                JComponent c = new JButton();
035:                FontMetrics fm = c.getFontMetrics(c.getFont());
036:                Rectangle viewRectangle = new Rectangle(1000, 1000);
037:                Rectangle iconRectangle = new Rectangle();
038:                Rectangle textRectangle = new Rectangle();
039:                SwingUtilities.layoutCompoundLabel(c, fm, "text", null,
040:                        SwingConstants.CENTER, SwingConstants.LEADING,
041:                        SwingConstants.CENTER, SwingConstants.TRAILING,
042:                        viewRectangle, iconRectangle, textRectangle, 0);
043:                int textHeight = fm.getHeight();
044:                assertEquals(new Rectangle(0,
045:                        (viewRectangle.height - textHeight) / 2 + textHeight
046:                                / 2, 0, 0), iconRectangle);
047:            }
048:
049:            public void testIsLeftMiddleRightMouseButton() {
050:                JComponent panel = new JPanel();
051:                panel.setPreferredSize(new Dimension(100, 100));
052:                MouseEvent button1DownEvent = new MouseEvent(panel, 100, 0,
053:                        InputEvent.BUTTON1_DOWN_MASK, 50, 50, 1, false);
054:                MouseEvent button1PressedEvent = new MouseEvent(panel,
055:                        MouseEvent.MOUSE_PRESSED, 0, 0, 50, 50, 1, false,
056:                        MouseEvent.BUTTON1);
057:                MouseEvent button1Released = new MouseEvent(panel,
058:                        MouseEvent.MOUSE_RELEASED, 0, 0, 50, 50, 1, false,
059:                        MouseEvent.BUTTON1);
060:                MouseEvent button1Clicked = new MouseEvent(panel,
061:                        MouseEvent.MOUSE_CLICKED, 0, 0, 50, 50, 1, false,
062:                        MouseEvent.BUTTON1);
063:                MouseEvent button1DraggedEvent = new MouseEvent(panel,
064:                        MouseEvent.MOUSE_DRAGGED, 0, 0, 50, 50, 1, false,
065:                        MouseEvent.BUTTON1);
066:                MouseEvent button2DownEvent = new MouseEvent(panel, 100, 0,
067:                        InputEvent.BUTTON2_DOWN_MASK, 50, 50, 1, false);
068:                MouseEvent button2PressedEvent = new MouseEvent(panel,
069:                        MouseEvent.MOUSE_PRESSED, 0, 0, 50, 50, 1, false,
070:                        MouseEvent.BUTTON2);
071:                MouseEvent button2Released = new MouseEvent(panel,
072:                        MouseEvent.MOUSE_RELEASED, 0, 0, 50, 50, 1, false,
073:                        MouseEvent.BUTTON2);
074:                MouseEvent button2Clicked = new MouseEvent(panel,
075:                        MouseEvent.MOUSE_CLICKED, 0, 0, 50, 50, 1, false,
076:                        MouseEvent.BUTTON2);
077:                MouseEvent button2DraggedEvent = new MouseEvent(panel,
078:                        MouseEvent.MOUSE_DRAGGED, 0, 0, 50, 50, 1, false,
079:                        MouseEvent.BUTTON2);
080:                MouseEvent button3DownEvent = new MouseEvent(panel, 100, 0,
081:                        InputEvent.BUTTON3_DOWN_MASK, 50, 50, 1, false);
082:                MouseEvent button3PressedEvent = new MouseEvent(panel,
083:                        MouseEvent.MOUSE_PRESSED, 0, 0, 50, 50, 1, false,
084:                        MouseEvent.BUTTON3);
085:                MouseEvent button3Released = new MouseEvent(panel,
086:                        MouseEvent.MOUSE_RELEASED, 0, 0, 50, 50, 1, false,
087:                        MouseEvent.BUTTON3);
088:                MouseEvent button3Clicked = new MouseEvent(panel,
089:                        MouseEvent.MOUSE_CLICKED, 0, 0, 50, 50, 1, false,
090:                        MouseEvent.BUTTON3);
091:                MouseEvent button3DraggedEvent = new MouseEvent(panel,
092:                        MouseEvent.MOUSE_DRAGGED, 0, 0, 50, 50, 1, false,
093:                        MouseEvent.BUTTON3);
094:                assertTrue(SwingUtilities.isLeftMouseButton(button1DownEvent));
095:                assertFalse(SwingUtilities.isLeftMouseButton(button2DownEvent));
096:                assertFalse(SwingUtilities.isLeftMouseButton(button3DownEvent));
097:                assertTrue(SwingUtilities
098:                        .isLeftMouseButton(button1PressedEvent));
099:                assertTrue(SwingUtilities.isLeftMouseButton(button1Released));
100:                assertTrue(SwingUtilities.isLeftMouseButton(button1Clicked));
101:                assertFalse(SwingUtilities
102:                        .isLeftMouseButton(button1DraggedEvent));
103:                assertFalse(SwingUtilities
104:                        .isMiddleMouseButton(button1DownEvent));
105:                assertTrue(SwingUtilities.isMiddleMouseButton(button2DownEvent));
106:                assertFalse(SwingUtilities
107:                        .isMiddleMouseButton(button3DownEvent));
108:                assertTrue(SwingUtilities
109:                        .isMiddleMouseButton(button2PressedEvent));
110:                assertTrue(SwingUtilities.isMiddleMouseButton(button2Released));
111:                assertTrue(SwingUtilities.isMiddleMouseButton(button2Clicked));
112:                assertFalse(SwingUtilities
113:                        .isMiddleMouseButton(button2DraggedEvent));
114:                assertFalse(SwingUtilities.isRightMouseButton(button1DownEvent));
115:                assertFalse(SwingUtilities.isRightMouseButton(button2DownEvent));
116:                assertTrue(SwingUtilities.isRightMouseButton(button3DownEvent));
117:                assertTrue(SwingUtilities
118:                        .isRightMouseButton(button3PressedEvent));
119:                assertTrue(SwingUtilities.isRightMouseButton(button3Released));
120:                assertTrue(SwingUtilities.isRightMouseButton(button3Clicked));
121:                assertFalse(SwingUtilities
122:                        .isRightMouseButton(button3DraggedEvent));
123:            }
124:
125:            public void testGetAncestorOfClass() {
126:                final Frame f = new Frame();
127:                final JDialog dialog = new JDialog(f);
128:                assertSame(f, SwingUtilities.getAncestorOfClass(Frame.class,
129:                        dialog));
130:            }
131:
132:            public void testDeadLoop_4820() {
133:                final int DEAD_LOOP_TIMEOUT = 1000;
134:                final int VALID_NUMBER_OF_CALLS = 15;
135:                final int counter[] = { 0 };
136:
137:                class MFrame extends Frame {
138:                    MFrame() {
139:                        setSize(300, 200);
140:                        show();
141:                    }
142:
143:                    public Component locate(int x, int y) {
144:                        counter[0]++;
145:                        return super .locate(x, y);
146:                    }
147:
148:                    public Component getComponentAt(int x, int y) {
149:                        counter[0]++;
150:                        return super .getComponentAt(x, y);
151:                    }
152:
153:                    public Component getComponentAt(java.awt.Point p) {
154:                        counter[0]++;
155:                        return super .getComponentAt(p);
156:                    }
157:                }
158:
159:                Frame f = new MFrame();
160:
161:                SwingUtilities.getDeepestComponentAt(f, 10, 10);
162:                try {
163:                    Thread.sleep(DEAD_LOOP_TIMEOUT);
164:                } catch (Exception e) {
165:                }
166:
167:                f.dispose();
168:
169:                assertTrue("Dead loop occured",
170:                        counter[0] <= VALID_NUMBER_OF_CALLS);
171:            }
172:
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.