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