89228d51cdf51e6a024792ec4c373ba5462df984
[jalview.git] / src / jalview / appletgui / ExtJmol.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.appletgui;
22
23 import jalview.api.AlignmentViewPanel;
24 import jalview.api.FeatureRenderer;
25 import jalview.api.SequenceRenderer;
26 import jalview.datamodel.PDBEntry;
27 import jalview.datamodel.SequenceI;
28 import jalview.ext.jmol.JalviewJmolBinding;
29 import jalview.gui.IProgressIndicator;
30 import jalview.io.DataSourceType;
31
32 import java.awt.Container;
33 import java.util.ArrayList;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Vector;
37
38 import org.jmol.api.JmolAppConsoleInterface;
39 import org.jmol.java.BS;
40 import org.jmol.viewer.Viewer;
41
42 /**
43  * bind an alignment view to an external Jmol instance.
44  * 
45  * @author JimP
46  * 
47  */
48 public class ExtJmol extends JalviewJmolBinding
49 {
50
51   private AlignmentPanel ap;
52
53   protected ExtJmol(AlignFrame alframe, PDBEntry[] pdbentry,
54           SequenceI[][] seq, DataSourceType protocol)
55   {
56     super(alframe.alignPanel.getStructureSelectionManager(), pdbentry, seq,
57             protocol);
58   }
59
60   public ExtJmol(Viewer viewer, AlignmentPanel alignPanel,
61           SequenceI[][] seqs)
62   {
63     super(alignPanel.getStructureSelectionManager(), seqs, viewer);
64     ap = alignPanel;
65     notifyFileLoaded(null, null, null, null, 0);
66   }
67
68   @Override
69   protected IProgressIndicator getIProgressIndicator()
70   {
71     // no progress indicators on applet (could access javascript for this)
72     return null;
73   }
74
75   @Override
76   public void updateColours(Object source)
77   {
78
79     // TODO Auto-generated method stub
80
81   }
82
83   @Override
84   public void showUrl(String arg0)
85   {
86     showUrl(arg0, "jmol");
87   }
88
89   @Override
90   public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
91   {
92     AlignmentPanel alignPanel = (AlignmentPanel) alignment;
93     if (alignPanel.av.isShowSequenceFeatures())
94     {
95       return alignPanel.getFeatureRenderer();
96     }
97     else
98     {
99       return null;
100     }
101   }
102
103
104   @Override
105   public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
106   {
107     return ((AlignmentPanel) alignment).getSequenceRenderer();
108   }
109
110   @Override
111   public void notifyScriptTermination(String strStatus, int msWalltime)
112   {
113     // ignore
114   }
115
116   @Override
117   public void sendConsoleEcho(String strEcho)
118   {
119     // ignore
120   }
121
122   @Override
123   public void sendConsoleMessage(String strStatus)
124   {
125     // ignore
126   }
127
128   @Override
129   public void showUrl(String url, String target)
130   {
131     ap.alignFrame.showURL(url, target);
132   }
133
134   @Override
135   public void refreshGUI()
136   {
137     // ignore
138   }
139
140   @Override
141   public void selectionChanged(BS arg0)
142   {
143     System.out.println(arg0);
144   }
145
146   @Override
147   public void refreshPdbEntries()
148   {
149     List<PDBEntry> pdbe = new ArrayList<>();
150     List<String> fileids = new ArrayList<>();
151     SequenceI[] sq = ap.av.getAlignment().getSequencesArray();
152     for (int s = 0; s < sq.length; s++)
153     {
154       Vector<PDBEntry> pdbids = sq[s].getAllPDBEntries();
155       if (pdbids != null)
156       {
157         for (int pe = 0, peSize = pdbids.size(); pe < peSize; pe++)
158         {
159           PDBEntry pentry = pdbids.elementAt(pe);
160           if (!fileids.contains(pentry.getId()))
161           {
162             pdbe.add(pentry);
163           }
164           else
165           {
166             fileids.add(pentry.getId());
167           }
168         }
169       }
170     }
171     PDBEntry[] newEntries = new PDBEntry[pdbe.size()];
172     for (int pe = 0; pe < pdbe.size(); pe++)
173     {
174       newEntries[pe] = pdbe.get(pe);
175     }
176     setPdbentry(newEntries);
177   }
178
179   @Override
180   public void showConsole(boolean show)
181   {
182     // This never gets called because we haven't overriden the associated Jmol's
183     // console
184     System.err.println(
185             "WARNING: unexpected call to ExtJmol's showConsole method. (showConsole="
186                     + show);
187   }
188
189   @Override
190   protected JmolAppConsoleInterface createJmolConsole(
191           Container consolePanel, String buttonsToShow)
192   {
193     // TODO Auto-generated method stub
194     return null;
195   }
196
197   @Override
198   protected void releaseUIResources()
199   {
200     ap = null;
201     closeConsole();
202
203   }
204
205   @Override
206   public void releaseReferences(Object svl)
207   {
208     // TODO Auto-generated method stub
209
210   }
211
212   @Override
213   public Map<String, Object> getJSpecViewProperty(String arg0)
214   {
215     // TODO Auto-generated method stub
216     return null;
217   }
218
219 }