src/share/classes/javax/swing/plaf/basic/BasicTreeUI.java

Print this page




1131     }
1132 
1133     //
1134     // Painting routines.
1135     //
1136 
1137     public void paint(Graphics g, JComponent c) {
1138         if (tree != c) {
1139             throw new InternalError("incorrect component");
1140         }
1141 
1142         // Should never happen if installed for a UI
1143         if(treeState == null) {
1144             return;
1145         }
1146 
1147         Rectangle        paintBounds = g.getClipBounds();
1148         Insets           insets = tree.getInsets();
1149         TreePath         initialPath = getClosestPathForLocation
1150                                        (tree, 0, paintBounds.y);
1151         Enumeration      paintingEnumerator = treeState.getVisiblePathsFrom
1152                                               (initialPath);
1153         int              row = treeState.getRowForPath(initialPath);
1154         int              endY = paintBounds.y + paintBounds.height;
1155 
1156         drawingCache.clear();
1157 
1158         if(initialPath != null && paintingEnumerator != null) {
1159             TreePath   parentPath = initialPath;
1160 
1161             // Draw the lines, knobs, and rows
1162 
1163             // Find each parent and have them draw a line to their last child
1164             parentPath = parentPath.getParentPath();
1165             while(parentPath != null) {
1166                 paintVerticalPartOfLeg(g, paintBounds, insets, parentPath);
1167                 drawingCache.put(parentPath, Boolean.TRUE);
1168                 parentPath = parentPath.getParentPath();
1169             }
1170 
1171             boolean         done = false;


1677         if (treeModel != null && treeModel.getRoot() != null) {
1678             TreePath rootPath = new TreePath(treeModel.getRoot());
1679             if (tree.isExpanded(rootPath)) {
1680                 updateLayoutCacheExpandedNodes();
1681             } else {
1682                 treeState.setExpandedState(rootPath, false);
1683             }
1684         }
1685     }
1686 
1687     /**
1688      * Updates the expanded state of all the descendants of <code>path</code>
1689      * by getting the expanded descendants from the tree and forwarding
1690      * to the tree state.
1691      */
1692     protected void updateExpandedDescendants(TreePath path) {
1693         completeEditing();
1694         if(treeState != null) {
1695             treeState.setExpandedState(path, true);
1696 
1697             Enumeration   descendants = tree.getExpandedDescendants(path);
1698 
1699             if(descendants != null) {
1700                 while(descendants.hasMoreElements()) {
1701                     path = (TreePath)descendants.nextElement();
1702                     treeState.setExpandedState(path, true);
1703                 }
1704             }
1705             updateLeadSelectionRow();
1706             updateSize();
1707         }
1708     }
1709 
1710     /**
1711      * Returns a path to the last child of <code>parent</code>.
1712      */
1713     protected TreePath getLastChildPath(TreePath parent) {
1714         if(treeModel != null) {
1715             int         childCount = treeModel.getChildCount
1716                 (parent.getLastPathComponent());
1717 




1131     }
1132 
1133     //
1134     // Painting routines.
1135     //
1136 
1137     public void paint(Graphics g, JComponent c) {
1138         if (tree != c) {
1139             throw new InternalError("incorrect component");
1140         }
1141 
1142         // Should never happen if installed for a UI
1143         if(treeState == null) {
1144             return;
1145         }
1146 
1147         Rectangle        paintBounds = g.getClipBounds();
1148         Insets           insets = tree.getInsets();
1149         TreePath         initialPath = getClosestPathForLocation
1150                                        (tree, 0, paintBounds.y);
1151         Enumeration<?>   paintingEnumerator = treeState.getVisiblePathsFrom
1152                                               (initialPath);
1153         int              row = treeState.getRowForPath(initialPath);
1154         int              endY = paintBounds.y + paintBounds.height;
1155 
1156         drawingCache.clear();
1157 
1158         if(initialPath != null && paintingEnumerator != null) {
1159             TreePath   parentPath = initialPath;
1160 
1161             // Draw the lines, knobs, and rows
1162 
1163             // Find each parent and have them draw a line to their last child
1164             parentPath = parentPath.getParentPath();
1165             while(parentPath != null) {
1166                 paintVerticalPartOfLeg(g, paintBounds, insets, parentPath);
1167                 drawingCache.put(parentPath, Boolean.TRUE);
1168                 parentPath = parentPath.getParentPath();
1169             }
1170 
1171             boolean         done = false;


1677         if (treeModel != null && treeModel.getRoot() != null) {
1678             TreePath rootPath = new TreePath(treeModel.getRoot());
1679             if (tree.isExpanded(rootPath)) {
1680                 updateLayoutCacheExpandedNodes();
1681             } else {
1682                 treeState.setExpandedState(rootPath, false);
1683             }
1684         }
1685     }
1686 
1687     /**
1688      * Updates the expanded state of all the descendants of <code>path</code>
1689      * by getting the expanded descendants from the tree and forwarding
1690      * to the tree state.
1691      */
1692     protected void updateExpandedDescendants(TreePath path) {
1693         completeEditing();
1694         if(treeState != null) {
1695             treeState.setExpandedState(path, true);
1696 
1697             Enumeration<?> descendants = tree.getExpandedDescendants(path);
1698 
1699             if(descendants != null) {
1700                 while(descendants.hasMoreElements()) {
1701                     path = (TreePath)descendants.nextElement();
1702                     treeState.setExpandedState(path, true);
1703                 }
1704             }
1705             updateLeadSelectionRow();
1706             updateSize();
1707         }
1708     }
1709 
1710     /**
1711      * Returns a path to the last child of <code>parent</code>.
1712      */
1713     protected TreePath getLastChildPath(TreePath parent) {
1714         if(treeModel != null) {
1715             int         childCount = treeModel.getChildCount
1716                 (parent.getLastPathComponent());
1717