Noticed the expanded and collapsed icon defaults were set to the wrong icons. Fixed this and reworked mousePressed to work with these changes.
2005-10-18 Lillian Angel <[EMAIL PROTECTED]> * javax/swing/plaf/basic/BasicTreeUI.java: Removed leafIcon field. (BasicTreeUI): Removed leafIcon initialization. (installDefaults): Icon defaults were wrong, fixed. (isLocationInExpandControl): Fixed to incorporated gap. (mousePressed): Fixed to include correct icon widths. Sometimes the labels icon is different from what the tree's default icon is set to. Added a check for this. (getCellBounds): No need to include gap here. (getCurrentControlIcon): Fixed to use expandedIcon and collapsedIcon. (paintRow): No need paint beyond preferred width of tree here. (updateCurrentVisiblePath): If nothing is selected, the root should be selected without focus. * javax/swing/plaf/metal/MetalTreeUI.java (installDefaults): Fixed defaults for the expanded/collapsed icons. On Mon, 2005-10-17 at 14:46 -0400, Lillian Angel wrote: > Now this is completely fixed. > > 2005-10-17 Lillian Angel <[EMAIL PROTECTED]> > > * javax/swing/plaf/basic/BasicTreeUI.java > (installUI): Moved call to installKeyboardActions and Listeners > to before expansion of root. > (paint): Added check to make sure the cached visible path is > updated. > (treeExpanded): Added call to update visible path. > (treeCollapsed): Likewise. > (treeNodesChanged): Likewise. > (treeNodesInserted): Likewise. > (treeNodesRemoved): Likewise. > (treeStructureChanged): Likewise. > (paintRecursive): Moved code to paintRow. > (paintControlIcons): Fixed to paint custom control icons > properly. > (paintExpandControl): Removed unneeded parameter. > (paintRow): Added code to paint the row with the correct width. > * javax/swing/plaf/metal/MetalTreeUI.java > (installUI): Moved code to expand the root after all the > listeners have been initialized. > > On Fri, 2005-10-14 at 17:42 -0400, Lillian Angel wrote: > > After testing some new apps, I noticed that there was a slight problem > > with some custom icons. I almost have it fixed completely. > > > > 2005-10-14 Lillian Angel <[EMAIL PROTECTED]> > > > > * javax/swing/LookAndFeel.java > > (makeIcon): Implemented. > > * javax/swing/plaf/basic/BasicTreeUI.java > > (updateCachedPreferredSize): Should only add with of control > > icon if > > not a leaf. > > (mousePressed): Fixed to use new gap field. > > (paintRecursive): Likewise. > > (paintRow): Likewise. > > (updateCurrentVisiblePath): Shouldn't include root if it is > > not of a valid size to be painted. > > > > _______________________________________________ > > Classpath-patches mailing list > > Classpath-patches@gnu.org > > http://lists.gnu.org/mailman/listinfo/classpath-patches > _______________________________________________ > Classpath-patches mailing list > Classpath-patches@gnu.org > http://lists.gnu.org/mailman/listinfo/classpath-patches
Index: javax/swing/plaf/basic/BasicTreeUI.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v retrieving revision 1.101 diff -u -r1.101 BasicTreeUI.java --- javax/swing/plaf/basic/BasicTreeUI.java 18 Oct 2005 15:02:42 -0000 1.101 +++ javax/swing/plaf/basic/BasicTreeUI.java 18 Oct 2005 17:38:54 -0000 @@ -225,9 +225,6 @@ /** Set to true if the editor has a different size than the renderer. */ protected boolean editorHasDifferentSize; - - /** Leaf icon for the tree. */ - Icon leafIcon; /** The action listener for the editor's Timer. */ Timer editorTimer = new EditorUpdateTimer(); @@ -285,7 +282,6 @@ editingRow = -1; lastSelectedRow = -1; - leafIcon = UIManager.getIcon("Tree.leafIcon"); } /** @@ -1233,8 +1229,8 @@ tree.setRowHeight(UIManager.getInt("Tree.rowHeight")); tree.requestFocusInWindow(false); tree.setScrollsOnExpand(UIManager.getBoolean("Tree.scrollsOnExpand")); - setExpandedIcon(UIManager.getIcon("Tree.openIcon")); - setCollapsedIcon(UIManager.getIcon("Tree.closedIcon")); + setExpandedIcon(UIManager.getIcon("Tree.expandedIcon")); + setCollapsedIcon(UIManager.getIcon("Tree.collapsedIcon")); } /** @@ -1673,11 +1669,10 @@ if (!isLeaf(row)) { - if (bounds == null) - bounds = getPathBounds(tree, path); + bounds = getPathBounds(tree, path); if (hasControlIcons() && (mouseX < bounds.x) - && (mouseX > (bounds.x - getCurrentControlIcon(path).getIconWidth()))) + && (mouseX > (bounds.x - getCurrentControlIcon(path).getIconWidth() - gap))) cntlClick = true; } return cntlClick; @@ -2310,13 +2305,29 @@ bounds = getPathBounds(tree, path); int row = getRowForPath(tree, path); boolean cntlClick = isLocationInExpandControl(path, click.x, click.y); - + boolean isLeaf = isLeaf(row); + + TreeCellRenderer tcr = getCellRenderer(); + Icon icon; if (isLeaf) - bounds.width += rightChildIndent + gap; - else if (hasControlIcons()) - bounds.width += getCurrentControlIcon(path).getIconWidth() + gap; + icon = UIManager.getIcon("Tree.leafIcon"); + else if (tree.isExpanded(path)) + icon = UIManager.getIcon("Tree.openIcon"); + else + icon = UIManager.getIcon("Tree.closedIcon"); + + if (tcr instanceof DefaultTreeCellRenderer) + { + Icon tmp = ((DefaultTreeCellRenderer) tcr).getIcon(); + if (tmp != null) + icon = tmp; + } + // add gap*2 for the space before and after the text + if (icon != null) + bounds.width += icon.getIconWidth() + gap*2; + boolean inBounds = bounds.contains(click.x, click.y); if ((inBounds || cntlClick) && tree.isVisible(path)) { @@ -3013,7 +3024,7 @@ FontMetrics fm = tree.getToolkit().getFontMetrics(f); if (s != null) - return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s) + gap, + return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s), fm.getHeight()); } return new Rectangle(x, y, 0, 0); @@ -3232,8 +3243,7 @@ */ boolean hasControlIcons() { - if (UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon") != null - || UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon") != null) + if (expandedIcon != null || collapsedIcon != null) return true; return false; } @@ -3247,8 +3257,8 @@ Icon getCurrentControlIcon(TreePath path) { if (tree.isExpanded(path)) - return UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon"); - return UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon"); + return expandedIcon; + return collapsedIcon; } /** @@ -3689,17 +3699,8 @@ if (tree.isVisible(path)) { - // need to set exact width of entire row - int iconWidth = 0; - if (!isLeaf && hasControlIcons()) - iconWidth = getCurrentControlIcon(path).getIconWidth(); - if (isLeaf && leafIcon != null) - iconWidth += leafIcon.getIconWidth(); - else if (isExpanded && expandedIcon != null) - iconWidth += expandedIcon.getIconWidth(); - else if (collapsedIcon != null) - iconWidth += collapsedIcon.getIconWidth(); - bounds.width += bounds.x + iconWidth + gap; + bounds.width = preferredSize.width; + bounds.x += gap; if (editingComponent != null && editingPath != null && isEditing(tree) && node.equals(editingPath.getLastPathComponent())) @@ -3715,7 +3716,6 @@ Component c = dtcr.getTreeCellRendererComponent(tree, node, selected, isExpanded, isLeaf, row, false); - bounds.x += gap; rendererPane.paintComponent(g, c, c.getParent(), bounds); } } @@ -3780,6 +3780,9 @@ } currentVisiblePath = current; tree.setVisibleRowCount(getRowCount(tree)); + if (tree.getSelectionModel() != null && tree.getSelectionCount() == 0 && + currentVisiblePath != null) + tree.addSelectionRow(0); } /** Index: javax/swing/plaf/metal/MetalTreeUI.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalTreeUI.java,v retrieving revision 1.11 diff -u -r1.11 MetalTreeUI.java --- javax/swing/plaf/metal/MetalTreeUI.java 18 Oct 2005 15:02:43 -0000 1.11 +++ javax/swing/plaf/metal/MetalTreeUI.java 18 Oct 2005 17:38:54 -0000 @@ -143,8 +143,8 @@ tree.setRowHeight(defaults.getInt("Tree.rowHeight")); tree.requestFocusInWindow(false); - setExpandedIcon(defaults.getIcon("Tree.openIcon")); - setCollapsedIcon(defaults.getIcon("Tree.closedIcon")); + setExpandedIcon(defaults.getIcon("Tree.expandedIcon")); + setCollapsedIcon(defaults.getIcon("Tree.collapsedIcon")); currentCellRenderer = createDefaultCellRenderer(); rendererPane = createCellRendererPane();
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches