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

Coding mistake in javax.swing.text.View.getViewIndex(float x, float y, Shape s)

XMLWordPrintable

    • b42
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.5.0_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b07)
      Java HotSpot(TM) Client VM (build 1.5.0_02-b07, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft WIndows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Please look at this method in class javax.swing.text.View :

          /**
           * Returns the child view index representing the given position in
           * the view. This iterates over all the children returning the
           * first with a bounds that contains <code>x</code>, <code>y</code>.
           *
           * @param x the x coordinate
           * @param y the y coordinate
           * @param allocation current allocation of the View.
           * @return index of the view representing the given location, or
           * -1 if no view represents that position
           * @since 1.4
           */
          public int getViewIndex(float x, float y, Shape allocation) {
      for (int counter = getViewCount() - 1; counter >= 0; counter--) {
      Shape childAllocation = getChildAllocation(counter, allocation);

                  if (childAllocation != null) {
                      Rectangle rect = (childAllocation instanceof Rectangle) ?
      (Rectangle)childAllocation : allocation.getBounds();

                      if (rect.contains(x, y)) {
                          return counter;
                      }
                  }
      }
      return -1;
          }

      I assume the last expression of the conditional operator should be "childAllocation.getBounds()" and not "allocation.getBounds()".


      REPRODUCIBILITY :
      This bug can be reproduced always.
      ###@###.### 2005-05-03 05:35:16 GMT

            mknyazevsunw Michael Knyazev (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: