Changeset 51


Ignore:
Timestamp:
10/07/04 16:03:39 (15 years ago)
Author:
curtis
Message:

More work on state save/restore. Save/restore of 2D displays works.

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

Legend:

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

    r49 r51  
    7474 
    7575 
    76   // -- Fields - state -- 
     76  // -- Fields - initial state -- 
    7777 
    7878  /** List of positions. */ 
     
    9292 
    9393  /** Creates a display capture handler. */ 
    94   public CaptureHandler(DisplayWindow dw) { window = dw; } 
     94  public CaptureHandler(DisplayWindow dw) { 
     95    window = dw; 
     96    positions = new Vector(); 
     97  } 
    9598 
    9699 
     
    362365  public void restoreState() { 
    363366    int numPositions = Integer.parseInt(window.getAttr("positions")); 
    364     positions = new Vector(numPositions); 
     367    Vector vn = new Vector(numPositions); 
    365368    for (int i=0; i<numPositions; i++) { 
    366369      DisplayPosition position = new DisplayPosition(); 
    367370      position.restoreState(window, "position" + i); 
    368       positions.add(position); 
    369     } 
     371      vn.add(position); 
     372    } 
     373    Vector vo = getPositions(); 
     374    if (vo != null) StateManager.mergeStates(vo, vn); 
     375 
    370376    movieSpeed = Integer.parseInt(window.getAttr("movieSpeed")); 
    371377    movieFPS = Integer.parseInt(window.getAttr("movieFPS")); 
  • trunk/loci/visbio/view/DisplayManager.java

    r46 r51  
    216216  protected void doGUI() { 
    217217    // control panel 
    218     bio.setStatus("Initializing display logic"); 
     218    bio.setSplashStatus("Initializing display logic"); 
    219219    displayControls = new DisplayControls(this); 
    220220    PanelManager pm = (PanelManager) bio.getManager(PanelManager.class); 
     
    222222 
    223223    // options 
    224     bio.setStatus(null); 
     224    bio.setSplashStatus(null); 
    225225    OptionManager om = (OptionManager) bio.getManager(OptionManager.class); 
    226226    om.addBooleanOption("Warnings", WARN_IMAGEJ, 'i', 
     
    230230 
    231231    // help topics 
    232     bio.setStatus(null); 
     232    bio.setSplashStatus(null); 
    233233    HelpManager hm = (HelpManager) bio.getManager(HelpManager.class); 
    234234    hm.addHelpTopic("Displays", "displays.html"); 
  • trunk/loci/visbio/view/DisplayWindow.java

    r37 r51  
    136136   */ 
    137137  public void repack() { 
     138    if (sliders == null) return; // not yet fully initialized 
    138139    sliders.removeAll(); 
    139140    sliders.add(transformHandler.getSliderPanel()); 
     
    348349    } 
    349350    else { 
    350       // Handlers' initState methods are smart enough to reinitialize 
    351       // their components only when necessary, to ensure efficiency. 
     351      // handlers' initState methods are smart enough to reinitialize 
     352      // their components only when necessary, to ensure efficiency 
    352353      viewHandler.initState(window.viewHandler); 
    353354      colorHandler.initState(window.colorHandler); 
  • trunk/loci/visbio/view/StackHandler.java

    r40 r51  
    4848 
    4949  public static final RealType ZBOX = RealType.getRealType("zbox"); 
    50  
    5150 
    5251 
  • trunk/loci/visbio/view/TransformHandler.java

    r40 r51  
    4444import loci.visbio.data.DataTransform; 
    4545 
     46import loci.visbio.state.StateManager; 
     47 
    4648import loci.visbio.util.VisUtil; 
    4749 
     
    8587  protected int animAxis; 
    8688 
     89  /** Thread responsible for animation. */ 
     90  protected Thread animThread; 
     91 
    8792  /** Synchronization object for animation. */ 
    8893  protected Object animSync = new Object(); 
     
    9095  /** Earliest time full-resolution burn-in is allowed. */ 
    9196  protected long burnTime; 
     97 
     98 
     99  // -- Fields - initial state -- 
     100 
     101  /** List of uninitialized links. */ 
     102  protected Vector newLinks; 
    92103 
    93104 
     
    179190    animating = on; 
    180191    if (!animating) return; 
    181  
    182     // start a new thread for animation 
    183     Thread animThread = new Thread(this); 
    184     animThread.start(); 
     192    startAnimation(); 
    185193  } 
    186194 
     
    237245  /** Writes the current state. */ 
    238246  public void saveState() { 
    239     // CTR TODO TransformHandler saveState 
     247    // save number of links 
     248    int len = links.size(); 
     249    window.setAttr("numLinks", "" + len); 
     250 
     251    // save all links 
     252    for (int i=0; i<len; i++) { 
     253      TransformLink link = (TransformLink) links.elementAt(i); 
     254      link.saveState(window, "link" + i); 
     255    } 
     256 
     257    // save other parameters 
     258    window.setAttr("animating", "" + animating); 
     259    window.setAttr("animFPS", "" + fps); 
     260    window.setAttr("animAxis", "" + animAxis); 
    240261  } 
    241262 
    242263  /** Restores the current state. */ 
    243264  public void restoreState() { 
    244     // CTR TODO TransformHandler restoreState 
     265    int len = Integer.parseInt(window.getAttr("numLinks")); 
     266    newLinks = new Vector(); 
     267    for (int i=0; i<len; i++) { 
     268      TransformLink link = new TransformLink(this); 
     269      link.restoreState(window, "link" + i); 
     270      newLinks.add(link); 
     271    } 
     272    animating = window.getAttr("animating").equalsIgnoreCase("true"); 
     273    fps = Integer.parseInt(window.getAttr("animFPS")); 
     274    animAxis = Integer.parseInt(window.getAttr("animAxis")); 
    245275  } 
    246276 
    247277  /** Tests whether two objects are in equivalent states. */ 
    248278  public boolean matches(TransformHandler handler) { 
    249     // CTR TODO TransformHandler matches 
    250     return false; 
     279    if (handler == null) return false; 
     280    int size = links.size(); 
     281    if (handler.links == null || handler.links.size() != size) return false; 
     282    for (int i=0; i<size; i++) { 
     283      TransformLink link = (TransformLink) links.elementAt(i); 
     284      TransformLink hlink = (TransformLink) handler.links.elementAt(i); 
     285      if (link == null && hlink == null) continue; 
     286      if (link == null || hlink == null || !link.matches(hlink)) return false; 
     287    } 
     288    return animating == handler.animating && 
     289      fps == handler.fps && animAxis == handler.animAxis; 
    251290  } 
    252291 
     
    257296   */  
    258297  public void initState(TransformHandler handler) { 
    259     // CTR TODO TransformHandler initState 
     298    if (handler == null) { 
     299      if (newLinks != null) { 
     300        // initialize new links 
     301        StateManager.mergeStates(links, newLinks); 
     302        links = newLinks; 
     303        newLinks = null; 
     304      } 
     305    } 
     306    else { 
     307      // merge handler links with current links 
     308      Vector vn = handler.newLinks == null ? handler.links : handler.newLinks; 
     309      StateManager.mergeStates(links, vn); 
     310      links = vn; 
     311      animating = handler.animating; 
     312      fps = handler.fps; 
     313      animAxis = handler.animAxis; 
     314    } 
     315 
     316    panel.removeAllTransforms(); 
     317    int size = links.size(); 
     318    for (int i=0; i<size; i++) { 
     319      TransformLink link = (TransformLink) links.elementAt(i); 
     320      panel.addTransform(link.getTransform()); 
     321    } 
     322 
     323    rebuild(); 
     324    if (animating) startAnimation(); 
    260325  } 
    261326 
     
    357422  } 
    358423 
     424  /** Starts a new thread for animation. */ 
     425  protected void startAnimation() { 
     426    if (animThread != null) { 
     427      try { animThread.join(); } 
     428      catch (InterruptedException exc) { } 
     429    } 
     430    animThread = new Thread(this); 
     431    animThread.start(); 
     432  } 
    359433 
    360434  // -- ChangeListener API methods -- 
  • trunk/loci/visbio/view/TransformLink.java

    r40 r51  
    2828import java.util.Vector; 
    2929 
    30 import loci.visbio.data.DataTransform; 
    31 import loci.visbio.data.ImageTransform; 
    32 import loci.visbio.data.ThumbnailHandler; 
    33 import loci.visbio.data.TransformEvent; 
    34 import loci.visbio.data.TransformListener; 
     30import loci.visbio.VisBioFrame; 
     31 
     32import loci.visbio.data.*; 
     33 
     34import loci.visbio.state.Dynamic; 
    3535 
    3636import loci.visbio.util.VisUtil; 
     
    4242/** Represents a link between a data transform and a display. */ 
    4343public class TransformLink 
    44   implements DisplayListener, Runnable, TransformListener 
     44  implements DisplayListener, Dynamic, Runnable, TransformListener 
    4545{ 
    4646 
    4747  // -- Constants -- 
    4848 
     49  /** Milliseconds until full-resolution burn-in. */ 
    4950  protected static final int BURN_DELAY = 3000; 
    5051 
     
    6465  protected DataRenderer rend; 
    6566 
     67  /** Separate thread for managing full-resolution burn-in. */ 
     68  protected Thread burnThread; 
     69 
    6670  /** Next clock time a full-resolution burn-in should occur. */ 
    6771  protected long burnTime; 
     
    8387 
    8488 
     89  // -- Fields - initial state -- 
     90 
     91  /** Whether data transform is visible onscreen. */ 
     92  protected boolean visible; 
     93 
     94 
    8595  // -- Constructor -- 
     96 
     97  /** Constructs an uninitialized transform link. */ 
     98  public TransformLink(TransformHandler h) { handler = h; } 
    8699 
    87100  /** 
     
    92105    handler = h; 
    93106    trans = t; 
    94  
    95     // build data reference 
    96     try { 
    97       ref = new DataReferenceImpl(trans.getName()); 
    98       DisplayImpl display = handler.getWindow().getDisplay(); 
    99       rend = display.getDisplayRenderer().makeDefaultRenderer(); 
    100       display.addDisplayListener(this); 
    101     } 
    102     catch (VisADException exc) { exc.printStackTrace(); } 
    103  
    104     // listen for changes to this transform 
    105     t.addTransformListener(this); 
    106  
    107     // initialize thread for handling full-resolution burn-in operations 
    108     Thread burnThread = new Thread(this); 
    109     burnThread.start(); 
     107    visible = true; 
     108    initState(null); 
    110109  } 
    111110 
     
    124123  /** Links this transform into the display. */ 
    125124  public void link() { 
    126     try { 
    127       DisplayImpl display = handler.getWindow().getDisplay(); 
    128       display.addReferences(rend, ref); 
    129     } 
     125    try { handler.getWindow().getDisplay().addReferences(rend, ref); } 
    130126    catch (VisADException exc) { exc.printStackTrace(); } 
    131127    catch (RemoteException exc) { exc.printStackTrace(); } 
     
    139135 
    140136  /** Gets visibility of the transform. */ 
    141   public boolean isVisible() { return rend.getEnabled(); } 
     137  public boolean isVisible() { 
     138    return rend == null ? visible : rend.getEnabled(); 
     139  } 
    142140 
    143141  /** Sets status messages displayed in display's bottom left-hand corner. */ 
     
    146144      new VisADException(trans.getName() + ": " + msg); 
    147145    doMessages(false); 
     146  } 
     147 
     148 
     149  // -- TransformLink API methods - state logic -- 
     150 
     151  /** Writes the current state. */ 
     152  public void saveState(DisplayWindow window, String attrName) { 
     153    VisBioFrame bio = handler.getWindow().getVisBio(); 
     154    DataManager dm = (DataManager) bio.getManager(DataManager.class); 
     155    Vector dataList = dm.getDataList(); 
     156    int ndx = dataList.indexOf(trans); 
     157    window.setAttr(attrName + "_dataIndex", "" + ndx); 
     158    window.setAttr(attrName + "_visible", "" + isVisible()); 
     159  } 
     160 
     161  /** Restores the current state. */ 
     162  public void restoreState(DisplayWindow window, String attrName) { 
     163    VisBioFrame bio = handler.getWindow().getVisBio(); 
     164    DataManager dm = (DataManager) bio.getManager(DataManager.class); 
     165    Vector dataList = dm.getDataList(); 
     166    int dataIndex = Integer.parseInt(window.getAttr(attrName + "_dataIndex")); 
     167    trans = (DataTransform) dataList.elementAt(dataIndex); 
     168    visible = window.getAttr(attrName + "_visible").equalsIgnoreCase("true"); 
    148169  } 
    149170 
     
    166187    } 
    167188  } 
     189 
     190 
     191  // -- Dynamic API methods -- 
     192 
     193  /** Tests whether two dynamic objects are equivalent. */ 
     194  public boolean matches(Dynamic dyn) { 
     195    if (!isCompatible(dyn)) return false; 
     196    TransformLink link = (TransformLink) dyn; 
     197    return getTransform().matches(link.getTransform()) && 
     198      isVisible() == link.isVisible(); 
     199  } 
     200 
     201  /** 
     202   * Tests whether the given dynamic object can be used as an argument to 
     203   * initState, for initializing this dynamic object. 
     204   */ 
     205  public boolean isCompatible(Dynamic dyn) { 
     206    return dyn instanceof TransformLink; 
     207  } 
     208 
     209  /** 
     210   * Modifies this object's state to match that of the given object. 
     211   * If the argument is null, the object is initialized according to 
     212   * its current state instead. 
     213   */ 
     214  public void initState(Dynamic dyn) { 
     215    if (dyn != null && !isCompatible(dyn)) return; 
     216 
     217    if (burnThread != null) { 
     218      alive = false; 
     219      try { burnThread.join(); } 
     220      catch (InterruptedException exc) { } 
     221      alive = true; 
     222    } 
     223 
     224    TransformLink link = (TransformLink) dyn; 
     225    if (link != null) { 
     226      if (trans != null) trans.removeTransformListener(this); 
     227      trans = link.getTransform(); 
     228      visible = link.isVisible(); 
     229    } 
     230 
     231    // remove old data reference 
     232    DisplayImpl display = handler.getWindow().getDisplay(); 
     233    if (ref != null) { 
     234      try { display.removeReference(ref); } 
     235      catch (VisADException exc) { exc.printStackTrace(); } 
     236      catch (RemoteException exc) { exc.printStackTrace(); } 
     237    } 
     238 
     239    // build data reference 
     240    try { 
     241      ref = new DataReferenceImpl(trans.getName()); 
     242      rend = display.getDisplayRenderer().makeDefaultRenderer(); 
     243      rend.toggle(visible); 
     244      display.addDisplayListener(this); 
     245    } 
     246    catch (VisADException exc) { exc.printStackTrace(); } 
     247 
     248    // listen for changes to this transform 
     249    trans.addTransformListener(this); 
     250 
     251    // initialize thread for handling full-resolution burn-in operations 
     252    burnThread = new Thread(this); 
     253    burnThread.start(); 
     254  } 
     255 
     256  /** 
     257   * Called when this object is being discarded in favor of 
     258   * another object with a matching state. 
     259   */ 
     260  public void discard() { destroy(); } 
    168261 
    169262 
  • trunk/loci/visbio/view/ViewHandler.java

    r24 r51  
    7373  protected DisplayWindow window; 
    7474 
    75   /** 
    76    * Matrix representing current display projection 
    77    * (for uninitialized view handlers only). 
    78    */ 
    79   protected double[] matrix; 
    80  
    8175  /** Aspect ratio of the display. */ 
    8276  protected double xasp, yasp, zasp; 
     
    9084  /** Whether display is in parallel projection mode. */ 
    9185  protected boolean parallel; 
     86 
     87 
     88  // -- Fields - initial state -- 
     89 
     90  /** Matrix representing current display projection. */ 
     91  protected double[] matrix; 
    9292 
    9393 
Note: See TracChangeset for help on using the changeset viewer.