Changeset 2886


Ignore:
Timestamp:
06/18/07 16:27:18 (12 years ago)
Author:
sorber
Message:

Misc. small changes.

Location:
trunk/loci/visbio/overlays
Files:
4 edited

Legend:

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

    r2875 r2886  
    398398  public double getCurveLength() { return curveLength; } 
    399399 
     400  /** Determines length of last line segment in this curve. */ 
     401  public double getLastSegmentLength() { 
     402    float[][] lastSeg = {getNodeCoords(getNumNodes()-1), 
     403      getNodeCoords(getNumNodes() - 2)}; 
     404    double[][] lastSegD = {{(double) lastSeg[0][0], (double) lastSeg[0][1]}, 
     405      {(double) lastSeg[1][0], (double) lastSeg[1][1]}}; 
     406    return MathUtil.getDistance(lastSegD[0], lastSegD[1]); 
     407  } 
     408 
    400409  /** Sets length of curve */ 
    401410  public void setCurveLength(double len) { curveLength = len; } 
     
    417426 
    418427  /** Sets coordinates of an existing node */ 
    419   public void setNodeCoords(int nodeIndex, float newX, float newY) { 
    420     if (nodeIndex >= 0 && nodeIndex < numNodes) { 
    421       nodes[0][nodeIndex] = newX; 
    422       nodes[1][nodeIndex] = newY; 
     428  public void setNodeCoords(int ndx, float newX, float newY) { 
     429    if (ndx >= 0 && ndx < numNodes) { 
     430      nodes[0][ndx] = newX; 
     431      nodes[1][ndx] = newY; 
    423432    } 
    424433    else { 
  • trunk/loci/visbio/overlays/OverlayNumericStrategy.java

    r2885 r2886  
    5555  protected static final float SMOOTHING_FACTOR = 0.35f; 
    5656 
     57  /** Maximum distance (in pixels) mouse can be from a node to be considered 
     58   *  pointing to it. */ 
     59  protected static final float POLYLINE_THRESH = 7.0f; 
     60 
    5761  // -- Constructor -- 
    5862   
     
    7983  /** Returns the single exponential smoothing factor. */ 
    8084  public static double getSmoothingFactor() { return SMOOTHING_FACTOR; } 
     85   
     86  /** Returns the polyline threshold. */ 
     87  public static double getPolylineThreshold() { return POLYLINE_THRESH; } 
    8188} 
  • trunk/loci/visbio/overlays/PolylineTool.java

    r2868 r2886  
    5151  /** Maximum distance (in pixels) mouse can be from a node to be considered 
    5252   *  pointing to it. */ 
    53   protected static final double THRESH = 7.0; 
     53  protected static final double THRESH = 
     54    OverlayNumericStrategy.getPolylineThreshold(); 
    5455 
    5556  /** Color for highlighting head or tail node of polyline when 'connecting' 
     
    384385  /** Adjusts last node and curve length */ 
    385386  private void adjustLastNode (OverlayPolyline line, float dx, float dy) { 
    386     double lastSegLength = getLastSegmentLength(); 
     387    double lastSegLength = line.getLastSegmentLength(); 
    387388    line.setLastNode(dx, dy); 
    388     double newLastSegLength = getLastSegmentLength(); 
     389    double newLastSegLength = line.getLastSegmentLength(); 
    389390    double delta = newLastSegLength - lastSegLength; 
    390391    line.setCurveLength(line.getCurveLength() + delta); 
    391392  } 
    392393 
     394  // TODO -- combine this method with the similar one for freeforms; 
    393395  /** Splits an overlay polyline in two */ 
    394396  private void split (OverlayPolyline line, int selectedNode) { 
     
    425427      l2.setDrawing(false); 
    426428      l2.setSelected(false); 
     429    } 
     430  } 
     431 
     432  /** Gets distance to the node specified, handling awkward casts. */ 
     433  private double getDistanceToNode(int ndx, int px, int py, 
     434    DisplayImpl display) { 
     435    double[] dPxlDbl = {(double) px, (double) py}; 
     436    float[] nDom = line.getNodeCoords(ndx); 
     437    double[] nDomDbl = {(double) nDom[0], (double) nDom[1]}; 
     438    int[] nPxl = CursorUtil.domainToPixel(display, nDomDbl); 
     439    double[] nPxlDbl = {(double) nPxl[0], (double) nPxl[1]}; 
     440    double dist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
     441    return dist; 
     442  } 
     443 
     444  /** Ends drawing of the current line */ 
     445  private void releaseLine() { 
     446    if (line != null) { 
     447      line.turnOffHighlighting(); 
     448      line.updateBoundingBox(); 
     449      line.computeLength(); 
     450      line.setDrawing(false); 
     451      line.setSelected(true); 
     452      unselect(); 
     453    } 
     454  } 
     455 
     456  /** Releases a selected node */ 
     457  private void unselect() { 
     458    line = null; 
     459    selectedNode = -1; 
     460  } 
     461 
     462  /** Selects a particular node */ 
     463  private void selectNode(OverlayPolyline pln, int node) { 
     464    line.setDrawing(false); 
     465    line.setSelected(true); 
     466    selectedNode = node; 
     467    pln.setHighlightNode(node, SEL); 
     468  } 
     469 
     470  /** Finds nearest (subject to a threshold) node of all polylines 
     471   *  in a list of OverlayObjects. 
     472   *  @param objects An array of OverlayObjects on this display 
     473   *  Returns an array int[2], with item 0 the index of the nearest polyline 
     474   *  in the objects array, item 1 the index of the nearest node in the nearest 
     475   *  polyline */ 
     476  private int[] getNearestNode(DisplayImpl display, 
     477      OverlayObject[] objects, int px, int py, double threshold) { 
     478    Vector polylines = new Vector(); 
     479    Vector indices = new Vector(); 
     480    double[] p = {(double) px, (double) py}; 
     481 
     482    for (int i=0; i<objects.length; i++) { 
     483      if (objects[i] instanceof OverlayPolyline) { 
     484        polylines.add(objects[i]); 
     485        indices.add(new Integer(i)); 
     486      } 
     487    } 
     488 
     489    int nearestPline = -1; 
     490    int nearestNode = -1; 
     491    double minDist = Double.POSITIVE_INFINITY; 
     492    for (int i=0; i<polylines.size(); i++) { 
     493      OverlayPolyline pln = (OverlayPolyline) polylines.get(i); 
     494      for (int j=0; j<pln.getNumNodes(); j++) { 
     495        float[] c = pln.getNodeCoords(j); 
     496        double[] cDbl = {c[0], c[1]}; // auto cast 
     497        int[] cPxl = CursorUtil.domainToPixel(display, cDbl); 
     498        double[] cPxlDbl = {(double) cPxl[0], (double) cPxl[1]}; 
     499        double dist = MathUtil.getDistance (cPxlDbl, p); 
     500        if (dist < minDist && dist < threshold) { 
     501          minDist = dist; 
     502          nearestPline = ((Integer) indices.get(i)).intValue(); 
     503          nearestNode = j; 
     504        } 
     505      } 
     506    } 
     507 
     508    if (nearestPline == -1) return null; 
     509    else return new int[]{nearestPline, nearestNode}; 
     510  } 
     511 
     512  // -- Helper methods for debugging -- 
     513 
     514  /** Prints node array of current freeform; for debugging */ 
     515  private void printNodes(float[][] nodes) { 
     516    System.out.println("Printing nodes..."); 
     517    for (int i = 0; i < nodes[0].length; i++){ 
     518      System.out.println(i+":("+nodes[0][i]+","+nodes[1][i]+")"); 
     519    } 
     520  } 
     521 
     522  /** Prints node array of current freeform; for debugging */ 
     523  private void printNodes() { 
     524    if (line!=null){ 
     525      float[][] nodes = line.getNodes(); 
     526      printNodes(nodes); 
     527    } 
     528  } 
     529 
     530  /** Prints a message for debugging */ 
     531  public void print(String methodName, String message) { 
     532    boolean toggle = true; 
     533    if (toggle) { 
     534      String header = "FreeformTool."; 
     535      String out = header + methodName + ": " + message; 
     536      System.out.println(out); 
    427537    } 
    428538  } 
     
    448558    System.out.println(method + "\t" + m); 
    449559  } 
    450  
    451   /** Gets distance to the node specified, handling awkward casts. */ 
    452   private double getDistanceToNode(int ndx, int px, int py, 
    453     DisplayImpl display) { 
    454     double[] dPxlDbl = {(double) px, (double) py}; 
    455     float[] nDom = line.getNodeCoords(ndx); 
    456     double[] nDomDbl = {(double) nDom[0], (double) nDom[1]}; 
    457     int[] nPxl = CursorUtil.domainToPixel(display, nDomDbl); 
    458     double[] nPxlDbl = {(double) nPxl[0], (double) nPxl[1]}; 
    459     double dist = MathUtil.getDistance (nPxlDbl, dPxlDbl); 
    460     return dist; 
    461   } 
    462  
    463   /** Determines length of last line segment. */ 
    464   private double getLastSegmentLength() { 
    465     float[][] lastSeg = {line.getNodeCoords(line.getNumNodes() -1), 
    466       line.getNodeCoords(line.getNumNodes() - 2)}; 
    467     double[][] lastSegD = {{(double) lastSeg[0][0], (double) lastSeg[0][1]}, 
    468       {(double) lastSeg[1][0], (double) lastSeg[1][1]}}; 
    469     return MathUtil.getDistance(lastSegD[0], lastSegD[1]); 
    470   } 
    471  
    472   /** Ends drawing of the current line */ 
    473   private void releaseLine() { 
    474     if (line != null) { 
    475       line.turnOffHighlighting(); 
    476       line.updateBoundingBox(); 
    477       line.computeLength(); 
    478       line.setDrawing(false); 
    479       line.setSelected(true); 
    480       unselect(); 
    481     } 
    482   } 
    483  
    484   /** Releases a selected node */ 
    485   private void unselect() { 
    486     line = null; 
    487     selectedNode = -1; 
    488   } 
    489  
    490   /** Selects a particular node */ 
    491   private void selectNode(OverlayPolyline pln, int node) { 
    492     line.setDrawing(false); 
    493     line.setSelected(true); 
    494     selectedNode = node; 
    495     pln.setHighlightNode(node, SEL); 
    496   } 
    497  
    498   /** Finds nearest (subject to a threshold) node of all polylines 
    499    *  in a list of OverlayObjects. 
    500    *  @param objects An array of OverlayObjects on this display 
    501    *  Returns an array int[2], with item 0 the index of the nearest polyline 
    502    *  in the objects array, item 1 the index of the nearest node in the nearest 
    503    *  polyline */ 
    504   private int[] getNearestNode(DisplayImpl display, 
    505       OverlayObject[] objects, int px, int py, double threshold) { 
    506     Vector polylines = new Vector(); 
    507     Vector indices = new Vector(); 
    508     double[] p = {(double) px, (double) py}; 
    509  
    510     for (int i=0; i<objects.length; i++) { 
    511       if (objects[i] instanceof OverlayPolyline) { 
    512         polylines.add(objects[i]); 
    513         indices.add(new Integer(i)); 
    514       } 
    515     } 
    516  
    517     int nearestPline = -1; 
    518     int nearestNode = -1; 
    519     double minDist = Double.POSITIVE_INFINITY; 
    520     for (int i=0; i<polylines.size(); i++) { 
    521       OverlayPolyline pln = (OverlayPolyline) polylines.get(i); 
    522       for (int j=0; j<pln.getNumNodes(); j++) { 
    523         float[] c = pln.getNodeCoords(j); 
    524         double[] cDbl = {c[0], c[1]}; // auto cast 
    525         int[] cPxl = CursorUtil.domainToPixel(display, cDbl); 
    526         double[] cPxlDbl = {(double) cPxl[0], (double) cPxl[1]}; 
    527         double dist = MathUtil.getDistance (cPxlDbl, p); 
    528         if (dist < minDist && dist < threshold) { 
    529           minDist = dist; 
    530           nearestPline = ((Integer) indices.get(i)).intValue(); 
    531           nearestNode = j; 
    532         } 
    533       } 
    534     } 
    535  
    536     if (nearestPline == -1) return null; 
    537     else return new int[]{nearestPline, nearestNode}; 
    538   } 
    539  
    540   /** Prints node array of current freeform; for debugging */ 
    541   private void printNodes(float[][] nodes) { 
    542     System.out.println("Printing nodes..."); 
    543     for (int i = 0; i < nodes[0].length; i++){ 
    544       System.out.println(i+":("+nodes[0][i]+","+nodes[1][i]+")"); 
    545     } 
    546   } 
    547  
    548   /** Prints node array of current freeform; for debugging */ 
    549   private void printNodes() { 
    550     if (line!=null){ 
    551       float[][] nodes = line.getNodes(); 
    552       printNodes(nodes); 
    553     } 
    554   } 
    555  
    556   /** Prints a message for debugging */ 
    557   public void print(String methodName, String message) { 
    558     boolean toggle = true; 
    559     if (toggle) { 
    560       String header = "FreeformTool."; 
    561       String out = header + methodName + ": " + message; 
    562       System.out.println(out); 
    563     } 
    564   } 
    565560} // end class PolylineTool 
  • trunk/loci/visbio/overlays/SpreadsheetLauncher.java

    r2837 r2886  
    2424package loci.visbio.overlays; 
    2525 
    26 //import com.jgoodies.looks.LookUtils; 
     26import com.jgoodies.plaf.LookUtils; 
    2727import java.io.File; 
    2828import java.io.IOException; 
    29 import java.util.Locale; 
    3029 
    3130/** Launches an external spreadsheet application. */ 
     
    4443  protected static final String MAC_PATH = 
    4544    "/Applications/Microsoft Office 2004/Microsoft Excel"; 
    46  
    47   /** The name of the OS. */ 
    48   // copied from LookUtils 
    49   // TODO can use LookUtils methods as soon as we update jgoodies.looks jar file 
    50   protected static final String OS_NAME = System.getProperty("os.name"); 
    5145 
    5246  // --  Fields -- 
     
    116110  /** Whether the OS is windows. */ 
    117111  protected static boolean isWindows() { 
    118     // return LookUtils.IS_OS_WINDOWS_MODERN; 
    119     // copied from LookUtils: 
    120     return OS_NAME.startsWith("Windows"); 
     112    return LookUtils.IS_OS_WINDOWS_MODERN; 
    121113  } 
    122114 
    123115  /** Whether the OS is mac. */ 
    124116  protected static boolean isMac() { 
    125     // return LookUtils.IS_OS_MAC; 
    126     // Copied from LookUtils 
    127     return OS_NAME.startsWith("Mac"); 
     117    return LookUtils.IS_OS_MAC; 
    128118  } 
    129119 
    130120  /** Whether OS is Linux. */ 
    131121  protected static boolean isLinux() { 
    132     // return LookUtils.IS_OS_LINUX; 
    133     return OS_NAME.toUpperCase(Locale.ENGLISH).startsWith("LINUX"); 
    134     // copied from LookUtils 
     122    return LookUtils.IS_OS_LINUX; 
    135123  } 
    136124 
Note: See TracChangeset for help on using the changeset viewer.