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