Some more fixes for painting.

2005-10-13  Lillian Angel  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicTreeUI.java:
        Added leafIcon field.
        (BasicTreeUI): Initialized leafIcon field.
        (installDefaults): Fixed icon defaults.
        (getPreferredSize): Fixed up code slightly.
        (startEditing): Called revalidate because size of
        view may change.
        (EditingStopped): Likewise.
        (EditingCanceled): Likewise.
        (mousePressed): Fixed up icon sizes.
        (paintRecursive): Fixed up width painted.
        * javax/swing/plaf/metal/MetalTreeUI.java
        (installDefaults): Fixed icon defaults.

Index: javax/swing/plaf/basic/BasicTreeUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.94
diff -u -r1.94 BasicTreeUI.java
--- javax/swing/plaf/basic/BasicTreeUI.java	13 Oct 2005 16:40:33 -0000	1.94
+++ javax/swing/plaf/basic/BasicTreeUI.java	13 Oct 2005 19:28:45 -0000
@@ -229,6 +229,9 @@
   /** 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();
 
@@ -281,6 +284,7 @@
 
     editingRow = -1;
     lastSelectedRow = -1;
+    leafIcon = UIManager.getIcon("Tree.leafIcon");
   }
 
   /**
@@ -1209,8 +1213,8 @@
     setRowHeight(UIManager.getInt("Tree.rowHeight"));
     tree.requestFocusInWindow(false);
     tree.setScrollsOnExpand(UIManager.getBoolean("Tree.scrollsOnExpand"));
-    setExpandedIcon(UIManager.getIcon("Tree.expandedIcon"));
-    setCollapsedIcon(UIManager.getIcon("Tree.collapsedIcon"));
+    setExpandedIcon(UIManager.getIcon("Tree.openIcon"));
+    setCollapsedIcon(UIManager.getIcon("Tree.closedIcon"));
   }
 
   /**
@@ -1320,8 +1324,8 @@
     tree = (JTree) c;
     prepareForUIInstall();
     super.installUI(c);
-
     installDefaults();
+
     installComponents();
 
     setCellEditor(createDefaultCellEditor());
@@ -1475,7 +1479,7 @@
   {
     // FIXME: checkConsistancy not implemented, c not used
     int maxWidth = 0;
-    int iconWidth = 0;
+    boolean isLeaf = false;
     if (currentVisiblePath != null)
       {
         Object[] path = currentVisiblePath.getPath();
@@ -1483,12 +1487,12 @@
           {
             TreePath curr = new TreePath(getPathToRoot(path[i], 0));
             Rectangle bounds = getPathBounds(tree, 
-                        curr);
-            iconWidth = 0;
+                        curr);  
+            if (treeModel != null)
+              isLeaf = treeModel.isLeaf(curr);
             if (hasControlIcons())
-              iconWidth = getCurrentControlIcon(curr).getIconWidth();
-            maxWidth = Math.max(maxWidth, bounds.x + bounds.width
-                                + iconWidth);
+              bounds.width += getCurrentControlIcon(curr).getIconWidth();
+            maxWidth = Math.max(maxWidth, bounds.x + bounds.width);
           }
         return new Dimension(maxWidth, (getRowHeight() * path.length));
       }
@@ -1616,6 +1620,7 @@
         editingComponent.getParent().validate();
         tree.add(editingComponent.getParent());
         editingComponent.getParent().validate();
+        tree.revalidate();
         ((JTextField) editingComponent).requestFocusInWindow(false);
         editorTimer.start();
         return true;
@@ -2058,6 +2063,8 @@
       isEditing = false;
       tree.requestFocusInWindow(false);
       editorTimer.stop();
+      tree.revalidate();
+      tree.repaint();
     }
 
     /**
@@ -2086,6 +2093,7 @@
       tree.requestFocusInWindow(false);
       editorTimer.stop();
       isEditing = false;
+      tree.revalidate();
       tree.repaint();
     }
   }// CellEditorHandler
@@ -2299,10 +2307,8 @@
           
           if (isLeaf(row))
               bounds.width += rightChildIndent + 4;
-          else if (tree.isExpanded(path) && expandedIcon != null)
-              bounds.width += expandedIcon.getIconWidth() + 4;
-          else if (collapsedIcon != null)
-              bounds.width += collapsedIcon.getIconWidth() + 4;
+          else if (hasControlIcons())
+            bounds.width += getCurrentControlIcon(path).getIconWidth() + 4;
 
           boolean inBounds = bounds.contains(click.x, click.y);
           if ((inBounds || cntlClick) && tree.isVisible(path))
@@ -3070,18 +3076,17 @@
     Rectangle bounds = getPathBounds(tree, path);
     Object root = mod.getRoot();
     int iconWidth = 0;
-    if (hasControlIcons())
-      iconWidth = getCurrentControlIcon(path).getIconWidth();      
+    if (!isLeaf && hasControlIcons())
+      iconWidth += getCurrentControlIcon(path).getIconWidth();
+    bounds.width += bounds.x + iconWidth;
     
     if (isLeaf)
       {
-        bounds.width += bounds.x;
         paintRow(g, clip, null, bounds, path, row, true, false, true);
         descent += getRowHeight();
       }
     else
       {
-        bounds.width += bounds.x + iconWidth;
         if (depth > 0 || isRootVisible)
           {
             paintRow(g, clip, null, bounds, path, row, isExpanded, false, false);
@@ -3659,10 +3664,7 @@
       {
         if (editingComponent != null && editingPath != null && isEditing(tree)
             && node.equals(editingPath.getLastPathComponent()))
-          {
-            if (hasControlIcons())
-              bounds.x += getCurrentControlIcon(path).getIconWidth() - 5;
-            bounds.width = editingComponent.getSize().width + bounds.x;
+          {    
             rendererPane.paintComponent(g, editingComponent.getParent(), null,
                                         bounds);
           }
Index: javax/swing/plaf/metal/MetalTreeUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalTreeUI.java,v
retrieving revision 1.8
diff -u -r1.8 MetalTreeUI.java
--- javax/swing/plaf/metal/MetalTreeUI.java	5 Oct 2005 21:29:18 -0000	1.8
+++ javax/swing/plaf/metal/MetalTreeUI.java	13 Oct 2005 19:28:45 -0000
@@ -142,8 +142,8 @@
     setRowHeight(defaults.getInt("Tree.rowHeight"));
     tree.requestFocusInWindow(false);
     
-    setExpandedIcon(defaults.getIcon("Tree.expandedIcon"));
-    setCollapsedIcon(defaults.getIcon("Tree.collapsedIcon"));
+    setExpandedIcon(defaults.getIcon("Tree.openIcon"));
+    setCollapsedIcon(defaults.getIcon("Tree.closedIcon"));
     
     currentCellRenderer = createDefaultCellRenderer();
     rendererPane = createCellRendererPane();
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to