From: gmungoc Date: Wed, 10 Jun 2015 14:23:33 +0000 (+0100) Subject: Merge remote-tracking branch X-Git-Tag: Release_2_10_0~612 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=7a3ba197b00d4016556f3cdd635919fe6817867b;p=jalview.git Merge remote-tracking branch 'origin/schema/JAL-1764_structureViewAttribute' into develop JAL-1764 save structure viewer type in project file --- 7a3ba197b00d4016556f3cdd635919fe6817867b diff --cc src/jalview/datamodel/StructureViewerModel.java index c23e320,098372b..8bc745a --- a/src/jalview/datamodel/StructureViewerModel.java +++ b/src/jalview/datamodel/StructureViewerModel.java @@@ -27,8 -27,6 +27,11 @@@ public class StructureViewerMode private String stateData = ""; + private String viewId; + ++ // CHIMERA or JMOL (for projects from Jalview 2.9 on) ++ private String type; ++ private Map fileData = new HashMap(); public class StructureData @@@ -86,7 -85,7 +89,7 @@@ public StructureViewerModel(int x, int y, int width, int height, boolean alignWithPanel, boolean colourWithAlignPanel, - boolean colourByViewer, String viewId) - boolean colourByViewer) ++ boolean colourByViewer, String viewId, String type) { this.x = x; this.y = y; @@@ -95,7 -94,6 +98,8 @@@ this.alignWithPanel = alignWithPanel; this.colourWithAlignPanel = colourWithAlignPanel; this.colourByViewer = colourByViewer; + this.viewId = viewId; ++ this.type = type; } public int getX() @@@ -188,8 -186,4 +192,13 @@@ this.fileData = fileData; } + public String getViewId() + { + return this.viewId; + } ++ ++ public String getType() ++ { ++ return this.type; ++ } } diff --cc src/jalview/gui/Jalview2XML.java index ce81e1c,f56e531..80cff07 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@@ -773,24 -753,6 +773,24 @@@ public class Jalview2XM 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()); + } + } } } @@@ -1455,9 -1364,18 +1455,7 @@@ 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); } } @@@ -3309,9 -3184,8 +3307,10 @@@ } 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 @@@ -3420,72 -3285,63 +3419,70 @@@ } /* - * 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 viewerData, AlignFrame af) + protected void createChimeraViewer(Entry viewerData, + AlignFrame af, + jarInputStreamProvider jprovider) { - final StructureViewerModel data = viewerData.getValue(); - String chimeraSession = data.getStateData(); - - if (new File(chimeraSession).exists()) - { - Set> fileData = data.getFileData() - .entrySet(); - List pdbs = new ArrayList(); - List allseqs = new ArrayList(); - for (Entry 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 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> fileData = data.getFileData() + .entrySet(); + List pdbs = new ArrayList(); + List allseqs = new ArrayList(); + for (Entry 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 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); } /** @@@ -3503,19 -3358,6 +3500,19 @@@ { 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 pdbfilenames = new ArrayList(); List seqmaps = new ArrayList(); List pdbids = new ArrayList(); @@@ -3645,6 -3489,6 +3642,18 @@@ } /** ++ * 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. diff --cc src/jalview/jbgui/GStructureViewer.java index c76fb23,c76fb23..7885f74 --- a/src/jalview/jbgui/GStructureViewer.java +++ b/src/jalview/jbgui/GStructureViewer.java @@@ -348,6 -348,6 +348,7 @@@ public abstract class GStructureViewer colourButtons.add(strandColour); colourButtons.add(turnColour); colourButtons.add(buriedColour); ++ colourButtons.add(purinePyrimidineColour); colourButtons.add(userColour); colourButtons.add(viewerColour);