From 03b4b7c1b8be6a6fb4410e87192870a3ef0c3faf Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 28 Aug 2008 11:12:25 +0000 Subject: [PATCH] bugfix for applet examples with 1gaq where new classloader jmol connection is used --- src/jalview/appletgui/AppletJmol.java | 66 +++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index 1533530..aa81764 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -75,7 +75,10 @@ public class AppletJmol extends EmbmenuFrame PDBEntry pdbentry; boolean colourBySequence = true; Vector atomsPicked = new Vector(); - + /** + * datasource protocol for access to PDBEntry + */ + String protocol=null; public AppletJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains, @@ -86,14 +89,32 @@ public class AppletJmol extends EmbmenuFrame this.sequence = seq; this.chains = chains; this.pdbentry = pdbentry; - - String alreadyMapped = StructureSelectionManager + this.protocol = protocol; + if (pdbentry.getId()==null || pdbentry.getId().length()<1) + { + if (jalview.bin.JalviewLite.debug) + { + System.err.println("Setting PDB id for file "+pdbentry.getFile()); + if (protocol.equals(AppletFormatAdapter.PASTE)) + { + pdbentry.setId("PASTED PDB"+(chains==null ? "_" : chains.toString())); + } else { + pdbentry.setId(pdbentry.getFile()); + } + } + } + if (jalview.bin.JalviewLite.debug) + { + System.err.println("AppletJmol: PDB ID is '"+pdbentry.getId()+"'"); + } + + String alreadyMapped = StructureSelectionManager .getStructureSelectionManager() .alreadyMappedToFile(pdbentry.getId()); - + MCview.PDBfile reader = null; if (alreadyMapped != null) { - StructureSelectionManager.getStructureSelectionManager() + reader = StructureSelectionManager.getStructureSelectionManager() .setMapping(seq, chains, pdbentry.getFile(), protocol); //PROMPT USER HERE TO ADD TO NEW OR EXISTING VIEW? //FOR NOW, LETS JUST OPEN A NEW WINDOW @@ -175,12 +196,35 @@ public class AppletJmol extends EmbmenuFrame // probably CLASSLOADER based datasource.. // Try and get a reader on the datasource, and pass that to Jmol try { - FileParse fparser = new jalview.io.FileParse(protocol, pdbentry.getFile()); - if (!fparser.isValid()) - { - throw new Exception("Invalid datasource. "+fparser.getWarningMessage()); + java.io.Reader freader = null; + if (reader!=null) { + if (jalview.bin.JalviewLite.debug) + { + System.err.println("AppletJmol:Trying to reuse existing PDBfile IO parser."); + } + // re-use the one we opened earlier + freader = reader.getReader(); + } + if (freader==null) { + if (jalview.bin.JalviewLite.debug) + { + System.err.println("AppletJmol:Creating new PDBfile IO parser."); + } + FileParse fp = new FileParse(pdbentry.getFile(), protocol); + fp.mark(); + // reader = new MCview.PDBfile(fp); + // could set ID, etc. + //if (!reader.isValid()) + //{ + // throw new Exception("Invalid datasource. "+reader.getWarningMessage()); + //} + //fp.reset(); + freader = fp.getReader(); + } + if (freader==null) { + throw new Exception("Invalid datasource. Could not obtain Reader."); } - viewer.openReader(pdbentry.getFile(), pdbentry.getId(), fparser.getReader()); + viewer.openReader(pdbentry.getFile(), pdbentry.getId(), freader); } catch (Exception e) { // give up! @@ -659,7 +703,7 @@ public class AppletJmol extends EmbmenuFrame { pdb = ssm.setMapping(sequence,chains, pdbentry.getFile(), - AppletFormatAdapter.URL); + protocol); } pdbentry.setId(pdb.id); -- 1.7.10.2