Changeset 2115


Ignore:
Timestamp:
01/17/07 13:52:37 (13 years ago)
Author:
sorber
Message:

Added dynamic list refreshing when selecting overlays with a TransientSelectBox

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/overlays/PointerTool.java

    r2096 r2115  
    2626import java.awt.event.InputEvent; 
    2727import loci.visbio.data.TransformEvent; 
     28import java.util.Vector; 
    2829 
    2930/** PointerTool is the tool for manipulating existing overlays. */ 
     
    3738  /** Location where an object was first "grabbed" with a mouse press. */ 
    3839  protected float grabX, grabY; 
     40 
     41  /** Vector of "grabbed" objects */ 
     42  protected Vector grabees;  // (the user being the grabber) 
    3943 
    4044  /** Location where mouseDown occurs */ 
     
    5357  protected float[][] bounds; 
    5458 
     59  /** Array of whether objects are selected at time of mouse press */ 
     60  protected boolean[] selected; 
     61   
    5562  // -- Constructor -- 
    5663 
     
    6976    boolean shift = (mods & InputEvent.SHIFT_MASK) != 0; 
    7077    boolean ctrl = (mods & InputEvent.CTRL_MASK) != 0; 
    71  
     78     
    7279    // pick nearest object 
    7380    objs = overlay.getObjects(pos); 
    7481    bounds = new float[objs.length][4]; 
     82    selected = new boolean[objs.length]; 
    7583 
    7684    double dist = Double.POSITIVE_INFINITY; 
     
    8290        ndx = i; 
    8391      } 
    84  
    85       // assemble array of distances 
     92    } 
     93     
     94    // assemble array of objects' bounding boxes  
     95    for (int i=0; i<objs.length; i++) { 
    8696      float[] bound = new float[4]; 
    8797      bound[0] = objs[i].getX(); 
     
    98108 
    99109    double threshold = 0.02 * overlay.getScalingValue(); 
    100     boolean selected = dist < threshold && objs[ndx].isSelected(); 
     110    boolean sel = dist < threshold && objs[ndx].isSelected(); 
    101111 
    102112    if (!shift && !ctrl) { 
     
    105115    } 
    106116 
     117    // compile array tracking initial selection state of all objs at this position 
     118    for (int i=0; i<objs.length; i++) { selected[i] = objs[i].isSelected(); } 
     119 
    107120    if (dist < threshold) { 
    108       if (selected && !ctrl && !shift) { 
     121      if (sel && !ctrl && !shift) { 
    109122        // grab object if it is already selected 
    110123        grabIndex = ndx; 
     
    113126      } 
    114127      // select (or deselect) picked object 
    115       objs[ndx].setSelected(ctrl ? !selected : true); 
     128      objs[ndx].setSelected(ctrl ? !sel : true); 
    116129    } else { 
    117130      // record location of click 
     
    172185 
    173186      // select objects inside the box 
     187      boolean stateChanged = false; 
    174188      for (int i=0; i<bounds.length; i++) { 
    175189        float bx1, bx2, by1, by2; 
     
    206220        } 
    207221 
    208         // determine whether object i is inside or outside of selection box 
     222        // determine whether object i is inside or outside of selection box  
     223        boolean inside = false; 
    209224        if (bx1 < ox1 && ox1 < bx2 && bx1 < ox2 && ox2 < bx2 && 
    210225          by1 < oy1 && oy1 < by2 && by1 < oy2 && oy2 < by2) 
    211226        { 
    212           objs[i].setSelected(true); 
    213         } 
    214         else objs[i].setSelected(false); 
    215       } 
     227          inside = true; 
     228        } 
     229 
     230        // code for static list refresh 
     231        // (add a refreshListSelection line to mouseUp 
     232        /* 
     233        if (inside) { 
     234          if (ctrl && !shift) objs[i].setSelected(!selected[i]); 
     235          else objs[i].setSelected(true); 
     236        } 
     237        else { 
     238          if (shift || ctrl) objs[i].setSelected(selected[i]); 
     239          else objs[i].setSelected(false); 
     240        } 
     241        */ 
     242 
     243        // code for dynamic list refresh 
     244        if (inside) { 
     245          if (ctrl && !shift) { 
     246            if (objs[i].isSelected() == selected[i]) { 
     247              objs[i].setSelected(!selected[i]); 
     248              stateChanged = true; 
     249            } 
     250          } 
     251          else if (!objs[i].isSelected()) { 
     252            objs[i].setSelected(true); 
     253            stateChanged = true; 
     254          } 
     255        } 
     256        else { 
     257          if (shift || ctrl) { 
     258            if (objs[i].isSelected() != selected[i]) { 
     259              objs[i].setSelected(selected[i]); 
     260              stateChanged = true; 
     261            } 
     262          } 
     263          else { 
     264            if (objs[i].isSelected()) { 
     265              objs[i].setSelected(false); 
     266              stateChanged = true; 
     267            } 
     268          } 
     269        } 
     270      } // end for 
     271      // do this only if state changed? 
     272      if (stateChanged) ((OverlayWidget) overlay.getControls()).refreshListSelection(); 
    216273      overlay.notifyListeners(new TransformEvent(overlay)); 
    217274    } 
Note: See TracChangeset for help on using the changeset viewer.