+ if (comp == null)
+ {
+ // create a new Jmol window.
+ // First parse the Jmol state to translate filenames loaded into the
+ // view, and record the order in which files are shown in the Jmol
+ // view, so we can add the sequence mappings in same order.
+ StringBuffer newFileLoc = null;
+ int cp = 0, ncp, ecp;
+ while ((ncp = state.indexOf("load ", cp)) > -1)
+ {
+ if (newFileLoc == null)
+ {
+ newFileLoc = new StringBuffer();
+ }
+ do {
+ // look for next filename in load statement
+ newFileLoc.append(state.substring(cp,
+ ncp = (state.indexOf("\"", ncp + 1) + 1)));
+ String oldfilenam = state.substring(ncp,
+ ecp = state.indexOf("\"", ncp));
+ // recover the new mapping data for this old filename
+ // have to normalize filename - since Jmol and jalview do filename
+ // translation differently.
+ Object[] filedat = oldFiles.get(new File(oldfilenam));
+ newFileLoc.append(Platform.escapeString((String) filedat[0]));
+ pdbfilenames.addElement((String) filedat[0]);
+ pdbids.addElement((String) filedat[1]);
+ seqmaps.addElement((SequenceI[]) ((Vector<SequenceI>) filedat[2])
+ .toArray(new SequenceI[0]));
+ newFileLoc.append("\"");
+ cp = ecp + 1; // advance beyond last \" and set cursor so we can
+ // look for next file statement.
+ } while ((ncp=state.indexOf("/*file*/",cp))>-1);
+ }
+ if (cp > 0)
+ {
+ // just append rest of state
+ newFileLoc.append(state.substring(cp));
+ }
+ else
+ {
+ System.err
+ .print("Ignoring incomplete Jmol state for PDB ids: ");
+ newFileLoc = new StringBuffer(state);
+ newFileLoc.append("; load append ");
+ for (File id : oldFiles.keySet())
+ {
+ // add this and any other pdb files that should be present in
+ // the viewer
+ Object[] filedat = oldFiles.get(id);
+ String nfilename;
+ newFileLoc.append(((String) filedat[0]));
+ pdbfilenames.addElement((String) filedat[0]);
+ pdbids.addElement((String) filedat[1]);
+ seqmaps.addElement((SequenceI[]) ((Vector<SequenceI>) filedat[2])
+ .toArray(new SequenceI[0]));
+ newFileLoc.append(" \"");
+ newFileLoc.append((String) filedat[0]);
+ newFileLoc.append("\"");