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

swing.text.BoxView.layout() method incorrectly counts child sizes.

XMLWordPrintable



      Name: aaC67449 Date: 11/23/99


      The method swing.text.BoxView.layout() incorrectly counts child sizes,
      in JDK1.3.0O.
      See example.
      The last child has y coordinate (35) more then the BoxView height(32),
      and the height of child is 5, but should be 4.
      This test works correctly in JDK1.3.0N

      Sorry for the big and unusual example, it is simply truncated JCK test.
      ------------------------- example ----------------
      import javax.swing.text.*;
      import java.awt.*;
      import javax.swing.*;
      import javax.swing.event.*;
      import javax.swing.plaf.basic.BasicTextFieldUI;

      public class Test extends java.applet.Applet{

          public static void main(String argv[]) {
              String buffer = "FieldView";
              JTextField textField = new JTextField(buffer);
              StubBoxUI textUI = new StubBoxUI(View.Y_AXIS);
              textField.setUI(textUI);
        

              // get the BoxView object
              StubBoxView c = (StubBoxView) textUI.getView();
        

              /* add 4 view child to the BoxView
               * child's minSize=3, prefSize=10
               */
       
              StubPlainView[] views = new StubPlainView[8];
              for (int i = 0; i < views.length; i++) {
                  views[i] = new StubPlainView(new StubElement());
                  views[i].setSize(50, 80);
              }
              c.replace(0, 0, views); // add views
       
              int width = 32;
              int height = 32;
              // try to layout the BoxView
              c.layout(width, height);
       
              // print 4th child size and location
              Rectangle alloc;
              alloc = new Rectangle(0, 0, 0, 0);
              c.childAllocation(7, alloc);
              System.out.println("the height of view =32");
              System.out.println("8th child rect =" + alloc);
          }
      }


      class StubBoxView extends BoxView {
          public boolean layoutRun = false;
          public boolean changedCalled = false;

          public StubBoxView(Element elem, int axis) {
              super(elem, axis);
                      setParent( null);
          }

          public void childAllocation(int index, Rectangle alloc) {
              super.childAllocation(index, alloc);
          }


          public void layout(int width, int height) {
              layoutRun = true;
              super.layout(width, height);
          }
              
      }

      class StubPlainView extends PlainView {
              public float min = 3;
              public float pref = 10;
              public float max = 40;

              public StubPlainView(Element elem) {
                      super( elem);
              }
              
              public float getMinimumSpan(int axis) {
                      return min;
              }
              public float getPreferredSpan(int axis) {
                      return pref;
              }
              public float getMaximumSpan(int axis) {
                      return max;
              }
      }

      class StubViewFactory implements ViewFactory {
              
              public StubViewFactory() {
              }

          public View create(Element elem) {
              return new StubPlainView(elem);
          }
      }


      class StubBoxUI extends BasicTextFieldUI {
              Element elem = null;
          View view;
          int axis;

          public StubBoxUI(int axis) {
              this.axis = axis;
          }

          public StubBoxUI(Element elem, int axis) {
              this.axis = axis;
                      this.elem = elem;
          }

          public View create(Element e) {
              if( elem == null) {
                              view = new StubBoxView(e, axis);
                      } else {
                              view = new StubBoxView(elem, axis);
                      }
              return view;
          }

          public View getView() {
              return view;
          }
              
              public ViewFactory getViewFactory() {
                      return new StubViewFactory();
              }
      }


      class StubElement implements Element {
          Document document = new DefaultStyledDocument();
          public Document getDocument() { return document; }
          public Element getParentElement() { return null; }
          public String getName() { return "StubElement"; }
          public AttributeSet getAttributes() { return new SimpleAttributeSet(); }
          public int getStartOffset() { return 0; }
          public int getEndOffset() { return document.getLength(); }
          public int getElementIndex(int offset) { return 0; }
          public int getElementCount() { return 1; }
          public Element getElement(int index) { return this; }
          public boolean isLeaf() { return true; }
      }
          
      -------------------- JDK1.3.0O -------------------
      the height of view =32
      8th child rect =java.awt.Rectangle[x=0,y=35,width=32,height=5]
      ------------------------- JDK1.3.0N ----------------
      the height of view =32
      8th child rect =java.awt.Rectangle[x=0,y=28,width=32,height=4]


      ======================================================================

            slunegov Sergey Lunegov (Inactive)
            alisunw Ali Ali (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: