X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAppJmol.java;h=19178f23b7d62ed8fd977c3ed19de3e023851dd4;hb=399514cca430f9f64b14c446e275fee599ba5881;hp=c361ab976b6b8cdd25fab6bb419a98f755e9c28a;hpb=2a38a45cf356c9edaaef4ec74aa83b6f76609514;p=jalview.git diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index c361ab9..19178f2 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -1,5 +1,5 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle * * This file is part of Jalview. @@ -40,6 +40,7 @@ import org.jmol.api.*; import org.jmol.adapter.smarter.SmarterJmolAdapter; import org.jmol.popup.*; import org.jmol.viewer.JmolConstants; +import org.openscience.jmol.app.jmolpanel.AppConsole; public class AppJmol extends GStructureViewer implements Runnable, SequenceStructureBinding @@ -47,7 +48,7 @@ public class AppJmol extends GStructureViewer implements Runnable, { AppJmolBinding jmb; - ScriptWindow scriptWindow; + JPanel scriptWindow; JSplitPane splitPane; @@ -59,24 +60,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 +135,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 +209,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 +255,13 @@ 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 +285,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 +298,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; } @@ -290,7 +334,17 @@ public class AppJmol extends GStructureViewer implements Runnable, this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER); jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(), getBounds().width, getBounds().height); - jmb.allocateViewer(renderPanel, true, "", null, null, ""); + if (scriptWindow == null) + { + BorderLayout bl = new BorderLayout(); + bl.setHgap(0); + bl.setVgap(0); + scriptWindow = new JPanel(bl); + scriptWindow.setVisible(false); + } + ; + jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow, + null); jmb.newJmolPopup(true, "Jmol", true); jmb.evalStateCommand(command); jmb.setFinishedInit(true); @@ -363,6 +417,7 @@ public class AppJmol extends GStructureViewer implements Runnable, void closeViewer() { jmb.closeViewer(); + // TODO: check for memory leaks where instance isn't finalised because jmb // holds a reference to the window jmb = null; @@ -392,6 +447,12 @@ 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 +465,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 +537,56 @@ 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; + long lastnotify = jmb.getLoadNotifiesHandled(); + 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); + } + // need to wait around until script has finished + while (lastnotify >= jmb.getLoadNotifiesHandled()) + ; { try { - Thread.sleep(20); + Thread.sleep(35); } catch (Exception e) { } - ; } - javax.swing.SwingUtilities.invokeLater(new Runnable() + // refresh the sequence colours for the new structure(s) + jmb.updateColours(ap); + // do superposition if asked to + if (alignAddedStructures) { - public void run() + javax.swing.SwingUtilities.invokeLater(new Runnable() { - jmb.superposeStructures(ap.av.getAlignment(), -1, null); - } - }); - alignAddedStructures = false; + public void run() + { + jmb.superposeStructures(ap.av.getAlignment(), -1, null); + } + }); + alignAddedStructures = false; + } + addingStructures = false; } - addingStructures = false; - } } _started = false; worker = null; @@ -723,8 +793,6 @@ public class AppJmol extends GStructureViewer implements Runnable, public void showConsole(boolean showConsole) { - if (scriptWindow == null) - scriptWindow = new ScriptWindow(this); if (showConsole) { @@ -734,15 +802,19 @@ public class AppJmol extends GStructureViewer implements Runnable, splitPane.setTopComponent(renderPanel); splitPane.setBottomComponent(scriptWindow); this.getContentPane().add(splitPane, BorderLayout.CENTER); + splitPane.setDividerLocation(getHeight() - 200); + scriptWindow.setVisible(true); + scriptWindow.validate(); + splitPane.validate(); } - splitPane.setDividerLocation(getHeight() - 200); - splitPane.validate(); } else { if (splitPane != null) + { splitPane.setVisible(false); + } splitPane = null;