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

method FixedHeightLayoutCache.getBounds returns bad Rectangle

    • beta
    • sparc
    • solaris_2.5



      Name: sdC67446 Date: 02/10/99


      The method of class FixedHeightLayoutCache
      public Rectangle getBounds(TreePath path, Rectangle placeIn) returns
      the Rectangle with field 'width' == 0 always. Value for this field
      should be calculated from the nodeDimensions specified previously.

      The doc says:
      --------------------------------------------------
      public Rectangle getBounds(TreePath path,
                                 Rectangle placeIn)

             Overrides:
                    getBounds in class AbstractLayoutCache


      // from AbstractLayoutCache class documentation //
      public void setNodeDimensions(AbstractLayoutCache.NodeDimensions nd)

             Sets the renderer that is responsible for drawing nodes in the
             tree.

      The test demonstrating the bug:
      -----------------Test.java------------------------
      import javax.swing.tree.*;
      import java.awt.Rectangle;

      public class Test {

          public static class DummyNodeDimensions extends AbstractLayoutCache.NodeDimensions {
      private Rectangle rectangle;
      public DummyNodeDimensions(Rectangle r) {
      rectangle = r;
      }
      public Rectangle getNodeDimensions(Object value, int row,
      int depth,
      boolean expanded,
      Rectangle bounds) {
      return rectangle;
      }
          }
          
          /* create the TreeModel of deep 1 with specified num of children */
          public static DefaultTreeModel getTreeModelILike(int childrenCount) {
              DefaultMutableTreeNode root =
                  new DefaultMutableTreeNode("root");
              
              for (int i = 0; i < childrenCount; i++) {
                  DefaultMutableTreeNode child =
                      new DefaultMutableTreeNode("root.child"+i);
                  root.insert(child,i);
              }
              return new DefaultTreeModel(root);
          }
         
          public static void main(String[] args) {
      int x = 1, y = 2, dx = 3, dy = 4, h = 3;

      DummyNodeDimensions dim = new DummyNodeDimensions(new Rectangle(x,y,dx,dy));

      FixedHeightLayoutCache fhlc = new FixedHeightLayoutCache();
      fhlc.setModel(getTreeModelILike(3));
      fhlc.setRootVisible(true);
      fhlc.setNodeDimensions(dim);
      fhlc.setRowHeight(h);
      int row = 0;
      TreePath path = fhlc.getPathForRow(row);
      System.out.println("path = "+path);


      Rectangle r = fhlc.getBounds(path,new Rectangle());
      Rectangle r2 = new Rectangle(x, row*h, dx, h);

      System.out.println("r1="+r);
      System.out.println("r2="+r2);
          }
      }
      ---------Output from the test---------------------
      path = [root]
      r1=java.awt.Rectangle[x=1,y=0,width=0,height=3]
      r2=java.awt.Rectangle[x=1,y=0,width=3,height=3]
      --------------------------------------------------
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: