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

Improve calculation of drop locations in JTree

    XMLWordPrintable

Details

    Description

      A DESCRIPTION OF THE REQUEST :
      The drag&drop support in Java 1.6 for JTree offers setting the drop mode, e.g.
      tree.setDropMode(DropMode.INSERT);

      This works fine except that there is no intuitive way to append a node at the end of an expanded node.

      See the example below and imagine the mouse cursor is in the lower half of "violet", then the drop line is currently painted for a subnode of root, the drop location is
      JTree$DropLocation[dropPoint=...,path=[root],childIndex=1]

      root
          colors
              blue
              violet
          -----------------
          sports
          food


      I would rather expect the drop line to be painted for a subnode of colors,
      JTree$DropLocation[dropPoint=...,path=[root, colors],childIndex=2]

      root
          colors
              blue
              violet
              -----------------
          sports
          food

      The childIndex of this drop location is 'out of bounds', but this is ok since the to be dropped node will get this index.

      If the mouse cursor is moved into the upper half of "sports", then the drop location of the first example would be correct.



      I tried to implement this by myself, but the possibilities for customization are improvable at this place (but this is probably a separate issue):
      (1) JTree.dropLocationForPoint(Point p) is package private and cannot be overridden.
      (2) The constructor of the final class JTree.DropLocation is private and makes the class unusable for derived trees.
      (3) I'm not sure whether the (again private, why?) method BasicTreeUI.paintDropLine(Graphics g) could cope with out-of-range child indices.


      JUSTIFICATION :
      Changing the calculation of the drop line would improve usability. Dropping nodes to a specified location would be more flexible and intuitive.

      Attachments

        Activity

          People

            alexp Alexander Potochkin (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: