3750c207603e68f762dc23231c371ee8c0b37026
[jalview.git] / src / jalview / appletgui / AppletJmolBinding.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 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 jalview.api.AlignmentViewPanel;
21 import jalview.datamodel.PDBEntry;
22 import jalview.datamodel.SequenceI;
23 import jalview.structure.StructureSelectionManager;
24
25 import java.awt.Container;
26 import java.util.BitSet;
27
28 import org.jmol.api.JmolAppConsoleInterface;
29 import org.jmol.api.JmolViewer;
30 import org.jmol.popup.JmolPopup;
31
32 class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding
33 {
34
35   /**
36    * Window that contains the bound Jmol instance
37    */
38   private AppletJmol appletJmolBinding;
39
40   public AppletJmolBinding(AppletJmol appletJmol, StructureSelectionManager sSm, PDBEntry[] pdbentry,
41           SequenceI[][] seq, String[][] chains, String protocol)
42   {
43     super(sSm, pdbentry, seq, chains, protocol);
44     appletJmolBinding = appletJmol;
45   }
46
47   public jalview.api.FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
48   {
49     AlignmentPanel ap = (AlignmentPanel)alignment;
50     if (appletJmolBinding.ap.av.showSequenceFeatures)
51     {
52       if (appletJmolBinding.fr == null)
53       {
54         appletJmolBinding.fr = new jalview.appletgui.FeatureRenderer(
55                 appletJmolBinding.ap.av);
56       }
57
58       appletJmolBinding.fr
59               .transferSettings(appletJmolBinding.ap.seqPanel.seqCanvas
60                       .getFeatureRenderer());
61     }
62
63     return appletJmolBinding.fr;
64   }
65
66   public jalview.api.SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
67   {
68     return new SequenceRenderer(((AlignmentPanel)alignment).av);
69   }
70
71   public void sendConsoleEcho(String strEcho)
72   {
73     if (appletJmolBinding.scriptWindow == null)
74       appletJmolBinding.showConsole(true);
75
76     appletJmolBinding.history.append("\n" + strEcho);
77   }
78
79   public void sendConsoleMessage(String strStatus)
80   {
81     if (appletJmolBinding.history != null && strStatus != null
82             && !strStatus.equals("Script completed"))
83     {
84       appletJmolBinding.history.append("\n" + strStatus);
85     }
86   }
87
88   public void showUrl(String url, String target)
89   {
90     appletJmolBinding.ap.alignFrame.showURL(url, target);
91
92   }
93
94   public void refreshGUI()
95   {
96     appletJmolBinding.updateTitleAndMenus();
97   }
98
99   public void updateColours(Object source)
100   {
101     AlignmentPanel ap = (AlignmentPanel) source;
102     colourBySequence(ap.av.getShowSequenceFeatures(), ap);
103   }
104
105   public void showUrl(String url)
106   {
107     try
108     {
109       appletJmolBinding.ap.av.applet.getAppletContext().showDocument(
110               new java.net.URL(url), "jmol");
111     } catch (java.net.MalformedURLException ex)
112     {
113     }
114   }
115
116   public void newJmolPopup(boolean translateLocale, String menuName,
117           boolean asPopup)
118   {
119
120     jmolpopup = new JmolPopup();
121     jmolpopup.initialize(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   }
179   @Override
180   public void resizeInnerPanel(String data)
181   {
182     // TODO Auto-generated method stub
183     
184   }
185 }