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