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