Changeset 48


Ignore:
Timestamp:
09/27/04 17:23:12 (15 years ago)
Author:
curtis
Message:

Some work on capture handler state logic.

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

Legend:

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

    r24 r48  
    4646 
    4747import loci.visbio.state.OptionManager; 
     48import loci.visbio.state.StateManager; 
    4849 
    4950import visad.*; 
     
    152153 
    153154  /** Creates a movie of the given transformation sequence. */ 
    154   public void captureMovie(Vector positions, double secPerTrans, 
     155  public void captureMovie(Vector matrices, double secPerTrans, 
    155156    int framesPerSec, boolean sine, boolean movie) 
    156157  { 
    157     final int size = positions.size(); 
     158    final int size = matrices.size(); 
    158159    if (size < 1) { 
    159160      JOptionPane.showMessageDialog(window, "Must have at least two display " + 
     
    208209    final int dotIndex = dot; 
    209210    final boolean isTiff = tiff, isJpeg = jpeg, isRaw = raw; 
    210     final Vector pos = positions; 
     211    final Vector pos = matrices; 
    211212    final int frm = framesPerTrans; 
    212213    final boolean doSine = sine; 
     
    303304  /** Writes the current state. */ 
    304305  public void saveState() { 
    305     // CTR START HERE - panel.getCaptureWindow(), extract settings from there 
    306     // CTR TODO CaptureHandler saveState 
    307     /* 
    308     window.setAttr("brightness", "" + brightness); 
    309     window.setAttr("contrast", "" + contrast); 
    310     window.setAttr("colorModel", "" + model); 
    311     window.setAttr("red", red == null ? "null" : red.getName()); 
    312     window.setAttr("green", green == null ? "null" : green.getName()); 
    313     window.setAttr("blue", blue == null ? "null" : blue.getName()); 
    314     window.setAttr("colorMin", ObjectUtil.arrayToString(getLo())); 
    315     window.setAttr("colorMax", ObjectUtil.arrayToString(getHi())); 
    316     window.setAttr("colorFixed", ObjectUtil.arrayToString(getFixed())); 
    317  
    318     float[][][] tables = getTables(); 
    319     if (tables == null) { 
    320       window.setAttr("tables", "null"); 
    321     } 
    322     else { 
    323       window.setAttr("tables", "" + tables.length); 
    324       for (int i=0; i<tables.length; i++) { 
    325         if (tables[i] == null) window.setAttr("table" + i, "null"); 
    326         else { 
    327           window.setAttr("table" + i, "" + tables[i].length); 
    328           for (int j=0; j<tables[i].length; j++) { 
    329             if (tables[i][j] == null) { 
    330               window.setAttr("table" + i + "-" + j, "null"); 
    331             } 
    332             else { 
    333               window.setAttr("table" + i + "-" + j, 
    334                 ObjectUtil.arrayToString(tables[i][j])); 
    335             } 
    336           } 
    337         } 
    338       } 
    339     } 
    340     */ 
     306    CaptureWindow captureWindow = panel.getCaptureWindow(); 
     307    Vector positions = captureWindow.getPositions(); 
     308    int speed = captureWindow.getSpeed(); 
     309    int fps = captureWindow.getFPS(); 
     310    boolean smooth = captureWindow.isSmooth(); 
     311 
     312    // save display positions 
     313    int numPositions = positions.size(); 
     314    window.setAttr("positions", "" + numPositions); 
     315    for (int i=0; i<numPositions; i++) { 
     316      DisplayPosition position = (DisplayPosition) positions.elementAt(i); 
     317      position.saveState(window, "position" + i); 
     318    } 
     319 
     320    // save other parameters 
     321    window.setAttr("movieSpeed", "" + speed); 
     322    window.setAttr("movieFPS", "" + fps); 
     323    window.setAttr("movieSmooth", "" + smooth); 
    341324  } 
    342325 
    343326  /** Restores the current state. */ 
    344327  public void restoreState() { 
    345     // CTR TODO CaptureHandler restoreState 
     328    // read in new display position list 
     329    int numPositions = Integer.parseInt(window.getAttr("positions")); 
     330    Vector vn = new Vector(); 
     331    for (int i=0; i<numPositions; i++) { 
     332      DisplayPosition position = new DisplayPosition(); 
     333      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); 
    346352  } 
    347353 
    348354  /** Tests whether two objects are in equivalent states. */ 
    349355  public boolean matches(CaptureHandler handler) { 
     356    // CTR START HERE implement matches and initState, 
     357    // then test this new capture state logic. 
    350358    // CTR TODO CaptureHandler matches 
    351359    return false; 
  • trunk/loci/visbio/view/CaptureWindow.java

    r30 r48  
    245245  public void setProgressMessage(String msg) { progress.setString(msg); } 
    246246 
     247  /** Sets positions on the list. */ 
     248  public void setPositions(Vector v) { 
     249    posListModel.removeAllElements(); 
     250    int size = v.size(); 
     251    for (int i=0; i<size; i++) posListModel.addElement(v.elementAt(i)); 
     252  } 
     253 
     254  /** Sets movie speed. */ 
     255  public void setSpeed(int speed) { 
     256    if (speed != getSpeed()) this.speed.setValue(speed); 
     257  } 
     258 
     259  /** Sets movie frames per second. */ 
     260  public void setFPS(int fps) { 
     261    if (fps != getFPS()) { 
     262      SpinnerNumberModel fpsModel = (SpinnerNumberModel) this.fps.getModel(); 
     263      fpsModel.setValue(new Integer(fps)); 
     264    } 
     265  } 
     266 
     267  /** Sets whether transitions use a smoothing sine function. */ 
     268  public void setSmooth(boolean smooth) { 
     269    if (smooth != isSmooth()) this.smooth.setSelected(smooth); 
     270  } 
     271 
     272  /** Gets positions on the list. */ 
     273  public Vector getPositions() { 
     274    int size = posListModel.size(); 
     275    Vector v = new Vector(size); 
     276    for (int i=0; i<size; i++) v.add(posListModel.elementAt(i)); 
     277    return v; 
     278  } 
     279 
     280  /** Gets movie speed. */ 
     281  public int getSpeed() { return speed.getValue(); } 
     282 
     283  /** Gets movie frames per second. */ 
     284  public int getFPS() { return ((Integer) fps.getValue()).intValue(); } 
     285 
     286  /** Gets whether transitions use a smoothing sine function. */ 
     287  public boolean isSmooth() { return smooth.isSelected(); } 
     288 
    247289 
    248290  // -- ActionListener API methods -- 
     
    324366    else if (cmd.equals("AviMovie") || cmd.equals("ImageSequence")) { 
    325367      int size = posListModel.size(); 
    326       Vector positions = new Vector(size); 
     368      Vector matrices = new Vector(size); 
    327369      for (int i=0; i<size; i++) { 
    328370        DisplayPosition pos = (DisplayPosition) posListModel.elementAt(i); 
    329         positions.add(pos.getMatrix()); 
     371        matrices.add(pos.getMatrix()); 
    330372      } 
    331373      double secPerTrans = Math.pow(2, 2 - speed.getValue() / 4.0); 
    332       int framesPerSec = ((Integer) fps.getValue()).intValue(); 
     374      int framesPerSec = getFPS(); 
    333375      boolean sine = smooth.isSelected(); 
    334376      boolean movie = cmd.equals("AviMovie"); 
    335       handler.captureMovie(positions, secPerTrans, framesPerSec, sine, movie); 
     377      handler.captureMovie(matrices, secPerTrans, framesPerSec, sine, movie); 
    336378    } 
    337379  } 
  • trunk/loci/visbio/view/DisplayPosition.java

    r2 r48  
    2424package loci.visbio.view; 
    2525 
    26 import loci.ome.xml.OMEElement; 
    27  
    2826import loci.visbio.state.Dynamic; 
    29 import loci.visbio.state.SaveException; 
    30 import loci.visbio.state.Saveable; 
    3127 
    3228import loci.visbio.util.ObjectUtil; 
    3329 
    3430/** DisplayPosition represents an orientation of VisAD display. */ 
    35 public class DisplayPosition implements Dynamic, Saveable { 
     31public class DisplayPosition implements Dynamic { 
    3632 
    3733  // -- Fields -- 
     
    5349    this.name = name; 
    5450    this.matrix = matrix; 
     51  } 
     52 
     53 
     54  // -- DisplayPosition API methods - state logic -- 
     55 
     56  /** Writes the current state to the given OME-CA XML object. */ 
     57  public void saveState(DisplayWindow window, String attrName) { 
     58    window.setAttr(attrName + "_name", name); 
     59    window.setAttr(attrName + "_matrix", ObjectUtil.arrayToString(matrix)); 
     60  } 
     61 
     62  /** Restores the current state from the given OME-CA XML object. */ 
     63  public void restoreState(DisplayWindow window, String attrName) { 
     64    name = window.getAttr(attrName + "_name"); 
     65    matrix = ObjectUtil.stringToDoubleArray( 
     66      window.getAttr(attrName + "_matrix")); 
    5567  } 
    5668 
     
    93105 
    94106 
    95   // -- Saveable API methods -- 
    96  
    97   /** Writes the current state to the given OME-CA XML object. */ 
    98   public void saveState(OMEElement ome) throws SaveException { 
    99     /* 
    100     fout.println(name); 
    101     ObjectUtil.writeArray(matrix, fout); 
    102     */ 
    103   } 
    104  
    105   /** Restores the current state from the given OME-CA XML object. */ 
    106   public void restoreState(OMEElement ome) throws SaveException { 
    107     /* 
    108     try { 
    109       name = fin.readLine(); 
    110       matrix = ObjectUtil.readArray(matrix, fin); 
    111     } 
    112     catch (IOException exc) { throw new SaveException(exc); } 
    113     */ 
    114   } 
    115  
    116  
    117107  // -- New API methods -- 
    118108 
Note: See TracChangeset for help on using the changeset viewer.