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

CompositeView.modelToView can pass modelToView to wrong View

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.2.2
    • 1.2.0
    • client-libs
    • None
    • 1.2.2
    • x86
    • windows_nt

      The following test case illustrates the bug. If no exception is thrown, it worked:
      /*
       * @test %I% %E%
       * @bug
       * @summary Makes sure CompositeView passes modelToView to the correct
       * components when invoked with a backward bias.
       * @author Scott Violet
       */

      import java.awt.*;
      import javax.swing.*;
      import javax.swing.text.*;

      public class ModelToViewTest implements Runnable {
          public static void main(String[] args) throws Throwable {
      new ModelToViewTest();
          }


          boolean done;
          JTextPane textPane;
          Throwable error;

          public ModelToViewTest() throws Throwable {
      textPane = new JTextPane();
      SimpleAttributeSet sas = new SimpleAttributeSet();
      StyleConstants.setBold(sas, true);
      try {
      textPane.getDocument().insertString(0, "foo", sas);
      } catch (BadLocationException ble) {
      System.out.println("BLE: " + ble);
      }
      JFrame frame = new JFrame();
      frame.getContentPane().add(textPane);
      frame.pack();
      frame.show();
      SwingUtilities.invokeLater(this);
      synchronized(this) {
      while (!done) {
      wait();
      }
      }
      if (error != null) {
      throw error;
      }
          }

          public void run() {
      Dimension pref = textPane.getPreferredSize();
      try {
      View root = textPane.getUI().getRootView(textPane);
      Rectangle rect = root.modelToView(0, Position.Bias.Forward,
      3, Position.Bias.Backward,
      textPane.getBounds()).
      getBounds();
      System.out.println("RECT: " + rect);
      for (int x = rect.x + 10; x >= rect.x; x--) {
      System.out.println(x + ": " + textPane.viewToModel
      (new Point(x, rect.y)));
      }
      } catch (BadLocationException ble) {
      error = ble;
      } catch (IllegalArgumentException iae) {
      error = iae;
      }
      synchronized(this) {
      done = true;
      notify();
      }
          }
      }

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: