JAL-1432 updated copyright notices
[jalview.git] / src / jalview / appletgui / ExtJmol.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3  * Copyright (C) 2014 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 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.appletgui;
20
21 import java.awt.Container;
22 import java.util.BitSet;
23 import java.util.Hashtable;
24 import java.util.Vector;
25
26 import org.jmol.api.JmolAppConsoleInterface;
27 import org.jmol.api.JmolViewer;
28
29 import jalview.api.AlignmentViewPanel;
30 import jalview.api.FeatureRenderer;
31 import jalview.api.SequenceRenderer;
32 import jalview.datamodel.PDBEntry;
33 import jalview.datamodel.SequenceI;
34 import jalview.ext.jmol.JalviewJmolBinding;
35
36 /**
37  * bind an alignment view to an external Jmol instance.
38  * 
39  * @author JimP
40  * 
41  */
42 public class ExtJmol extends JalviewJmolBinding
43 {
44
45   private AlignmentPanel ap;
46
47   protected ExtJmol(jalview.appletgui.AlignFrame alframe,
48           PDBEntry[] pdbentry, SequenceI[][] seq, String[][] chains,
49           String protocol)
50   {
51     super(alframe.alignPanel.getStructureSelectionManager(), pdbentry, seq,
52             chains, protocol);
53   }
54
55   public ExtJmol(JmolViewer viewer, AlignmentPanel alignPanel,
56           SequenceI[][] seqs)
57   {
58     super(alignPanel.getStructureSelectionManager(), viewer);
59     ap = alignPanel;
60     this.sequence = seqs;
61     notifyFileLoaded(null, null, null, null, 0);
62   }
63
64   public void updateColours(Object source)
65   {
66
67     // TODO Auto-generated method stub
68
69   }
70
71   public void showUrl(String arg0)
72   {
73     showUrl(arg0, "jmol");
74   }
75
76   public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
77   {
78     AlignmentPanel ap = (AlignmentPanel) alignment;
79     if (ap.av.showSequenceFeatures)
80     {
81       return ap.getFeatureRenderer();
82     }
83     else
84     {
85       return null;
86     }
87   }
88
89   public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
90   {
91     return ((AlignmentPanel) alignment).getSequenceRenderer();
92   }
93
94   public void notifyScriptTermination(String strStatus, int msWalltime)
95   {
96     // ignore
97   }
98
99   public void sendConsoleEcho(String strEcho)
100   {
101     // ignore
102   }
103
104   public void sendConsoleMessage(String strStatus)
105   {
106     // ignore
107   }
108
109   public void showUrl(String url, String target)
110   {
111     ap.alignFrame.showURL(url, target);
112   }
113
114   public void refreshGUI()
115   {
116     // ignore
117   }
118
119   public void selectionChanged(BitSet arg0)
120   {
121     System.out.println(arg0);
122   }
123
124   public void refreshPdbEntries()
125   {
126     Vector pdbe = new Vector();
127     Hashtable fileids = new Hashtable();
128     SequenceI[] sq = ap.av.getAlignment().getSequencesArray();
129     for (int s = 0; s < sq.length; s++)
130     {
131       Vector pdbids = sq[s].getPDBId();
132       if (pdbids != null)
133       {
134         for (int pe = 0, peSize = pdbids.size(); pe < peSize; pe++)
135         {
136           PDBEntry pentry = (PDBEntry) pdbids.elementAt(pe);
137           if (!fileids.containsKey(pentry.getId()))
138           {
139             pdbe.addElement(pentry);
140           }
141         }
142       }
143     }
144     pdbentry = new PDBEntry[pdbe.size()];
145     for (int pe = 0; pe < pdbe.size(); pe++)
146     {
147       pdbentry[pe] = (PDBEntry) pdbe.elementAt(pe);
148     }
149   }
150
151   @Override
152   public void showConsole(boolean show)
153   {
154     // This never gets called because we haven't overriden the associated Jmol's
155     // console
156     System.err
157             .println("WARNING: unexpected call to ExtJmol's showConsole method. (showConsole="
158                     + show);
159   }
160
161   @Override
162   protected JmolAppConsoleInterface createJmolConsole(JmolViewer viewer2,
163           Container consolePanel, String buttonsToShow)
164   {
165     // TODO Auto-generated method stub
166     return null;
167   }
168
169   @Override
170   protected void releaseUIResources()
171   {
172     ap = null;
173     if (console != null)
174     {
175       try
176       {
177         console.setVisible(false);
178       } catch (Error e)
179       {
180       } catch (Exception x)
181       {
182       }
183       ;
184       console = null;
185     }
186
187   }
188
189   @Override
190   public void releaseReferences(Object svl)
191   {
192     // TODO Auto-generated method stub
193
194   }
195
196 }