Changeset 2910


Ignore:
Timestamp:
06/26/07 18:39:36 (12 years ago)
Author:
sorber
Message:

Reordered OverlayObject API methods for consistency.

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

Legend:

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

    r2823 r2910  
    6464  // -- OverlayObject API methods -- 
    6565 
     66  /** Returns whether this object is drawable, i.e., is of nonzero 
     67   *  size, area, length, etc. 
     68   */ 
     69  public boolean hasData() { return (x1 != x2 || y1 != y2); } 
     70 
    6671  /** Gets VisAD data object representing this overlay. */ 
    6772  public DataImpl getData() { 
     
    116121    return field; 
    117122  } 
    118  
    119   /** Returns whether this object is drawable, i.e., is of nonzero 
    120    *  size, area, length, etc. 
    121    */ 
    122   public boolean hasData() { return (x1 != x2 || y1 != y2); } 
    123123 
    124124  /** Computes the shortest distance from this object to the given point. */ 
  • trunk/loci/visbio/overlays/OverlayBox.java

    r2824 r2910  
    6767  // -- OverlayObject API methods -- 
    6868 
     69  /** Returns whether this object is drawable, i.e., is of nonzero 
     70   *  size, area, length, etc. 
     71   */ 
     72  public boolean hasData() { return (x1 != x2 && y1 != y2); } 
     73 
    6974  /** Gets VisAD data object representing this overlay. */ 
    7075  public DataImpl getData() { 
     
    118123    return field; 
    119124  } 
    120  
    121   /** Returns whether this object is drawable, i.e., is of nonzero 
    122    *  size, area, length, etc. 
    123    */ 
    124   public boolean hasData() { return (x1 != x2 && y1 != y2); } 
    125125 
    126126  /** Computes the shortest distance from this object to the given point. */ 
  • trunk/loci/visbio/overlays/OverlayMarker.java

    r2904 r2910  
    6161  // -- OverlayObject API methods -- 
    6262 
    63   /** Returns the defualt width of this marker. */ 
    64   protected float getDefaultWidth() { 
    65     return 0.02f * overlay.getScalingValue(); 
    66   } 
    67  
    68   /** Returns the width of this marker. */ 
    69   protected float getWidth() { return width; } 
     63  /** Returns whether this object is drawable, i.e., is of nonzero 
     64   *  size, area, length, etc. 
     65   */ 
     66  public boolean hasData() { return true; } 
    7067 
    7168  /** Gets VisAD data object representing this overlay. */ 
     
    10299  } 
    103100 
    104   /** Returns whether this object is drawable, i.e., is of nonzero 
    105    *  size, area, length, etc. 
    106    */ 
    107   public boolean hasData() { return true; } 
    108  
    109101  /** Computes the shortest distance from this object to the given point. */ 
    110102  public double getDistance(double x, double y) { 
     
    138130  } 
    139131 
     132  // -- Overlay Marker API methods -- 
     133  
     134  /** Returns the defualt width of this marker. */ 
     135  protected float getDefaultWidth() { 
     136    return 0.02f * overlay.getScalingValue(); 
     137  } 
     138 
     139  /** Returns the width of this marker. */ 
     140  protected float getWidth() { return width; } 
     141 
     142 
    140143  // -- Object API methods -- 
    141144 
  • trunk/loci/visbio/overlays/OverlayNodedObject.java

    r2909 r2910  
    238238  } 
    239239 
     240  /** Returns a specific statistic of this object */ 
     241  public String getStat(String name) { 
     242    if (name.equals(BOUNDS)) { 
     243      return "(" + x1 + ", " + y1 + "), (" + x2 + ", " + y2 + ")"; 
     244    } 
     245    else if (name.equals(NODES)) { 
     246      return "" + numNodes; 
     247    } 
     248    else if (name.equals(LENGTH)) { 
     249      return "" + (float) curveLength; 
     250    } 
     251    else return "No such statistic for this overlay type"; 
     252  } 
     253 
     254  /** Retrieves useful statistics about this overlay. */ 
     255  public String getStatistics() { 
     256    return BOUNDS + " = (" + x1 + ", " + y1 + "), (" + x2 + ", " + y2 + ")\n" + 
     257      NODES +" = " + numNodes + "\n" + 
     258      LENGTH + " = " + (float) curveLength + "\n"; 
     259  } 
     260 
     261  /** True iff this overlay has an endpoint coordinate pair. */ 
     262  public boolean hasEndpoint() { return true; } 
     263 
     264  /** True iff this overlay has a second endpoint coordinate pair. */ 
     265  public boolean hasEndpoint2() { return true; } 
     266 
     267  /** True iff this overlay supports the filled parameter. */ 
     268  public boolean canBeFilled() { return true; } 
     269 
     270  /** True iff this overlay can be resized using X1, X2, Y1, Y2 entry boxes */ 
     271  public boolean areBoundsEditable() { return false; } 
     272  // currently, only non-noded objects can be resized this way. 
     273  // (Actually could perform scaling on all nodes) 
     274 
     275  // -- OverlayNodedObject API methods -- 
     276 
     277  /** True iff there is a highlighted node. */ 
     278  public boolean isHighlightNode() { return highlightNode; } 
     279 
     280  /** Returns index of highlighted node. */ 
     281  public int getHighlightedNodeIndex() { return highlightIndex; } 
     282 
    240283  /** Gets the nearest node to the given point. */ 
    241284  protected double[] getNearestNode(float x, float y) { 
     
    258301    return new double[]{minDist, (double) minIndex}; 
    259302  } 
    260  
    261   /** Returns a specific statistic of this object */ 
    262   public String getStat(String name) { 
    263     if (name.equals(BOUNDS)) { 
    264       return "(" + x1 + ", " + y1 + "), (" + x2 + ", " + y2 + ")"; 
    265     } 
    266     else if (name.equals(NODES)) { 
    267       return "" + numNodes; 
    268     } 
    269     else if (name.equals(LENGTH)) { 
    270       return "" + (float) curveLength; 
    271     } 
    272     else return "No such statistic for this overlay type"; 
    273   } 
    274  
    275   /** Retrieves useful statistics about this overlay. */ 
    276   public String getStatistics() { 
    277     return BOUNDS + " = (" + x1 + ", " + y1 + "), (" + x2 + ", " + y2 + ")\n" + 
    278       NODES +" = " + numNodes + "\n" + 
    279       LENGTH + " = " + (float) curveLength + "\n"; 
    280   } 
    281  
    282   /** True iff this overlay has an endpoint coordinate pair. */ 
    283   public boolean hasEndpoint() { return true; } 
    284  
    285   /** True iff this overlay has a second endpoint coordinate pair. */ 
    286   public boolean hasEndpoint2() { return true; } 
    287  
    288   /** True iff there is a highlighted node. */ 
    289   public boolean isHighlightNode() { return highlightNode; } 
    290  
    291   /** Returns index of highlighted node. */ 
    292   public int getHighlightedNodeIndex() { return highlightIndex; } 
    293  
    294   /** True iff this overlay supports the filled parameter. */ 
    295   public boolean canBeFilled() { return true; } 
    296  
    297   /** True iff this overlay can be resized using X1, X2, Y1, Y2 entry boxes */ 
    298   public boolean areBoundsEditable() { return false; } 
    299   // currently, only non-noded objects can be resized this way. 
    300   // (Actually could perform scaling on all nodes) 
    301  
    302   // -- Object API methods -- 
    303  
    304303  /** Computes the shortest distance from this object's bounding box to the 
    305304   * given point. */ 
     
    664663  } 
    665664 
     665  /**  
     666   * Creates a new freeform by connecting the tail of this freeform to the 
     667   * head of the freeform supplied. 
     668   * @param f2 The freeform to connect to this freeform 
     669   */ 
     670  public OverlayFreeform connectTo(OverlayFreeform f2) { 
     671    float[][] f1Nodes = this.getNodes(); 
     672    float[][] f2Nodes = f2.getNodes(); 
     673    int len1 = f1Nodes[0].length;  
     674    int len2 = f2Nodes[0].length; 
     675 
     676    // Obtain coordinates of last node of f1 and first of f2. 
     677    float[] f1End = {f1Nodes[0][len1-1], f1Nodes[1][len1-1]}; 
     678    float[] f2Beg = {f2Nodes[0][0], f2Nodes[1][0]}; 
     679    // If the last node in f1 and the first node in f2 are the same, 
     680    // this method won't copy the last node of f1 into the node array used to 
     681    // construct f3. 
     682    int offset;  
     683    if (MathUtil.areSame(f1End, f2Beg)) offset = 1;  
     684    else offset = 0; 
     685 
     686    float[][] newNodes = new float[2][len1 + len2 - offset]; 
     687    for (int i=0; i<2; i++) { 
     688      System.arraycopy(f1Nodes[i], 0, newNodes[i], 0, len1-offset);  
     689      System.arraycopy(f2Nodes[i], 0, newNodes[i], len1-offset, len2); 
     690    } 
     691 
     692    OverlayFreeform f3 = new OverlayFreeform (overlay, newNodes); 
     693    return f3; 
     694  } 
     695 
     696  /** Reverses the node array (and therefore its internal orientation) */ 
     697  public void reverseNodes() { 
     698    truncateNodeArray(); 
     699    // Q: Is the above call ever necessary? 
     700    // truncateNodeArray() is called at mouseUp in FreeformTool. 
     701    // Will there ever be an extension 
     702    // of the node array s.t. maxNodes > numNodes during an interior edit before 
     703    // an extension 
     704    // A: Yes, if extend mode is entered directly from edit mode 
     705    synchronized (nodesSync) { 
     706      float[][] temp = new float[2][maxNodes]; 
     707      for (int j = 0; j < 2; j++) { 
     708        for (int i = 0; i < maxNodes; i++) { 
     709          temp[j][maxNodes-i-1] = nodes[j][i]; 
     710        } 
     711      } 
     712      nodes = temp; 
     713    } 
     714  } 
     715 
     716  /** Deletes buffer nodes from the tail of the node array */ 
     717  public void truncateNodeArray() { 
     718     resizeNodeArray(numNodes); 
     719  } 
     720 
     721  /** Resizes the node array, truncating if necessary. */ 
     722  // TODO is it possible to use System.arraycopy here? 
     723  protected void resizeNodeArray(int newLength) { 
     724    synchronized (nodesSync) { 
     725      int loopMax = Math.min(nodes[0].length, newLength); 
     726      float[][] a2 = new float[2][newLength]; 
     727      for (int j=0; j<2; j++) { //manually copy nodes to a2 
     728        for (int i=0; i<loopMax; i++) { 
     729          a2[j][i] = nodes[j][i]; 
     730        } 
     731        // case where newLength > a.length: 
     732        // fills rest of new array with nodes co-locational with last node 
     733        for (int i=loopMax; i < a2[0].length; i++) { 
     734          a2[j][i] = nodes[j][loopMax-1]; 
     735        } 
     736      } 
     737      nodes = a2; 
     738      maxNodes = newLength; 
     739    } 
     740  } 
     741 
     742  // -- Helper methods -- 
     743   
    666744  // NOTE: Right now this method returns Freeforms only, though it could be used 
    667745  // on Polylines too.  
     
    736814  } 
    737815 
    738   /**  
    739    * Creates a new freeform by connecting the tail of this freeform to the 
    740    * head of the freeform supplied. 
    741    * @param f2 The freeform to connect to this freeform 
    742    */ 
    743   public OverlayFreeform connectTo(OverlayFreeform f2) { 
    744     float[][] f1Nodes = this.getNodes(); 
    745     float[][] f2Nodes = f2.getNodes(); 
    746     int len1 = f1Nodes[0].length;  
    747     int len2 = f2Nodes[0].length; 
    748  
    749     // Obtain coordinates of last node of f1 and first of f2. 
    750     float[] f1End = {f1Nodes[0][len1-1], f1Nodes[1][len1-1]}; 
    751     float[] f2Beg = {f2Nodes[0][0], f2Nodes[1][0]}; 
    752     // If the last node in f1 and the first node in f2 are the same, 
    753     // this method won't copy the last node of f1 into the node array used to 
    754     // construct f3. 
    755     int offset;  
    756     if (MathUtil.areSame(f1End, f2Beg)) offset = 1;  
    757     else offset = 0; 
    758  
    759     float[][] newNodes = new float[2][len1 + len2 - offset]; 
    760     for (int i=0; i<2; i++) { 
    761       System.arraycopy(f1Nodes[i], 0, newNodes[i], 0, len1-offset);  
    762       System.arraycopy(f2Nodes[i], 0, newNodes[i], len1-offset, len2); 
    763     } 
    764  
    765     OverlayFreeform f3 = new OverlayFreeform (overlay, newNodes); 
    766     return f3; 
    767   } 
    768  
    769   /** Reverses the node array (and therefore its internal orientation) */ 
    770   public void reverseNodes() { 
    771     truncateNodeArray(); 
    772     // Q: Is the above call ever necessary? 
    773     // truncateNodeArray() is called at mouseUp in FreeformTool. 
    774     // Will there ever be an extension 
    775     // of the node array s.t. maxNodes > numNodes during an interior edit before 
    776     // an extension 
    777     // A: Yes, if extend mode is entered directly from edit mode 
    778     synchronized (nodesSync) { 
    779       float[][] temp = new float[2][maxNodes]; 
    780       for (int j = 0; j < 2; j++) { 
    781         for (int i = 0; i < maxNodes; i++) { 
    782           temp[j][maxNodes-i-1] = nodes[j][i]; 
    783         } 
    784       } 
    785       nodes = temp; 
    786     } 
    787   } 
    788  
    789   /** Deletes buffer nodes from the tail of the node array */ 
    790   public void truncateNodeArray() { 
    791      resizeNodeArray(numNodes); 
    792   } 
    793  
    794   /** Resizes the node array, truncating if necessary. */ 
    795   // TODO is it possible to use System.arraycopy here? 
    796   protected void resizeNodeArray(int newLength) { 
    797     synchronized (nodesSync) { 
    798       int loopMax = Math.min(nodes[0].length, newLength); 
    799       float[][] a2 = new float[2][newLength]; 
    800       for (int j=0; j<2; j++) { //manually copy nodes to a2 
    801         for (int i=0; i<loopMax; i++) { 
    802           a2[j][i] = nodes[j][i]; 
    803         } 
    804         // case where newLength > a.length: 
    805         // fills rest of new array with nodes co-locational with last node 
    806         for (int i=loopMax; i < a2[0].length; i++) { 
    807           a2[j][i] = nodes[j][loopMax-1]; 
    808         } 
    809       } 
    810       nodes = a2; 
    811       maxNodes = newLength; 
    812     } 
    813   } 
    814  
    815816  // -- Helper Methods for Debugging --  
    816817 
  • trunk/loci/visbio/overlays/OverlayText.java

    r2823 r2910  
    8181  // -- OverlayObject API methods -- 
    8282 
     83  /** Returns whether this object is drawable, i.e., is of nonzero 
     84   *  size, area, length, etc. 
     85   */ 
     86  public boolean hasData() { return true; } 
     87 
    8388  /** Gets VisAD data object representing this overlay. */ 
    8489  public DataImpl getData() { 
     
    105110    return field; 
    106111  } 
    107  
    108   /** Returns whether this object is drawable, i.e., is of nonzero 
    109    *  size, area, length, etc. 
    110    */ 
    111   public boolean hasData() { return true; } 
    112112 
    113113  /** Computes the shortest distance from this object to the given point. */ 
Note: See TracChangeset for help on using the changeset viewer.