JAL-2422 pull up refactoring in preparation for ChimeraX subclasses
[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.api.structures.JalviewStructureDisplayI;
25 import jalview.bin.Cache;
26 import jalview.datamodel.PDBEntry;
27 import jalview.datamodel.SequenceI;
28 import jalview.ext.jmol.JalviewJmolBinding;
29 import jalview.io.DataSourceType;
30 import jalview.structure.StructureSelectionManager;
31
32 import java.awt.Container;
33 import java.util.Map;
34
35 import javax.swing.JComponent;
36
37 import org.jmol.api.JmolAppConsoleInterface;
38 import org.jmol.java.BS;
39 import org.openscience.jmol.app.jmolpanel.console.AppConsole;
40
41 public class AppJmolBinding extends JalviewJmolBinding
42 {
43   public AppJmolBinding(AppJmol appJmol, StructureSelectionManager sSm,
44           PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
45           DataSourceType protocol)
46   {
47     super(sSm, pdbentry, sequenceIs, protocol);
48     setViewer(appJmol);
49   }
50
51   @Override
52   public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
53   {
54     return new SequenceRenderer(((AlignmentPanel) alignment).av);
55   }
56
57   @Override
58   public void sendConsoleEcho(String strEcho)
59   {
60     if (console != null)
61     {
62       console.sendConsoleEcho(strEcho);
63     }
64   }
65
66   @Override
67   public void sendConsoleMessage(String strStatus)
68   {
69     if (console != null && strStatus != null)
70     // && !strStatus.equals("Script completed"))
71     // should we squash the script completed string ?
72     {
73       console.sendConsoleMessage(strStatus);
74     }
75   }
76
77   @Override
78   public void showUrl(String url, String target)
79   {
80     try
81     {
82       jalview.util.BrowserLauncher.openURL(url);
83     } catch (Exception e)
84     {
85       Cache.log.error("Failed to launch Jmol-associated url " + url, e);
86       // TODO: 2.6 : warn user if browser was not configured.
87     }
88   }
89
90   @Override
91   public void refreshGUI()
92   {
93     // appJmolWindow.repaint();
94     javax.swing.SwingUtilities.invokeLater(new Runnable()
95     {
96       @Override
97       public void run()
98       {
99         JalviewStructureDisplayI theViewer = getViewer();
100         theViewer.updateTitleAndMenus();
101         ((JComponent) theViewer).revalidate();
102       }
103     });
104   }
105
106   @Override
107   public void updateColours(Object source)
108   {
109     AlignmentPanel ap = (AlignmentPanel) source;
110     // ignore events from panels not used to colour this view
111     if (!getViewer().isUsedForColourBy(ap))
112     {
113       return;
114     }
115     if (!isLoadingFromArchive())
116     {
117       colourBySequence(ap);
118     }
119   }
120
121   @Override
122   public void notifyScriptTermination(String strStatus, int msWalltime)
123   {
124     // todo - script termination doesn't happen ?
125     // if (console != null)
126     // console.notifyScriptTermination(strStatus,
127     // msWalltime);
128   }
129
130   @Override
131   public void showUrl(String url)
132   {
133     showUrl(url, "jmol");
134   }
135
136   public void newJmolPopup(String menuName)
137   {
138     // jmolpopup = new JmolAwtPopup();
139     // jmolpopup.jpiInitialize((viewer), menuName);
140   }
141
142   @Override
143   public void selectionChanged(BS arg0)
144   {
145     // TODO Auto-generated method stub
146
147   }
148
149   @Override
150   public void refreshPdbEntries()
151   {
152     // TODO Auto-generated method stub
153
154   }
155
156   @Override
157   public void showConsole(boolean b)
158   {
159     getViewer().showConsole(b);
160   }
161
162   @Override
163   protected JmolAppConsoleInterface createJmolConsole(
164           Container consolePanel, String buttonsToShow)
165   {
166     jmolViewer.setJmolCallbackListener(this);
167     return new AppConsole(jmolViewer, consolePanel, buttonsToShow);
168   }
169
170   @Override
171   protected void releaseUIResources()
172   {
173     setViewer(null);
174     closeConsole();
175   }
176
177   @Override
178   public void releaseReferences(Object svl)
179   {
180     if (svl instanceof SeqPanel)
181     {
182       getViewer().removeAlignmentPanel(((SeqPanel) svl).ap);
183     }
184   }
185
186   @Override
187   public Map<String, Object> getJSpecViewProperty(String arg0)
188   {
189     // TODO Auto-generated method stub
190     return null;
191   }
192 }