interface for objects at root of a jalview session's
[jalview.git] / src / jalview / appletgui / AppletJmolBinding.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.appletgui;
19
20 import java.awt.Container;
21 import java.util.BitSet;
22
23 import jalview.api.AlignmentViewPanel;
24 import jalview.datamodel.AlignmentI;
25 import jalview.datamodel.PDBEntry;
26 import jalview.datamodel.SequenceI;
27
28 import org.jmol.api.JmolAppConsoleInterface;
29 import org.jmol.api.JmolViewer;
30 import org.jmol.applet.AppletConsole;
31 import org.jmol.popup.JmolPopup;
32
33 class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding
34 {
35
36   /**
37    * Window that contains the bound Jmol instance
38    */
39   private AppletJmol appletJmolBinding;
40
41   public AppletJmolBinding(AppletJmol appletJmol, PDBEntry[] pdbentry,
42           SequenceI[][] seq, String[][] chains, String protocol)
43   {
44     super(pdbentry, seq, chains, protocol);
45     appletJmolBinding = appletJmol;
46   }
47
48   public jalview.api.FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
49   {
50     AlignmentPanel ap = (AlignmentPanel)alignment;
51     if (appletJmolBinding.ap.av.showSequenceFeatures)
52     {
53       if (appletJmolBinding.fr == null)
54       {
55         appletJmolBinding.fr = new jalview.appletgui.FeatureRenderer(
56                 appletJmolBinding.ap.av);
57       }
58
59       appletJmolBinding.fr
60               .transferSettings(appletJmolBinding.ap.seqPanel.seqCanvas
61                       .getFeatureRenderer());
62     }
63
64     return appletJmolBinding.fr;
65   }
66
67   public jalview.api.SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
68   {
69     return new SequenceRenderer(((AlignmentPanel)alignment).av);
70   }
71
72   public void sendConsoleEcho(String strEcho)
73   {
74     if (appletJmolBinding.scriptWindow == null)
75       appletJmolBinding.showConsole(true);
76
77     appletJmolBinding.history.append("\n" + strEcho);
78   }
79
80   public void sendConsoleMessage(String strStatus)
81   {
82     if (appletJmolBinding.history != null && strStatus != null
83             && !strStatus.equals("Script completed"))
84     {
85       appletJmolBinding.history.append("\n" + strStatus);
86     }
87   }
88
89   public void showUrl(String url, String target)
90   {
91     appletJmolBinding.ap.alignFrame.showURL(url, target);
92
93   }
94
95   public void refreshGUI()
96   {
97     appletJmolBinding.updateTitleAndMenus();
98   }
99
100   public void updateColours(Object source)
101   {
102     AlignmentPanel ap = (AlignmentPanel) source;
103     colourBySequence(ap.av.getShowSequenceFeatures(), ap);
104   }
105
106   public void showUrl(String url)
107   {
108     try
109     {
110       appletJmolBinding.ap.av.applet.getAppletContext().showDocument(
111               new java.net.URL(url), "jmol");
112     } catch (java.net.MalformedURLException ex)
113     {
114     }
115   }
116
117   public void newJmolPopup(boolean translateLocale, String menuName,
118           boolean asPopup)
119   {
120
121     jmolpopup = JmolPopup.newJmolPopup(viewer, translateLocale, menuName,
122             asPopup);
123   }
124
125   public void notifyScriptTermination(String strStatus, int msWalltime)
126   {
127     // do nothing.
128   }
129
130   public void selectionChanged(BitSet arg0)
131   {
132     // TODO Auto-generated method stub
133
134   }
135
136   public void refreshPdbEntries()
137   {
138     // TODO Auto-generated method stub
139
140   }
141
142   @Override
143   public void showConsole(boolean show)
144   {
145     appletJmolBinding.showConsole(show);
146   }
147
148   @Override
149   protected JmolAppConsoleInterface createJmolConsole(JmolViewer viewer2,
150           Container consolePanel, String buttonsToShow)
151   {
152     return new AppletConsole(viewer2, consolePanel);
153   }
154
155   @Override
156   protected void releaseUIResources()
157   {
158     appletJmolBinding = null;
159     if (console != null)
160     {
161       try
162       {
163         console.setVisible(false);
164       } catch (Error e)
165       {
166       } catch (Exception x)
167       {
168       }
169       ;
170       console = null;
171     }
172
173   }
174
175   @Override
176   public void releaseReferences(Object svl)
177   {
178     // TODO Auto-generated method stub
179     
180   }
181
182 }