StructureViewerBase viewFrame = (StructureViewerBase) frames[f];
matchedFile = saveStructureState(ap, jds, pdb, entry,
viewIds, matchedFile, viewFrame);
+ /*
+ * Only store each structure viewer's state once in each XML
+ * document. First time through only (storeDS==false)
+ */
+ String viewId = viewFrame.getViewId();
+ if (!storeDS && !viewIds.contains(viewId))
+ {
+ viewIds.add(viewId);
+ try
+ {
- writeJarEntry(jout, "viewer_" + viewId,
++ writeJarEntry(jout, getViewerJarEntryName(viewId),
+ viewFrame.getStateInfo().getBytes());
+ } catch (IOException e)
+ {
+ System.err.println("Error saving viewer state: "
+ + e.getMessage());
+ }
+ }
}
}
state.setAlignwithAlignPanel(viewFrame.isUsedforaligment(ap));
state.setColourwithAlignPanel(viewFrame.isUsedforcolourby(ap));
state.setColourByJmol(viewFrame.isColouredByViewer());
- // FIXME add attribute to schema and enable next line
- // state.setType(viewFrame.getViewerType().toString());
- state.setContent(viewFrame.getViewerType().toString());
- /*
- * Only store each structure viewer's state once in each XML document.
- */
- if (!viewIds.contains(viewId))
- {
- viewIds.add(viewId);
- state.setContent(statestring.replaceAll("\n", ""));
- }
- else
- {
- state.setContent("# duplicate state");
- }
++ state.setType(viewFrame.getViewerType().toString());
pdb.addStructureState(state);
}
}
}
if (!structureViewers.containsKey(sviewid))
{
- structureViewers.put(sviewid, new StructureViewerModel(x, y,
- width, height, false, false, true));
+ structureViewers.put(sviewid,
+ new StructureViewerModel(x, y, width, height, false,
- false, true, structureState.getViewId()));
++ false, true, structureState.getViewId(),
++ structureState.getType()));
// Legacy pre-2.7 conversion JAL-823 :
// do not assume any view has to be linked for colour by
// sequence
}
/*
- * 2.8.2: stateData contains "chimera..." (session file name), or JMOL state
- * string
- *
- * 2.9: stateData.type contains JMOL or CHIMERA, data is in jar entry
- * Pending an XML element for ViewerType, just check if stateData contains
- * "chimera" (part of the chimera session filename).
++ * From 2.9: stateData.type contains JMOL or CHIMERA, data is in jar entry
+ * "viewer_"+stateData.viewId
*/
- // FIXME use stateData.getType() instead once schema updated
- if (ViewerType.CHIMERA.toString().equals(stateData.getStateData())
- || stateData.getStateData().indexOf("chimera") > -1)
- if (svattrib.getStateData().indexOf("chimera") > -1)
++ if (ViewerType.CHIMERA.toString().equals(stateData.getType()))
{
- createChimeraViewer(viewerData, af);
+ createChimeraViewer(viewerData, af, jprovider);
}
else
{
- createJmolViewer(viewerData, af);
++ /*
++ * else Jmol (if pre-2.9, stateData contains JMOL state string)
++ */
+ createJmolViewer(viewerData, af, jprovider);
}
}
/**
* Create a new Chimera viewer.
*
- * @param viewerData
+ * @param data
* @param af
+ * @param jprovider
*/
- protected void createChimeraViewer(
- Entry<String, StructureViewerModel> viewerData, AlignFrame af)
+ protected void createChimeraViewer(Entry<String, StructureViewerModel> viewerData,
+ AlignFrame af,
+ jarInputStreamProvider jprovider)
{
- final StructureViewerModel data = viewerData.getValue();
- String chimeraSession = data.getStateData();
-
- if (new File(chimeraSession).exists())
- {
- Set<Entry<File, StructureData>> fileData = data.getFileData()
- .entrySet();
- List<PDBEntry> pdbs = new ArrayList<PDBEntry>();
- List<SequenceI[]> allseqs = new ArrayList<SequenceI[]>();
- for (Entry<File, StructureData> pdb : fileData)
- {
- String filePath = pdb.getValue().getFilePath();
- String pdbId = pdb.getValue().getPdbId();
- // pdbs.add(new PDBEntry(filePath, pdbId));
- pdbs.add(new PDBEntry(pdbId, null, PDBEntry.Type.PDB, filePath));
- final List<SequenceI> seqList = pdb.getValue().getSeqList();
- SequenceI[] seqs = seqList.toArray(new SequenceI[seqList.size()]);
- allseqs.add(seqs);
- }
+ StructureViewerModel data = viewerData.getValue();
+ String chimeraSessionFile = data.getStateData();
- boolean colourByChimera = data.isColourByViewer();
- boolean colourBySequence = data.isColourWithAlignPanel();
-
- // TODO can/should this be done via StructureViewer (like Jmol)?
- final PDBEntry[] pdbArray = pdbs.toArray(new PDBEntry[pdbs.size()]);
- final SequenceI[][] seqsArray = allseqs.toArray(new SequenceI[allseqs
- .size()][]);
- new ChimeraViewFrame(chimeraSession, af.alignPanel, pdbArray,
- seqsArray, colourByChimera, colourBySequence);
- }
- else
- {
- Cache.log.error("Chimera session file " + chimeraSession
- + " not found");
- }
+ /*
+ * Copy Chimera session from jar entry "viewer_"+viewId to a temporary file
+ *
+ * Note this is the 'saved' viewId as in the project file XML, _not_ the
+ * 'uniquified' sviewid used to reconstruct the viewer here
+ */
+ chimeraSessionFile = copyJarEntry(jprovider,
- "viewer_" + data.getViewId(), "chimera");
++ getViewerJarEntryName(data.getViewId()), "chimera");
+
+ Set<Entry<File, StructureData>> fileData = data.getFileData()
+ .entrySet();
+ List<PDBEntry> pdbs = new ArrayList<PDBEntry>();
+ List<SequenceI[]> allseqs = new ArrayList<SequenceI[]>();
+ for (Entry<File, StructureData> pdb : fileData)
+ {
+ String filePath = pdb.getValue().getFilePath();
+ String pdbId = pdb.getValue().getPdbId();
+ // pdbs.add(new PDBEntry(filePath, pdbId));
+ pdbs.add(new PDBEntry(pdbId, null, PDBEntry.Type.PDB, filePath));
+ final List<SequenceI> seqList = pdb.getValue().getSeqList();
+ SequenceI[] seqs = seqList.toArray(new SequenceI[seqList.size()]);
+ allseqs.add(seqs);
+ }
+
+ boolean colourByChimera = data.isColourByViewer();
+ boolean colourBySequence = data.isColourWithAlignPanel();
+
+ // TODO use StructureViewer as a factory here, see JAL-1761
+ final PDBEntry[] pdbArray = pdbs.toArray(new PDBEntry[pdbs.size()]);
+ final SequenceI[][] seqsArray = allseqs.toArray(new SequenceI[allseqs
+ .size()][]);
+ String newViewId = viewerData.getKey();
+ new ChimeraViewFrame(chimeraSessionFile, af.alignPanel, pdbArray,
+ seqsArray, colourByChimera, colourBySequence, newViewId);
}
/**
{
final StructureViewerModel svattrib = viewerData.getValue();
String state = svattrib.getStateData();
+
+ /*
+ * Pre-2.9: state element value is the Jmol state string
+ *
+ * 2.9+: @type is "JMOL", state data is in a Jar file member named "viewer_"
+ * + viewId
+ */
- // FIXME use getType once Castor regenerated for new attribute
- if (ViewerType.JMOL.toString().equals(state /* svattrib.getType() */))
++ if (ViewerType.JMOL.toString().equals(svattrib.getType()))
+ {
- state = readJarEntry(jprovider, "viewer_" + svattrib.getViewId());
++ state = readJarEntry(jprovider,
++ getViewerJarEntryName(svattrib.getViewId()));
+ }
+
List<String> pdbfilenames = new ArrayList<String>();
List<SequenceI[]> seqmaps = new ArrayList<SequenceI[]>();
List<String> pdbids = new ArrayList<String>();
}
/**
++ * Generates a name for the entry in the project jar file to hold state
++ * information for a structure viewer
++ *
++ * @param viewId
++ * @return
++ */
++ protected String getViewerJarEntryName(String viewId)
++ {
++ return "viewer_" + viewId;
++ }
++
++ /**
* Returns any open frame that matches given structure viewer data. The match
* is based on the unique viewId, or (for older project versions) the frame's
* geometry.