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