Source Code Cross Referenced for MetalToolBarUITest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » plaf » metal » 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.plaf.metal 
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.plaf.metal;
021:
022:        import java.awt.BorderLayout;
023:        import java.awt.Insets;
024:        import java.awt.Point;
025:        import java.awt.event.ContainerListener;
026:        import java.awt.event.MouseEvent;
027:        import java.beans.PropertyChangeListener;
028:        import java.util.Arrays;
029:        import javax.swing.JButton;
030:        import javax.swing.JFrame;
031:        import javax.swing.JLabel;
032:        import javax.swing.JToolBar;
033:        import javax.swing.SwingTestCase;
034:        import javax.swing.border.Border;
035:        import javax.swing.border.EmptyBorder;
036:        import javax.swing.plaf.ComponentUI;
037:        import javax.swing.plaf.UIResource;
038:
039:        public class MetalToolBarUITest extends SwingTestCase {
040:            private class TestMetalToolBarUI extends MetalToolBarUI {
041:                public class TestMetalDockingListener extends
042:                        MetalDockingListener {
043:                    TestMetalDockingListener(final JToolBar toolBar) {
044:                        super (toolBar);
045:                    }
046:
047:                    boolean isDragging() {
048:                        return isDragging;
049:                    }
050:
051:                    Point getOrigin() {
052:                        return origin;
053:                    }
054:                }
055:
056:                public Border nonRolloverBorder;
057:
058:                private boolean dragToCalled;
059:
060:                @Override
061:                protected PropertyChangeListener createRolloverListener() {
062:                    return new MetalRolloverListener();
063:                }
064:
065:                @Override
066:                protected ContainerListener createContainerListener() {
067:                    return new MetalContainerListener();
068:                }
069:
070:                public Point getDragWindowOffset() {
071:                    return dragWindow.getOffset();
072:                }
073:
074:                @Override
075:                protected Border createNonRolloverBorder() {
076:                    nonRolloverBorder = super .createNonRolloverBorder();
077:                    return nonRolloverBorder;
078:                }
079:
080:                @Override
081:                protected void dragTo(final Point position, final Point origin) {
082:                    dragToCalled = true;
083:                    super .dragTo(position, origin);
084:                }
085:            }
086:
087:            private JFrame frame;
088:
089:            private JToolBar toolBar;
090:
091:            private MetalToolBarUI ui;
092:
093:            private JButton b;
094:
095:            private JLabel label;
096:
097:            @Override
098:            protected void setUp() throws Exception {
099:                super .setUp();
100:                b = new JButton();
101:                label = new JLabel();
102:                toolBar = new JToolBar();
103:                ui = new MetalToolBarUI();
104:                toolBar.setUI(ui);
105:            }
106:
107:            @Override
108:            protected void tearDown() throws Exception {
109:                super .tearDown();
110:                if (frame != null) {
111:                    frame.dispose();
112:                    frame = null;
113:                }
114:            }
115:
116:            public MetalToolBarUITest(final String name) {
117:                super (name);
118:            }
119:
120:            public void testUpdate() {
121:                // painting code, cannot test
122:            }
123:
124:            public void testUninstallUI() {
125:                // nothing to test
126:            }
127:
128:            public void testInstallUI() {
129:                // nothing to test
130:            }
131:
132:            public void testCreateUI() {
133:                ComponentUI ui1 = MetalToolBarUI.createUI(toolBar);
134:                assertTrue(ui1 instanceof  MetalToolBarUI);
135:                ComponentUI ui2 = MetalToolBarUI.createUI(toolBar);
136:                assertNotSame(ui1, ui2);
137:            }
138:
139:            public void testCreateDockingListener() {
140:                assertTrue(ui.createDockingListener() instanceof  MetalToolBarUI.MetalDockingListener);
141:            }
142:
143:            public void testCreateRolloverBorder() {
144:                assertNotNull(ui.createRolloverBorder());
145:                if (isHarmony()) {
146:                    assertTrue(ui.createRolloverBorder() instanceof  UIResource);
147:                }
148:            }
149:
150:            public void testCreateNonRolloverBorder() {
151:                assertNotNull(ui.createNonRolloverBorder());
152:                if (isHarmony()) {
153:                    assertTrue(ui.createNonRolloverBorder() instanceof  UIResource);
154:                }
155:            }
156:
157:            public void testInstallListeners() {
158:                TestMetalToolBarUI ui = new TestMetalToolBarUI();
159:                toolBar.setUI(ui);
160:                assertTrue(Arrays.asList(toolBar.getContainerListeners())
161:                        .contains(ui.contListener));
162:                assertTrue(Arrays.asList(toolBar.getPropertyChangeListeners())
163:                        .contains(ui.rolloverListener));
164:                assertFalse(Arrays
165:                        .asList(
166:                                toolBar
167:                                        .getPropertyChangeListeners("JToolBar.isRollover"))
168:                        .contains(ui.rolloverListener));
169:            }
170:
171:            public void testUninstallListeners() {
172:                TestMetalToolBarUI ui = new TestMetalToolBarUI();
173:                toolBar.setUI(ui);
174:                ui.uninstallListeners();
175:                assertFalse(Arrays.asList(toolBar.getContainerListeners())
176:                        .contains(ui.contListener));
177:                assertFalse(Arrays.asList(toolBar.getPropertyChangeListeners())
178:                        .contains(ui.rolloverListener));
179:            }
180:
181:            public void testSetBorderToNonRollover() {
182:                TestMetalToolBarUI ui = new TestMetalToolBarUI();
183:                toolBar.setUI(ui);
184:                ui.setBorderToNonRollover(b);
185:                assertSame(ui.nonRolloverBorder, b.getBorder());
186:                assertFalse(b.isRolloverEnabled());
187:                Border border = new EmptyBorder(new Insets(0, 0, 0, 0));
188:                b.setBorder(border);
189:                ui.setBorderToNonRollover(b);
190:                assertSame(border, b.getBorder());
191:                ui.setBorderToNonRollover(label);
192:                assertNull(label.getBorder());
193:                ui.setBorderToNonRollover(null);
194:            }
195:
196:            public void testMetalToolBarUI() {
197:                // nothing to test
198:            }
199:
200:            public void testCreateContainerListener() {
201:                assertNull(ui.createContainerListener());
202:            }
203:
204:            public void testCreateRolloverListener() {
205:                assertNull(ui.createRolloverListener());
206:            }
207:
208:            public void testSetDragOffset() {
209:                TestMetalToolBarUI ui = new TestMetalToolBarUI();
210:                toolBar.setUI(ui);
211:                Point offset = new Point(1, 2);
212:                ui.setDragOffset(offset);
213:                assertEquals(offset, ui.getDragWindowOffset());
214:            }
215:
216:            public void testMetalDockingListener() {
217:                TestMetalToolBarUI ui = new TestMetalToolBarUI();
218:                toolBar.setUI(ui);
219:                toolBar.add(b);
220:                createAndShowFrame();
221:                TestMetalToolBarUI.TestMetalDockingListener l = ui.new TestMetalDockingListener(
222:                        toolBar);
223:                MouseEvent e = new MouseEvent(toolBar,
224:                        MouseEvent.MOUSE_PRESSED, 0, 0, toolBar.getWidth(),
225:                        toolBar.getHeight(), 0, false);
226:                l.mousePressed(e);
227:                e = new MouseEvent(toolBar, MouseEvent.MOUSE_DRAGGED, 0, 0,
228:                        toolBar.getWidth(), toolBar.getHeight(), 0, false);
229:                l.mouseDragged(e);
230:                // false because drag should occur only on bumps
231:                assertFalse(l.isDragging());
232:                assertFalse(ui.dragToCalled);
233:                Point p = new Point(4, 8);
234:                e = new MouseEvent(toolBar, MouseEvent.MOUSE_PRESSED, 0, 0,
235:                        p.x, p.y, 0, false);
236:                l.mousePressed(e);
237:                e = new MouseEvent(toolBar, MouseEvent.MOUSE_DRAGGED, 0, 0,
238:                        p.x, p.y, 0, false);
239:                l.mouseDragged(e);
240:                assertTrue(l.isDragging());
241:                assertTrue(ui.dragToCalled);
242:            }
243:
244:            private void createAndShowFrame() {
245:                frame = new JFrame();
246:                frame.setSize(90, 90);
247:                frame.getContentPane().add(toolBar, BorderLayout.NORTH);
248:                frame.setVisible(true);
249:            }
250:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.