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

swing.text.LabelView.viewToModel(float, float, Shape) doesn't work properly

XMLWordPrintable



      Name: asC58863 Date: 02/26/98


      java.awt.swing.text.LabelView.viewToModel(float, float, Shape)
      does not work as specified in the JavaDoc.

      (See JavaDoc comments)
      "public int viewToModel(float x,
      float y,
          Shape a)
      [...]
       Returns: the location within the model that best represents the
                given point of view.
      "

        JavaDoc says that the method should return the location within the
       model that *best* represents the given point of view. But in case when
       point is to the left of the model method returns the last position within
       the model. However, the *best* location is the first position.



      Here is the example demonstrating the bug:
      ------------------ Test.java -----------------
      import java.awt.*;
      import java.awt.swing.*;
      import java.awt.swing.text.*;
      import java.awt.swing.plaf.basic.*;

      class Test {

        public static void main(String[] argv) {
          JTextPane textField = new JTextPane();
          StubTextUI textUI = new StubTextUI();
          textField.setUI(textUI);

          LabelView view = (LabelView)textUI.getView();
          
          try {
            Shape a = new Rectangle( 0, 0, 130, 50);
            float fx = view.modelToView( 0, a).getBounds().x-12;
            float fy = a.getBounds().y+1;

            textField.setText("LabelView Test");
            System.out.println(" viewToModel = "+view.viewToModel( fx, fy, a) );
          } catch(Throwable e) {
            System.out.println(e+" has been thrown ");
          }

          System.exit(0);
        }
      }

      class StubTextUI extends BasicTextFieldUI {
        View view;

        public StubTextUI() {
        }

        public View create(Element e) {
          view = new LabelView(e);
          return view;
        }

        public View getView() {
          return view;
        }

      }
      -------------- Output from the test -----------------
      :\>java Test
        viewToModel = 15
      ------------------------------------------------------

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

            apikalev Andrey Pikalev
            asemidetsunw Alexei Semidetnov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: