Changeset 49


Ignore:
Timestamp:
09/28/04 16:23:31 (15 years ago)
Author:
curtis
Message:

Finish off capture handler state logic.

Location:
trunk/loci/visbio/view
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/view/CaptureHandler.java

    r48 r49  
    5959public class CaptureHandler { 
    6060 
    61   // -- Fields -- 
     61  // -- Fields - GUI components -- 
    6262 
    6363  /** Associated display window. */ 
     
    7474 
    7575 
     76  // -- Fields - state -- 
     77 
     78  /** List of positions. */ 
     79  protected Vector positions; 
     80 
     81  /** Movie speed. */ 
     82  protected int movieSpeed; 
     83 
     84  /** Movie frames per second. */ 
     85  protected int movieFPS; 
     86 
     87  /** Whether transitions use a smoothing sine function. */ 
     88  protected boolean movieSmooth; 
     89 
     90 
    7691  // -- Constructor -- 
    7792 
     
    8196 
    8297  // -- CaptureHandler API methods -- 
     98 
     99  /** Gets positions on the list. */ 
     100  public Vector getPositions() { 
     101    return panel == null ? positions : panel.getCaptureWindow().getPositions(); 
     102  } 
     103 
     104  /** Gets movie speed. */ 
     105  public int getSpeed() { 
     106    return panel == null ? movieSpeed : panel.getCaptureWindow().getSpeed(); 
     107  } 
     108 
     109  /** Gets movie frames per second. */ 
     110  public int getFPS() { 
     111    return panel == null ? movieFPS : panel.getCaptureWindow().getFPS(); 
     112  } 
     113 
     114  /** Gets whether transitions use a smoothing sine function. */ 
     115  public boolean isSmooth() { 
     116    return panel == null ? movieSmooth : panel.getCaptureWindow().isSmooth(); 
     117  } 
    83118 
    84119  /** Gets associated display window. */ 
     
    305340  public void saveState() { 
    306341    CaptureWindow captureWindow = panel.getCaptureWindow(); 
    307     Vector positions = captureWindow.getPositions(); 
     342    Vector pos = captureWindow.getPositions(); 
    308343    int speed = captureWindow.getSpeed(); 
    309344    int fps = captureWindow.getFPS(); 
     
    311346 
    312347    // save display positions 
    313     int numPositions = positions.size(); 
     348    int numPositions = pos.size(); 
    314349    window.setAttr("positions", "" + numPositions); 
    315350    for (int i=0; i<numPositions; i++) { 
    316       DisplayPosition position = (DisplayPosition) positions.elementAt(i); 
     351      DisplayPosition position = (DisplayPosition) pos.elementAt(i); 
    317352      position.saveState(window, "position" + i); 
    318353    } 
     
    326361  /** Restores the current state. */ 
    327362  public void restoreState() { 
    328     // read in new display position list 
    329363    int numPositions = Integer.parseInt(window.getAttr("positions")); 
    330     Vector vn = new Vector(); 
     364    positions = new Vector(numPositions); 
    331365    for (int i=0; i<numPositions; i++) { 
    332366      DisplayPosition position = new DisplayPosition(); 
    333367      position.restoreState(window, "position" + i); 
    334       vn.add(position); 
    335     } 
    336  
    337     // merge old and new display position lists 
    338     CaptureWindow captureWindow = panel.getCaptureWindow(); 
    339     Vector vo = captureWindow.getPositions(); 
    340     StateManager.mergeStates(vo, vn); 
    341  
    342     // read in other parameters 
    343     int speed = Integer.parseInt(window.getAttr("movieSpeed")); 
    344     int fps = Integer.parseInt(window.getAttr("movieFPS")); 
    345     boolean smooth = window.getAttr("movieSmooth").equalsIgnoreCase("true"); 
    346  
    347     // restore capture state 
    348     captureWindow.setPositions(vn); 
    349     captureWindow.setSpeed(speed); 
    350     captureWindow.setFPS(fps); 
    351     captureWindow.setSmooth(smooth); 
     368      positions.add(position); 
     369    } 
     370    movieSpeed = Integer.parseInt(window.getAttr("movieSpeed")); 
     371    movieFPS = Integer.parseInt(window.getAttr("movieFPS")); 
     372    movieSmooth = window.getAttr("movieSmooth").equalsIgnoreCase("true"); 
    352373  } 
    353374 
    354375  /** Tests whether two objects are in equivalent states. */ 
    355376  public boolean matches(CaptureHandler handler) { 
    356     // CTR START HERE implement matches and initState, 
    357     // then test this new capture state logic. 
    358     // CTR TODO CaptureHandler matches 
    359     return false; 
     377    if (handler == null) return false; 
     378    Vector vo = getPositions(); 
     379    Vector vn = handler.getPositions(); 
     380    if (vo == null && vn != null) return false; 
     381    if (vo != null && !vo.equals(vn)) return false; 
     382    if (getSpeed() != handler.getSpeed() || 
     383      getFPS() != handler.getFPS() || isSmooth() != handler.isSmooth()) 
     384    { 
     385      return false; 
     386    } 
     387    return true; 
    360388  } 
    361389 
     
    366394   */  
    367395  public void initState(CaptureHandler handler) { 
    368     // CTR TODO CaptureHandler initState 
    369396    if (handler != null) { 
    370       //this.thing = that.thing... 
     397      // merge old and new position vectors 
     398      Vector vo = getPositions(); 
     399      Vector vn = handler.getPositions(); 
     400      StateManager.mergeStates(vo, vn); 
     401      positions = vn; 
     402 
     403      // set other parameters 
     404      movieSpeed = handler.getSpeed(); 
     405      movieFPS = handler.getFPS(); 
     406      movieSmooth = handler.isSmooth(); 
    371407    } 
    372408 
     
    388424        new String[] {"avi"}, "AVI movies")); 
    389425    } 
     426 
     427    // set capture window state to match 
     428    CaptureWindow captureWindow = panel.getCaptureWindow(); 
     429    captureWindow.setPositions(positions); 
     430    captureWindow.setSpeed(movieSpeed); 
     431    captureWindow.setFPS(movieFPS); 
     432    captureWindow.setSmooth(movieSmooth); 
    390433  } 
    391434 
  • trunk/loci/visbio/view/CaptureWindow.java

    r48 r49  
    248248  public void setPositions(Vector v) { 
    249249    posListModel.removeAllElements(); 
     250    if (v == null) return; 
    250251    int size = v.size(); 
    251252    for (int i=0; i<size; i++) posListModel.addElement(v.elementAt(i)); 
Note: See TracChangeset for help on using the changeset viewer.