update author list in license for (JAL-826)
[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, J Engelhardt, LM Lui, 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 import jalview.structure.StructureSelectionManager;
28
29 import org.jmol.api.JmolAppConsoleInterface;
30 import org.jmol.api.JmolViewer;
31 import org.jmol.applet.AppletConsole;
32 import org.jmol.popup.JmolPopup;
33
34 class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding
35 {
36
37   /**
38    * Window that contains the bound Jmol instance
39    */
40   private AppletJmol appletJmolBinding;
41
42   public AppletJmolBinding(AppletJmol appletJmol, StructureSelectionManager sSm, PDBEntry[] pdbentry,
43           SequenceI[][] seq, String[][] chains, String protocol)
44   {
45     super(sSm, pdbentry, seq, chains, protocol);
46     appletJmolBinding = appletJmol;
47   }
48
49   public jalview.api.FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
50   {
51     AlignmentPanel ap = (AlignmentPanel)alignment;
52     if (appletJmolBinding.ap.av.showSequenceFeatures)
53     {
54       if (appletJmolBinding.fr == null)
55       {
56         appletJmolBinding.fr = new jalview.appletgui.FeatureRenderer(
57                 appletJmolBinding.ap.av);
58       }
59
60       appletJmolBinding.fr
61               .transferSettings(appletJmolBinding.ap.seqPanel.seqCanvas
62                       .getFeatureRenderer());
63     }
64
65     return appletJmolBinding.fr;
66   }
67
68   public jalview.api.SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
69   {
70     return new SequenceRenderer(((AlignmentPanel)alignment).av);
71   }
72
73   public void sendConsoleEcho(String strEcho)
74   {
75     if (appletJmolBinding.scriptWindow == null)
76       appletJmolBinding.showConsole(true);
77
78     appletJmolBinding.history.append("\n" + strEcho);
79   }
80
81   public void sendConsoleMessage(String strStatus)
82   {
83     if (appletJmolBinding.history != null && strStatus != null
84             && !strStatus.equals("Script completed"))
85     {
86       appletJmolBinding.history.append("\n" + strStatus);
87     }
88   }
89
90   public void showUrl(String url, String target)
91   {
92     appletJmolBinding.ap.alignFrame.showURL(url, target);
93
94   }
95
96   public void refreshGUI()
97   {
98     appletJmolBinding.updateTitleAndMenus();
99   }
100
101   public void updateColours(Object source)
102   {
103     AlignmentPanel ap = (AlignmentPanel) source;
104     colourBySequence(ap.av.getShowSequenceFeatures(), ap);
105   }
106
107   public void showUrl(String url)
108   {
109     try
110     {
111       appletJmolBinding.ap.av.applet.getAppletContext().showDocument(
112               new java.net.URL(url), "jmol");
113     } catch (java.net.MalformedURLException ex)
114     {
115     }
116   }
117
118   public void newJmolPopup(boolean translateLocale, String menuName,
119           boolean asPopup)
120   {
121
122     jmolpopup = JmolPopup.newJmolPopup(viewer, translateLocale, menuName,
123             asPopup);
124   }
125
126   public void notifyScriptTermination(String strStatus, int msWalltime)
127   {
128     // do nothing.
129   }
130
131   public void selectionChanged(BitSet arg0)
132   {
133     // TODO Auto-generated method stub
134
135   }
136
137   public void refreshPdbEntries()
138   {
139     // TODO Auto-generated method stub
140
141   }
142
143   @Override
144   public void showConsole(boolean show)
145   {
146     appletJmolBinding.showConsole(show);
147   }
148
149   @Override
150   protected JmolAppConsoleInterface createJmolConsole(JmolViewer viewer2,
151           Container consolePanel, String buttonsToShow)
152   {
153     return new AppletConsole(viewer2, consolePanel);
154   }
155
156   @Override
157   protected void releaseUIResources()
158   {
159     appletJmolBinding = null;
160     if (console != null)
161     {
162       try
163       {
164         console.setVisible(false);
165       } catch (Error e)
166       {
167       } catch (Exception x)
168       {
169       }
170       ;
171       console = null;
172     }
173
174   }
175
176   @Override
177   public void releaseReferences(Object svl)
178   {
179   }
180
181 }