Changed getPreferredSize to use updateCachedPreferredSize instead. Also
fixed a problem in JTree where height was being used instead of width
(and vice versa). Also, fixed several doc errors.


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

        * javax/swing/JTree.java
        (getAccessibleSelectionCount): Fixed API documentation.
        (getScrollableTracksViewportWidth): Was using height instead of
        width, fixed this.
        (getScrollableTracksViewportHeight): Likewise.
        * javax/swing/plaf/basic/BasicTreeUI.java
        (BasicTreeUI): Initialized validCachedPreferredSize.
        (updateCachedPreferredSize): Implemented.
        (pathWasExpanded): Implemented.
        (pathWasCollapsed): Implemented.
        (installDefaults): Fixed API documentation.
        (uninstallDefaults): Likewise.
        (setPreferredMinSize): Likewise.
        (getPreferredMinSize): Likewise.
        (getPreferredSize): Reimplemented to use 
        updateCachedPreferredSize.
        (startEditing): set validCachedPreferredSize.
        (editingStopped): Likewise.
        (editingCanceled): Likewise.
        (treeExpanded): Likewise.
        (treeCollaped): Likewise.
        (treeNodesInserted): Likewise.
        (treeNodesRemoved): Likewise.
        (treeStructureChanged): Likewise.
        (getNextVisibleNode): Fixed API documentation.
        (getNextNode): Likewise.
        (getNextSibling): Likewise.
        (getPreviousSibling): Likewise.
        (getLevel): Likewise.
        (paintVerticalPartOfLeg): Likewise.

Index: javax/swing/JTree.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTree.java,v
retrieving revision 1.45
diff -u -r1.45 JTree.java
--- javax/swing/JTree.java	7 Oct 2005 14:30:19 -0000	1.45
+++ javax/swing/JTree.java	14 Oct 2005 14:16:22 -0000
@@ -976,8 +976,6 @@
     
     /**
      * Returns the number of items currently selected.
-     * 
-     * @param the number of selected accessibles.
      */
     public int getAccessibleSelectionCount()
     {
@@ -1632,14 +1630,14 @@
     return 1;
   }
 
-  public boolean getScrollableTracksViewportWidth()
+  public boolean getScrollableTracksViewportHeight()
   {
     if (getParent() instanceof JViewport)
       return ((JViewport) getParent()).getHeight() > getPreferredSize().height;
     return false;
   }
 
-  public boolean getScrollableTracksViewportHeight()
+  public boolean getScrollableTracksViewportWidth()
   {
     if (getParent() instanceof JViewport)
       return ((JViewport) getParent()).getWidth() > getPreferredSize().width;
Index: javax/swing/plaf/basic/BasicTreeUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.95
diff -u -r1.95 BasicTreeUI.java
--- javax/swing/plaf/basic/BasicTreeUI.java	13 Oct 2005 19:34:08 -0000	1.95
+++ javax/swing/plaf/basic/BasicTreeUI.java	14 Oct 2005 14:16:22 -0000
@@ -138,9 +138,6 @@
    */
   protected int totalChildIndent;
 
-  /** Minimum preferred size. */
-  protected Dimension preferredMinsize;
-
   /** Index of the row that was last selected. */
   protected int lastSelectedRow;
 
@@ -267,6 +264,7 @@
    */
   public BasicTreeUI()
   {
+    validCachedPreferredSize = false;
     drawingCache = new Hashtable();
     nodeDimensions = createNodeDimensions();
     configureLayoutCache();
@@ -1167,14 +1165,30 @@
 
   /**
    * Updates the <code>preferredSize</code> instance variable, which is
-   * returned from <code>getPreferredSize()</code>. For left to right
-   * orientations, the size is determined from the current AbstractLayoutCache.
-   * For RTL orientations, the preferred size becomes the width minus the
-   * minimum x position.
+   * returned from <code>getPreferredSize()</code>.
    */
   protected void updateCachedPreferredSize()
   {
-    // FIXME: not implemented
+    int maxWidth = 0;
+    boolean isLeaf = false;
+    if (currentVisiblePath != null)
+      {
+        Object[] path = currentVisiblePath.getPath();
+        for (int i = 0; i < path.length; i++)
+          {
+            TreePath curr = new TreePath(getPathToRoot(path[i], 0));
+            Rectangle bounds = getPathBounds(tree, 
+                        curr);  
+            if (treeModel != null)
+              isLeaf = treeModel.isLeaf(curr);
+            if (hasControlIcons())
+              bounds.width += getCurrentControlIcon(curr).getIconWidth();
+            maxWidth = Math.max(maxWidth, bounds.x + bounds.width);
+          }
+        preferredSize = new Dimension(maxWidth, (getRowHeight() * path.length));
+      }
+    else preferredSize = new Dimension(0, 0);
+    validCachedPreferredSize = true;
   }
 
   /**
@@ -1185,7 +1199,9 @@
    */
   protected void pathWasExpanded(TreePath path)
   {
-    // FIXME: not implemented
+    validCachedPreferredSize = false;
+    tree.revalidate();
+    tree.repaint();
   }
 
   /**
@@ -1193,14 +1209,13 @@
    */
   protected void pathWasCollapsed(TreePath path)
   {
-    // FIXME: not implemented
+    validCachedPreferredSize = false;
+    tree.revalidate();
+    tree.repaint();
   }
 
   /**
    * Install all defaults for the tree.
-   * 
-   * @param tree
-   *          is the JTree to install defaults for
    */
   protected void installDefaults()
   {
@@ -1349,9 +1364,6 @@
 
   /**
    * Uninstall the defaults for the tree
-   * 
-   * @param tree
-   *          to uninstall defaults for
    */
   protected void uninstallDefaults()
   {
@@ -1436,7 +1448,7 @@
    */
   public void setPreferredMinSize(Dimension newSize)
   {
-    // FIXME: not implemented
+    preferredMinSize = newSize;
   }
 
   /**
@@ -1446,8 +1458,7 @@
    */
   public Dimension getPreferredMinSize()
   {
-    // FIXME: not implemented
-    return null;
+    return preferredMinSize;
   }
 
   /**
@@ -1477,26 +1488,10 @@
    */
   public Dimension getPreferredSize(JComponent c, boolean checkConsistancy)
   {
-    // FIXME: checkConsistancy not implemented, c not used
-    int maxWidth = 0;
-    boolean isLeaf = false;
-    if (currentVisiblePath != null)
-      {
-        Object[] path = currentVisiblePath.getPath();
-        for (int i = 0; i < path.length; i++)
-          {
-            TreePath curr = new TreePath(getPathToRoot(path[i], 0));
-            Rectangle bounds = getPathBounds(tree, 
-                        curr);  
-            if (treeModel != null)
-              isLeaf = treeModel.isLeaf(curr);
-            if (hasControlIcons())
-              bounds.width += getCurrentControlIcon(curr).getIconWidth();
-            maxWidth = Math.max(maxWidth, bounds.x + bounds.width);
-          }
-        return new Dimension(maxWidth, (getRowHeight() * path.length));
-      }
-    return new Dimension(0, 0);
+    // FIXME: checkConsistancy not implemented, c not used 
+    if(!validCachedPreferredSize) 
+      updateCachedPreferredSize();
+    return preferredSize;
   }
 
   /**
@@ -1620,6 +1615,7 @@
         editingComponent.getParent().validate();
         tree.add(editingComponent.getParent());
         editingComponent.getParent().validate();
+        validCachedPreferredSize = false;
         tree.revalidate();
         ((JTextField) editingComponent).requestFocusInWindow(false);
         editorTimer.start();
@@ -2063,6 +2059,7 @@
       isEditing = false;
       tree.requestFocusInWindow(false);
       editorTimer.stop();
+      validCachedPreferredSize = false;
       tree.revalidate();
       tree.repaint();
     }
@@ -2093,6 +2090,7 @@
       tree.requestFocusInWindow(false);
       editorTimer.stop();
       isEditing = false;
+      validCachedPreferredSize = false;
       tree.revalidate();
       tree.repaint();
     }
@@ -2549,6 +2547,7 @@
      */
     public void treeExpanded(TreeExpansionEvent event)
     {
+      validCachedPreferredSize = false;
       tree.revalidate();
       tree.repaint();
     }
@@ -2561,6 +2560,7 @@
      */
     public void treeCollapsed(TreeExpansionEvent event)
     {
+      validCachedPreferredSize = false;
       tree.revalidate();
       tree.repaint();
     }
@@ -2756,6 +2756,7 @@
      */
     public void treeNodesInserted(TreeModelEvent e)
     {
+      validCachedPreferredSize = false;
       tree.revalidate();
       tree.repaint();
     }
@@ -2773,6 +2774,7 @@
      */
     public void treeNodesRemoved(TreeModelEvent e)
     {
+      validCachedPreferredSize = false;
       tree.revalidate();
       tree.repaint();
     }
@@ -2789,6 +2791,7 @@
      */
     public void treeStructureChanged(TreeModelEvent e)
     {
+      validCachedPreferredSize = false;
       tree.revalidate();
       tree.repaint();
     }
@@ -3272,7 +3275,7 @@
    * Get previous visible node in the tree. Package private for use in inner
    * classes.
    * 
-   * @param the
+   * @param node -
    *          current node
    * @return the next visible node in the JTree. Return null if there are no
    *         more.
@@ -3295,7 +3298,7 @@
   /**
    * Returns the next node in the tree Package private for use in inner classes.
    * 
-   * @param the
+   * @param curr - 
    *          current node
    * @return the next node in the tree
    */
@@ -3355,7 +3358,7 @@
    * Returns the next sibling in the tree Package private for use in inner
    * classes.
    * 
-   * @param the
+   * @param node - 
    *          current node
    * @return the next sibling in the tree
    */
@@ -3380,7 +3383,7 @@
    * Returns the previous sibling in the tree Package private for use in inner
    * classes.
    * 
-   * @param the
+   * @param node -
    *          current node
    * @return the previous sibling in the tree
    */
@@ -3464,7 +3467,7 @@
   /**
    * Returns the level of the node in the tree.
    * 
-   * @param the
+   * @param node -
    *          current node
    * @return the number of the level
    */
@@ -3626,7 +3629,7 @@
    * clipBounds, insets.
    * 
    * @param g - the graphics configuration.
-   * @param clipbounds - 
+   * @param clipBounds - 
    * @param insets - 
    * @param path - the path to draw the vertical part for.
    */
@@ -3703,7 +3706,10 @@
                                              boolean hasBeenExpanded,
                                              boolean isLeaf)
   {
-    // FIXME: not implemented.
+    Object node = path.getLastPathComponent();
+    if (treeModel != null && (!isLeaf && !node.equals(treeModel.getRoot())) && 
+        (tree.isRootVisible() || getLevel(node) != 1))
+      return true;
     return false;
   }
   
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to