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