apply jalview code style
[jalview.git] / src / jalview / gui / AppJmolBinding.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.gui;
19
20 import java.awt.Container;
21 import java.awt.event.ComponentEvent;
22 import java.awt.event.ComponentListener;
23 import java.awt.event.ContainerEvent;
24 import java.awt.event.ContainerListener;
25 import java.util.BitSet;
26
27 import javax.swing.JPanel;
28
29 import jalview.bin.Cache;
30 import jalview.datamodel.PDBEntry;
31 import jalview.datamodel.SequenceI;
32
33 import org.jmol.api.JmolAppConsoleInterface;
34 import org.jmol.api.JmolViewer;
35 import org.jmol.popup.JmolPopup;
36 import org.openscience.jmol.app.jmolpanel.AppConsole;
37
38 public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding
39 {
40
41   /**
42    * 
43    */
44   private AppJmol appJmolWindow;
45
46   public AppJmolBinding(AppJmol appJmol, PDBEntry[] pdbentry,
47           SequenceI[][] sequenceIs, String[][] chains, String protocol)
48   {
49     super(pdbentry, sequenceIs, chains, protocol);
50     appJmolWindow = appJmol;
51   }
52
53   FeatureRenderer fr = null;
54
55   @Override
56   public jalview.api.FeatureRenderer getFeatureRenderer()
57   {
58     if (appJmolWindow.ap.av.showSequenceFeatures)
59     {
60       if (fr == null)
61       {
62         fr = new FeatureRenderer(appJmolWindow.ap);
63       }
64
65       fr.transferSettings(appJmolWindow.ap.seqPanel.seqCanvas
66               .getFeatureRenderer());
67     }
68
69     return fr;
70   }
71
72   @Override
73   public jalview.api.SequenceRenderer getSequenceRenderer()
74   {
75     return new SequenceRenderer(appJmolWindow.ap.av);
76   }
77
78   public void sendConsoleEcho(String strEcho)
79   {
80     if (console != null)
81     {
82       console.sendConsoleEcho(strEcho);
83     }
84   }
85
86   public void sendConsoleMessage(String strStatus)
87   {
88     if (console != null && strStatus != null)
89     // && !strStatus.equals("Script completed"))
90     // should we squash the script completed string ?
91     {
92       console.sendConsoleMessage(strStatus);
93     }
94   }
95
96   @Override
97   public void showUrl(String url, String target)
98   {
99     try
100     {
101       jalview.util.BrowserLauncher.openURL(url);
102     } catch (Exception e)
103     {
104       Cache.log.error("Failed to launch Jmol-associated url " + url, e);
105       // TODO: 2.6 : warn user if browser was not configured.
106     }
107   }
108
109   @Override
110   public void refreshGUI()
111   {
112     // appJmolWindow.repaint();
113     javax.swing.SwingUtilities.invokeLater(new Runnable()
114     {
115       public void run()
116       {
117         appJmolWindow.updateTitleAndMenus();
118         appJmolWindow.revalidate();
119       }
120     });
121   }
122
123   public void updateColours(Object source)
124   {
125     AlignmentPanel ap = (AlignmentPanel) source;
126     if (appJmolWindow.ap.alignFrame.getCurrentView() != ap.av)
127       return;
128
129     colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment);
130   }
131
132   public void notifyScriptTermination(String strStatus, int msWalltime)
133   {
134     // todo - script termination doesn't happen ?
135     // if (console != null)
136     // console.notifyScriptTermination(strStatus,
137     // msWalltime);
138   }
139
140   public void showUrl(String url)
141   {
142     showUrl(url, "jmol");
143   }
144
145   public void newJmolPopup(boolean translateLocale, String menuName,
146           boolean asPopup)
147   {
148
149     jmolpopup = JmolPopup.newJmolPopup(viewer, translateLocale, menuName,
150             asPopup);
151   }
152
153   public void selectionChanged(BitSet arg0)
154   {
155     // TODO Auto-generated method stub
156
157   }
158
159   public void refreshPdbEntries()
160   {
161     // TODO Auto-generated method stub
162
163   }
164
165   public void showConsole(boolean b)
166   {
167     appJmolWindow.showConsole(b);
168   }
169
170   /**
171    * add the given sequences to the mapping scope for the given pdb file handle
172    * 
173    * @param pdbFile
174    *          - pdbFile identifier
175    * @param seq
176    *          - set of sequences it can be mapped to
177    */
178   public void addSequenceForStructFile(String pdbFile, SequenceI[] seq)
179   {
180     for (int pe = 0; pe < pdbentry.length; pe++)
181     {
182       if (pdbentry[pe].getFile().equals(pdbFile))
183       {
184         addSequence(pe, seq);
185       }
186     }
187   }
188
189   @Override
190   protected JmolAppConsoleInterface createJmolConsole(JmolViewer viewer2,
191           Container consolePanel, String buttonsToShow)
192   {
193     return new AppConsole(viewer, consolePanel, buttonsToShow);
194   }
195
196   @Override
197   protected void releaseUIResources()
198   {
199     appJmolWindow = null;
200     if (console != null)
201     {
202       try
203       {
204         console.setVisible(false);
205       } catch (Error e)
206       {
207       } catch (Exception x)
208       {
209       }
210       ;
211       console = null;
212     }
213
214   }
215 }