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