Source Code Cross Referenced for BasicTreeUITest.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) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *     http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         */
0017:        /**
0018:         * @author Sergey Burlak
0019:         * @version $Revision$
0020:         */package javax.swing.plaf.basic;
0021:
0022:        import java.awt.Color;
0023:        import java.awt.Component;
0024:        import java.awt.ComponentOrientation;
0025:        import java.awt.Container;
0026:        import java.awt.Dimension;
0027:        import java.awt.Graphics;
0028:        import java.awt.Rectangle;
0029:        import java.awt.event.ComponentEvent;
0030:        import java.awt.event.InputEvent;
0031:        import java.awt.event.KeyEvent;
0032:        import java.awt.event.MouseEvent;
0033:        import java.util.EventObject;
0034:        import javax.swing.BasicSwingTestCase;
0035:        import javax.swing.SwingUtilities;
0036:        import javax.swing.SwingWaitTestCase;
0037:        import javax.swing.BorderFactory;
0038:        import javax.swing.Icon;
0039:        import javax.swing.ImageIcon;
0040:        import javax.swing.JComponent;
0041:        import javax.swing.JFrame;
0042:        import javax.swing.JLabel;
0043:        import javax.swing.JScrollPane;
0044:        import javax.swing.JTree;
0045:        import javax.swing.Timer;
0046:        import javax.swing.UIManager;
0047:        import javax.swing.UnsupportedLookAndFeelException;
0048:        import javax.swing.plaf.basic.BasicTreeUI.ComponentHandler;
0049:        import javax.swing.text.JTextComponent;
0050:        import javax.swing.tree.DefaultMutableTreeNode;
0051:        import javax.swing.tree.DefaultTreeCellEditor;
0052:        import javax.swing.tree.DefaultTreeCellRenderer;
0053:        import javax.swing.tree.DefaultTreeModel;
0054:        import javax.swing.tree.DefaultTreeSelectionModel;
0055:        import javax.swing.tree.FixedHeightLayoutCache;
0056:        import javax.swing.tree.TreeCellEditor;
0057:        import javax.swing.tree.TreePath;
0058:        import javax.swing.tree.VariableHeightLayoutCache;
0059:        import javax.swing.tree.AbstractLayoutCache.NodeDimensions;
0060:
0061:        public class BasicTreeUITest extends BasicSwingTestCase {
0062:            private BasicTreeUI ui;
0063:
0064:            private JTree tree;
0065:
0066:            private DefaultMutableTreeNode root;
0067:
0068:            private DefaultMutableTreeNode node1;
0069:
0070:            private DefaultMutableTreeNode node2;
0071:
0072:            private DefaultMutableTreeNode node3;
0073:
0074:            private DefaultMutableTreeNode node11;
0075:
0076:            private DefaultMutableTreeNode node21;
0077:
0078:            private DefaultMutableTreeNode node22;
0079:
0080:            @Override
0081:            protected void setUp() throws Exception {
0082:                super .setUp();
0083:                try {
0084:                    UIManager.setLookAndFeel(new BasicLookAndFeel() {
0085:                        private static final long serialVersionUID = 1L;
0086:
0087:                        @Override
0088:                        public boolean isNativeLookAndFeel() {
0089:                            return true;
0090:                        }
0091:
0092:                        @Override
0093:                        public boolean isSupportedLookAndFeel() {
0094:                            return true;
0095:                        }
0096:
0097:                        @Override
0098:                        public String getDescription() {
0099:                            return null;
0100:                        }
0101:
0102:                        @Override
0103:                        public String getID() {
0104:                            return null;
0105:                        }
0106:
0107:                        @Override
0108:                        public String getName() {
0109:                            return null;
0110:                        }
0111:                    });
0112:                } catch (UnsupportedLookAndFeelException e) {
0113:                    e.printStackTrace();
0114:                }
0115:                root = new DefaultMutableTreeNode("root");
0116:                node1 = new DefaultMutableTreeNode("node1");
0117:                node2 = new DefaultMutableTreeNode("node2");
0118:                node3 = new DefaultMutableTreeNode("node3");
0119:                node11 = new DefaultMutableTreeNode("node11");
0120:                node21 = new DefaultMutableTreeNode("node21");
0121:                node22 = new DefaultMutableTreeNode("node22");
0122:                root.add(node1);
0123:                node1.add(node11);
0124:                root.add(node1);
0125:                node2.add(node21);
0126:                node2.add(node22);
0127:                root.add(node2);
0128:                root.add(node3);
0129:                tree = new JTree(root);
0130:                ui = new BasicTreeUI();
0131:                tree.setUI(ui);
0132:            }
0133:
0134:            @Override
0135:            protected void tearDown() throws Exception {
0136:                ui = null;
0137:                tree = null;
0138:                root = null;
0139:                node1 = null;
0140:                node2 = null;
0141:                node3 = null;
0142:                node11 = null;
0143:                node21 = null;
0144:                node22 = null;
0145:                super .tearDown();
0146:            }
0147:
0148:            public void testPaint() {
0149:                Graphics g = createTestGraphics();
0150:                g.setClip(0, 0, 100, 100);
0151:                ui.paint(g, tree);
0152:            }
0153:
0154:            public void testGetPreferredSize() {
0155:                assertFalse(ui.validCachedPreferredSize);
0156:                assertEquals(new Dimension(0, 0), ui.preferredSize);
0157:                assertNotSame(new Dimension(0, 0), ui.getPreferredSize(tree));
0158:                assertTrue(ui.validCachedPreferredSize);
0159:                assertEquals(ui.preferredSize, ui.getPreferredSize(tree));
0160:                assertNotSame(ui.preferredSize, ui.getPreferredSize(tree));
0161:                assertNotSame(ui.getPreferredSize(tree), ui
0162:                        .getPreferredSize(tree));
0163:                ui.preferredSize = new Dimension(100, 100);
0164:                assertNotNull(ui.getPreferredSize(tree));
0165:                assertEquals(ui.preferredSize, ui.getPreferredSize(tree));
0166:                assertEquals(ui.preferredSize, new Dimension(100, 100));
0167:                assertEquals(new Dimension(100, 100), ui.getPreferredSize(tree,
0168:                        false));
0169:                assertEquals(new Dimension(100, 100), ui.getPreferredSize(tree,
0170:                        true));
0171:                assertTrue(ui.validCachedPreferredSize);
0172:                ui.validCachedPreferredSize = false;
0173:                assertNotSame(new Dimension(100, 100), ui.getPreferredSize(
0174:                        tree, true));
0175:            }
0176:
0177:            public void testGetMinimumSize() {
0178:                assertEquals(new Dimension(0, 0), ui.getMinimumSize(tree));
0179:                ui.preferredMinSize = new Dimension(100, 100);
0180:                assertEquals(ui.preferredMinSize, ui.getMinimumSize(tree));
0181:                ui.preferredMinSize = new Dimension(-100, -100);
0182:                assertEquals(ui.preferredMinSize, ui.getMinimumSize(tree));
0183:                ui.preferredMinSize = null;
0184:                assertEquals(new Dimension(0, 0), ui.getMinimumSize(tree));
0185:            }
0186:
0187:            public void testGetMaximumSize() {
0188:                assertEquals(ui.getPreferredSize(null), ui.getMaximumSize(null));
0189:                ui.preferredSize = new Dimension(-100, -100);
0190:                assertEquals(new Dimension(-100, -100), ui.getMaximumSize(tree));
0191:                ui = new BasicTreeUI() {
0192:                    @Override
0193:                    public Dimension getPreferredSize(final JComponent c) {
0194:                        return null;
0195:                    }
0196:                };
0197:                ui.installUI(tree);
0198:                assertNull(ui.getMaximumSize(tree));
0199:            }
0200:
0201:            public void testUninstallUI() {
0202:            }
0203:
0204:            public void testInstallUI() {
0205:                ui.uninstallUI(tree);
0206:                ui.installUI(tree);
0207:                assertNotNull(ui.treeModel);
0208:                assertNotNull(ui.treeSelectionModel);
0209:            }
0210:
0211:            public void testCreateUI() {
0212:                assertNotSame(BasicTreeUI.createUI(tree), BasicTreeUI
0213:                        .createUI(tree));
0214:            }
0215:
0216:            public void testGetClosestPathForLocation() {
0217:                assertEquals(ui.getClosestPathForLocation(tree, 5, 5),
0218:                        ui.treeState.getPathClosestTo(5, 5));
0219:            }
0220:
0221:            public void testGetPathBounds() {
0222:                tree.setBorder(BorderFactory.createEmptyBorder(5, 12, 15, 20));
0223:                TreePath p1 = new TreePath(new Object[] { root, node2 });
0224:                TreePath p2 = new TreePath(new Object[] { root, node3 });
0225:                Rectangle bounds = ui.treeState.getBounds(p1, new Rectangle());
0226:                bounds.x += 12;
0227:                bounds.y += 5;
0228:                assertEquals(ui.getPathBounds(tree, p1), bounds);
0229:                bounds = ui.treeState.getBounds(p2, new Rectangle());
0230:                bounds.x += 12;
0231:                bounds.y += 5;
0232:                assertEquals(ui.getPathBounds(tree, p2), bounds);
0233:            }
0234:
0235:            public void testGetPathForRow() {
0236:                TreePath p = new TreePath(new Object[] { root, node2 });
0237:                assertTrue(tree.isRootVisible());
0238:                assertNull(ui.getPathForRow(tree, 7));
0239:                assertEquals(p, ui.treeState.getPathForRow(2));
0240:                assertEquals(p, ui.getPathForRow(new JTree(), 2));
0241:                tree.expandPath(p);
0242:                assertEquals(
0243:                        new TreePath(new Object[] { root, node2, node22 }), ui
0244:                                .getPathForRow(tree, 4));
0245:                assertEquals(new TreePath(new Object[] { root, node3 }), ui
0246:                        .getPathForRow(tree, 5));
0247:                ui.treeState = new VariableHeightLayoutCache() {
0248:                    @Override
0249:                    public TreePath getPathForRow(final int row) {
0250:                        return new TreePath(new Object[] { node3 });
0251:                    }
0252:                };
0253:                assertEquals(new TreePath(new Object[] { node3 }), ui
0254:                        .getPathForRow(tree, -400));
0255:                assertEquals(ui.treeState.getPathForRow(2), ui.getPathForRow(
0256:                        tree, 5));
0257:            }
0258:
0259:            public void testGetRowCount() {
0260:                assertTrue(tree.isRootVisible());
0261:                assertEquals(4, ui.treeState.getRowCount());
0262:                assertEquals(4, ui.getRowCount(new JTree()));
0263:                TreePath p = new TreePath(new Object[] { root, node2 });
0264:                tree.expandPath(p);
0265:                assertEquals(6, ui.getRowCount(tree));
0266:                ui.treeState = new VariableHeightLayoutCache() {
0267:                    @Override
0268:                    public int getRowCount() {
0269:                        return -200;
0270:                    }
0271:                };
0272:                assertEquals(ui.getRowCount(new JTree()), ui.treeState
0273:                        .getRowCount());
0274:                assertEquals(-200, ui.getRowCount(tree));
0275:            }
0276:
0277:            public void testGetRowForPath() {
0278:                assertTrue(tree.isRootVisible());
0279:                TreePath p = new TreePath(new Object[] { root, node2 });
0280:                assertEquals(2, ui.getRowForPath(tree, p));
0281:                assertEquals(2, ui.getRowForPath(new JTree(), p));
0282:                tree.expandPath(new TreePath(new Object[] { root, node1 }));
0283:                ui.treeState = new VariableHeightLayoutCache() {
0284:                    @Override
0285:                    public int getRowForPath(final TreePath p) {
0286:                        return -200;
0287:                    }
0288:                };
0289:                assertEquals(ui.getRowForPath(tree, p), ui.treeState
0290:                        .getRowForPath(p));
0291:                assertEquals(-200, ui.getRowForPath(tree, p));
0292:            }
0293:
0294:            public void testIsEditing() {
0295:                assertFalse(ui.isEditing(tree));
0296:                ui.editingComponent = new JLabel();
0297:                assertTrue(ui.isEditing(tree));
0298:            }
0299:
0300:            public void testGetEditingPath() {
0301:                assertNull(ui.getEditingPath(tree));
0302:                ui.editingPath = new TreePath(root);
0303:                assertNotNull(ui.getEditingPath(tree));
0304:            }
0305:
0306:            public void testStartEditingAtPath() {
0307:                assertFalse(ui.isEditing(tree));
0308:                ui.startEditingAtPath(tree, new TreePath(root));
0309:                assertFalse(ui.isEditing(tree));
0310:                assertNull(ui.getCellEditor());
0311:                tree.setEditable(true);
0312:                assertNotNull(ui.getCellEditor());
0313:                assertNull(ui.editingComponent);
0314:                assertNull(ui.editingPath);
0315:                assertEquals(0, ui.editingRow);
0316:                TreePath path = new TreePath(root).pathByAddingChild(node1);
0317:                ui.startEditingAtPath(tree, path);
0318:                assertTrue(ui.isEditing(tree));
0319:                assertEquals(path, ui.getEditingPath(tree));
0320:                assertEquals(1, ui.editingRow);
0321:                assertNotNull(ui.editingComponent);
0322:                assertEquals(node1.getUserObject(), ui.getCellEditor()
0323:                        .getCellEditorValue());
0324:                ui.cancelEditing(tree);
0325:                assertFalse(ui.isEditing(tree));
0326:                ui.startEditingAtPath(tree, null);
0327:                assertFalse(ui.isEditing(tree));
0328:            }
0329:
0330:            public void testStartEditing() {
0331:                assertFalse(ui.isEditing(tree));
0332:                ui.startEditing(new TreePath(root), null);
0333:                assertFalse(ui.isEditing(tree));
0334:                tree.setEditable(true);
0335:                assertFalse(ui.isEditing(tree));
0336:                ui.startEditing(new TreePath(root), null);
0337:                assertTrue(ui.isEditing(tree));
0338:                ui.cancelEditing(tree);
0339:                assertFalse(ui.isEditing(tree));
0340:                tree.setCellEditor(new DefaultTreeCellEditor(tree,
0341:                        (DefaultTreeCellRenderer) tree.getCellRenderer()) {
0342:                    @Override
0343:                    public boolean shouldSelectCell(final EventObject event) {
0344:                        return false;
0345:                    }
0346:                });
0347:                ui.startEditing(new TreePath(root), null);
0348:                assertTrue(ui.isEditing(tree));
0349:            }
0350:
0351:            public void testCancelEditing() {
0352:                String initialValue = node1.getUserObject().toString();
0353:                tree.setEditable(true);
0354:                ui.startEditing(new TreePath(root).pathByAddingChild(node1),
0355:                        null);
0356:                JTextComponent editor = (JTextComponent) ((Container) ui.editingComponent)
0357:                        .getComponent(0);
0358:                assertEquals(initialValue, editor.getText());
0359:                editor.setText("any value");
0360:                ui.cancelEditing(tree);
0361:                assertEquals(initialValue, node1.getUserObject());
0362:                assertNull(ui.editingComponent);
0363:                assertNull(ui.editingPath);
0364:                assertEquals(1, ui.editingRow);
0365:            }
0366:
0367:            public void testStopEditing() {
0368:                String initialValue = node1.getUserObject().toString();
0369:                tree.setEditable(true);
0370:                ui.startEditing(new TreePath(root).pathByAddingChild(node1),
0371:                        null);
0372:                JTextComponent editor = (JTextComponent) ((Container) ui.editingComponent)
0373:                        .getComponent(0);
0374:                assertEquals(initialValue, editor.getText());
0375:                editor.setText("new value");
0376:                assertTrue(ui.stopEditing(tree));
0377:                assertEquals("new value", node1.getUserObject());
0378:                assertNull(ui.editingComponent);
0379:                assertNull(ui.editingPath);
0380:                assertEquals(1, ui.editingRow);
0381:                assertFalse(ui.stopEditing(tree));
0382:            }
0383:
0384:            public void testSetGetHashColor() {
0385:                assertEquals(UIManager.getColor("Tree.hash"), ui.getHashColor());
0386:                ui.setHashColor(Color.RED);
0387:                assertEquals(Color.RED, ui.getHashColor());
0388:            }
0389:
0390:            public void testSetGetLeftChildIndent() {
0391:                assertEquals(UIManager.getInt("Tree.leftChildIndent"), ui
0392:                        .getLeftChildIndent());
0393:                ui.setLeftChildIndent(20);
0394:                assertEquals(20, ui.getLeftChildIndent());
0395:                ui.setLeftChildIndent(-20);
0396:                assertEquals(-20, ui.getLeftChildIndent());
0397:            }
0398:
0399:            public void testSetGetRightChildIndent() {
0400:                assertEquals(UIManager.getInt("Tree.rightChildIndent"), ui
0401:                        .getRightChildIndent());
0402:                ui.setRightChildIndent(20);
0403:                assertEquals(20, ui.getRightChildIndent());
0404:                ui.setRightChildIndent(-20);
0405:                assertEquals(-20, ui.getRightChildIndent());
0406:            }
0407:
0408:            public void testSetGetExpandedIcon() {
0409:                assertNull(ui.getExpandedIcon());
0410:                ImageIcon imageIcon = new ImageIcon("icon");
0411:                ui.setExpandedIcon(imageIcon);
0412:                assertEquals(imageIcon, ui.getExpandedIcon());
0413:            }
0414:
0415:            public void testSetGetCollapsedIcon() {
0416:                assertNull(ui.getCollapsedIcon());
0417:                ImageIcon imageIcon = new ImageIcon("icon");
0418:                ui.setCollapsedIcon(imageIcon);
0419:                assertEquals(imageIcon, ui.getCollapsedIcon());
0420:            }
0421:
0422:            public void testSetIsLargeModel() {
0423:                assertFalse(ui.isLargeModel());
0424:                ui.setLargeModel(true);
0425:                assertTrue(ui.isLargeModel());
0426:            }
0427:
0428:            public void testSetGetRowHeight() {
0429:                assertEquals(UIManager.getInt("Tree.rowHeight"), ui
0430:                        .getRowHeight());
0431:                tree.setRowHeight(20);
0432:                assertEquals(20, ui.getRowHeight());
0433:                tree.setRowHeight(-20);
0434:                assertEquals(-20, ui.getRowHeight());
0435:            }
0436:
0437:            public void testSetGetCellRenderer() {
0438:                assertTrue(ui.getCellRenderer() instanceof  DefaultTreeCellRenderer);
0439:                DefaultTreeCellRenderer r = new DefaultTreeCellRenderer();
0440:                tree.setCellRenderer(r);
0441:                assertEquals(r, ui.getCellRenderer());
0442:                assertEquals(r, ui.currentCellRenderer);
0443:                ui.setCellRenderer(new DefaultTreeCellRenderer());
0444:                assertEquals(r, ui.currentCellRenderer);
0445:                assertEquals(r, ui.getCellRenderer());
0446:                ui.createdRenderer = false;
0447:                assertFalse(ui.createdRenderer);
0448:                ui.currentCellRenderer = null;
0449:                ui.setCellRenderer(null);
0450:                assertFalse(ui.createdRenderer);
0451:                assertEquals(r, ui.currentCellRenderer);
0452:                assertEquals(r, ui.getCellRenderer());
0453:                tree.setCellRenderer(new DefaultTreeCellRenderer());
0454:                assertNotNull(tree.getCellRenderer());
0455:                assertNotNull(ui.getCellRenderer());
0456:            }
0457:
0458:            public void testSetGetModel() {
0459:                assertTrue(ui.getModel() instanceof  DefaultTreeModel);
0460:                DefaultTreeModel m = new DefaultTreeModel(
0461:                        new DefaultMutableTreeNode("root"));
0462:                ui.setModel(m);
0463:                assertSame(m, ui.getModel());
0464:                assertSame(m, ui.treeModel);
0465:            }
0466:
0467:            public void testSetIsRootVisible() {
0468:                assertTrue(ui.isRootVisible());
0469:                tree.setRootVisible(false);
0470:                assertFalse(ui.isRootVisible());
0471:                assertFalse(ui.treeState.isRootVisible());
0472:                ui.setRootVisible(true);
0473:                assertFalse(ui.isRootVisible());
0474:                assertTrue(ui.treeState.isRootVisible());
0475:            }
0476:
0477:            public void testSetGetShowsRootHandles() {
0478:                assertFalse(ui.getShowsRootHandles());
0479:                tree.setShowsRootHandles(true);
0480:                assertTrue(ui.getShowsRootHandles());
0481:                if (!isHarmony()) {
0482:                    ui.setShowsRootHandles(false);
0483:                    assertTrue(ui.getShowsRootHandles());
0484:                }
0485:            }
0486:
0487:            public void testSetGetCellEditor() {
0488:                assertNull(ui.getCellEditor());
0489:                DefaultTreeCellEditor editor = new DefaultTreeCellEditor(tree,
0490:                        new DefaultTreeCellRenderer());
0491:                tree.setCellEditor(editor);
0492:                assertEquals(editor, ui.getCellEditor());
0493:                ui.setCellEditor(new DefaultTreeCellEditor(tree,
0494:                        new DefaultTreeCellRenderer()));
0495:                assertEquals(editor, ui.getCellEditor());
0496:            }
0497:
0498:            public void testSetIsEditable() {
0499:                assertFalse(ui.isEditable());
0500:                assertNull(ui.getCellEditor());
0501:                tree.setEditable(true);
0502:                assertTrue(ui.isEditable());
0503:                assertNotNull(ui.getCellEditor());
0504:                ui.setEditable(false);
0505:                assertTrue(ui.isEditable());
0506:                assertNotNull(ui.getCellEditor());
0507:                tree.setEditable(false);
0508:                assertFalse(ui.isEditable());
0509:                assertNotNull(ui.getCellEditor());
0510:            }
0511:
0512:            public void testSetGetSelectionModel() {
0513:                assertTrue(ui.getSelectionModel() instanceof  DefaultTreeSelectionModel);
0514:                DefaultTreeSelectionModel m = new DefaultTreeSelectionModel();
0515:                ui.setSelectionModel(m);
0516:                assertSame(m, ui.getSelectionModel());
0517:                assertSame(m, ui.treeSelectionModel);
0518:            }
0519:
0520:            public void testPrepareForUIInstallUninstall() {
0521:                ui = new BasicTreeUI();
0522:                ui.tree = tree;
0523:                ui.prepareForUIInstall();
0524:                assertEquals(new Dimension(), ui.preferredSize);
0525:                assertEquals(0, ui.drawingCache.size());
0526:                ui.prepareForUIUninstall();
0527:            }
0528:
0529:            public void testCompleteUIInstallUninstall() {
0530:                assertEquals(0, ui.drawingCache.size());
0531:                assertEquals(tree.getModel(), ui.treeModel);
0532:                ui.completeUIUninstall();
0533:                assertNull(ui.drawingCache);
0534:                assertNull(ui.treeModel);
0535:            }
0536:
0537:            public void testInstallUninstallDefaults() {
0538:                assertNull(ui.collapsedIcon);
0539:                assertNull(ui.expandedIcon);
0540:                assertNull(ui.preferredMinSize);
0541:                assertSame(tree, ui.tree);
0542:                assertNotNull(ui.currentCellRenderer);
0543:                assertNull(ui.cellEditor);
0544:                assertNotNull(ui.rendererPane);
0545:                assertNotNull(ui.preferredSize);
0546:                assertNotNull(ui.treeState);
0547:                assertNotNull(ui.drawingCache);
0548:                assertNotNull(ui.nodeDimensions);
0549:                assertNotNull(ui.treeModel);
0550:                assertNotNull(ui.treeSelectionModel);
0551:                assertNull(ui.editingComponent);
0552:                assertNull(ui.editingPath);
0553:                assertEquals(UIManager.getInt("Tree.leftChildIndent"),
0554:                        ui.leftChildIndent);
0555:                assertEquals(UIManager.getInt("Tree.rightChildIndent"),
0556:                        ui.rightChildIndent);
0557:                assertEquals(ui.leftChildIndent + ui.rightChildIndent,
0558:                        ui.totalChildIndent);
0559:                assertEquals(-1, ui.lastSelectedRow);
0560:                assertEquals(0, ui.depthOffset);
0561:                assertEquals(0, ui.editingRow);
0562:                assertTrue(ui.createdRenderer);
0563:                assertFalse(ui.createdCellEditor);
0564:                assertTrue(ui.stopEditingInCompleteEditing);
0565:                assertFalse(ui.validCachedPreferredSize);
0566:                assertFalse(ui.editorHasDifferentSize);
0567:                assertFalse(ui.largeModel);
0568:                ui.uninstallDefaults();
0569:            }
0570:
0571:            public void testInstallUninstallListeners() {
0572:                if (!isHarmony()) {
0573:                    return;
0574:                }
0575:                assertTrue(hasListener(tree.getFocusListeners(),
0576:                        BasicTreeUI.FocusHandler.class));
0577:                assertTrue(hasListener(tree.getKeyListeners(),
0578:                        BasicTreeUI.KeyHandler.class));
0579:                assertTrue(hasListener(tree.getMouseListeners(),
0580:                        BasicTreeUI.MouseHandler.class));
0581:                assertTrue(hasListener(tree.getMouseMotionListeners(),
0582:                        BasicTreeUI.MouseHandler.class));
0583:                assertTrue(hasListener(tree.getPropertyChangeListeners(),
0584:                        BasicTreeUI.PropertyChangeHandler.class));
0585:                assertTrue(hasListener(tree.getTreeExpansionListeners(),
0586:                        BasicTreeUI.TreeExpansionHandler.class));
0587:                assertTrue(hasListener(((DefaultTreeModel) tree.getModel())
0588:                        .getTreeModelListeners(),
0589:                        BasicTreeUI.TreeModelHandler.class));
0590:                assertTrue(hasListener(((DefaultTreeSelectionModel) tree
0591:                        .getSelectionModel()).getTreeSelectionListeners(),
0592:                        BasicTreeUI.TreeSelectionHandler.class));
0593:                assertTrue(hasListener(((DefaultTreeSelectionModel) tree
0594:                        .getSelectionModel()).getPropertyChangeListeners(),
0595:                        BasicTreeUI.SelectionModelPropertyChangeHandler.class));
0596:                ui.uninstallListeners();
0597:                assertFalse(hasListener(tree.getFocusListeners(),
0598:                        BasicTreeUI.FocusHandler.class));
0599:                assertFalse(hasListener(tree.getKeyListeners(),
0600:                        BasicTreeUI.KeyHandler.class));
0601:                assertFalse(hasListener(tree.getMouseListeners(),
0602:                        BasicTreeUI.MouseHandler.class));
0603:                assertFalse(hasListener(tree.getMouseMotionListeners(),
0604:                        BasicTreeUI.MouseHandler.class));
0605:                assertFalse(hasListener(tree.getPropertyChangeListeners(),
0606:                        BasicTreeUI.PropertyChangeHandler.class));
0607:                assertFalse(hasListener(tree.getTreeExpansionListeners(),
0608:                        BasicTreeUI.TreeExpansionHandler.class));
0609:                assertFalse(hasListener(tree.getTreeSelectionListeners(),
0610:                        BasicTreeUI.TreeSelectionHandler.class));
0611:                assertFalse(hasListener(((DefaultTreeModel) tree.getModel())
0612:                        .getTreeModelListeners(),
0613:                        BasicTreeUI.TreeModelHandler.class));
0614:                assertFalse(hasListener(((DefaultTreeSelectionModel) tree
0615:                        .getSelectionModel()).getTreeSelectionListeners(),
0616:                        BasicTreeUI.TreeSelectionHandler.class));
0617:                assertFalse(hasListener(((DefaultTreeSelectionModel) tree
0618:                        .getSelectionModel()).getPropertyChangeListeners(),
0619:                        BasicTreeUI.SelectionModelPropertyChangeHandler.class));
0620:            }
0621:
0622:            public void testInstallUninstallKeyboardActions() {
0623:                ui.installKeyboardActions();
0624:                assertNotNull(SwingUtilities.getUIInputMap(tree,
0625:                        JComponent.WHEN_FOCUSED));
0626:                assertNotNull(SwingUtilities.getUIInputMap(tree,
0627:                        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));
0628:                ui.uninstallKeyboardActions();
0629:                assertNull(SwingUtilities.getUIInputMap(tree,
0630:                        JComponent.WHEN_FOCUSED));
0631:                assertNull(SwingUtilities.getUIInputMap(tree,
0632:                        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));
0633:            }
0634:
0635:            public void testInstallUninstallComponents() {
0636:                ui.uninstallComponents();
0637:                assertEquals(0, tree.getComponentCount());
0638:                ui.installComponents();
0639:                assertEquals(1, tree.getComponentCount());
0640:                assertSame(ui.rendererPane, tree.getComponent(0));
0641:                assertEquals(new Rectangle(), ui.rendererPane.getBounds());
0642:                assertFalse(ui.rendererPane.isVisible());
0643:                ui.uninstallComponents();
0644:                assertEquals(0, tree.getComponentCount());
0645:                assertNotNull(ui.rendererPane);
0646:            }
0647:
0648:            public void testCreateNodeDimensions() throws Exception {
0649:                tree.setRowHeight(40);
0650:                ui.setLeftChildIndent(10);
0651:                ui.setRightChildIndent(20);
0652:                ui.depthOffset = 3;
0653:                assertNotNull(ui.createNodeDimensions());
0654:                assertTrue(ui.createNodeDimensions() instanceof  BasicTreeUI.NodeDimensionsHandler);
0655:                assertNotSame(ui.createNodeDimensions(), ui
0656:                        .createNodeDimensions());
0657:                tree.setFont(tree.getFont().deriveFont(40f));
0658:                NodeDimensions n = ui.createNodeDimensions();
0659:                Component c = ui.getCellRenderer()
0660:                        .getTreeCellRendererComponent(tree, root.toString(),
0661:                                false, false, false, 0, false);
0662:                assertEquals(new Rectangle(
0663:                        ui.totalChildIndent * ui.depthOffset, 0, c
0664:                                .getPreferredSize().width,
0665:                        c.getPreferredSize().height), n.getNodeDimensions(root,
0666:                        0, 0, true, new Rectangle()));
0667:                c = ui.getCellRenderer().getTreeCellRendererComponent(tree,
0668:                        node1.toString(), false, false, false, 0, false);
0669:                assertEquals(new Rectangle(
0670:                        ui.totalChildIndent * ui.depthOffset, 0, c
0671:                                .getPreferredSize().width,
0672:                        c.getPreferredSize().height), n.getNodeDimensions(
0673:                        node1, 0, 0, true, new Rectangle()));
0674:                Rectangle rectangle = new Rectangle(10, 10, 20, 20);
0675:                c = ui.getCellRenderer().getTreeCellRendererComponent(tree,
0676:                        root.toString(), false, false, false, 0, false);
0677:                assertEquals(
0678:                        new Rectangle(ui.totalChildIndent * ui.depthOffset
0679:                                + ui.totalChildIndent * 3, rectangle.y, c
0680:                                .getPreferredSize().width,
0681:                                c.getPreferredSize().height), n
0682:                                .getNodeDimensions(root, 2, 3, true, rectangle));
0683:            }
0684:
0685:            public void testCreateNodeDimensionsRTL() throws Exception {
0686:                tree.setRowHeight(40);
0687:                tree
0688:                        .setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
0689:                NodeDimensions n = ui.createNodeDimensions();
0690:                Component c = ui.getCellRenderer()
0691:                        .getTreeCellRendererComponent(tree, root.toString(),
0692:                                false, false, false, 0, false);
0693:                assertEquals(
0694:                        new Rectangle(
0695:                                tree.getWidth()
0696:                                        - (ui.totalChildIndent * ui.depthOffset + ui.totalChildIndent * 0)
0697:                                        - c.getPreferredSize().width, 0, c
0698:                                        .getPreferredSize().width, c
0699:                                        .getPreferredSize().height), n
0700:                                .getNodeDimensions(root, 0, 0, true,
0701:                                        new Rectangle()));
0702:                assertEquals(
0703:                        new Rectangle(
0704:                                tree.getWidth()
0705:                                        - (ui.totalChildIndent * ui.depthOffset + ui.totalChildIndent * 2)
0706:                                        - c.getPreferredSize().width, 0, c
0707:                                        .getPreferredSize().width, c
0708:                                        .getPreferredSize().height), n
0709:                                .getNodeDimensions(root, 0, 2, true,
0710:                                        new Rectangle()));
0711:                c = ui.getCellRenderer().getTreeCellRendererComponent(tree,
0712:                        node1.toString(), false, false, false, 0, false);
0713:                assertEquals(
0714:                        new Rectangle(
0715:                                tree.getWidth()
0716:                                        - (ui.totalChildIndent * ui.depthOffset + ui.totalChildIndent * 0)
0717:                                        - c.getPreferredSize().width, 0, c
0718:                                        .getPreferredSize().width, c
0719:                                        .getPreferredSize().height), n
0720:                                .getNodeDimensions(node1, 0, 0, true,
0721:                                        new Rectangle()));
0722:                assertEquals(
0723:                        new Rectangle(
0724:                                tree.getWidth()
0725:                                        - (ui.totalChildIndent * ui.depthOffset + ui.totalChildIndent * 2)
0726:                                        - c.getPreferredSize().width, 0, c
0727:                                        .getPreferredSize().width, c
0728:                                        .getPreferredSize().height), n
0729:                                .getNodeDimensions(node1, 0, 2, true,
0730:                                        new Rectangle()));
0731:            }
0732:
0733:            public void testCreatePropertyChangeListener() {
0734:                assertNotNull(ui.createPropertyChangeListener());
0735:                if (isHarmony()) {
0736:                    assertTrue(ui.createPropertyChangeListener() instanceof  BasicTreeUI.PropertyChangeHandler);
0737:                    assertNotSame(ui.createPropertyChangeListener(), ui
0738:                            .createPropertyChangeListener());
0739:                }
0740:            }
0741:
0742:            public void testCreateMouseListener() {
0743:                assertNotNull(ui.createMouseListener());
0744:                if (isHarmony()) {
0745:                    assertTrue(ui.createMouseListener() instanceof  BasicTreeUI.MouseHandler);
0746:                    assertNotSame(ui.createMouseListener(), ui
0747:                            .createMouseListener());
0748:                }
0749:            }
0750:
0751:            public void testCreateFocusListener() {
0752:                assertNotNull(ui.createFocusListener());
0753:                if (isHarmony()) {
0754:                    assertTrue(ui.createFocusListener() instanceof  BasicTreeUI.FocusHandler);
0755:                    assertNotSame(ui.createFocusListener(), ui
0756:                            .createFocusListener());
0757:                }
0758:            }
0759:
0760:            public void testCreateKeyListener() {
0761:                assertNotNull(ui.createKeyListener());
0762:                if (isHarmony()) {
0763:                    assertTrue(ui.createKeyListener() instanceof  BasicTreeUI.KeyHandler);
0764:                    assertNotSame(ui.createKeyListener(), ui
0765:                            .createKeyListener());
0766:                }
0767:            }
0768:
0769:            public void testCreateSelectionModelPropertyChangeListener() {
0770:                assertNotNull(ui.createSelectionModelPropertyChangeListener());
0771:                if (isHarmony()) {
0772:                    assertTrue(ui.createSelectionModelPropertyChangeListener() instanceof  BasicTreeUI.SelectionModelPropertyChangeHandler);
0773:                    assertNotSame(ui
0774:                            .createSelectionModelPropertyChangeListener(), ui
0775:                            .createSelectionModelPropertyChangeListener());
0776:                }
0777:            }
0778:
0779:            public void testCreateTreeSelectionListener() {
0780:                assertNotNull(ui.createTreeSelectionListener());
0781:                if (isHarmony()) {
0782:                    assertTrue(ui.createTreeSelectionListener() instanceof  BasicTreeUI.TreeSelectionHandler);
0783:                    assertNotSame(ui.createTreeSelectionListener(), ui
0784:                            .createTreeSelectionListener());
0785:                }
0786:            }
0787:
0788:            public void testCreateCellEditorListener() {
0789:                assertNotNull(ui.createCellEditorListener());
0790:                if (isHarmony()) {
0791:                    assertTrue(ui.createCellEditorListener() instanceof  BasicTreeUI.CellEditorHandler);
0792:                    assertNotSame(ui.createCellEditorListener(), ui
0793:                            .createCellEditorListener());
0794:                }
0795:            }
0796:
0797:            public void testCreateComponentListener() {
0798:                assertNotNull(ui.createComponentListener());
0799:                assertTrue(ui.createComponentListener() instanceof  BasicTreeUI.ComponentHandler);
0800:                assertNotSame(ui.createComponentListener(), ui
0801:                        .createComponentListener());
0802:            }
0803:
0804:            public void testCreateTreeExpansionListener() {
0805:                assertNotNull(ui.createTreeExpansionListener());
0806:                if (isHarmony()) {
0807:                    assertTrue(ui.createTreeExpansionListener() instanceof  BasicTreeUI.TreeExpansionHandler);
0808:                    assertNotSame(ui.createTreeExpansionListener(), ui
0809:                            .createTreeExpansionListener());
0810:                }
0811:            }
0812:
0813:            public void testCreateLayoutCache() {
0814:                tree.setRowHeight(0);
0815:                assertNotNull(ui.createLayoutCache());
0816:                assertNotSame(ui.createLayoutCache(), ui.createLayoutCache());
0817:                assertTrue(ui.createLayoutCache() instanceof  VariableHeightLayoutCache);
0818:                assertTrue(ui.treeState instanceof  VariableHeightLayoutCache);
0819:                tree.setRowHeight(10);
0820:                assertTrue(ui.createLayoutCache() instanceof  VariableHeightLayoutCache);
0821:                assertTrue(ui.treeState instanceof  VariableHeightLayoutCache);
0822:                tree.setRowHeight(0);
0823:                tree.setLargeModel(true);
0824:                assertTrue(ui.createLayoutCache() instanceof  VariableHeightLayoutCache);
0825:                assertTrue(ui.treeState instanceof  VariableHeightLayoutCache);
0826:                tree.setRowHeight(10);
0827:                assertTrue(ui.createLayoutCache() instanceof  FixedHeightLayoutCache);
0828:                assertTrue(ui.treeState instanceof  FixedHeightLayoutCache);
0829:            }
0830:
0831:            public void testCreateCellRendererPane() {
0832:                assertNotNull(ui.createCellRendererPane());
0833:                assertNotSame(ui.createCellRendererPane(), ui
0834:                        .createCellRendererPane());
0835:            }
0836:
0837:            public void testCreateDefaultCellEditor() {
0838:                assertTrue(ui.createDefaultCellEditor() instanceof  DefaultTreeCellEditor);
0839:                assertNotSame(ui.createDefaultCellEditor(), ui
0840:                        .createDefaultCellEditor());
0841:            }
0842:
0843:            public void testCreateDefaultCellRenderer() {
0844:                assertTrue(ui.createDefaultCellRenderer() instanceof  DefaultTreeCellRenderer);
0845:                assertNotSame(ui.createDefaultCellRenderer(), ui
0846:                        .createDefaultCellRenderer());
0847:            }
0848:
0849:            public void testCreateTreeModelListener() {
0850:                assertNotNull(ui.createTreeModelListener());
0851:                if (isHarmony()) {
0852:                    assertTrue(ui.createTreeModelListener() instanceof  BasicTreeUI.TreeModelHandler);
0853:                    assertNotSame(ui.createTreeModelListener(), ui
0854:                            .createTreeModelListener());
0855:                }
0856:            }
0857:
0858:            public void testShouldPaintExpandControl() {
0859:                TreePath rootPath = new TreePath(root);
0860:                assertFalse(ui.shouldPaintExpandControl(rootPath, -10, false,
0861:                        false, false));
0862:                assertFalse(ui.shouldPaintExpandControl(rootPath, 10, false,
0863:                        false, false));
0864:                assertFalse(ui.shouldPaintExpandControl(rootPath, 100, true,
0865:                        true, false));
0866:                TreePath path1 = rootPath.pathByAddingChild(node1);
0867:                assertFalse(ui.shouldPaintExpandControl(path1, -10, false,
0868:                        false, true));
0869:                assertTrue(ui.shouldPaintExpandControl(path1, 10, false, false,
0870:                        false));
0871:                assertTrue(ui.shouldPaintExpandControl(path1, 100, false, true,
0872:                        false));
0873:                assertTrue(ui.shouldPaintExpandControl(path1, -100, true,
0874:                        false, false));
0875:                tree.setRootVisible(false);
0876:                assertFalse(ui.shouldPaintExpandControl(rootPath, -1, false,
0877:                        false, false));
0878:                assertFalse(ui.shouldPaintExpandControl(path1, 0, true, true,
0879:                        false));
0880:                tree.setShowsRootHandles(true);
0881:                assertTrue(ui.shouldPaintExpandControl(rootPath, -1, false,
0882:                        false, false));
0883:                assertTrue(ui.shouldPaintExpandControl(path1, 0, true, true,
0884:                        false));
0885:                tree.setShowsRootHandles(false);
0886:                TreePath path11 = path1.pathByAddingChild(node11);
0887:                assertFalse(ui.shouldPaintExpandControl(path11, -1, false,
0888:                        false, true));
0889:                assertTrue(ui.shouldPaintExpandControl(path11, -1, false,
0890:                        false, false));
0891:                tree.setRootVisible(true);
0892:                TreePath unexisted = new TreePath(node1)
0893:                        .pathByAddingChild(node11);
0894:                assertTrue(ui.shouldPaintExpandControl(unexisted, -1, false,
0895:                        false, false));
0896:            }
0897:
0898:            public void testGetVerticalLegBuffer() {
0899:                assertEquals(0, ui.getVerticalLegBuffer());
0900:            }
0901:
0902:            public void testGetHorizontalLegBuffer() {
0903:                assertEquals(0, ui.getHorizontalLegBuffer());
0904:            }
0905:
0906:            public void testGetRowX() {
0907:                assertEquals(0, ui.getRowX(-10, 0));
0908:                assertEquals(ui.totalChildIndent, ui.getRowX(-10, 1));
0909:                ui.totalChildIndent = 15;
0910:                assertEquals(ui.totalChildIndent, ui.getRowX(-10, 1));
0911:                assertEquals(3 * ui.totalChildIndent, ui.getRowX(-10, 3));
0912:                ui.depthOffset = 10;
0913:                assertEquals(ui.depthOffset * ui.totalChildIndent, ui.getRowX(
0914:                        -100, 0));
0915:                assertEquals(ui.depthOffset * ui.totalChildIndent + 2
0916:                        * ui.totalChildIndent, ui.getRowX(-100, 2));
0917:                ui.depthOffset = 0;
0918:                tree.setRootVisible(false);
0919:                assertEquals(-ui.totalChildIndent, ui.getRowX(-10, 0));
0920:                assertEquals(0, ui.getRowX(-10, 1));
0921:                assertEquals(2 * ui.totalChildIndent, ui.getRowX(-10, 3));
0922:                tree.setBorder(BorderFactory.createEmptyBorder(5, 10, 15, 20));
0923:                assertEquals(-ui.totalChildIndent, ui.getRowX(-10, 0));
0924:                assertEquals(0, ui.getRowX(-10, 1));
0925:                assertEquals(2 * ui.totalChildIndent, ui.getRowX(-10, 3));
0926:            }
0927:
0928:            public void testUpdateLayoutCacheExpandedNodes() {
0929:                ui.treeModel = null;
0930:                ui.updateLayoutCacheExpandedNodes();
0931:            }
0932:
0933:            public void testUpdateExpandedDescendants() {
0934:                TreePath pathToExpand = new TreePath(tree.getModel().getRoot())
0935:                        .pathByAddingChild(node1);
0936:                tree.expandPath(pathToExpand);
0937:                assertTrue(ui.treeState.isExpanded(pathToExpand));
0938:                ui.treeState = new VariableHeightLayoutCache();
0939:                ui.treeState.setModel(tree.getModel());
0940:                assertFalse(ui.treeState.isExpanded(pathToExpand));
0941:                ui.updateExpandedDescendants(new TreePath(tree.getModel()
0942:                        .getRoot()));
0943:                assertTrue(ui.treeState.isExpanded(pathToExpand));
0944:            }
0945:
0946:            public void testGetLastChildPath() {
0947:                TreePath rootPath = new TreePath(root);
0948:                TreePath lastChildPath = rootPath.pathByAddingChild(tree
0949:                        .getModel().getChild(root,
0950:                                tree.getModel().getChildCount(root) - 1));
0951:                assertEquals(lastChildPath, ui.getLastChildPath(rootPath));
0952:                TreePath leafPath = rootPath.pathByAddingChild(node1)
0953:                        .pathByAddingChild(node11);
0954:                assertNull(ui.getLastChildPath(leafPath));
0955:            }
0956:
0957:            public void testUpdateDepthOffset() {
0958:                ui.depthOffset = -100;
0959:                ui.updateDepthOffset();
0960:                assertEquals(0, ui.depthOffset);
0961:                tree.setRootVisible(false);
0962:                ui.depthOffset = -100;
0963:                ui.updateDepthOffset();
0964:                assertEquals(-1, ui.depthOffset);
0965:                tree.setRootVisible(true);
0966:                assertEquals(0, ui.depthOffset);
0967:                tree.setShowsRootHandles(true);
0968:                assertEquals(1, ui.depthOffset);
0969:            }
0970:
0971:            public void testUpdateCellEditor() {
0972:                DefaultTreeCellEditor e1 = new DefaultTreeCellEditor(tree,
0973:                        new DefaultTreeCellRenderer());
0974:                tree.setCellEditor(e1);
0975:                assertSame(e1, tree.getCellEditor());
0976:                assertNull(ui.cellEditor);
0977:                assertSame(e1, ui.getCellEditor());
0978:                tree.setEditable(true);
0979:                assertSame(e1, ui.cellEditor);
0980:                assertSame(e1, ui.getCellEditor());
0981:                DefaultTreeCellEditor e2 = new DefaultTreeCellEditor(tree,
0982:                        new DefaultTreeCellRenderer());
0983:                ui.cellEditor = e2;
0984:                assertSame(e1, ui.getCellEditor());
0985:                assertSame(e2, ui.cellEditor);
0986:                ui.updateCellEditor();
0987:                assertSame(e1, ui.cellEditor);
0988:                assertSame(e1, tree.getCellEditor());
0989:                ui.cellEditor = null;
0990:                assertFalse(ui.createdCellEditor);
0991:                ui.createdCellEditor = true;
0992:                assertTrue(ui.createdCellEditor);
0993:                ui.updateCellEditor();
0994:                assertFalse(ui.createdCellEditor);
0995:                assertSame(e1, ui.cellEditor);
0996:                assertSame(e1, tree.getCellEditor());
0997:                tree.setCellRenderer(new DefaultTreeCellRenderer());
0998:                assertFalse(ui.createdCellEditor);
0999:                assertSame(e1, ui.cellEditor);
1000:                assertSame(e1, tree.getCellEditor());
1001:                ui.createdCellEditor = true;
1002:                tree.setCellRenderer(new DefaultTreeCellRenderer());
1003:                assertTrue(ui.createdCellEditor);
1004:                assertNotSame(e1, ui.cellEditor);
1005:                assertNotSame(e1, tree.getCellEditor());
1006:            }
1007:
1008:            public void testUpdateRenderer() {
1009:                DefaultTreeCellRenderer r1 = new DefaultTreeCellRenderer();
1010:                tree.setCellRenderer(r1);
1011:                assertSame(r1, tree.getCellRenderer());
1012:                assertSame(r1, ui.currentCellRenderer);
1013:                assertSame(r1, ui.getCellRenderer());
1014:                DefaultTreeCellRenderer r2 = new DefaultTreeCellRenderer();
1015:                ui.currentCellRenderer = r2;
1016:                assertSame(r2, ui.getCellRenderer());
1017:                ui.updateRenderer();
1018:                assertSame(r1, ui.currentCellRenderer);
1019:                assertSame(r1, tree.getCellRenderer());
1020:                ui.currentCellRenderer = null;
1021:                assertFalse(ui.createdRenderer);
1022:                ui.createdRenderer = true;
1023:                assertTrue(ui.createdRenderer);
1024:                ui.updateRenderer();
1025:                assertFalse(ui.createdRenderer);
1026:                assertSame(r1, ui.currentCellRenderer);
1027:                assertSame(r1, tree.getCellRenderer());
1028:            }
1029:
1030:            public void testConfigureLayoutCache() {
1031:                TreePath expandedPath = new TreePath(tree.getModel().getRoot())
1032:                        .pathByAddingChild(node1);
1033:                tree.expandPath(expandedPath);
1034:                ui.treeState = new VariableHeightLayoutCache();
1035:                ui.configureLayoutCache();
1036:                assertSame(tree.getModel(), ui.treeState.getModel());
1037:                assertSame(tree.getSelectionModel(), ui.treeState
1038:                        .getSelectionModel());
1039:                assertSame(ui.nodeDimensions, ui.treeState.getNodeDimensions());
1040:                assertEquals(tree.getRowHeight(), ui.treeState.getRowHeight());
1041:                assertTrue(ui.treeState.isExpanded(expandedPath));
1042:                assertTrue(ui.treeState.isRootVisible());
1043:            }
1044:
1045:            public void testUpdateSize() {
1046:                ui.preferredSize = new Dimension(100, 100);
1047:                ui.preferredMinSize = new Dimension(200, 200);
1048:                ui.validCachedPreferredSize = true;
1049:                ui.updateSize();
1050:                assertFalse(ui.validCachedPreferredSize);
1051:                assertEquals(ui.preferredSize, new Dimension(100, 100));
1052:                assertEquals(ui.preferredMinSize, new Dimension(200, 200));
1053:            }
1054:
1055:            public void testUpdateCachedPreferredSize() {
1056:                Dimension originalSize = ui.getPreferredSize(tree);
1057:                ui.preferredSize = new Dimension(100, 100);
1058:                assertTrue(ui.validCachedPreferredSize);
1059:                ui.validCachedPreferredSize = false;
1060:                ui.updateCachedPreferredSize();
1061:                assertTrue(ui.validCachedPreferredSize);
1062:                assertEquals(ui.preferredSize, originalSize);
1063:                assertEquals(new Dimension(
1064:                        ui.treeState.getPreferredWidth(null), ui.treeState
1065:                                .getPreferredHeight()), ui.preferredSize);
1066:            }
1067:
1068:            public void testPathWasExpanded() {
1069:                TreePath rootPath = new TreePath(root);
1070:                TreePath path1 = rootPath.pathByAddingChild(node1);
1071:                assertFalse(ui.treeState.isExpanded(path1));
1072:                ui.pathWasExpanded(path1);
1073:                assertTrue(ui.treeState.isExpanded(path1));
1074:                assertFalse(tree.isExpanded(path1));
1075:            }
1076:
1077:            public void testPathWasCollapsed() {
1078:                TreePath rootPath = new TreePath(root);
1079:                TreePath path1 = rootPath.pathByAddingChild(node1);
1080:                tree.expandPath(path1);
1081:                assertTrue(ui.treeState.isExpanded(path1));
1082:                ui.pathWasCollapsed(path1);
1083:                assertFalse(ui.treeState.isExpanded(path1));
1084:            }
1085:
1086:            public void testGetSetPreferredMinSize() {
1087:                assertNull(ui.preferredMinSize);
1088:                assertNull(ui.getPreferredMinSize());
1089:                Dimension prefMinSize = new Dimension(10, 10);
1090:                ui.setPreferredMinSize(prefMinSize);
1091:                assertEquals(ui.preferredMinSize, ui.getPreferredMinSize());
1092:                assertEquals(ui.preferredMinSize, prefMinSize);
1093:            }
1094:
1095:            public void testCompleteEditing() {
1096:                final Marker stopMarker = new Marker();
1097:                final Marker cancelMarker = new Marker();
1098:                final Marker valueMarker = new Marker();
1099:                ui = new BasicTreeUI() {
1100:                    @Override
1101:                    protected void completeEditing(final boolean messageStop,
1102:                            final boolean messageCancel,
1103:                            final boolean messageTree) {
1104:                        super .completeEditing(messageStop, messageCancel,
1105:                                messageTree);
1106:                        stopMarker.setOccurred(messageStop);
1107:                        cancelMarker.setOccurred(messageCancel);
1108:                        valueMarker.setOccurred(messageTree);
1109:                    }
1110:                };
1111:                ui.installUI(tree);
1112:                final Marker editorMarker = new Marker();
1113:                TreeCellEditor editor = new DefaultTreeCellEditor(tree,
1114:                        new DefaultTreeCellRenderer()) {
1115:                    @Override
1116:                    public boolean stopCellEditing() {
1117:                        editorMarker.setOccurred();
1118:                        return super .stopCellEditing();
1119:                    }
1120:                };
1121:                tree.setCellEditor(editor);
1122:                editorMarker.reset();
1123:                stopMarker.reset();
1124:                cancelMarker.reset();
1125:                valueMarker.reset();
1126:                ui.completeEditing();
1127:                assertFalse(editorMarker.isOccurred());
1128:                assertFalse(stopMarker.isOccurred());
1129:                assertTrue(cancelMarker.isOccurred());
1130:                assertFalse(valueMarker.isOccurred());
1131:                editorMarker.reset();
1132:                stopMarker.reset();
1133:                cancelMarker.reset();
1134:                valueMarker.reset();
1135:                tree.setInvokesStopCellEditing(true);
1136:                ui.completeEditing();
1137:                assertFalse(editorMarker.isOccurred());
1138:                if (isHarmony()) {
1139:                    assertTrue(stopMarker.isOccurred());
1140:                    assertFalse(cancelMarker.isOccurred());
1141:                } else {
1142:                    assertFalse(stopMarker.isOccurred());
1143:                    assertTrue(cancelMarker.isOccurred());
1144:                }
1145:                assertFalse(valueMarker.isOccurred());
1146:                tree.setEditable(true);
1147:                ui.startEditingAtPath(tree, new TreePath(root));
1148:                assertTrue(ui.isEditing(tree));
1149:                ui.completeEditing(false, false, false);
1150:                assertFalse(ui.isEditing(tree));
1151:            }
1152:
1153:            public void testCheckForClickInExpandControl() {
1154:                TreePath path1 = new TreePath(root).pathByAddingChild(node1);
1155:                assertFalse(tree.isExpanded(path1));
1156:                assertTrue(ui.isLocationInExpandControl(path1, 8, 20));
1157:                ui.checkForClickInExpandControl(path1, 8, 20);
1158:                assertTrue(tree.isExpanded(path1));
1159:                ui.checkForClickInExpandControl(path1, 8, 20);
1160:                assertFalse(tree.isExpanded(path1));
1161:            }
1162:
1163:            public void testIsLocationInExpandControl() {
1164:                TreePath rootPath = new TreePath(root);
1165:                TreePath path1 = rootPath.pathByAddingChild(node1);
1166:                assertFalse(ui.isLocationInExpandControl(rootPath, 0, 5));
1167:                assertFalse(ui.isLocationInExpandControl(path1, 2, 20));
1168:                assertTrue(ui.isLocationInExpandControl(path1, 3, 20));
1169:                assertTrue(ui.isLocationInExpandControl(path1, 11, 20));
1170:                assertFalse(ui.isLocationInExpandControl(path1, 12, 20));
1171:                ui.setLeftChildIndent(10);
1172:                ui.setRightChildIndent(20);
1173:                assertEquals(30, ui.totalChildIndent);
1174:                assertFalse(ui.isLocationInExpandControl(path1, 5, 20));
1175:                assertTrue(ui.isLocationInExpandControl(path1, 6, 20));
1176:                assertTrue(ui.isLocationInExpandControl(path1, 14, 20));
1177:                assertFalse(ui.isLocationInExpandControl(path1, 15, 20));
1178:                ui.setLeftChildIndent(11);
1179:                assertEquals(31, ui.totalChildIndent);
1180:                assertFalse(ui.isLocationInExpandControl(path1, 6, 20));
1181:                assertTrue(ui.isLocationInExpandControl(path1, 7, 20));
1182:                assertTrue(ui.isLocationInExpandControl(path1, 15, 20));
1183:                assertFalse(ui.isLocationInExpandControl(path1, 16, 20));
1184:                ui.setRightChildIndent(21);
1185:                assertEquals(32, ui.totalChildIndent);
1186:                assertFalse(ui.isLocationInExpandControl(path1, 6, 20));
1187:                assertTrue(ui.isLocationInExpandControl(path1, 7, 20));
1188:                assertTrue(ui.isLocationInExpandControl(path1, 15, 20));
1189:                assertFalse(ui.isLocationInExpandControl(path1, 16, 20));
1190:                ui.setLeftChildIndent(1);
1191:                assertEquals(22, ui.totalChildIndent);
1192:                assertTrue(ui.isLocationInExpandControl(path1, 0, 20));
1193:                assertTrue(ui.isLocationInExpandControl(path1, 5, 20));
1194:                assertFalse(ui.isLocationInExpandControl(path1, 6, 20));
1195:                ui.setLeftChildIndent(2);
1196:                assertEquals(23, ui.totalChildIndent);
1197:                assertTrue(ui.isLocationInExpandControl(path1, 0, 20));
1198:                assertTrue(ui.isLocationInExpandControl(path1, 6, 20));
1199:                assertFalse(ui.isLocationInExpandControl(path1, 7, 20));
1200:                ui.setLeftChildIndent(3);
1201:                assertTrue(ui.isLocationInExpandControl(path1, 0, 20));
1202:                assertTrue(ui.isLocationInExpandControl(path1, 7, 20));
1203:                assertFalse(ui.isLocationInExpandControl(path1, 8, 20));
1204:                ui.setLeftChildIndent(4);
1205:                assertTrue(ui.isLocationInExpandControl(path1, 0, 20));
1206:                assertTrue(ui.isLocationInExpandControl(path1, 8, 20));
1207:                assertFalse(ui.isLocationInExpandControl(path1, 9, 20));
1208:                ui.setLeftChildIndent(5);
1209:                assertFalse(ui.isLocationInExpandControl(path1, 0, 20));
1210:                assertTrue(ui.isLocationInExpandControl(path1, 1, 20));
1211:                assertTrue(ui.isLocationInExpandControl(path1, 9, 20));
1212:                assertFalse(ui.isLocationInExpandControl(path1, 10, 20));
1213:                ui.expandedIcon = new Icon() {
1214:                    public void paintIcon(Component c, Graphics g, int x, int y) {
1215:                    }
1216:
1217:                    public int getIconWidth() {
1218:                        return 14;
1219:                    }
1220:
1221:                    public int getIconHeight() {
1222:                        return 100;
1223:                    }
1224:                };
1225:                ui.setLeftChildIndent(30);
1226:                ui.setRightChildIndent(100);
1227:                assertFalse(ui.isLocationInExpandControl(path1, 22, 20));
1228:                assertTrue(ui.isLocationInExpandControl(path1, 23, 20));
1229:                assertTrue(ui.isLocationInExpandControl(path1, 37, 20));
1230:                assertFalse(ui.isLocationInExpandControl(path1, 38, 20));
1231:            }
1232:
1233:            public void testHandleExpandControlClick() {
1234:                TreePath path1 = new TreePath(root).pathByAddingChild(node1);
1235:                assertFalse(tree.isExpanded(path1));
1236:                ui.handleExpandControlClick(path1, -10, -10);
1237:                assertTrue(tree.isExpanded(path1));
1238:                ui.handleExpandControlClick(path1, -10, -10);
1239:                assertFalse(tree.isExpanded(path1));
1240:            }
1241:
1242:            public void testToggleExpandState() {
1243:                TreePath path1 = new TreePath(root).pathByAddingChild(node1);
1244:                assertFalse(tree.isExpanded(path1));
1245:                ui.toggleExpandState(path1);
1246:                assertTrue(tree.isExpanded(path1));
1247:                ui.toggleExpandState(path1);
1248:                assertFalse(tree.isExpanded(path1));
1249:            }
1250:
1251:            public void testIsToggleSelectionEvent() {
1252:                assertTrue(ui.isToggleSelectionEvent(new MouseEvent(tree,
1253:                        MouseEvent.MOUSE_PRESSED, 0, InputEvent.CTRL_DOWN_MASK,
1254:                        0, 0, 1, false, MouseEvent.BUTTON1)));
1255:                assertTrue(ui.isToggleSelectionEvent(new MouseEvent(tree,
1256:                        MouseEvent.MOUSE_PRESSED, 0, InputEvent.CTRL_DOWN_MASK,
1257:                        0, 0, 2, false, MouseEvent.BUTTON1)));
1258:                assertFalse(ui.isToggleSelectionEvent(new MouseEvent(tree,
1259:                        MouseEvent.MOUSE_PRESSED, 0, InputEvent.CTRL_DOWN_MASK,
1260:                        0, 0, 1, false, MouseEvent.BUTTON2)));
1261:                assertFalse(ui.isToggleSelectionEvent(new MouseEvent(tree,
1262:                        MouseEvent.MOUSE_PRESSED, 0, InputEvent.CTRL_DOWN_MASK,
1263:                        0, 0, 1, false, MouseEvent.BUTTON3)));
1264:                assertFalse(ui.isToggleSelectionEvent(new MouseEvent(tree,
1265:                        MouseEvent.MOUSE_PRESSED, 0,
1266:                        InputEvent.SHIFT_DOWN_MASK, 0, 0, 1, false,
1267:                        MouseEvent.BUTTON1)));
1268:            }
1269:
1270:            public void testIsMultiSelectEvent() {
1271:                assertTrue(ui.isMultiSelectEvent(new MouseEvent(tree,
1272:                        MouseEvent.MOUSE_PRESSED, 0,
1273:                        InputEvent.SHIFT_DOWN_MASK, 0, 0, 1, false,
1274:                        MouseEvent.BUTTON1)));
1275:                assertTrue(ui.isMultiSelectEvent(new MouseEvent(tree,
1276:                        MouseEvent.MOUSE_PRESSED, 0,
1277:                        InputEvent.SHIFT_DOWN_MASK, 0, 0, 2, false,
1278:                        MouseEvent.BUTTON1)));
1279:                assertFalse(ui.isMultiSelectEvent(new MouseEvent(tree,
1280:                        MouseEvent.MOUSE_PRESSED, 0,
1281:                        InputEvent.SHIFT_DOWN_MASK, 0, 0, 1, false,
1282:                        MouseEvent.BUTTON2)));
1283:                assertFalse(ui.isMultiSelectEvent(new MouseEvent(tree,
1284:                        MouseEvent.MOUSE_PRESSED, 0,
1285:                        InputEvent.SHIFT_DOWN_MASK, 0, 0, 1, false,
1286:                        MouseEvent.BUTTON3)));
1287:                assertFalse(ui.isMultiSelectEvent(new MouseEvent(tree,
1288:                        MouseEvent.MOUSE_PRESSED, 0, InputEvent.CTRL_DOWN_MASK,
1289:                        0, 0, 1, false, MouseEvent.BUTTON1)));
1290:            }
1291:
1292:            public void testIsToggleEvent() {
1293:                assertTrue(ui.isToggleEvent(new MouseEvent(tree,
1294:                        MouseEvent.MOUSE_PRESSED, 0, 0, 0, 0, 2, false,
1295:                        MouseEvent.BUTTON1)));
1296:                assertFalse(ui.isToggleEvent(new MouseEvent(tree,
1297:                        MouseEvent.MOUSE_PRESSED, 0, 0, 0, 0, 3, false,
1298:                        MouseEvent.BUTTON1)));
1299:                assertFalse(ui.isToggleEvent(new MouseEvent(tree,
1300:                        MouseEvent.MOUSE_PRESSED, 0, 0, 0, 0, 1, false,
1301:                        MouseEvent.BUTTON1)));
1302:                assertFalse(ui.isToggleEvent(new MouseEvent(tree,
1303:                        MouseEvent.MOUSE_PRESSED, 0, 0, 0, 0, 2, false,
1304:                        MouseEvent.BUTTON2)));
1305:                assertFalse(ui.isToggleEvent(new MouseEvent(tree,
1306:                        MouseEvent.MOUSE_PRESSED, 0, 0, 0, 0, 2, false,
1307:                        MouseEvent.BUTTON3)));
1308:                assertTrue(ui.isToggleEvent(new MouseEvent(tree,
1309:                        MouseEvent.MOUSE_PRESSED, InputEvent.CTRL_DOWN_MASK, 0,
1310:                        0, 0, 2, false, MouseEvent.BUTTON1)));
1311:                assertTrue(ui.isToggleEvent(new MouseEvent(tree,
1312:                        MouseEvent.MOUSE_PRESSED, InputEvent.SHIFT_DOWN_MASK,
1313:                        0, 0, 0, 2, false, MouseEvent.BUTTON1)));
1314:            }
1315:
1316:            public void testSelectPathForEvent() {
1317:                TreePath rootPath = new TreePath(root);
1318:                TreePath path1 = rootPath.pathByAddingChild(node1);
1319:                TreePath path11 = path1.pathByAddingChild(node11);
1320:                assertTrue(tree.isSelectionEmpty());
1321:                MouseEvent toggleSelectionEvent = new MouseEvent(tree,
1322:                        MouseEvent.MOUSE_PRESSED, 0, InputEvent.CTRL_DOWN_MASK,
1323:                        0, 0, 1, false, MouseEvent.BUTTON1);
1324:                ui.selectPathForEvent(rootPath, toggleSelectionEvent);
1325:                assertEquals(new TreePath[] { rootPath }, tree
1326:                        .getSelectionPaths());
1327:                ui.selectPathForEvent(rootPath, toggleSelectionEvent);
1328:                assertTrue(tree.isSelectionEmpty());
1329:                ui.selectPathForEvent(rootPath, toggleSelectionEvent);
1330:                ui.selectPathForEvent(path1, toggleSelectionEvent);
1331:                assertEquals(new TreePath[] { rootPath, path1 }, tree
1332:                        .getSelectionPaths());
1333:                MouseEvent toggleEvent = new MouseEvent(tree,
1334:                        MouseEvent.MOUSE_PRESSED, 0, 0, 0, 0, 2, false,
1335:                        MouseEvent.BUTTON1);
1336:                ui.selectPathForEvent(rootPath, toggleEvent);
1337:                assertFalse(tree.isExpanded(rootPath));
1338:                assertEquals(new TreePath[] { rootPath }, tree
1339:                        .getSelectionPaths());
1340:                ui.selectPathForEvent(path1, toggleEvent);
1341:                assertTrue(tree.isExpanded(rootPath));
1342:                assertTrue(tree.isExpanded(path1));
1343:                assertEquals(new TreePath[] { path1 }, tree.getSelectionPaths());
1344:                MouseEvent multiSelectionEvent = new MouseEvent(tree,
1345:                        MouseEvent.MOUSE_PRESSED, 0,
1346:                        InputEvent.SHIFT_DOWN_MASK, 0, 0, 1, false,
1347:                        MouseEvent.BUTTON1);
1348:                ui.selectPathForEvent(rootPath, multiSelectionEvent);
1349:                assertEquals(new TreePath[] { rootPath, path1 }, tree
1350:                        .getSelectionPaths());
1351:                MouseEvent pressEvent = new MouseEvent(tree,
1352:                        MouseEvent.MOUSE_PRESSED, 0, 0, 0, 0, 1, false,
1353:                        MouseEvent.BUTTON1);
1354:                ui.selectPathForEvent(rootPath, pressEvent);
1355:                assertEquals(new TreePath[] { rootPath }, tree
1356:                        .getSelectionPaths());
1357:                ui.selectPathForEvent(path11, pressEvent);
1358:                assertEquals(new TreePath[] { path11 }, tree
1359:                        .getSelectionPaths());
1360:                MouseEvent wrongPressEvent = new MouseEvent(tree,
1361:                        MouseEvent.MOUSE_PRESSED, 0, 0, 0, 0, 1, false,
1362:                        MouseEvent.BUTTON3);
1363:                ui.selectPathForEvent(rootPath, wrongPressEvent);
1364:                assertEquals(new TreePath[] { path11 }, tree
1365:                        .getSelectionPaths());
1366:                MouseEvent notPressEvent = new MouseEvent(tree,
1367:                        MouseEvent.MOUSE_DRAGGED, 0, 0, 0, 0, 1, false,
1368:                        MouseEvent.BUTTON1);
1369:                ui.selectPathForEvent(rootPath, notPressEvent);
1370:                assertEquals(new TreePath[] { path11 }, tree
1371:                        .getSelectionPaths());
1372:            }
1373:
1374:            public void testIsLeaf() {
1375:                assertFalse(ui.isLeaf(0));
1376:                assertFalse(ui.isLeaf(1));
1377:                tree.expandRow(1);
1378:                assertTrue(ui.isLeaf(2));
1379:            }
1380:
1381:            public void testKeyHandler() throws Exception {
1382:                BasicTreeUI.KeyHandler handler = ui.new KeyHandler();
1383:                assertFalse(handler.isKeyDown);
1384:                assertNull(handler.repeatKeyAction);
1385:                handler.keyPressed(new KeyEvent(tree, KeyEvent.KEY_PRESSED, 0,
1386:                        0, 'a', 'a'));
1387:                assertFalse(handler.isKeyDown);
1388:                assertNull(handler.repeatKeyAction);
1389:                handler.isKeyDown = true;
1390:                handler.keyReleased(new KeyEvent(tree, KeyEvent.KEY_RELEASED,
1391:                        0, 0, 'a', 'a'));
1392:                assertTrue(handler.isKeyDown);
1393:                assertNull(handler.repeatKeyAction);
1394:                assertTrue(tree.isSelectionEmpty());
1395:                handler.keyTyped(new KeyEvent(tree, KeyEvent.KEY_TYPED, 0, 0,
1396:                        KeyEvent.VK_UNDEFINED, 'a'));
1397:                assertTrue(tree.isSelectionEmpty());
1398:                handler.isKeyDown = false;
1399:                JFrame f = new JFrame();
1400:                f.getContentPane().add(tree);
1401:                f.pack();
1402:                f.setVisible(true);
1403:                SwingWaitTestCase.isRealized(f);
1404:                tree.requestFocus();
1405:                assertTrue(waitForFocus(tree));
1406:                TreePath rootPath = new TreePath(root);
1407:                TreePath path1 = rootPath.pathByAddingChild(node1);
1408:                TreePath path2 = rootPath.pathByAddingChild(node2);
1409:                handler.keyTyped(new KeyEvent(tree, KeyEvent.KEY_TYPED, 0, 0,
1410:                        KeyEvent.VK_UNDEFINED, 'n',
1411:                        KeyEvent.KEY_LOCATION_UNKNOWN));
1412:                assertEquals(new TreePath[] { path1 }, tree.getSelectionPaths());
1413:                handler.keyTyped(new KeyEvent(tree, KeyEvent.KEY_TYPED, 0, 0,
1414:                        KeyEvent.VK_UNDEFINED, 'o',
1415:                        KeyEvent.KEY_LOCATION_UNKNOWN));
1416:                assertEquals(new TreePath[] { path1 }, tree.getSelectionPaths());
1417:                handler.keyTyped(new KeyEvent(tree, KeyEvent.KEY_TYPED, 0, 0,
1418:                        KeyEvent.VK_UNDEFINED, 'd',
1419:                        KeyEvent.KEY_LOCATION_UNKNOWN));
1420:                assertEquals(new TreePath[] { path1 }, tree.getSelectionPaths());
1421:                handler.keyTyped(new KeyEvent(tree, KeyEvent.KEY_TYPED, 0, 0,
1422:                        KeyEvent.VK_UNDEFINED, 'e',
1423:                        KeyEvent.KEY_LOCATION_UNKNOWN));
1424:                assertEquals(new TreePath[] { path1 }, tree.getSelectionPaths());
1425:                handler.keyTyped(new KeyEvent(tree, KeyEvent.KEY_TYPED, 0, 0,
1426:                        KeyEvent.VK_UNDEFINED, '2',
1427:                        KeyEvent.KEY_LOCATION_UNKNOWN));
1428:                assertEquals(new TreePath[] { path2 }, tree.getSelectionPaths());
1429:                handler.keyTyped(new KeyEvent(tree, KeyEvent.KEY_TYPED, 0, 0,
1430:                        KeyEvent.VK_UNDEFINED, '1',
1431:                        KeyEvent.KEY_LOCATION_UNKNOWN));
1432:                assertEquals(new TreePath[] { path2 }, tree.getSelectionPaths());
1433:                f.dispose();
1434:            }
1435:
1436:            public void testComponentHandler() throws Exception {
1437:                JScrollPane pane = new JScrollPane(tree);
1438:                assertFalse(hasListener(tree.getComponentListeners(),
1439:                        BasicTreeUI.ComponentHandler.class));
1440:                tree.setLargeModel(true);
1441:                assertTrue(hasListener(tree.getComponentListeners(),
1442:                        BasicTreeUI.ComponentHandler.class));
1443:                tree.setRowHeight(0);
1444:                assertFalse(hasListener(tree.getComponentListeners(),
1445:                        BasicTreeUI.ComponentHandler.class));
1446:                tree.setRowHeight(10);
1447:                assertTrue(hasListener(tree.getComponentListeners(),
1448:                        BasicTreeUI.ComponentHandler.class));
1449:                BasicTreeUI.ComponentHandler handler = (ComponentHandler) getListener(
1450:                        tree.getComponentListeners(),
1451:                        BasicTreeUI.ComponentHandler.class);
1452:                assertNull(handler.timer);
1453:                assertNull(handler.scrollBar);
1454:                assertSame(pane, handler.getScrollPane());
1455:                ui.getPreferredSize(tree);
1456:                assertTrue(ui.validCachedPreferredSize);
1457:                handler.getScrollPane().getVerticalScrollBar()
1458:                        .setValueIsAdjusting(true);
1459:                handler.componentMoved(new ComponentEvent(tree,
1460:                        ComponentEvent.COMPONENT_MOVED));
1461:                assertNotNull(handler.timer);
1462:                assertSame(handler.scrollBar, pane.getVerticalScrollBar());
1463:                assertEquals(200, handler.timer.getDelay());
1464:                assertSame(handler, handler.timer.getActionListeners()[0]);
1465:                assertTrue(handler.timer.isRunning());
1466:                ui.validCachedPreferredSize = true;
1467:                assertTrue(ui.validCachedPreferredSize);
1468:                handler.actionPerformed(null);
1469:                assertTrue(handler.timer.isRunning());
1470:                assertTrue(ui.validCachedPreferredSize);
1471:                handler.getScrollPane().getVerticalScrollBar()
1472:                        .setValueIsAdjusting(false);
1473:                assertTrue(handler.timer.isRunning());
1474:                Timer timer = handler.timer;
1475:                handler.actionPerformed(null);
1476:                if (isHarmony()) {
1477:                    assertNotNull(handler.timer);
1478:                } else {
1479:                    assertNull(handler.timer);
1480:                }
1481:                assertFalse(timer.isRunning());
1482:                assertFalse(ui.validCachedPreferredSize);
1483:            }
1484:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.