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

unclear doc for DefaultTreeSelectionModel.insureRowContinuity()

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.3
    • CPU:
      sparc
    • OS:
      solaris_2.5.1
    • Verification:
      Verified

      Description



      Name: sdC67446 Date: 06/15/99


      The doc for method:
          protected void insureRowContinuity()
      of class javax.swing.DefaultTreeSelectionModel
      says:
      ---
           Useful for CONTIGUOUS_TREE_SELECTION. If the rows that are selected
           are not contiguous then the selection is reset to be contiguous.
           Or if the selection mode is single selection and more than one
           this is selected the selection is reset.
      ---
      It is should be clearly clarified what the method does when "selection
      is reset to be contiguous". Currently this method takes only the
      subselection of paths with smallest rows and cuts off other part of
      selection.

      Also the way of reset should be documented when the selection mode is
      single selection.

      This is the example:
      ----------------------------------------------
      import javax.swing.tree.*;

      public class Test {

          public static class DummyDefaultTreeSelectionModel extends DefaultTreeSelectionModel {
              public void insureRowContinuity() {
                  super.insureRowContinuity();
              }
              public TreePath[] getField_selection() {
                  return selection;
              }
          }

          public static class DummyRowMapper implements RowMapper {

              // this is it - returning row of the path is the count of path's components
              // ["1"] -> 1
              // ["1", "2"] -> 2
              // ["1", "2", "3"] -> 3
              
              public int[] getRowsForPaths(TreePath[] path) {
                  int rows[] = new int[path.length];
                  for (int i=0;i<path.length;i++) {
                      String userObject = (String)path[i].getPathComponent(0);
                      rows[i] = path[i].getPathCount();
                  }
                  return rows;
              }
          }
          public static void main(String[] args) {
              Object objs1[] = {"1"};
              Object objs2[] = {"1", "2"};
              Object objs3[] = {"1", "2", "3"};
              Object objs4[] = {"1", "2", "3", "4"};
         
              DummyDefaultTreeSelectionModel model = new DummyDefaultTreeSelectionModel();
          
              TreePath sPaths[] = {
                  new TreePath(objs1),
                  new TreePath(objs2),
                  new TreePath(objs4)
              };

              model.setSelectionPaths(sPaths);
              model.setRowMapper(new DummyRowMapper());
              model.setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);

              System.out.println("rows of selection");
              for (int i=0;i<model.getField_selection().length;i++) {
                  System.out.println("selection["+i+"] == "+
                                     model.getField_selection()[i]);
              }

              model.insureRowContinuity();

              System.out.println("rows of selection");
              for (int i=0;i<model.getField_selection().length;i++) {
                  System.out.println("selection["+i+"] == "+
                                     model.getField_selection()[i]);
              }
          };
      }
      ----------------------------------------------
      The example's output:
      rows of selection
      selection[0] == [1]
      selection[1] == [1, 2]
      selection[2] == [1, 2, 3, 4]
      rows of selection
      selection[0] == [1]
      selection[1] == [1, 2]

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

        Attachments

          Activity

            People

            Assignee:
            sharonz Sharon Zakhour (Inactive)
            Reporter:
            dsvsunw Dsv Dsv (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: