Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4264241

AbstractLayoutCache.getPreferredWidth includes extra path

    XMLWordPrintable

Details

    Description



      Name: sdC67446 Date: 08/20/99


      The method
          public int getPreferredWidth(Rectangle bounds)
      of class AbstractLayoutCache calculates width unfairly.
      The method include one extra path when getPrefferedWidth is passed a
      rectangle.

      For example:
        the method returns non-zero width for Rectangle(0,0,0,0).

      The doc says:
      --------------------------------------------------
      public int getPreferredWidth(Rectangle bounds)

           Returns the preferred width for the passed in region. If bounds
           is null, the preferred width for all the nodes will be returned
           (and this may be VERY expensive).
           
      The test demonstrating the bug:
      -----------------Test.java------------------------
      import javax.swing.tree.*;
      import javax.swing.event.*;
      import java.awt.Rectangle;

      public class Test extends FixedHeightLayoutCache {

          public Test() {
      super();
          }
          
          public DefaultTreeModel getTreeModelILike(int children) {
              DefaultMutableTreeNode root =
                  new DefaultMutableTreeNode(new String("root"));
              
              for (int i = 0; i < children; i++) {
                  DefaultMutableTreeNode child =
              // {***} getBounds will return {1,2,3}
                      new DefaultMutableTreeNode(new Integer(i+1));
                  root.insert(child,i);
              }
              return new DefaultTreeModel(root);
          }

          public Rectangle getBounds(TreePath path, Rectangle bounds) {
      DefaultMutableTreeNode node =
      (DefaultMutableTreeNode)path.getLastPathComponent();
      int width = ((Integer)((node).getUserObject())).intValue();
      System.out.println("getBounds("+path+", ..)");
              // {***}
      return new Rectangle(0,0,width,0);
          }

          public static void main(String[] args) {
      Test test = new Test();
      test.setModel(test.getTreeModelILike(3));
      int width = test.getPreferredWidth(new Rectangle(0,0,0,0));
              System.out.println(width);
          }
      }
      ---------Output from the test---------------------
      getBounds([root, 1], ..)
      getBounds([root, 2], ..)
      1
      --------------------------------------------------
      ======================================================================

      Attachments

        Activity

          People

            svioletsunw Scott Violet (Inactive)
            dsvsunw Dsv Dsv (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: