From: jprocter Date: Wed, 8 Sep 2010 14:15:02 +0000 (+0000) Subject: JAL-634 and JAL-635 X-Git-Tag: Release_2_6~58 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=3357d18e685c4fd5f089df73f0290eb1b72ce0ee;p=jalview.git JAL-634 and JAL-635 --- diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index c361ab9..74a9c22 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -59,24 +59,60 @@ public class AppJmol extends GStructureViewer implements Runnable, private boolean addingStructures = false; + /** + * + * @param file + * @param id + * @param seq + * @param ap + * @param loadStatus + * @param bounds + * @deprecated defaults to AppJmol(String[] files, ... , viewid); + */ public AppJmol(String file, String id, SequenceI[] seq, AlignmentPanel ap, String loadStatus, Rectangle bounds) { this(file, id, seq, ap, loadStatus, bounds, null); } + /** + * @deprecated + */ public AppJmol(String file, String id, SequenceI[] seq, AlignmentPanel ap, String loadStatus, Rectangle bounds, String viewid) { - PDBEntry pdbentry = new PDBEntry(); - pdbentry.setFile(file); - pdbentry.setId(id); + this(new String[] + { file }, new String[] + { id }, new SequenceI[][] + { seq }, ap, loadStatus, bounds, viewid); + } + + /** + * + * @param files + * @param ids + * @param seqs + * @param ap + * @param loadStatus + * @param bounds + * @param viewid + */ + public AppJmol(String[] files, String[] ids, SequenceI[][] seqs, + AlignmentPanel ap, String loadStatus, Rectangle bounds, + String viewid) + { + PDBEntry[] pdbentrys = new PDBEntry[files.length]; + for (int i = 0; i < pdbentrys.length; i++) + { + PDBEntry pdbentry = new PDBEntry(); + pdbentry.setFile(files[i]); + pdbentry.setId(ids[i]); + pdbentrys[i] = pdbentry; + } // / TODO: check if protocol is needed to be set, and if chains are // autodiscovered. - jmb = new AppJmolBinding(this, new PDBEntry[] - { pdbentry }, new SequenceI[][] - { seq }, null, null); + jmb = new AppJmolBinding(this, pdbentrys, seqs, null, null); jmb.setLoadingFromArchive(true); this.ap = ap; @@ -98,9 +134,12 @@ public class AppJmol extends GStructureViewer implements Runnable, } + IProgressIndicator progressBar = null; + public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains, AlignmentPanel ap) { + progressBar = ap.alignFrame; // //////////////////////////////// // Is the pdb file already loaded? String alreadyMapped = StructureSelectionManager @@ -169,7 +208,7 @@ public class AppJmol extends GStructureViewer implements Runnable, JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { - topJmol.addStructure(pdbentry, seq, chains, true); + topJmol.addStructure(pdbentry, seq, chains, true, ap.alignFrame); return; } } @@ -215,11 +254,12 @@ public class AppJmol extends GStructureViewer implements Runnable, * @param pdbentry * @param seq * @param chains + * @param alignFrame * @param align * if true, new structure(s) will be align using associated alignment */ private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq, - final String[] chains, final boolean b) + final String[] chains, final boolean b, final IProgressIndicator alignFrame) { if (pdbentry.getFile() == null) { @@ -243,7 +283,7 @@ public class AppJmol extends GStructureViewer implements Runnable, } // and call ourselves again. - addStructure(pdbentry, seq, chains, b); + addStructure(pdbentry, seq, chains, b, alignFrame); } }).start(); return; @@ -256,6 +296,8 @@ public class AppJmol extends GStructureViewer implements Runnable, { chains }); addingStructures = true; _started = false; + alignAddedStructures = b; + progressBar = alignFrame; // visual indication happens on caller frame. (worker = new Thread(this)).start(); return; } @@ -392,6 +434,13 @@ public class AppJmol extends GStructureViewer implements Runnable, { // retrieve the pdb and store it locally AlignmentI pdbseq = null; + pdbid = jmb.pdbentry[pi].getId(); + long hdl=pdbid.hashCode()-System.currentTimeMillis(); + if (progressBar != null) + { + progressBar.setProgressBar("Fetching PDB " + pdbid, + hdl); + } try { pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi] @@ -404,6 +453,10 @@ public class AppJmol extends GStructureViewer implements Runnable, ex.printStackTrace(); errormsgs.append("'" + pdbid + "'"); } + if (progressBar != null) + { + progressBar.setProgressBar("Finished.", hdl); + } if (pdbseq != null) { // just transfer the file name from the first sequence's first @@ -472,51 +525,55 @@ public class AppJmol extends GStructureViewer implements Runnable, { Cache.log.error("Couldn't open Jmol viewer!", ex); } - } - else - { - StringBuffer cmd = new StringBuffer(); - cmd.append("load APPEND "); - cmd.append(files.toString()); - cmd.append("\n"); - final String command = cmd.toString(); - cmd = null; - try - { - jmb.evalStateCommand(command); - } catch (OutOfMemoryError oomerror) - { - new OOMWarning("When trying to add structures to the Jmol viewer!", - oomerror); - Cache.log.debug("File locations are " + files); - } catch (Exception ex) - { - Cache.log.error("Couldn't add files to Jmol viewer!", ex); } - if (alignAddedStructures) + else { - // may need to wait around until script has finished - while (jmb.viewer.isScriptExecuting()) + StringBuffer cmd = new StringBuffer(); + cmd.append("loadingJalviewdata=true\nload APPEND "); + cmd.append(files.toString()); + cmd.append("\nloadingJalviewdata=null"); + final String command = cmd.toString(); + cmd = null; + try { - try - { - Thread.sleep(20); - } catch (Exception e) - { - } - ; - } - javax.swing.SwingUtilities.invokeLater(new Runnable() + jmb.evalStateCommand(command); + } catch (OutOfMemoryError oomerror) { - public void run() + new OOMWarning( + "When trying to add structures to the Jmol viewer!", + oomerror); + Cache.log.debug("File locations are " + files); + } catch (Exception ex) + { + Cache.log.error("Couldn't add files to Jmol viewer!", ex); + } + long lastnotify=jmb.getLoadNotifiesHandled(); + // need to wait around until script has finished + while (lastnotify>=jmb.getLoadNotifiesHandled()); { - jmb.superposeStructures(ap.av.getAlignment(), -1, null); + try + { + Thread.sleep(35); + } catch (Exception e) + { + } } - }); - alignAddedStructures = false; + // refresh the sequence colours for the new structure(s) + jmb.updateColours(ap); + // do superposition if asked to + if (alignAddedStructures) + { + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + jmb.superposeStructures(ap.av.getAlignment(), -1, null); + } + }); + alignAddedStructures = false; + } + addingStructures = false; } - addingStructures = false; - } } _started = false; worker = null;