JAL-2177 Jmol update from: Jmol-14.2.14_2015.06.11 to Jmol-14.6.4_2016.10.26
[jalview.git] / src / jalview / appletgui / AppletJmolBinding.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.appletgui;
22
23 import jalview.api.AlignmentViewPanel;
24 import jalview.datamodel.PDBEntry;
25 import jalview.datamodel.SequenceI;
26 import jalview.ext.jmol.JalviewJmolBinding;
27 import jalview.structure.StructureSelectionManager;
28
29 import java.awt.Container;
30 import java.util.Map;
31
32 import org.jmol.api.JmolAppConsoleInterface;
33 import org.jmol.console.AppletConsole;
34 import org.jmol.java.BS;
35
36 class AppletJmolBinding extends JalviewJmolBinding
37 {
38
39   /**
40    * Window that contains the bound Jmol instance
41    */
42   private AppletJmol appletJmolBinding;
43
44   public AppletJmolBinding(AppletJmol appletJmol,
45           StructureSelectionManager sSm, PDBEntry[] pdbentry,
46           SequenceI[][] seq, String[][] chains, String protocol)
47   {
48     super(sSm, pdbentry, seq, chains, protocol);
49     appletJmolBinding = appletJmol;
50   }
51
52   @Override
53   public jalview.api.FeatureRenderer getFeatureRenderer(
54           AlignmentViewPanel alignment)
55   {
56     AlignmentPanel ap = (AlignmentPanel) alignment;
57     if (appletJmolBinding.ap.av.isShowSequenceFeatures())
58     {
59       if (appletJmolBinding.fr == null)
60       {
61         appletJmolBinding.fr = new jalview.appletgui.FeatureRenderer(
62                 appletJmolBinding.ap.av);
63       }
64
65       appletJmolBinding.fr
66               .transferSettings(appletJmolBinding.ap.seqPanel.seqCanvas
67                       .getFeatureRenderer());
68     }
69
70     return appletJmolBinding.fr;
71   }
72
73   @Override
74   public jalview.api.SequenceRenderer getSequenceRenderer(
75           AlignmentViewPanel alignment)
76   {
77     return new SequenceRenderer(((AlignmentPanel) alignment).av);
78   }
79
80   @Override
81   public void sendConsoleEcho(String strEcho)
82   {
83     if (appletJmolBinding.scriptWindow == null)
84     {
85       appletJmolBinding.showConsole(true);
86     }
87
88     appletJmolBinding.addToHistory(strEcho);
89   }
90
91   @Override
92   public void sendConsoleMessage(String strStatus)
93   {
94     if (appletJmolBinding.history != null && strStatus != null
95             && !strStatus.equals("Script completed"))
96     {
97       appletJmolBinding.addToHistory(strStatus);
98     }
99   }
100
101   @Override
102   public void showUrl(String url, String target)
103   {
104     appletJmolBinding.ap.alignFrame.showURL(url, target);
105
106   }
107
108   @Override
109   public void refreshGUI()
110   {
111     appletJmolBinding.updateTitleAndMenus();
112   }
113
114   @Override
115   public void updateColours(Object source)
116   {
117     AlignmentPanel ap = (AlignmentPanel) source;
118     colourBySequence(ap);
119   }
120
121   @Override
122   public void showUrl(String url)
123   {
124     try
125     {
126       appletJmolBinding.ap.av.applet.getAppletContext().showDocument(
127               new java.net.URL(url), "jmol");
128     } catch (java.net.MalformedURLException ex)
129     {
130     }
131   }
132
133   public void newJmolPopup(boolean translateLocale, String menuName,
134           boolean asPopup)
135   {
136     // jmolpopup = new JmolAwtPopup(); // is this used?
137     // jmolpopup.jpiInitialize((viewer), menuName);
138   }
139
140   @Override
141   public void notifyScriptTermination(String strStatus, int msWalltime)
142   {
143     // do nothing.
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     // noop
157   }
158
159   @Override
160   public void showConsole(boolean show)
161   {
162     appletJmolBinding.showConsole(show);
163   }
164
165   @Override
166   protected JmolAppConsoleInterface createJmolConsole(
167           Container consolePanel, String buttonsToShow)
168   {
169     JmolAppConsoleInterface appc = new AppletConsole();
170     appc.start(viewer);
171     return appc;
172   }
173
174   @Override
175   protected void releaseUIResources()
176   {
177     appletJmolBinding = null;
178     closeConsole();
179   }
180
181   @Override
182   public void releaseReferences(Object svl)
183   {
184   }
185
186   @Override
187   public int[] resizeInnerPanel(String data)
188   {
189     // TODO Auto-generated method stub
190     return null;
191   }
192
193   @Override
194   public Map<String, Object> getJSpecViewProperty(String arg0)
195   {
196     // TODO Auto-generated method stub
197     return null;
198   }
199 }