6ee68e878992459ac9ae36a366adbcd95785abe9
[jalview.git] / src / jalview / appletgui / AppletJmolBinding.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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,
41           StructureSelectionManager sSm, PDBEntry[] pdbentry,
42           SequenceI[][] seq, String[][] chains, String protocol)
43   {
44     super(sSm, pdbentry, seq, chains, protocol);
45     appletJmolBinding = appletJmol;
46   }
47
48   public jalview.api.FeatureRenderer getFeatureRenderer(
49           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(
69           AlignmentViewPanel alignment)
70   {
71     return new SequenceRenderer(((AlignmentPanel) alignment).av);
72   }
73
74   public void sendConsoleEcho(String strEcho)
75   {
76     if (appletJmolBinding.scriptWindow == null)
77       appletJmolBinding.showConsole(true);
78
79     appletJmolBinding.history.append("\n" + strEcho);
80   }
81
82   public void sendConsoleMessage(String strStatus)
83   {
84     if (appletJmolBinding.history != null && strStatus != null
85             && !strStatus.equals("Script completed"))
86     {
87       appletJmolBinding.history.append("\n" + strStatus);
88     }
89   }
90
91   public void showUrl(String url, String target)
92   {
93     appletJmolBinding.ap.alignFrame.showURL(url, target);
94
95   }
96
97   public void refreshGUI()
98   {
99     appletJmolBinding.updateTitleAndMenus();
100   }
101
102   public void updateColours(Object source)
103   {
104     AlignmentPanel ap = (AlignmentPanel) source;
105     colourBySequence(ap.av.getShowSequenceFeatures(), ap);
106   }
107
108   public void showUrl(String url)
109   {
110     try
111     {
112       appletJmolBinding.ap.av.applet.getAppletContext().showDocument(
113               new java.net.URL(url), "jmol");
114     } catch (java.net.MalformedURLException ex)
115     {
116     }
117   }
118
119   public void newJmolPopup(boolean translateLocale, String menuName,
120           boolean asPopup)
121   {
122
123     jmolpopup = new JmolPopup();
124     jmolpopup.initialize(viewer, translateLocale, menuName, asPopup);
125   }
126
127   public void notifyScriptTermination(String strStatus, int msWalltime)
128   {
129     // do nothing.
130   }
131
132   public void selectionChanged(BitSet arg0)
133   {
134     // TODO Auto-generated method stub
135
136   }
137
138   public void refreshPdbEntries()
139   {
140     // TODO Auto-generated method stub
141
142   }
143
144   @Override
145   public void showConsole(boolean show)
146   {
147     appletJmolBinding.showConsole(show);
148   }
149
150   @Override
151   protected JmolAppConsoleInterface createJmolConsole(JmolViewer viewer2,
152           Container consolePanel, String buttonsToShow)
153   {
154     // return new org.jmol.console.AppletConsole(viewer2, consolePanel);
155     JmolAppConsoleInterface appc = new org.jmol.console.AppletConsole()
156             .getAppConsole(viewer2);
157     return appc;
158   }
159
160   @Override
161   protected void releaseUIResources()
162   {
163     appletJmolBinding = null;
164     if (console != null)
165     {
166       try
167       {
168         console.setVisible(false);
169       } catch (Error e)
170       {
171       } catch (Exception x)
172       {
173       }
174       ;
175       console = null;
176     }
177
178   }
179
180   @Override
181   public void releaseReferences(Object svl)
182   {
183   }
184
185   @Override
186   public void resizeInnerPanel(String data)
187   {
188     // TODO Auto-generated method stub
189
190   }
191 }