Bugfix to enable accurate chain extraction/association with models loaded in Chimera...
[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 protocol)
49   {
50     super(sSm, pdbentry, seq, 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   @Override
117   public void updateColours(Object source)
118   {
119     AlignmentPanel ap = (AlignmentPanel) source;
120     colourBySequence(ap);
121   }
122
123   @Override
124   public void showUrl(String url)
125   {
126     try
127     {
128       appletJmolBinding.ap.av.applet.getAppletContext().showDocument(
129               new java.net.URL(url), "jmol");
130     } catch (java.net.MalformedURLException ex)
131     {
132     }
133   }
134
135   public void newJmolPopup(boolean translateLocale, String menuName,
136           boolean asPopup)
137   {
138     // jmolpopup = new JmolAwtPopup(); // is this used?
139     // jmolpopup.jpiInitialize((viewer), menuName);
140   }
141
142   @Override
143   public void notifyScriptTermination(String strStatus, int msWalltime)
144   {
145     // do nothing.
146   }
147
148   @Override
149   public void selectionChanged(BS arg0)
150   {
151     // TODO Auto-generated method stub
152
153   }
154
155   @Override
156   public void refreshPdbEntries()
157   {
158     // noop
159   }
160
161   @Override
162   public void showConsole(boolean show)
163   {
164     appletJmolBinding.showConsole(show);
165   }
166
167   @Override
168   protected JmolAppConsoleInterface createJmolConsole(
169           Container consolePanel, String buttonsToShow)
170   {
171     JmolAppConsoleInterface appc = new AppletConsole();
172     appc.start(viewer);
173     return appc;
174   }
175
176   @Override
177   protected void releaseUIResources()
178   {
179     appletJmolBinding = null;
180     closeConsole();
181   }
182
183   @Override
184   public void releaseReferences(Object svl)
185   {
186   }
187
188   @Override
189   public Dimension resizeInnerPanel(String data)
190   {
191     // TODO Auto-generated method stub
192     return null;
193   }
194
195   @Override
196   public Map<String, Object> getJSpecViewProperty(String arg0)
197   {
198     // TODO Auto-generated method stub
199     return null;
200   }
201 }