Changeset 373 for trunk/loci/visbio/view


Ignore:
Timestamp:
05/05/05 16:49:48 (15 years ago)
Author:
curtis
Message:

Some work on restoring state of displays.

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

Legend:

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

    r364 r373  
    424424    int numPositions = pos.size(); 
    425425    Element child = XMLUtil.createChild(el, "Capture"); 
    426     child.setAttribute("positions", "" + numPositions); 
    427426    for (int i=0; i<numPositions; i++) { 
    428427      DisplayPosition position = (DisplayPosition) pos.elementAt(i); 
     
    438437  /** Restores the current state from the given DOM element ("Display"). */ 
    439438  public void restoreState(Element el) throws SaveException { 
    440     /* CTR TODO for v3.00 final 
    441     int numPositions = Integer.parseInt(window.getAttr("positions")); 
    442     Vector vn = new Vector(numPositions); 
    443     for (int i=0; i<numPositions; i++) { 
     439    Element child = XMLUtil.getFirstChild(el, "Capture"); 
     440 
     441    // restore display positions 
     442    Element[] els = XMLUtil.getChildren(child, "DisplayPosition"); 
     443    Vector vn = new Vector(els.length); 
     444    for (int i=0; i<els.length; i++) { 
    444445      DisplayPosition position = new DisplayPosition(); 
    445       position.restoreState(window, "position" + i); 
     446      position.restoreState(els[i]); 
    446447      vn.add(position); 
    447448    } 
     
    449450    if (vo != null) StateManager.mergeStates(vo, vn); 
    450451 
    451     movieSpeed = Integer.parseInt(window.getAttr("movieSpeed")); 
    452     movieFPS = Integer.parseInt(window.getAttr("movieFPS")); 
    453     movieSmooth = window.getAttr("movieSmooth").equalsIgnoreCase("true"); 
    454     */ 
     452    // restore other parameters 
     453    movieSpeed = Integer.parseInt(child.getAttribute("movieSpeed")); 
     454    movieFPS = Integer.parseInt(child.getAttribute("movieFPS")); 
     455    movieSmooth = child.getAttribute("movieSmooth").equalsIgnoreCase("true"); 
    455456  } 
    456457 
  • trunk/loci/visbio/view/ColorHandler.java

    r364 r373  
    353353  public void saveState(Element el) throws SaveException { 
    354354    Element child = XMLUtil.createChild(el, "Colors"); 
     355 
     356    // save attributes 
    355357    child.setAttribute("brightness", "" + brightness); 
    356358    child.setAttribute("contrast", "" + contrast); 
     
    366368    child.setAttribute("max", ObjectUtil.arrayToString(getHi())); 
    367369    child.setAttribute("fixed", ObjectUtil.arrayToString(getFixed())); 
     370 
     371    // save color tables 
    368372    float[][][] tables = getTables(); 
    369373    if (tables != null) { 
     
    382386  } 
    383387 
    384   /** Restores the current state from the given DOM element ("Display"). */ 
     388  /** 
     389   * Restores the current state from the given DOM element ("TransformLink"). 
     390   */ 
    385391  public void restoreState(Element el) throws SaveException { 
    386     /* CTR TODO for v3.00 final 
    387     DisplayWindow window = getWindow(); 
    388     brightness = Integer.parseInt(window.getAttr(attrName + "_brightness")); 
    389     contrast = Integer.parseInt(window.getAttr(attrName + "_contrast")); 
    390     opacityValue = Integer.parseInt( 
    391       window.getAttr(attrName + "_opacityValue")); 
    392     opacityModel = Integer.parseInt( 
    393       window.getAttr(attrName + "_opacityModel")); 
    394     colorModel = Integer.parseInt(window.getAttr(attrName + "_colorModel")); 
    395  
    396     String r = window.getAttr(attrName + "_red"); 
    397     String g = window.getAttr(attrName + "_green"); 
    398     String b = window.getAttr(attrName + "_blue"); 
     392    Element child = XMLUtil.getFirstChild(el, "Colors"); 
     393 
     394    // restore attributes 
     395    brightness = Integer.parseInt(child.getAttribute("brightness")); 
     396    contrast = Integer.parseInt(child.getAttribute("contrast")); 
     397    opacityValue = Integer.parseInt(child.getAttribute("opacityValue")); 
     398    String om = child.getAttribute("opacityModel"); 
     399    if ("constant".equals(om)) opacityModel = ColorUtil.CONSTANT_ALPHA; 
     400    else if ("curved".equals(om)) opacityModel = ColorUtil.CURVED_ALPHA; 
     401    else { 
     402      System.err.println("Warning: invalid opacity model (" + om + ")"); 
     403      opacityModel = -1; 
     404    } 
     405    String cm = child.getAttribute("colorModel"); 
     406    if ("rgb".equals(cm)) colorModel = ColorUtil.RGB_MODEL; 
     407    else if ("hsv".equals(cm)) colorModel = ColorUtil.HSV_MODEL; 
     408    else if ("composite".equals(cm)) colorModel = ColorUtil.COMPOSITE_MODEL; 
     409    else { 
     410      System.err.println("Warning: invalid color model (" + cm + ")"); 
     411      colorModel = -1; 
     412    } 
     413    String r = child.getAttribute("red"); 
    399414    red = r.equals("null") ? null : RealType.getRealType(r); 
     415    String g = child.getAttribute("green"); 
    400416    green = g.equals("null") ? null : RealType.getRealType(g); 
     417    String b = child.getAttribute("blue"); 
    401418    blue = b.equals("null") ? null : RealType.getRealType(b); 
    402  
    403     String min = window.getAttr(attrName + "_colorMin"); 
    404     String max = window.getAttr(attrName + "_colorMax"); 
    405     String fix = window.getAttr(attrName + "_colorFixed"); 
    406     lo = ObjectUtil.stringToDoubleArray(min); 
    407     hi = ObjectUtil.stringToDoubleArray(max); 
    408     fixed = ObjectUtil.stringToBooleanArray(fix); 
    409  
     419    lo = ObjectUtil.stringToDoubleArray(child.getAttribute("min")); 
     420    hi = ObjectUtil.stringToDoubleArray(child.getAttribute("max")); 
     421    fixed = ObjectUtil.stringToBooleanArray(child.getAttribute("fixed")); 
     422 
     423    // restore attributes 
    410424    colorTables = null; 
    411     String s = window.getAttr(attrName + "_tables"); 
    412     if (!s.equals("null")) { 
    413       int ilen = Integer.parseInt(s); 
    414       colorTables = new float[ilen][][]; 
    415       for (int i=0; i<ilen; i++) { 
    416         s = window.getAttr(attrName + "_table" + i); 
    417         if (s.equals("null")) colorTables[i] = null; 
    418         else { 
    419           int jlen = Integer.parseInt(s); 
    420           colorTables[i] = new float[jlen][]; 
    421           for (int j=0; j<jlen; j++) { 
    422             colorTables[i][j] = ObjectUtil.stringToFloatArray( 
    423               window.getAttr(attrName + "_table" + i + "-" + j)); 
     425    Element[] tels = XMLUtil.getChildren(child, "ColorTable"); 
     426    if (tels != null) { 
     427      colorTables = new float[tels.length][][]; 
     428      for (int i=0; i<tels.length; i++) { 
     429        Element[] cels = XMLUtil.getChildren(tels[i], "ColorChannel"); 
     430        if (cels != null) { 
     431          colorTables[i] = new float[cels.length][]; 
     432          for (int j=0; j<cels.length; j++) { 
     433            colorTables[i][j] = 
     434              ObjectUtil.stringToFloatArray(XMLUtil.getText(cels[j])); 
    424435          } 
    425436        } 
    426437      } 
    427438    } 
    428     */ 
    429439  } 
    430440 
  • trunk/loci/visbio/view/DisplayManager.java

    r364 r373  
    2525 
    2626import java.awt.Component; 
     27import java.util.Vector; 
    2728import javax.swing.JOptionPane; 
    2829import loci.visbio.*; 
     
    148149  /** Restores the current state from the given DOM element ("VisBio"). */ 
    149150  public void restoreState(Element el) throws SaveException { 
    150     /* CTR TODO for v3.00 final 
    151     CAElement custom = ome.getCustomAttr(); 
    152  
    153     // read number of displays 
    154     String[] dCount = custom.getAttributes(DISPLAY_MANAGER, "count"); 
    155     int count = -1; 
    156     if (dCount != null && dCount.length > 0) { 
    157       try { count = Integer.parseInt(dCount[0]); } 
    158       catch (NumberFormatException exc) { } 
    159     } 
    160     if (count < 0) { 
    161       System.err.println("Failed to restore display count."); 
    162       count = 0; 
    163     } 
    164  
     151    Element child = XMLUtil.getFirstChild(el, "Displays"); 
     152    Element[] els = XMLUtil.getChildren(child, "Display"); 
     153 
     154    // create new display list 
    165155    Vector vn = new Vector(); 
    166     for (int i=0; i<count; i++) { 
     156    for (int i=0; i<els.length; i++) { 
    167157      // construct display 
    168158      DisplayWindow window = new DisplayWindow(this); 
    169159 
    170160      // restore display state 
    171       window.restoreState(ome, i); 
     161      window.restoreState(els[i]); 
    172162      vn.add(window); 
    173163    } 
     
    192182      if (!vn.contains(display)) removeDisplay(display); 
    193183    } 
    194     */ 
    195184  } 
    196185 
  • trunk/loci/visbio/view/DisplayWindow.java

    r364 r373  
    384384  } 
    385385 
    386   /** Restores the current state from the given DOM element ("Displays"). */ 
     386  /** Restores the current state from the given DOM element ("Display"). */ 
    387387  public void restoreState(Element el) throws SaveException { 
    388     /* CTR TODO for v3.00 final 
    389     custom = ome.getCustomAttr(); 
    390     String[] idList = custom.getAttributes(DISPLAY_DIALOG, "id"); 
    391  
    392     // identify transform index 
    393     index = -1; 
    394     for (int i=0; i<idList.length; i++) { 
    395       try { 
    396         int iid = Integer.parseInt(idList[i]); 
    397         if (id == iid) { 
    398           index = i; 
    399           break; 
    400         } 
    401       } 
    402       catch (NumberFormatException exc) { } 
    403     } 
    404     if (index < 0) { 
    405       System.err.println("Attributes for display #" + id + " not found."); 
    406       return; 
    407     } 
    408  
    409     name = getAttr("name"); 
    410     threeD = getAttr("threeD").equalsIgnoreCase("true"); 
     388    name = el.getAttribute("name"); 
     389    threeD = el.getAttribute("threeD").equalsIgnoreCase("true"); 
    411390 
    412391    createHandlers(); 
    413     viewHandler.restoreState(); 
    414     captureHandler.restoreState(); 
    415     transformHandler.restoreState(); 
    416     */ 
     392    viewHandler.restoreState(el); 
     393    captureHandler.restoreState(el); 
     394    transformHandler.restoreState(el); 
    417395  } 
    418396 
  • trunk/loci/visbio/view/StackHandler.java

    r185 r373  
    2828import loci.visbio.data.DataTransform; 
    2929import loci.visbio.data.ImageTransform; 
     30import loci.visbio.state.SaveException; 
     31import loci.visbio.util.XMLUtil; 
     32import org.w3c.dom.Element; 
    3033import visad.*; 
    3134 
     
    5962  protected Vector positions; 
    6063 
    61   /** 
    62    * Whether each transform is currently displaying thumbnails 
    63    * vs full-resolution data. 
    64    */ 
    65   protected Vector thumbnails; 
    66  
    6764  /** Resolution of stack images. */ 
    6865  protected int stackRes; 
     
    7572    super(dw); 
    7673    positions = new Vector(); 
    77     thumbnails = new Vector(); 
    7874    stackRes = DEFAULT_STACK_RESOLUTION; 
    7975  } 
     
    128124  } 
    129125 
     126 
     127  // -- Saveable API methods -- 
     128 
     129  /** Writes the current state to the given DOM element ("Display"). */ 
     130  public void saveState(Element el) throws SaveException { 
     131    super.saveState(el); 
     132    Element child = XMLUtil.getFirstChild(el, "LinkedData"); 
     133 
     134    // save other parameters 
     135    child.setAttribute("stackRes", "" + stackRes); 
     136  } 
     137 
     138  /** Restores the current state from the given DOM element ("Display"). */ 
     139  public void restoreState(Element el) throws SaveException { 
     140    Element child = XMLUtil.getFirstChild(el, "LinkedData"); 
     141 
     142    // restore links 
     143    Element[] els = XMLUtil.getChildren(child, null); 
     144    newLinks = new Vector(); 
     145    for (int i=0; i<els.length; i++) { 
     146      String linkType = els[i].getTagName(); 
     147      TransformLink link = null; 
     148      if (linkType.equals("TransformLink")) link = new TransformLink(this); 
     149      else if (linkType.equals("StackLink")) link = new StackLink(this); 
     150      if (link == null) { 
     151        System.err.println("Warning: cannot restore linked data of " + 
     152          "unknown type (" + linkType + ")"); 
     153        continue; 
     154      } 
     155      link.restoreState(els[i]); 
     156      newLinks.add(link); 
     157    } 
     158 
     159    // restore other parameters 
     160    animating = child.getAttribute("animating").equalsIgnoreCase("true"); 
     161    fps = Integer.parseInt(child.getAttribute("FPS")); 
     162    animAxis = Integer.parseInt(child.getAttribute("animationAxis")); 
     163    stackRes = Integer.parseInt(child.getAttribute("stackRes")); 
     164  } 
     165 
    130166} 
  • trunk/loci/visbio/view/StackLink.java

    r365 r373  
    3333import visad.*; 
    3434 
     35/** 
     36 * Represents a link between a data transform and a display 
     37 * that produces an image stack. 
     38 */ 
    3539public class StackLink extends TransformLink { 
    3640 
     
    6569 
    6670 
     71  // -- Fields - initial state -- 
     72 
     73  /** Data transform's current slice. */ 
     74  protected int currentSlice; 
     75 
     76  /** Flags indicating visibility of each slice of the stack. */ 
     77  protected boolean[] visSlices; 
     78 
     79 
    6780  // -- Constructor -- 
     81 
     82  /** Constructs an uninitialized stack link. */ 
     83  public StackLink(StackHandler h) { super(h); } 
    6884 
    6985  /** 
     
    142158   */ 
    143159  public int getCurrentSlice() { 
     160    if (handler == null) return currentSlice; 
    144161    int[] pos = handler.getPos(trans); 
    145162    return stackAxis >= 0 && stackAxis < pos.length ? pos[stackAxis] : -1; 
     
    154171  /** Gets visibility at the specified slice index. */ 
    155172  public boolean isSliceVisible(int slice) { 
     173    if (renderers == null) { 
     174      return visSlices != null && slice >= 0 && slice < visSlices.length ? 
     175        visSlices[slice] : false; 
     176    } 
    156177    if (slice < 0 || slice >= renderers.size()) return false; 
    157178    return ((DataRenderer) renderers.elementAt(slice)).getEnabled(); 
     
    263284  public void saveState(Element el) throws SaveException { 
    264285    super.saveState(el); 
    265     Element child = XMLUtil.getFirstChild(el, "TransformLink"); 
    266     child.setAttribute("axis", "" + getStackAxis()); 
     286 
     287    // find appropriate TransformLink 
     288    Element child = null; 
     289    Element[] els = XMLUtil.getChildren(el, "TransformLink"); 
     290    String id = "" + trans.getTransformId(); 
     291    for (int i=0; i<els.length; i++) { 
     292      if (id.equals(els[i].getAttribute("id"))) { 
     293        child = els[i]; 
     294        break; 
     295      } 
     296    } 
     297 
     298    // save stack parameters 
     299    child.setAttribute("axis", "" + stackAxis); 
    267300    child.setAttribute("slice", "" + getCurrentSlice()); 
    268301    int sliceCount = getSliceCount(); 
     
    270303    for (int i=0; i<sliceCount; i++) sb.append(isSliceVisible(i) ? "y" : "n"); 
    271304    child.setAttribute("visibleSlices", sb.toString()); 
    272     child.setAttribute("boxVisible", "" + isBoundingBoxVisible()); 
    273305    child.setAttribute("isVolume", "" + isVolumeRendered()); 
    274306    child.setAttribute("volumeResolution", "" + getVolumeResolution()); 
    275307  } 
    276308 
    277   /** 
    278    * Restores the current state from the given DOM element ("TransformLink"). 
    279    */ 
     309  /** Restores the current state from the given DOM element ("StackLink"). */ 
    280310  public void restoreState(Element el) throws SaveException { 
    281     // CTR TODO for v3.00 final 
     311    super.restoreState(el); 
     312 
     313    // restore stack parameters 
     314    stackAxis = Integer.parseInt(el.getAttribute("axis")); 
     315    currentSlice = Integer.parseInt(el.getAttribute("slice")); 
     316    String s = el.getAttribute("visibleSlices"); 
     317    visSlices = new boolean[s.length()]; 
     318    for (int i=0; i<visSlices.length; i++) visSlices[i] = s.charAt(i) == 'y'; 
     319    volume = el.getAttribute("isVolume").equalsIgnoreCase("true"); 
     320    volumeRes = Integer.parseInt(el.getAttribute("volumeResolution")); 
    282321  } 
    283322 
  • trunk/loci/visbio/view/TransformHandler.java

    r365 r373  
    556556    Element child = XMLUtil.createChild(el, "LinkedData"); 
    557557 
    558     // save all links 
     558    // save links 
    559559    int len = links.size(); 
    560560    for (int i=0; i<len; i++) { 
     
    571571  /** Restores the current state from the given DOM element ("Display"). */ 
    572572  public void restoreState(Element el) throws SaveException { 
    573     /* CTR TODO for v3.00 final 
    574     int len = Integer.parseInt(window.getAttr("numLinks")); 
     573    Element child = XMLUtil.getFirstChild(el, "LinkedData"); 
     574 
     575    // restore links 
     576    Element[] els = XMLUtil.getChildren(child, "TransformLink"); 
    575577    newLinks = new Vector(); 
    576     for (int i=0; i<len; i++) { 
     578    for (int i=0; i<els.length; i++) { 
    577579      TransformLink link = new TransformLink(this); 
    578       link.restoreState(window, "link" + i); 
     580      link.restoreState(els[i]); 
    579581      newLinks.add(link); 
    580582    } 
    581     animating = window.getAttr("animating").equalsIgnoreCase("true"); 
    582     fps = Integer.parseInt(window.getAttr("animFPS")); 
    583     animAxis = Integer.parseInt(window.getAttr("animAxis")); 
    584     */ 
     583 
     584    // restore other parameters 
     585    animating = child.getAttribute("animating").equalsIgnoreCase("true"); 
     586    fps = Integer.parseInt(child.getAttribute("FPS")); 
     587    animAxis = Integer.parseInt(child.getAttribute("animationAxis")); 
    585588  } 
    586589 
  • trunk/loci/visbio/view/TransformLink.java

    r365 r373  
    2727import java.rmi.RemoteException; 
    2828import java.util.Vector; 
     29import loci.visbio.VisBioFrame; 
    2930import loci.visbio.data.*; 
    3031import loci.visbio.state.*; 
     
    3435import visad.util.Util; 
    3536 
    36 /** Represents a link between a data transform and a display. */ 
     37/** 
     38 * Represents a link between a data transform and a display 
     39 * that produces a single image. 
     40 */ 
    3741public class TransformLink 
    3842  implements DisplayListener, Dynamic, Runnable, TransformListener 
     
    313317   */ 
    314318  public void restoreState(Element el) throws SaveException { 
    315     /* CTR TODO for v3.00 final 
    316319    VisBioFrame bio = handler.getWindow().getVisBio(); 
    317320    DataManager dm = (DataManager) bio.getManager(DataManager.class); 
    318     Vector dataList = dm.getDataList(); 
    319     int dataIndex = Integer.parseInt(window.getAttr(attrName + "_dataIndex")); 
    320     trans = (DataTransform) dataList.elementAt(dataIndex); 
    321     if (colorHandler != null) colorHandler.restoreState(attrName); 
    322     visible = window.getAttr(attrName + "_visible").equalsIgnoreCase("true"); 
    323     */ 
     321    trans = dm.getDataById(Integer.parseInt(el.getAttribute("id"))); 
     322    if (colorHandler != null) colorHandler.restoreState(el); 
     323    visible = el.getAttribute("visible").equalsIgnoreCase("true"); 
    324324  } 
    325325 
  • trunk/loci/visbio/view/ViewHandler.java

    r364 r373  
    351351  /** Restores the current state from the given DOM element ("Display"). */ 
    352352  public void restoreState(Element el) throws SaveException { 
    353     /* CTR TODO for v3.00 final 
    354     matrix = ObjectUtil.stringToDoubleArray(window.getAttr("matrix")); 
    355     xasp = ObjectUtil.stringToDouble(window.getAttr("aspectX")); 
    356     yasp = ObjectUtil.stringToDouble(window.getAttr("aspectY")); 
    357     zasp = ObjectUtil.stringToDouble(window.getAttr("aspectZ")); 
    358     showScale = window.getAttr("showScale").equalsIgnoreCase("true"); 
    359     boundingBox = window.getAttr("boundingBox").equalsIgnoreCase("true"); 
    360     parallel = window.getAttr("parallel").equalsIgnoreCase("true"); 
    361     */ 
    362   } 
     353    Element child = XMLUtil.getFirstChild(el, "Appearance"); 
     354    matrix = ObjectUtil.stringToDoubleArray(child.getAttribute("matrix")); 
     355    xasp = ObjectUtil.stringToDouble(child.getAttribute("aspectX")); 
     356    yasp = ObjectUtil.stringToDouble(child.getAttribute("aspectY")); 
     357    zasp = ObjectUtil.stringToDouble(child.getAttribute("aspectZ")); 
     358    showScale = child.getAttribute("showScale").equalsIgnoreCase("true"); 
     359    boundingBox = child.getAttribute("boundingBox").equalsIgnoreCase("true"); 
     360    parallel = child.getAttribute("parallel").equalsIgnoreCase("true"); 
     361  } 
     362 
     363 
    363364  // -- Helper methods -- 
    364365 
Note: See TracChangeset for help on using the changeset viewer.