JAL-1683 replace year/version strings with tokens in source
[jalview.git] / src / jalview / gui / AppJmolBinding.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.gui;
22
23 import jalview.api.AlignmentViewPanel;
24 import jalview.bin.Cache;
25 import jalview.datamodel.PDBEntry;
26 import jalview.datamodel.SequenceI;
27 import jalview.ext.jmol.JalviewJmolBinding;
28 import jalview.structure.StructureSelectionManager;
29
30 import java.awt.Container;
31 import java.util.BitSet;
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 JalviewJmolBinding
39 {
40   private AppJmol appJmolWindow;
41
42   private FeatureRenderer fr = null;
43
44   public AppJmolBinding(AppJmol appJmol, StructureSelectionManager sSm,
45           PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
46           String protocol)
47   {
48     super(sSm, pdbentry, sequenceIs, chains, protocol);
49     appJmolWindow = appJmol;
50   }
51
52   @Override
53   public FeatureRenderer getFeatureRenderer(
54           AlignmentViewPanel alignment)
55   {
56     AlignmentPanel ap = (alignment == null) ? appJmolWindow.getAlignmentPanel()
57             : (AlignmentPanel) alignment;
58     if (ap.av.isShowSequenceFeatures())
59     {
60       if (fr == null)
61       {
62         fr = (jalview.gui.FeatureRenderer) ap.cloneFeatureRenderer();
63       }
64       else
65       {
66         ap.updateFeatureRenderer(fr);
67       }
68     }
69
70     return fr;
71   }
72
73   @Override
74   public SequenceRenderer getSequenceRenderer(
75           AlignmentViewPanel alignment)
76   {
77     return new SequenceRenderer(((AlignmentPanel) alignment).av);
78   }
79
80   public void sendConsoleEcho(String strEcho)
81   {
82     if (console != null)
83     {
84       console.sendConsoleEcho(strEcho);
85     }
86   }
87
88   public void sendConsoleMessage(String strStatus)
89   {
90     if (console != null && strStatus != null)
91     // && !strStatus.equals("Script completed"))
92     // should we squash the script completed string ?
93     {
94       console.sendConsoleMessage(strStatus);
95     }
96   }
97
98   @Override
99   public void showUrl(String url, String target)
100   {
101     try
102     {
103       jalview.util.BrowserLauncher.openURL(url);
104     } catch (Exception e)
105     {
106       Cache.log.error("Failed to launch Jmol-associated url " + url, e);
107       // TODO: 2.6 : warn user if browser was not configured.
108     }
109   }
110
111   @Override
112   public void refreshGUI()
113   {
114     // appJmolWindow.repaint();
115     javax.swing.SwingUtilities.invokeLater(new Runnable()
116     {
117       public void run()
118       {
119         appJmolWindow.updateTitleAndMenus();
120         appJmolWindow.revalidate();
121       }
122     });
123   }
124
125   public void updateColours(Object source)
126   {
127     AlignmentPanel ap = (AlignmentPanel) source, topap;
128     // ignore events from panels not used to colour this view
129     if (!appJmolWindow.isUsedforcolourby(ap))
130     {
131       return;
132     }
133     if (!isLoadingFromArchive())
134     {
135       colourBySequence(ap.av.isShowSequenceFeatures(), ap);
136     }
137   }
138
139   public void notifyScriptTermination(String strStatus, int msWalltime)
140   {
141     // todo - script termination doesn't happen ?
142     // if (console != null)
143     // console.notifyScriptTermination(strStatus,
144     // msWalltime);
145   }
146
147   public void showUrl(String url)
148   {
149     showUrl(url, "jmol");
150   }
151
152   public void newJmolPopup(boolean translateLocale, String menuName,
153           boolean asPopup)
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   @Override
177   protected JmolAppConsoleInterface createJmolConsole(JmolViewer viewer2,
178           Container consolePanel, String buttonsToShow)
179   {
180     return new AppConsole(viewer, consolePanel, buttonsToShow);
181   }
182
183   @Override
184   protected void releaseUIResources()
185   {
186     appJmolWindow = null;
187     closeConsole();
188   }
189
190   @Override
191   public void releaseReferences(Object svl)
192   {
193     if (svl instanceof SeqPanel)
194     {
195       appJmolWindow.removeAlignmentPanel(((SeqPanel) svl).ap);
196     }
197   }
198 }