2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.awt.Container;
25 import java.util.ArrayList;
26 import java.util.List;
29 import javax.swing.JComponent;
31 import org.jmol.api.JmolAppConsoleInterface;
32 import org.openscience.jmol.app.jmolpanel.console.AppConsole;
34 import jalview.api.AlignmentViewPanel;
35 import jalview.api.structures.JalviewStructureDisplayI;
36 import jalview.bin.Console;
37 import jalview.bin.Jalview;
38 import jalview.datamodel.PDBEntry;
39 import jalview.datamodel.SequenceI;
40 import jalview.ext.jmol.JalviewJmolBinding;
41 import jalview.io.DataSourceType;
42 import jalview.structure.StructureSelectionManager;
43 import jalview.util.MessageManager;
44 import jalview.util.Platform;
45 import javajs.util.BS;
47 public class AppJmolBinding extends JalviewJmolBinding
49 public AppJmolBinding(AppJmol appJmol, StructureSelectionManager sSm,
50 PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
51 DataSourceType protocol)
53 super(sSm, pdbentry, sequenceIs, protocol);
58 public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
60 return new SequenceRenderer(((AlignmentPanel) alignment).av);
64 public void sendConsoleEcho(String strEcho)
68 console.sendConsoleEcho(strEcho);
73 public void sendConsoleMessage(String strStatus)
75 if (console != null && strStatus != null)
76 // && !strStatus.equals("Script completed"))
77 // should we squash the script completed string ?
79 console.sendConsoleMessage(strStatus);
84 public void showUrl(String url, String target)
88 jalview.util.BrowserLauncher.openURL(url);
91 Console.error("Failed to launch Jmol-associated url " + url, e);
92 // TODO: 2.6 : warn user if browser was not configured.
97 public void refreshGUI()
99 if (getMappedStructureCount() == 0)
104 // appJmolWindow.repaint();
105 javax.swing.SwingUtilities.invokeLater(new Runnable()
110 JalviewStructureDisplayI theViewer = getViewer();
111 // invokes colourbySequence() via seqColour_ActionPerformed()
112 theViewer.updateTitleAndMenus();
113 ((JComponent) theViewer).revalidate();
119 public void notifyScriptTermination(String strStatus, int msWalltime)
121 // todo - script termination doesn't happen ?
122 // if (console != null)
123 // console.notifyScriptTermination(strStatus,
128 public void showUrl(String url)
130 showUrl(url, "jmol");
133 public void newJmolPopup(String menuName)
135 // jmolpopup = new JmolAwtPopup();
136 // jmolpopup.jpiInitialize((viewer), menuName);
140 public void selectionChanged(BS arg0)
145 public void showConsole(boolean b)
147 getViewer().showConsole(b);
151 protected JmolAppConsoleInterface createJmolConsole(
152 Container consolePanel, String buttonsToShow)
154 jmolViewer.setJmolCallbackListener(this);
155 // BH comment: can't do this yet [for JS only, or generally?]
156 return Platform.isJS() || Jalview.isHeadlessMode() ? null
157 : new AppConsole(jmolViewer, consolePanel, buttonsToShow);
161 protected void releaseUIResources()
168 public void releaseReferences(Object svl)
170 if (svl instanceof SeqPanel)
172 getViewer().removeAlignmentPanel(((SeqPanel) svl).ap);
177 public Map<String, Object> getJSpecViewProperty(String arg0)
179 // TODO Auto-generated method stub
183 @SuppressWarnings("unused")
184 public void cacheFiles(List<File> files)
192 Platform.cacheFileData(f);
197 * Retrieves and saves as file any modelled PDB entries for which we do not
198 * already have a file saved. Returns a list of absolute paths to structure
199 * files which were either retrieved, or already stored but not modelled in
200 * the structure viewer (i.e. files to add to the viewer display).
202 * Currently only used by Jmol - similar but different code used for Chimera/X
203 * and Pymol so still need to refactor
205 * @param structureViewer
206 * UI proxy for the structure viewer
207 * @return list of absolute paths to structures retrieved that need to be
208 * added to the display
210 public List<String> fetchPdbFiles(StructureViewerBase structureViewer)
212 // todo - record which pdbids were successfully imported.
213 StringBuilder errormsgs = new StringBuilder();
215 List<String> files = new ArrayList<>();
219 String[] filesInViewer = getStructureFiles();
220 // TODO: replace with reference fetching/transfer code (validate PDBentry
223 for (int pi = 0; pi < getPdbCount(); pi++)
225 PDBEntry strucEntry = getPdbEntry(pi);
227 String file = strucEntry.getFile();
230 pdbid = strucEntry.getId();
233 file = structureViewer.fetchPdbFile(strucEntry);
234 } catch (OutOfMemoryError oomerror)
236 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
237 } catch (Exception ex)
239 ex.printStackTrace();
240 errormsgs.append("'").append(pdbid).append("'");
249 errormsgs.append("'").append(pdbid).append("' ");
254 if (filesInViewer != null && filesInViewer.length > 0)
256 structureViewer.setAddingStructures(true); // already files loaded.
257 for (int c = 0; c < filesInViewer.length; c++)
259 if (Platform.pathEquals(filesInViewer[c], file))
272 } catch (OutOfMemoryError oomerror)
274 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
275 } catch (Exception ex)
277 ex.printStackTrace();
278 errormsgs.append("When retrieving pdbfiles : current was: '")
279 .append(pdbid).append("'");
281 if (errormsgs.length() > 0)
283 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
284 MessageManager.formatMessage(
285 "label.pdb_entries_couldnt_be_retrieved", new String[]
286 { errormsgs.toString() }),
287 MessageManager.getString("label.couldnt_load_file"),
288 JvOptionPane.ERROR_MESSAGE);