Changeset 2431


Ignore:
Timestamp:
03/13/07 17:47:32 (13 years ago)
Author:
sorber
Message:

Polyline last node highlights on mouse-over.

File:
1 edited

Legend:

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

    r2393 r2431  
    4646  protected static final int CLOSE_LOOP = 6; 
    4747  protected static final int SELECTED_TAIL = 7; 
    48  
     48  protected static final int EXTEND_ON_TAIL = 8; 
     49  protected static final int BEG_EXTEND = 9; 
     50   
    4951 
    5052  /** Maximum distance (in pixels) mouse can be from a node to be considered 
     
    6567  protected OverlayPolyline line; 
    6668 
    67   /** Curve close to the mouse when drawing is not occurring */ 
     69  /** Curve close to the mouse when drawing is not occurring. */ 
    6870  protected OverlayPolyline selectedPln; 
    6971 
    70   /** Nearest node on selected PolyLine */ 
     72  /** Nearest node on selected PolyLine. */ 
    7173  protected int selectedNode; 
    7274 
    73   /** Whether the active node of the polyline is anchored. */ 
    74   protected boolean anchored; 
    75  
    76   /** Whether the mouse is currently near the last node of  
    77    *  the active polyline. */ 
    78   protected boolean nearTail; 
    79  
    80   /** Whether the mouse is currently near the first node of  
    81    *  the active polyline. */ 
    82   protected boolean nearHead; 
    83  
    84   /** Whether the mouse has moved sufficiently far from the  
    85    *  last node placed. */ 
    86   protected boolean departed; 
    87  
    88   /** Has the user entered resume mode */ 
    89   protected boolean resume; 
    90  
     75  /** 
     76   * The current mode of the state machine represented in/by the 
     77   * mouse methods of this tool. 
     78   */ 
    9179  protected int mode; 
    9280 
     
    9785    super(overlay, "Polyline", "Polyline", "polyline.png"); 
    9886    line = null; 
    99     anchored = false; 
    100     nearTail = false; 
    101     nearHead = false; 
    102     departed = false; 
    10387    mode = WAIT; 
    10488    unselect(); 
     
    121105      mode = WAIT; 
    122106    } 
     107 
    123108    if (mode == WAIT) { 
    124109      line =  new OverlayPolyline(overlay, dx, dy, dx, dy); 
     
    205190      } 
    206191    } 
    207     else if (mode == EXTEND) { 
     192    else if (mode == EXTEND || mode == BEG_EXTEND) { 
    208193      line.setLastNode(dx, dy); 
    209194      line.computeLength(); 
    210195      mode = PLACE; 
     196    } 
     197    else if (mode == EXTEND_ON_TAIL) { 
     198      line.deleteNode(line.getNumNodes()-1); 
     199      releaseLine(); 
     200      unselect(); 
     201      mode = WAIT; 
    211202    } 
    212203 
     
    255246      overlay.notifyListeners(new TransformEvent(overlay)); 
    256247    } 
    257     else if (mode == PLACE || mode == EXTEND) { 
     248    else if (mode == PLACE || mode == EXTEND || mode == BEG_EXTEND || 
     249        mode == EXTEND_ON_TAIL) { 
    258250      mouseMoved(e, px, py, dx, dy, pos, mods); 
    259251    } 
     
    285277      selectNode(display, line, line.getNumNodes() - 1); 
    286278      mode = SELECT; 
     279    } 
     280    else if (mode == EXTEND_ON_TAIL) { 
     281      mouseDown(e, px, py, dx, dy, pos, mods); 
     282      // basically delete last node and end line 
    287283    } 
    288284  } 
     
    315311    else if (mode == PLACE) { 
    316312      line.setNextNode(dx, dy); 
    317       mode = EXTEND; 
    318     } 
    319     else if (mode == EXTEND) { 
     313      mode = BEG_EXTEND; 
     314    } 
     315    else if (mode == EXTEND || mode == EXTEND_ON_TAIL) { 
    320316      line.setLastNode(dx, dy); 
     317       
    321318      // determine if near head:  
    322319      int ndx = 0; // index of head 
     
    326323      int[] nPxl = DisplayUtil.domainToPixel(display, nDomDbl); 
    327324      double[] nPxlDbl = {(double) nPxl[0], (double) nPxl[1]}; 
    328       double dist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
    329        
     325      double hdist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
     326       
     327      // determine if near last node placed  
     328      ndx = line.getNumNodes() - 2; 
     329      dPxlDbl = new double[] {(double) px, (double) py}; 
     330      nDom = line.getNodeCoords(ndx); 
     331      nDomDbl = new double[] {(double) nDom[0], (double) nDom[1]}; 
     332      nPxl = DisplayUtil.domainToPixel(display, nDomDbl); 
     333      nPxlDbl = new double[] {(double) nPxl[0], (double) nPxl[1]}; 
     334      double ldist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
     335 
    330336      // if near ndx, highlight selected node differently  
    331       if (dist < THRESH) { 
     337      int flag = -1;  
     338      if (ldist < THRESH)  
     339        if (hdist < ldist) flag = 0; 
     340        else if (hdist > ldist) flag = 1; 
     341        else ; 
     342      else if (hdist < THRESH) flag = 0; 
     343 
     344       
     345      if (flag == 0) { 
     346        line.setActiveDisplay(display); 
     347        line.setHighlightNode(0, CON); 
     348        mode = CLOSE_LOOP; 
     349      } 
     350      else if (flag == 1) { 
     351        line.setActiveDisplay(display); 
     352        line.setHighlightNode(line.getNumNodes()-1, SEL); 
     353        mode = EXTEND_ON_TAIL; 
     354      } 
     355      else if (flag == -1) { 
     356        line.turnOffHighlighting(); 
     357        mode = EXTEND; 
     358      } 
     359    } 
     360    else if (mode == BEG_EXTEND) { 
     361      line.setLastNode(dx, dy); 
     362       
     363      // determine if near head:  
     364      int ndx = 0; // index of head 
     365      double[] dPxlDbl = {(double) px, (double) py}; 
     366      float[] nDom = line.getNodeCoords(ndx); 
     367      double[] nDomDbl = {(double) nDom[0], (double) nDom[1]}; 
     368      int[] nPxl = DisplayUtil.domainToPixel(display, nDomDbl); 
     369      double[] nPxlDbl = {(double) nPxl[0], (double) nPxl[1]}; 
     370      double hdist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
     371       
     372      // determine if near last node placed  
     373      ndx = line.getNumNodes() - 2; 
     374      dPxlDbl = new double[] {(double) px, (double) py}; 
     375      nDom = line.getNodeCoords(ndx); 
     376      nDomDbl = new double[] {(double) nDom[0], (double) nDom[1]}; 
     377      nPxl = DisplayUtil.domainToPixel(display, nDomDbl); 
     378      nPxlDbl = new double[] {(double) nPxl[0], (double) nPxl[1]}; 
     379      double ldist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
     380 
     381      if (hdist < THRESH) { 
    332382        line.setActiveDisplay(display); 
    333383        line.setHighlightNode(line.getNumNodes()-1, CON); 
    334384        mode = CLOSE_LOOP; 
    335385      } 
    336       // mode remains extend otherwise 
     386      
     387      // if you've dragged far enough from last node placed 
     388      if (ldist > 10.0) { 
     389        mode = EXTEND; 
     390      } 
    337391    } 
    338392    else if (mode == CLOSE_LOOP) { 
Note: See TracChangeset for help on using the changeset viewer.