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