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