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