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