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
> [email protected]
> 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.99
diff -u -r1.99 BasicTreeUI.java
--- javax/swing/plaf/basic/BasicTreeUI.java 14 Oct 2005 22:37:07 -0000 1.99
+++ javax/swing/plaf/basic/BasicTreeUI.java 17 Oct 2005 18:38:45 -0000
@@ -1187,7 +1187,6 @@
isLeaf = treeModel.isLeaf(path[i]);
if (!isLeaf && hasControlIcons())
bounds.width += getCurrentControlIcon(curr).getIconWidth();
-
maxWidth = Math.max(maxWidth, bounds.x + bounds.width);
}
preferredSize = new Dimension(maxWidth, (getRowHeight() * path.length));
@@ -1347,7 +1346,9 @@
installDefaults();
installComponents();
-
+ installKeyboardActions();
+ installListeners();
+
setCellEditor(createDefaultCellEditor());
createdCellEditor = true;
isEditing = false;
@@ -1362,8 +1363,6 @@
}
treeSelectionModel = tree.getSelectionModel();
- installKeyboardActions();
- installListeners();
completeUIInstall();
}
@@ -1410,13 +1409,16 @@
public void paint(Graphics g, JComponent c)
{
JTree tree = (JTree) c;
+ if (currentVisiblePath == null)
+ updateCurrentVisiblePath();
+
if (treeModel != null)
{
Object root = treeModel.getRoot();
paintRecursive(g, 0, 0, 0, tree, treeModel, root);
if (hasControlIcons())
- paintControlIcons(g, 0, 0, 0, 0, tree, treeModel, root);
+ paintControlIcons(g, 0, 0, 0, tree, treeModel, root);
}
}
@@ -2554,6 +2556,7 @@
public void treeExpanded(TreeExpansionEvent event)
{
validCachedPreferredSize = false;
+ updateCurrentVisiblePath();
tree.revalidate();
tree.repaint();
}
@@ -2567,6 +2570,7 @@
public void treeCollapsed(TreeExpansionEvent event)
{
validCachedPreferredSize = false;
+ updateCurrentVisiblePath();
tree.revalidate();
tree.repaint();
}
@@ -2750,6 +2754,7 @@
public void treeNodesChanged(TreeModelEvent e)
{
validCachedPreferredSize = false;
+ updateCurrentVisiblePath();
tree.revalidate();
tree.repaint();
}
@@ -2765,6 +2770,7 @@
public void treeNodesInserted(TreeModelEvent e)
{
validCachedPreferredSize = false;
+ updateCurrentVisiblePath();
tree.revalidate();
tree.repaint();
}
@@ -2783,6 +2789,7 @@
public void treeNodesRemoved(TreeModelEvent e)
{
validCachedPreferredSize = false;
+ updateCurrentVisiblePath();
tree.revalidate();
tree.repaint();
}
@@ -2800,6 +2807,7 @@
public void treeStructureChanged(TreeModelEvent e)
{
validCachedPreferredSize = false;
+ updateCurrentVisiblePath();
tree.revalidate();
tree.repaint();
}
@@ -3085,11 +3093,7 @@
boolean isLeaf = mod.isLeaf(curr);
Rectangle bounds = getPathBounds(tree, path);
Object root = mod.getRoot();
- int iconWidth = 0;
- if (!isLeaf && hasControlIcons())
- iconWidth += getCurrentControlIcon(path).getIconWidth();
- bounds.width += bounds.x + iconWidth + gap;
-
+
if (isLeaf)
{
paintRow(g, clip, null, bounds, path, row, true, false, true);
@@ -3162,10 +3166,9 @@
* @return int current descent of the tree
*/
int paintControlIcons(Graphics g, int indentation, int descent,
- int childNumber, int depth, JTree tree, TreeModel mod,
+ int depth, JTree tree, TreeModel mod,
Object node)
{
- int h = descent;
int rowHeight = getRowHeight();
TreePath path = new TreePath(getPathToRoot(node, 0));
Icon icon = getCurrentControlIcon(path);
@@ -3178,27 +3181,40 @@
if (mod.isLeaf(node))
descent += rowHeight;
else
- {
- if (depth > 0 || tree.isRootVisible())
- descent += rowHeight;
-
- int max = 0;
- if (!mod.isLeaf(node))
- max = mod.getChildCount(node);
-
+ {
if (!node.equals(mod.getRoot()) &&
(tree.isRootVisible() || getLevel(node) != 1))
- icon.paintIcon(tree, g, indentation - rightChildIndent - 3, h);
+ {
+ int width = icon.getIconWidth();
+ int height = icon.getIconHeight() + 2;
+ int posX = indentation - rightChildIndent;
+ int posY = descent;
+ if (width > rightChildIndent)
+ posX -= gap;
+ else posX += width/2;
+
+ if (height < rowHeight)
+ posY += height/2;
+
+ icon.paintIcon(tree, g, posX, posY);
+ }
+
+ if (depth > 0 || tree.isRootVisible())
+ descent += rowHeight;
if (tree.isExpanded(path))
{
+ int max = 0;
+ if (!mod.isLeaf(node))
+ max = mod.getChildCount(node);
+
for (int i = 0; i < max; i++)
{
int indent = indentation + rightChildIndent;
if (depth == 0 && !tree.isRootVisible())
indent = 1;
- descent = paintControlIcons(g, indent, descent, i, depth + 1,
+ descent = paintControlIcons(g, indent, descent, depth + 1,
tree, mod, mod.getChild(node, i));
}
}
@@ -3604,7 +3620,7 @@
boolean isLeaf)
{
if (treeModel != null && hasControlIcons())
- paintControlIcons(g, 0, 0, 0, 0, tree, treeModel, path.getLastPathComponent());
+ paintControlIcons(g, 0, 0, 0, tree, treeModel, path.getLastPathComponent());
}
/**
@@ -3672,6 +3688,18 @@
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;
+
if (editingComponent != null && editingPath != null && isEditing(tree)
&& node.equals(editingPath.getLastPathComponent()))
{
Index: javax/swing/plaf/metal/MetalTreeUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalTreeUI.java,v
retrieving revision 1.9
diff -u -r1.9 MetalTreeUI.java
--- javax/swing/plaf/metal/MetalTreeUI.java 13 Oct 2005 19:34:08 -0000 1.9
+++ javax/swing/plaf/metal/MetalTreeUI.java 17 Oct 2005 18:41:03 -0000
@@ -152,12 +152,7 @@
createdCellEditor = true;
TreeModel mod = tree.getModel();
setModel(mod);
- if (mod != null)
- {
- TreePath path = new TreePath(mod.getRoot());
- if (!tree.isExpanded(path))
- toggleExpandState(path);
- }
+
treeSelectionModel = tree.getSelectionModel();
drawingCache = new Hashtable();
nodeDimensions = createNodeDimensions();
@@ -188,6 +183,13 @@
tree.addTreeExpansionListener(treeExpansionListener);
if (treeModel != null)
treeModel.addTreeModelListener(treeModelListener);
+
+ if (mod != null)
+ {
+ TreePath path = new TreePath(mod.getRoot());
+ if (!tree.isExpanded(path))
+ toggleExpandState(path);
+ }
completeUIInstall();
}
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches