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