JAL-1990 suggested revision to separate references to UI components from datamodel...
[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.Map;
32
33 import org.jmol.api.JmolAppConsoleInterface;
34 import org.jmol.java.BS;
35 import org.openscience.jmol.app.jmolpanel.console.AppConsole;
36
37 public class AppJmolBinding extends JalviewJmolBinding
38 {
39   private AppJmol appJmolWindow;
40
41   private FeatureRenderer fr = null;
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   @Override
52   protected IProgressIndicator getIProgressIndicator()
53   {
54     return appJmolWindow.progressBar;
55   }
56   @Override
57   public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
58   {
59     AlignmentPanel ap = (alignment == null) ? appJmolWindow
60             .getAlignmentPanel() : (AlignmentPanel) alignment;
61     if (ap.av.isShowSequenceFeatures())
62     {
63       if (fr == null)
64       {
65         fr = (jalview.gui.FeatureRenderer) ap.cloneFeatureRenderer();
66       }
67       else
68       {
69         ap.updateFeatureRenderer(fr);
70       }
71     }
72
73     return fr;
74   }
75
76   @Override
77   public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
78   {
79     return new SequenceRenderer(((AlignmentPanel) alignment).av);
80   }
81
82   @Override
83   public void sendConsoleEcho(String strEcho)
84   {
85     if (console != null)
86     {
87       console.sendConsoleEcho(strEcho);
88     }
89   }
90
91   @Override
92   public void sendConsoleMessage(String strStatus)
93   {
94     if (console != null && strStatus != null)
95     // && !strStatus.equals("Script completed"))
96     // should we squash the script completed string ?
97     {
98       console.sendConsoleMessage(strStatus);
99     }
100   }
101
102   @Override
103   public void showUrl(String url, String target)
104   {
105     try
106     {
107       jalview.util.BrowserLauncher.openURL(url);
108     } catch (Exception e)
109     {
110       Cache.log.error("Failed to launch Jmol-associated url " + url, e);
111       // TODO: 2.6 : warn user if browser was not configured.
112     }
113   }
114
115   @Override
116   public void refreshGUI()
117   {
118     // appJmolWindow.repaint();
119     javax.swing.SwingUtilities.invokeLater(new Runnable()
120     {
121       @Override
122       public void run()
123       {
124         appJmolWindow.updateTitleAndMenus();
125         appJmolWindow.revalidate();
126       }
127     });
128   }
129
130   @Override
131   public void updateColours(Object source)
132   {
133     AlignmentPanel ap = (AlignmentPanel) source;
134     // ignore events from panels not used to colour this view
135     if (!appJmolWindow.isUsedforcolourby(ap))
136     {
137       return;
138     }
139     if (!isLoadingFromArchive())
140     {
141       colourBySequence(ap);
142     }
143   }
144
145   @Override
146   public void notifyScriptTermination(String strStatus, int msWalltime)
147   {
148     // todo - script termination doesn't happen ?
149     // if (console != null)
150     // console.notifyScriptTermination(strStatus,
151     // msWalltime);
152   }
153
154   @Override
155   public void showUrl(String url)
156   {
157     showUrl(url, "jmol");
158   }
159
160   public void newJmolPopup(String menuName)
161   {
162     // jmolpopup = new JmolAwtPopup();
163     // jmolpopup.jpiInitialize((viewer), menuName);
164   }
165
166   @Override
167   public void selectionChanged(BS arg0)
168   {
169     // TODO Auto-generated method stub
170
171   }
172
173   @Override
174   public void refreshPdbEntries()
175   {
176     // TODO Auto-generated method stub
177
178   }
179
180   @Override
181   public void showConsole(boolean b)
182   {
183     appJmolWindow.showConsole(b);
184   }
185
186   @Override
187   protected JmolAppConsoleInterface createJmolConsole(
188           Container consolePanel, String buttonsToShow)
189   {
190     viewer.setJmolCallbackListener(this);
191     return new AppConsole(viewer, consolePanel, buttonsToShow);
192   }
193
194   @Override
195   protected void releaseUIResources()
196   {
197     appJmolWindow = null;
198     closeConsole();
199   }
200
201   @Override
202   public void releaseReferences(Object svl)
203   {
204     if (svl instanceof SeqPanel)
205     {
206       appJmolWindow.removeAlignmentPanel(((SeqPanel) svl).ap);
207     }
208   }
209
210   @Override
211   public Map<String, Object> getJSpecViewProperty(String arg0)
212   {
213     // TODO Auto-generated method stub
214     return null;
215   }
216 }