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