Clover icon

Coverage Report

  1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.gui

File AppJmolBinding.java

 

Coverage histogram

../../img/srcFileCovDistChart6.png
37% of files have more coverage

Code metrics

28
61
18
1
293
216
40
0.66
3.39
18
2.22

Classes

Class Line # Actions
AppJmolBinding 47 61 40
0.6074766560.7%
 

Contributing tests

This file is covered by 39 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.gui;
22   
23    import java.awt.Container;
24    import java.io.File;
25    import java.util.ArrayList;
26    import java.util.List;
27    import java.util.Map;
28   
29    import javax.swing.JComponent;
30   
31    import org.jmol.api.JmolAppConsoleInterface;
32    import org.openscience.jmol.app.jmolpanel.console.AppConsole;
33   
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;
46   
 
47    public class AppJmolBinding extends JalviewJmolBinding
48    {
 
49  45 toggle public AppJmolBinding(AppJmol appJmol, StructureSelectionManager sSm,
50    PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
51    DataSourceType protocol)
52    {
53  45 super(sSm, pdbentry, sequenceIs, protocol);
54  45 setViewer(appJmol);
55    }
56   
 
57  316 toggle @Override
58    public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
59    {
60  316 return new SequenceRenderer(((AlignmentPanel) alignment).av);
61    }
62   
 
63  32 toggle @Override
64    public void sendConsoleEcho(String strEcho)
65    {
66  32 if (console != null)
67    {
68  18 console.sendConsoleEcho(strEcho);
69    }
70    }
71   
 
72  0 toggle @Override
73    public void sendConsoleMessage(String strStatus)
74    {
75  0 if (console != null && strStatus != null)
76    // && !strStatus.equals("Script completed"))
77    // should we squash the script completed string ?
78    {
79  0 console.sendConsoleMessage(strStatus);
80    }
81    }
82   
 
83  0 toggle @Override
84    public void showUrl(String url, String target)
85    {
86  0 try
87    {
88  0 jalview.util.BrowserLauncher.openURL(url);
89    } catch (Exception e)
90    {
91  0 Console.error("Failed to launch Jmol-associated url " + url, e);
92    // TODO: 2.6 : warn user if browser was not configured.
93    }
94    }
95   
 
96  101 toggle @Override
97    public void refreshGUI()
98    {
99  101 if (getMappedStructureCount() == 0)
100    {
101    // too soon!
102  53 return;
103    }
104    // appJmolWindow.repaint();
105  48 javax.swing.SwingUtilities.invokeLater(new Runnable()
106    {
 
107  48 toggle @Override
108    public void run()
109    {
110  48 JalviewStructureDisplayI theViewer = getViewer();
111    // invokes colourbySequence() via seqColour_ActionPerformed()
112  48 theViewer.updateTitleAndMenus();
113  42 ((JComponent) theViewer).revalidate();
114    }
115    });
116    }
117   
 
118  8 toggle @Override
119    public void notifyScriptTermination(String strStatus, int msWalltime)
120    {
121    // todo - script termination doesn't happen ?
122    // if (console != null)
123    // console.notifyScriptTermination(strStatus,
124    // msWalltime);
125    }
126   
 
127  0 toggle @Override
128    public void showUrl(String url)
129    {
130  0 showUrl(url, "jmol");
131    }
132   
 
133  0 toggle public void newJmolPopup(String menuName)
134    {
135    // jmolpopup = new JmolAwtPopup();
136    // jmolpopup.jpiInitialize((viewer), menuName);
137    }
138   
 
139  0 toggle @Override
140    public void selectionChanged(BS arg0)
141    {
142    }
143   
 
144  0 toggle @Override
145    public void showConsole(boolean b)
146    {
147  0 getViewer().showConsole(b);
148    }
149   
 
150  45 toggle @Override
151    protected JmolAppConsoleInterface createJmolConsole(
152    Container consolePanel, String buttonsToShow)
153    {
154  45 jmolViewer.setJmolCallbackListener(this);
155    // BH comment: can't do this yet [for JS only, or generally?]
156  45 return Platform.isJS() || Jalview.isHeadlessMode() ? null
157    : new AppConsole(jmolViewer, consolePanel, buttonsToShow);
158    }
159   
 
160  23 toggle @Override
161    protected void releaseUIResources()
162    {
163  23 setViewer(null);
164  23 closeConsole();
165    }
166   
 
167  42 toggle @Override
168    public void releaseReferences(Object svl)
169    {
170  42 if (svl instanceof SeqPanel)
171    {
172  42 getViewer().removeAlignmentPanel(((SeqPanel) svl).ap);
173    }
174    }
175   
 
176  0 toggle @Override
177    public Map<String, Object> getJSpecViewProperty(String arg0)
178    {
179    // TODO Auto-generated method stub
180  0 return null;
181    }
182   
 
183  0 toggle @SuppressWarnings("unused")
184    public void cacheFiles(List<File> files)
185    {
186  0 if (files == null)
187    {
188  0 return;
189    }
190  0 for (File f : files)
191    {
192  0 Platform.cacheFileData(f);
193    }
194    }
195   
196    /**
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).
201    *
202    * Currently only used by Jmol - similar but different code used for Chimera/X
203    * and Pymol so still need to refactor
204    *
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
209    */
 
210  39 toggle public List<String> fetchPdbFiles(StructureViewerBase structureViewer)
211    {
212    // todo - record which pdbids were successfully imported.
213  39 StringBuilder errormsgs = new StringBuilder();
214   
215  39 List<String> files = new ArrayList<>();
216  39 String pdbid = "";
217  39 try
218    {
219  39 String[] filesInViewer = getStructureFiles();
220    // TODO: replace with reference fetching/transfer code (validate PDBentry
221    // as a DBRef?)
222   
223  79 for (int pi = 0; pi < getPdbCount(); pi++)
224    {
225  40 PDBEntry strucEntry = getPdbEntry(pi);
226   
227  40 String file = strucEntry.getFile();
228  40 if (file == null)
229    {
230  0 pdbid = strucEntry.getId();
231  0 try
232    {
233  0 file = structureViewer.fetchPdbFile(strucEntry);
234    } catch (OutOfMemoryError oomerror)
235    {
236  0 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
237    } catch (Exception ex)
238    {
239  0 ex.printStackTrace();
240  0 errormsgs.append("'").append(pdbid).append("'");
241    }
242  0 if (file != null)
243    {
244    // success
245  0 files.add(file);
246    }
247    else
248    {
249  0 errormsgs.append("'").append(pdbid).append("' ");
250    }
251    }
252    else
253    {
254  40 if (filesInViewer != null && filesInViewer.length > 0)
255    {
256  2 structureViewer.setAddingStructures(true); // already files loaded.
257  3 for (int c = 0; c < filesInViewer.length; c++)
258    {
259  2 if (Platform.pathEquals(filesInViewer[c], file))
260    {
261  1 file = null;
262  1 break;
263    }
264    }
265    }
266  40 if (file != null)
267    {
268  39 files.add(file);
269    }
270    }
271    }
272    } catch (OutOfMemoryError oomerror)
273    {
274  0 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
275    } catch (Exception ex)
276    {
277  0 ex.printStackTrace();
278  0 errormsgs.append("When retrieving pdbfiles : current was: '")
279    .append(pdbid).append("'");
280    }
281  39 if (errormsgs.length() > 0)
282    {
283  0 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);
289    }
290  39 return files;
291    }
292   
293    }