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