apply jalview code style
[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,
40           SequenceI[][] seq, 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(
53                 appletJmolBinding.ap.av);
54       }
55
56       appletJmolBinding.fr
57               .transferSettings(appletJmolBinding.ap.seqPanel.seqCanvas
58                       .getFeatureRenderer());
59     }
60
61     return appletJmolBinding.fr;
62   }
63
64   public jalview.api.SequenceRenderer getSequenceRenderer()
65   {
66     return new SequenceRenderer(appletJmolBinding.ap.av);
67   }
68
69   public void sendConsoleEcho(String strEcho)
70   {
71     if (appletJmolBinding.scriptWindow == null)
72       appletJmolBinding.showConsole(true);
73
74     appletJmolBinding.history.append("\n" + strEcho);
75   }
76
77   public void sendConsoleMessage(String strStatus)
78   {
79     if (appletJmolBinding.history != null && strStatus != null
80             && !strStatus.equals("Script completed"))
81     {
82       appletJmolBinding.history.append("\n" + strStatus);
83     }
84   }
85
86   public void showUrl(String url, String target)
87   {
88     appletJmolBinding.ap.alignFrame.showURL(url, target);
89
90   }
91
92   public void refreshGUI()
93   {
94     appletJmolBinding.updateTitleAndMenus();
95   }
96
97   public void updateColours(Object source)
98   {
99     AlignmentPanel ap = (AlignmentPanel) source;
100     colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment);
101   }
102
103   public void showUrl(String url)
104   {
105     try
106     {
107       appletJmolBinding.ap.av.applet.getAppletContext().showDocument(
108               new java.net.URL(url), "jmol");
109     } catch (java.net.MalformedURLException ex)
110     {
111     }
112   }
113
114   public void newJmolPopup(boolean translateLocale, String menuName,
115           boolean asPopup)
116   {
117
118     jmolpopup = JmolPopup.newJmolPopup(viewer, translateLocale, menuName,
119             asPopup);
120   }
121
122   public void notifyScriptTermination(String strStatus, int msWalltime)
123   {
124     // do nothing.
125   }
126
127   public void selectionChanged(BitSet arg0)
128   {
129     // TODO Auto-generated method stub
130
131   }
132
133   public void refreshPdbEntries()
134   {
135     // TODO Auto-generated method stub
136
137   }
138
139   @Override
140   public void showConsole(boolean show)
141   {
142     appletJmolBinding.showConsole(show);
143   }
144
145   @Override
146   protected JmolAppConsoleInterface createJmolConsole(JmolViewer viewer2,
147           Container consolePanel, String buttonsToShow)
148   {
149     return new AppletConsole(viewer2, consolePanel);
150   }
151
152   @Override
153   protected void releaseUIResources()
154   {
155     appletJmolBinding = null;
156     if (console != null)
157     {
158       try
159       {
160         console.setVisible(false);
161       } catch (Error e)
162       {
163       } catch (Exception x)
164       {
165       }
166       ;
167       console = null;
168     }
169
170   }
171
172 }