JAL-3148 SequenceRenderer, ResidueColourFinder overloads and
[jalview.git] / src / jalview / gui / AppJmolBinding.java
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 jalview.api.AlignmentViewPanel;
24 import jalview.api.SequenceRendererI;
25 import jalview.api.structures.JalviewStructureDisplayI;
26 import jalview.bin.Cache;
27 import jalview.datamodel.PDBEntry;
28 import jalview.datamodel.SequenceI;
29 import jalview.ext.jmol.JalviewJmolBinding;
30 import jalview.io.DataSourceType;
31 import jalview.structure.StructureSelectionManager;
32
33 import java.awt.Container;
34 import java.util.Map;
35
36 import org.jmol.api.JmolAppConsoleInterface;
37 import org.jmol.java.BS;
38 import org.openscience.jmol.app.jmolpanel.console.AppConsole;
39
40 public class AppJmolBinding extends JalviewJmolBinding
41 {
42   private AppJmol appJmolWindow;
43
44   public AppJmolBinding(AppJmol appJmol, StructureSelectionManager sSm,
45           PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
46           DataSourceType protocol)
47   {
48     super(sSm, pdbentry, sequenceIs, protocol);
49     appJmolWindow = appJmol;
50   }
51
52   @Override
53   protected IProgressIndicator getIProgressIndicator()
54   {
55     return appJmolWindow.progressBar;
56   }
57
58   @Override
59   public void sendConsoleEcho(String strEcho)
60   {
61     if (console != null)
62     {
63       console.sendConsoleEcho(strEcho);
64     }
65   }
66
67   @Override
68   public void sendConsoleMessage(String strStatus)
69   {
70     if (console != null && strStatus != null)
71     // && !strStatus.equals("Script completed"))
72     // should we squash the script completed string ?
73     {
74       console.sendConsoleMessage(strStatus);
75     }
76   }
77
78   @Override
79   public void showUrl(String url, String target)
80   {
81     try
82     {
83       jalview.util.BrowserLauncher.openURL(url);
84     } catch (Exception e)
85     {
86       Cache.log.error("Failed to launch Jmol-associated url " + url, e);
87       // TODO: 2.6 : warn user if browser was not configured.
88     }
89   }
90
91   @Override
92   public void refreshGUI()
93   {
94     // appJmolWindow.repaint();
95     javax.swing.SwingUtilities.invokeLater(new Runnable()
96     {
97       @Override
98       public void run()
99       {
100         appJmolWindow.updateTitleAndMenus();
101         appJmolWindow.revalidate();
102       }
103     });
104   }
105
106   @Override
107   public void notifyScriptTermination(String strStatus, int msWalltime)
108   {
109     // todo - script termination doesn't happen ?
110     // if (console != null)
111     // console.notifyScriptTermination(strStatus,
112     // msWalltime);
113   }
114
115   @Override
116   public void showUrl(String url)
117   {
118     showUrl(url, "jmol");
119   }
120
121   public void newJmolPopup(String menuName)
122   {
123     // jmolpopup = new JmolAwtPopup();
124     // jmolpopup.jpiInitialize((viewer), menuName);
125   }
126
127   @Override
128   public void selectionChanged(BS arg0)
129   {
130   }
131
132   @Override
133   public void refreshPdbEntries()
134   {
135   }
136
137   @Override
138   public void showConsole(boolean b)
139   {
140     appJmolWindow.showConsole(b);
141   }
142
143   @Override
144   protected JmolAppConsoleInterface createJmolConsole(
145           Container consolePanel, String buttonsToShow)
146   {
147     viewer.setJmolCallbackListener(this);
148     return new AppConsole(viewer, consolePanel, buttonsToShow);
149   }
150
151   @Override
152   protected void releaseUIResources()
153   {
154     appJmolWindow = null;
155     closeConsole();
156   }
157
158   @Override
159   public void releaseReferences(Object svl)
160   {
161     if (svl instanceof SeqPanel)
162     {
163       appJmolWindow.removeAlignmentPanel(((SeqPanel) svl).ap);
164     }
165   }
166
167   @Override
168   public Map<String, Object> getJSpecViewProperty(String arg0)
169   {
170     return null;
171   }
172
173   @Override
174   public JalviewStructureDisplayI getViewer()
175   {
176     return appJmolWindow;
177   }
178
179   @Override
180   public jalview.api.FeatureRenderer getFeatureRenderer(
181           AlignmentViewPanel alignment)
182   {
183     AlignmentPanel ap = (alignment == null)
184             ? appJmolWindow.getAlignmentPanel()
185             : (AlignmentPanel) alignment;
186     if (ap.av.isShowSequenceFeatures())
187     {
188       return ap.av.getAlignPanel().getSeqPanel().seqCanvas.fr;
189     }
190
191     return null;
192   }
193 }