Source Code Cross Referenced for BasicToolBarUITest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » plaf » basic » 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.basic 
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.basic;
021:
022:        import java.awt.BorderLayout;
023:        import java.awt.Color;
024:        import java.awt.Container;
025:        import java.awt.Insets;
026:        import java.awt.Point;
027:        import java.awt.event.ContainerEvent;
028:        import java.awt.event.ContainerListener;
029:        import java.awt.event.FocusEvent;
030:        import java.awt.event.FocusListener;
031:        import java.awt.event.MouseEvent;
032:        import java.awt.event.WindowListener;
033:        import java.util.Arrays;
034:        import javax.swing.JButton;
035:        import javax.swing.JComponent;
036:        import javax.swing.JDialog;
037:        import javax.swing.JFrame;
038:        import javax.swing.JLabel;
039:        import javax.swing.JPanel;
040:        import javax.swing.JToolBar;
041:        import javax.swing.RootPaneContainer;
042:        import javax.swing.SwingConstants;
043:        import javax.swing.SwingTestCase;
044:        import javax.swing.SwingUtilities;
045:        import javax.swing.UIManager;
046:        import javax.swing.border.Border;
047:        import javax.swing.border.EmptyBorder;
048:        import javax.swing.plaf.BorderUIResource;
049:        import javax.swing.plaf.ComponentUI;
050:        import javax.swing.plaf.UIResource;
051:        import javax.swing.plaf.basic.BasicToolBarUI.DragWindow;
052:
053:        public class BasicToolBarUITest extends SwingTestCase {
054:            private class TestBasicToolBarUI extends BasicToolBarUI {
055:                public Border rolloverBorder;
056:
057:                public Border nonRolloverBorder;
058:
059:                public Container floatingWindow;
060:
061:                public boolean setFloatingCalled;
062:
063:                public boolean setFloatingBParam;
064:
065:                private boolean dragToCalled;
066:
067:                @Override
068:                protected Border createRolloverBorder() {
069:                    rolloverBorder = super .createRolloverBorder();
070:                    return rolloverBorder;
071:                }
072:
073:                @Override
074:                protected Border createNonRolloverBorder() {
075:                    nonRolloverBorder = super .createNonRolloverBorder();
076:                    return nonRolloverBorder;
077:                }
078:
079:                @Override
080:                protected RootPaneContainer createFloatingWindow(
081:                        final JToolBar toolbar) {
082:                    RootPaneContainer result = super 
083:                            .createFloatingWindow(toolbar);
084:                    if (result instanceof  Container) {
085:                        floatingWindow = (Container) result;
086:                    }
087:                    return result;
088:                }
089:
090:                @Override
091:                public void setFloating(final boolean b, final Point p) {
092:                    setFloatingCalled = true;
093:                    setFloatingBParam = b;
094:                    super .setFloating(b, p);
095:                }
096:
097:                @Override
098:                protected void dragTo(final Point position, final Point origin) {
099:                    dragToCalled = true;
100:                    super .dragTo(position, origin);
101:                }
102:            }
103:
104:            private class TestJButton extends JButton {
105:                private static final long serialVersionUID = 1L;
106:
107:                @Override
108:                public void requestFocus() {
109:                    BasicToolBarUITest.this .ui.focusedCompIndex = toolBar
110:                            .getComponentIndex(this );
111:                    super .requestFocus();
112:                }
113:            }
114:
115:            private JToolBar toolBar;
116:
117:            private TestBasicToolBarUI ui;
118:
119:            private JButton b;
120:
121:            private JLabel label;
122:
123:            private JFrame frame;
124:
125:            @Override
126:            protected void setUp() throws Exception {
127:                super .setUp();
128:                toolBar = new JToolBar();
129:                ui = new TestBasicToolBarUI();
130:                toolBar.setUI(ui);
131:                b = new JButton();
132:                label = new JLabel();
133:            }
134:
135:            @Override
136:            protected void tearDown() throws Exception {
137:                super .tearDown();
138:                if (frame != null) {
139:                    frame.dispose();
140:                    frame = null;
141:                }
142:            }
143:
144:            public BasicToolBarUITest(final String name) {
145:                super (name);
146:            }
147:
148:            public void testInstallUI() {
149:                ui = new TestBasicToolBarUI();
150:                ui.installUI(toolBar);
151:                assertSame(ui.toolBar, toolBar);
152:                assertEquals(UIManager.getColor("ToolBar.dockingForeground"),
153:                        ui.dockingBorderColor);
154:                assertTrue(Arrays.asList(toolBar.getContainerListeners())
155:                        .contains(ui.toolBarContListener));
156:                assertSame(UIManager.get("ToolBar.ancestorInputMap"),
157:                        SwingUtilities.getUIInputMap(toolBar,
158:                                JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));
159:            }
160:
161:            public void testUninstallUI() {
162:                ui.uninstallUI(toolBar);
163:                assertNull(toolBar.getBorder());
164:                assertFalse(Arrays.asList(toolBar.getContainerListeners())
165:                        .contains(ui.toolBarContListener));
166:                assertNull(SwingUtilities.getUIInputMap(toolBar,
167:                        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));
168:            }
169:
170:            public void testUninstallUIWhenFloating() {
171:                prepareToTestFloating();
172:                Point p = new Point(1, 2);
173:                ui.dragTo(p, p);
174:                ui.setFloatingLocation(p.x, p.y);
175:                ui.setFloating(true, null);
176:                ui.uninstallUI(toolBar);
177:                assertFalse(ui.isFloating());
178:                assertTrue(frame.isAncestorOf(toolBar));
179:                assertNull(ui.dragWindow);
180:            }
181:
182:            public void testCreateUI() {
183:                ComponentUI ui1 = BasicToolBarUI.createUI(toolBar);
184:                assertTrue(ui1 instanceof  BasicToolBarUI);
185:                ComponentUI ui2 = BasicToolBarUI.createUI(toolBar);
186:                assertNotSame(ui1, ui2);
187:            }
188:
189:            public void testBasicToolBarUI() {
190:                ui = new TestBasicToolBarUI();
191:                assertEquals(BorderLayout.NORTH, ui.constraintBeforeFloating);
192:                assertEquals(-1, ui.focusedCompIndex);
193:            }
194:
195:            public void testCanDock() {
196:                JPanel panel = new JPanel();
197:                panel.add(toolBar);
198:                panel.setSize(400, 300);
199:                panel.doLayout();
200:                assertTrue(ui.canDock(panel, new Point(panel.getWidth() / 2,
201:                        toolBar.getHeight() - 1)));
202:                assertTrue(ui.canDock(panel, new Point(panel.getWidth() / 2,
203:                        panel.getHeight() - (toolBar.getHeight() - 1))));
204:                assertTrue(ui.canDock(panel, new Point(toolBar.getHeight() - 1,
205:                        panel.getHeight() / 2)));
206:                assertTrue(ui.canDock(panel, new Point(panel.getWidth()
207:                        - (toolBar.getHeight() - 1), panel.getHeight() / 2)));
208:                assertFalse(ui.canDock(panel, new Point(
209:                        toolBar.getHeight() + 1, toolBar.getHeight() + 1)));
210:                assertFalse(ui.canDock(panel, new Point(panel.getWidth(), panel
211:                        .getHeight())));
212:            }
213:
214:            public void testCreateDockingListener() {
215:                assertNotNull(ui.createDockingListener());
216:            }
217:
218:            public void testCreateDragWindow() {
219:                DragWindow dragWindow = ui.createDragWindow(toolBar);
220:                assertNotNull(ui.createDragWindow(toolBar));
221:                assertNotNull(dragWindow.getOwner());
222:            }
223:
224:            public void testCreateFloatingFrame() {
225:                toolBar.setName("The toolbar");
226:                JFrame floatingFrame = ui.createFloatingFrame(toolBar);
227:                assertEquals("The toolbar", floatingFrame.getTitle());
228:                assertFalse(floatingFrame.isAncestorOf(toolBar));
229:                assertTrue(floatingFrame.getWindowListeners().length > 0);
230:                assertFalse(floatingFrame.isResizable());
231:            }
232:
233:            public void testCreateFloatingWindow() {
234:                toolBar.setName("The toolbar");
235:                RootPaneContainer floatingWindow = ui
236:                        .createFloatingWindow(toolBar);
237:                assertTrue(floatingWindow instanceof  JDialog);
238:                JDialog floatingFrame = (JDialog) floatingWindow;
239:                assertFalse(floatingFrame.isAncestorOf(toolBar));
240:                assertEquals("The toolbar", floatingFrame.getTitle());
241:                assertTrue(floatingFrame.getWindowListeners().length > 0);
242:            }
243:
244:            public void testCreateFrameListener() {
245:                assertTrue(ui.createFrameListener() instanceof  BasicToolBarUI.FrameListener);
246:            }
247:
248:            public void testCreateNonRolloverBorder() {
249:                assertNotNull(ui.createRolloverBorder());
250:                if (isHarmony()) {
251:                    assertTrue(ui.createRolloverBorder() instanceof  UIResource);
252:                }
253:            }
254:
255:            public void testCreatePropertyListener() {
256:                assertNotNull(ui.createPropertyListener());
257:            }
258:
259:            public void testCreateRolloverBorder() {
260:                assertNotNull(ui.createRolloverBorder());
261:                if (isHarmony()) {
262:                    assertTrue(ui.createRolloverBorder() instanceof  UIResource);
263:                }
264:            }
265:
266:            public void testCreateToolBarContListener() {
267:                assertNotNull(ui.createToolBarContListener());
268:            }
269:
270:            public void testCreateToolBarFocusListener() {
271:                assertNotNull(ui.createToolBarFocusListener());
272:            }
273:
274:            public void testDragTo() {
275:                prepareToTestFloating();
276:                Point origin = new Point(1, 2);
277:                Point position1 = frame.getLocation();
278:                position1.translate(frame.getWidth() + 1, 0);
279:                toolBar.setFloatable(false);
280:                ui.dragTo(position1, origin);
281:                assertNull(ui.dragWindow);
282:                toolBar.setFloatable(true);
283:                ui.dragTo(position1, origin);
284:                assertNotNull(ui.dragWindow);
285:                assertTrue(ui.dragWindow.isVisible());
286:                Point dragWindowPosition1 = ui.dragWindow.getLocation();
287:                Point position2 = new Point(position1);
288:                position2.translate(1, 2);
289:                ui.dragTo(position2, origin);
290:                Point dragWindowPosition2 = ui.dragWindow.getLocation();
291:                position2.translate(-position1.x, -position1.y);
292:                dragWindowPosition2.translate(-dragWindowPosition1.x,
293:                        -dragWindowPosition1.y);
294:                assertEquals(position2, dragWindowPosition2);
295:            }
296:
297:            public void testFloatAt() {
298:                prepareToTestFloating();
299:                Point origin = new Point(1, 2);
300:                Point position1 = frame.getLocation();
301:                position1.translate(frame.getWidth() + 1, 0);
302:                toolBar.setFloatable(false);
303:                ui.dragTo(position1, origin);
304:                ui.floatAt(position1, origin);
305:                assertNull(ui.floatingWindow);
306:                toolBar.setFloatable(true);
307:                ui.dragTo(position1, origin);
308:                ui.floatAt(position1, origin);
309:                assertFalse(ui.dragWindow.isVisible());
310:                assertTrue(ui.isFloating());
311:                assertTrue(ui.floatingWindow.isVisible());
312:                assertTrue(ui.floatingWindow.isAncestorOf(toolBar));
313:            }
314:
315:            public void testSetGetDockingColor() {
316:                assertSame(ui.getDockingColor(), ui.dockingColor);
317:                Color c = Color.RED;
318:                ui.setDockingColor(c);
319:                assertSame(c, ui.dockingColor);
320:                assertSame(ui.getDockingColor(), c);
321:            }
322:
323:            public void testSetGetFloatingColor() {
324:                assertSame(ui.getFloatingColor(), ui.floatingColor);
325:                Color c = Color.RED;
326:                ui.setFloatingColor(c);
327:                assertSame(c, ui.floatingColor);
328:                assertSame(ui.getFloatingColor(), c);
329:            }
330:
331:            public void testInstallComponents() {
332:                toolBar.add(b);
333:                ui.uninstallComponents();
334:                int compCount = toolBar.getComponentCount();
335:                ui.installComponents();
336:                assertEquals(compCount, toolBar.getComponentCount());
337:            }
338:
339:            public void testUninstallComponents() {
340:                toolBar.add(b);
341:                int compCount = toolBar.getComponentCount();
342:                ui.uninstallComponents();
343:                assertEquals(compCount, toolBar.getComponentCount());
344:            }
345:
346:            public void testInstallDefaults() {
347:                ui = new TestBasicToolBarUI();
348:                ui.toolBar = toolBar;
349:                toolBar.add(b);
350:                b.setBorder(null);
351:                ui.installDefaults();
352:                assertTrue(toolBar.getForeground() instanceof  UIResource);
353:                assertTrue(toolBar.getForeground() instanceof  UIResource);
354:                assertTrue(toolBar.getFont() instanceof  UIResource);
355:                assertTrue(toolBar.getBorder() instanceof  UIResource);
356:                assertEquals(UIManager.getColor("ToolBar.dockingForeground"),
357:                        ui.dockingBorderColor);
358:                assertEquals(UIManager.getColor("ToolBar.dockingBackground"),
359:                        ui.dockingColor);
360:                assertEquals(UIManager.getColor("ToolBar.floatingForeground"),
361:                        ui.floatingBorderColor);
362:                assertEquals(UIManager.getColor("ToolBar.floatingBackground"),
363:                        ui.floatingColor);
364:                assertTrue(toolBar.isOpaque());
365:                if (isHarmony()) {
366:                    assertTrue(b.getBorder() instanceof  UIResource);
367:                }
368:            }
369:
370:            public void testUninstallDefaults() {
371:                b.setBorder(null);
372:                toolBar.add(b);
373:                ui.uninstallDefaults();
374:                assertNull(toolBar.getBorder());
375:                assertNull(b.getBorder());
376:                assertTrue(toolBar.isOpaque());
377:            }
378:
379:            public void testInstallKeyboardActions() {
380:                ui.uninstallKeyboardActions();
381:                ui.installKeyboardActions();
382:                assertSame(UIManager.get("ToolBar.ancestorInputMap"),
383:                        SwingUtilities.getUIInputMap(toolBar,
384:                                JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));
385:                assertNotNull(SwingUtilities.getUIActionMap(toolBar));
386:            }
387:
388:            public void testUninstallKeyboardActions() {
389:                ui.uninstallKeyboardActions();
390:                assertNull(SwingUtilities.getUIInputMap(toolBar,
391:                        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));
392:                assertNull(SwingUtilities.getUIActionMap(toolBar));
393:            }
394:
395:            public void testInstallListeners() {
396:                ui.uninstallListeners();
397:                toolBar.add(b);
398:                ui.installListeners();
399:                assertTrue(Arrays.asList(toolBar.getContainerListeners())
400:                        .contains(ui.toolBarContListener));
401:                assertTrue(Arrays.asList(toolBar.getPropertyChangeListeners())
402:                        .contains(ui.propertyListener));
403:                assertTrue(Arrays.asList(toolBar.getMouseListeners()).contains(
404:                        ui.dockingListener));
405:                assertTrue(Arrays.asList(toolBar.getMouseMotionListeners())
406:                        .contains(ui.dockingListener));
407:                assertFalse(Arrays.asList(toolBar.getFocusListeners())
408:                        .contains(ui.toolBarFocusListener));
409:                assertTrue(Arrays.asList(b.getFocusListeners()).contains(
410:                        ui.toolBarFocusListener));
411:            }
412:
413:            public void testUninstallListeners() {
414:                toolBar.add(b);
415:                ui.uninstallListeners();
416:                assertFalse(Arrays.asList(toolBar.getContainerListeners())
417:                        .contains(ui.toolBarContListener));
418:                assertFalse(Arrays.asList(toolBar.getPropertyChangeListeners())
419:                        .contains(ui.propertyListener));
420:                assertFalse(Arrays.asList(toolBar.getMouseListeners())
421:                        .contains(ui.dockingListener));
422:                assertFalse(Arrays.asList(toolBar.getMouseMotionListeners())
423:                        .contains(ui.dockingListener));
424:                assertFalse(Arrays.asList(toolBar.getFocusListeners())
425:                        .contains(ui.toolBarFocusListener));
426:                assertFalse(Arrays.asList(b.getFocusListeners()).contains(
427:                        ui.toolBarFocusListener));
428:            }
429:
430:            public void testInstallNonRolloverBorders() {
431:                toolBar.add(b);
432:                toolBar.add(label);
433:                b.setBorder(null);
434:                label.setBorder(null);
435:                ui.installNonRolloverBorders(toolBar);
436:                assertSame(ui.nonRolloverBorder, b.getBorder());
437:                assertNull(label.getBorder());
438:            }
439:
440:            public void testInstallNormalBorders() {
441:                Border bBorder = b.getBorder();
442:                Border labelBorder = label.getBorder();
443:                toolBar.add(b);
444:                toolBar.add(label);
445:                ui.installNormalBorders(toolBar);
446:                assertSame(bBorder, b.getBorder());
447:                assertSame(labelBorder, label.getBorder());
448:            }
449:
450:            public void testInstallRolloverBorders() {
451:                toolBar.add(b);
452:                toolBar.add(label);
453:                b.setBorder(null);
454:                label.setBorder(null);
455:                ui.installRolloverBorders(toolBar);
456:                assertSame(ui.rolloverBorder, b.getBorder());
457:                assertNull(label.getBorder());
458:            }
459:
460:            public void testNavigateFocusedComp() {
461:                toolBar.add(new TestJButton());
462:                toolBar.add(new TestJButton());
463:                toolBar.add(new TestJButton());
464:                ui.focusedCompIndex = 0;
465:                ui.navigateFocusedComp(SwingConstants.EAST);
466:                assertEquals(1, ui.focusedCompIndex);
467:                ui.navigateFocusedComp(SwingConstants.WEST);
468:                assertEquals(0, ui.focusedCompIndex);
469:                ui.navigateFocusedComp(SwingConstants.NORTH);
470:                assertEquals(2, ui.focusedCompIndex);
471:                ui.navigateFocusedComp(SwingConstants.SOUTH);
472:                assertEquals(0, ui.focusedCompIndex);
473:            }
474:
475:            public void testPaintDragWindow() {
476:                // Note: painting code, cannot test
477:            }
478:
479:            public void testSetBorderToNonRollover() {
480:                ui.setBorderToNonRollover(b);
481:                assertSame(ui.nonRolloverBorder, b.getBorder());
482:                assertFalse(b.isRolloverEnabled());
483:                Border border = new EmptyBorder(new Insets(0, 0, 0, 0));
484:                b.setBorder(border);
485:                ui.setBorderToNonRollover(b);
486:                assertSame(border, b.getBorder());
487:                ui.setBorderToNonRollover(label);
488:                assertNull(label.getBorder());
489:                ui.setBorderToNonRollover(null);
490:            }
491:
492:            public void testSetBorderToNormal() {
493:                Border oldBorder = b.getBorder();
494:                boolean oldRolloverEnabled = b.isRolloverEnabled();
495:                ui.setBorderToRollover(b);
496:                if (isHarmony()) {
497:                    ui.setBorderToNonRollover(b);
498:                }
499:                ui.setBorderToNormal(b);
500:                assertSame(oldBorder, b.getBorder());
501:                assertEquals(oldRolloverEnabled, b.isRolloverEnabled());
502:                ui.setBorderToRollover(b);
503:                b
504:                        .setBorder(new BorderUIResource.LineBorderUIResource(
505:                                Color.RED));
506:                ui.setBorderToNormal(b);
507:                assertSame(oldBorder, b.getBorder());
508:            }
509:
510:            public void testSetBorderToRollover() {
511:                b.setRolloverEnabled(false);
512:                ui.setBorderToRollover(b);
513:                assertSame(ui.rolloverBorder, b.getBorder());
514:                assertTrue(b.isRolloverEnabled());
515:                Border border = new EmptyBorder(new Insets(0, 0, 0, 0));
516:                b.setBorder(border);
517:                ui.setBorderToRollover(b);
518:                assertSame(border, b.getBorder());
519:                ui.setBorderToRollover(label);
520:                assertNull(label.getBorder());
521:                ui.setBorderToRollover(null);
522:            }
523:
524:            public void testSetIsFloating() {
525:                prepareToTestFloating();
526:                Point origin = new Point(1, 2);
527:                Point position1 = frame.getLocation();
528:                position1.translate(frame.getWidth() + 1, 0);
529:                ui.dragTo(position1, origin);
530:                Container parent = toolBar.getParent();
531:                Object constraint = ((BorderLayout) parent.getLayout())
532:                        .getConstraints(toolBar);
533:                ui.setFloatingLocation(position1.x, position1.y);
534:                ui.setFloating(true, null);
535:                assertTrue(ui.isFloating());
536:                if (isHarmony()) {
537:                    Point offset = SwingUtilities.convertPoint(toolBar,
538:                            ui.dragWindow.getOffset(), SwingUtilities
539:                                    .getWindowAncestor(toolBar));
540:                    position1.translate(-offset.x, -offset.y);
541:                }
542:                assertEquals(position1, ui.floatingWindow.getLocation());
543:                assertTrue(ui.floatingWindow.isAncestorOf(toolBar));
544:                assertTrue(ui.floatingWindow.isVisible());
545:                ui.setFloating(false, null);
546:                assertFalse(ui.isFloating());
547:                assertFalse(ui.floatingWindow.isVisible());
548:                assertSame(parent, toolBar.getParent());
549:                assertEquals(constraint, ((BorderLayout) parent.getLayout())
550:                        .getConstraints(toolBar));
551:                ui.setFloating(false, new Point(1, frame.getHeight() / 2));
552:                assertFalse(ui.isFloating());
553:                assertFalse(ui.floatingWindow.isVisible());
554:                assertSame(parent, toolBar.getParent());
555:                assertEquals(BorderLayout.WEST, ((BorderLayout) parent
556:                        .getLayout()).getConstraints(toolBar));
557:            }
558:
559:            public void testSetFloatingLocation() {
560:                prepareToTestFloating();
561:                Point origin = new Point(100, 200);
562:                Point position1 = frame.getLocation();
563:                position1.translate(frame.getWidth() + 1, 0);
564:                ui.dragTo(position1, origin);
565:                Point p = new Point(100, 200);
566:                ui.setFloatingLocation(p.x, p.y);
567:                ui.setFloating(true, null);
568:                if (isHarmony()) {
569:                    Point offset = SwingUtilities.convertPoint(toolBar,
570:                            ui.dragWindow.getOffset(), SwingUtilities
571:                                    .getWindowAncestor(toolBar));
572:                    p.translate(-offset.x, -offset.y);
573:                }
574:                assertEquals(p, ui.floatingWindow.getLocation());
575:            }
576:
577:            public void testSetOrientation() {
578:                ui.setOrientation(SwingConstants.VERTICAL);
579:                assertEquals(SwingConstants.VERTICAL, toolBar.getOrientation());
580:                ui.setOrientation(SwingConstants.HORIZONTAL);
581:                assertEquals(SwingConstants.HORIZONTAL, toolBar
582:                        .getOrientation());
583:            }
584:
585:            public void testSetIsRolloverBorders() {
586:                ui.setRolloverBorders(false);
587:                toolBar.add(b);
588:                toolBar.add(label);
589:                b.setBorder(null);
590:                label.setBorder(null);
591:                ui.setRolloverBorders(true);
592:                assertSame(ui.rolloverBorder, b.getBorder());
593:                assertNull(label.getBorder());
594:                assertTrue(ui.isRolloverBorders());
595:                b.setBorder(null);
596:                ui.setRolloverBorders(false);
597:                assertSame(ui.nonRolloverBorder, b.getBorder());
598:                assertFalse(ui.isRolloverBorders());
599:            }
600:
601:            public void testDockingListener() {
602:                createAndShowFrame();
603:                BasicToolBarUI.DockingListener l = ui.new DockingListener(
604:                        toolBar);
605:                MouseEvent e = new MouseEvent(toolBar,
606:                        MouseEvent.MOUSE_DRAGGED, 0, 0, 0, 0, 0, false);
607:                l.mouseDragged(e);
608:                assertTrue(l.isDragging);
609:                assertFalse(new Point(0, 0).equals(l.origin));
610:                assertTrue(ui.dragToCalled);
611:                e = new MouseEvent(toolBar, MouseEvent.MOUSE_DRAGGED, 0, 0, 0,
612:                        0, 1, false);
613:                l.mouseReleased(e);
614:                assertFalse(l.isDragging);
615:                assertTrue(ui.setFloatingCalled);
616:            }
617:
618:            public void testFrameListener() {
619:                prepareToTestFloating();
620:                WindowListener l = ui.createFrameListener();
621:                ui.dragTo(new Point(1, 1), new Point(0, 0));
622:                ui.floatAt(new Point(1, 1), new Point(0, 0));
623:                l.windowClosing(null);
624:                assertTrue(ui.setFloatingCalled);
625:                if (isHarmony()) {
626:                    assertFalse(ui.setFloatingBParam);
627:                }
628:            }
629:
630:            public void testPropertyListener() {
631:                toolBar.setRollover(false);
632:                toolBar.add(b);
633:                toolBar.setRollover(true);
634:                assertSame(ui.rolloverBorder, b.getBorder());
635:                toolBar.setRollover(false);
636:                assertSame(ui.nonRolloverBorder, b.getBorder());
637:            }
638:
639:            public void testToolBarContListener() {
640:                ContainerListener l = ui.createToolBarContListener();
641:                Border border = b.getBorder();
642:                ContainerEvent e = new ContainerEvent(toolBar,
643:                        ContainerEvent.COMPONENT_ADDED, b);
644:                l.componentAdded(e);
645:                assertNotSame(border, b.getBorder());
646:                e = new ContainerEvent(toolBar,
647:                        ContainerEvent.COMPONENT_REMOVED, b);
648:                l.componentRemoved(e);
649:                assertSame(border, b.getBorder());
650:            }
651:
652:            public void testToolBarFocusListener() {
653:                toolBar.add(b);
654:                FocusListener l = ui.createToolBarFocusListener();
655:                FocusEvent e = new FocusEvent(b, FocusEvent.FOCUS_GAINED);
656:                l.focusGained(e);
657:                assertEquals(toolBar.getComponentIndex(b), ui.focusedCompIndex);
658:            }
659:
660:            private void createAndShowFrame() {
661:                frame = new JFrame();
662:                frame.setSize(90, 90);
663:                frame.getContentPane().add(toolBar, BorderLayout.NORTH);
664:                frame.setVisible(true);
665:            }
666:
667:            private void prepareToTestFloating() {
668:                createAndShowFrame();
669:                toolBar.add(b);
670:                toolBar.setFloatable(true);
671:            }
672:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.