Jalview 2.6 source licence
[jalview.git] / src / jalview / appletgui / ExtJmol.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
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  */
18 package jalview.appletgui;
19
20 import java.awt.Container;
21 import java.util.BitSet;
22 import java.util.Hashtable;
23 import java.util.Vector;
24
25 import org.jmol.api.JmolAppConsoleInterface;
26 import org.jmol.api.JmolViewer;
27
28 import jalview.api.FeatureRenderer;
29 import jalview.api.SequenceRenderer;
30 import jalview.datamodel.PDBEntry;
31 import jalview.datamodel.SequenceI;
32 import jalview.ext.jmol.JalviewJmolBinding;
33
34 /**
35  * bind an alignment view to an external Jmol instance.
36  * @author JimP
37  *
38  */
39 public class ExtJmol extends JalviewJmolBinding
40 {
41
42   private AlignmentPanel ap;
43
44   protected ExtJmol(jalview.appletgui.AlignFrame alframe, PDBEntry[] pdbentry, SequenceI[][] seq, String[][] chains,
45           String protocol)
46   {
47     super(pdbentry, seq, chains, protocol);
48   }
49
50   public ExtJmol(JmolViewer viewer, AlignmentPanel alignPanel,
51           SequenceI[][] seqs)
52   {
53     super(viewer);
54     ap = alignPanel;
55     this.sequence = seqs;
56     notifyFileLoaded(null, null, null, null, 0);
57   }
58
59   public void updateColours(Object source)
60   {
61     
62     // TODO Auto-generated method stub
63
64   }
65
66   public void showUrl(String arg0)
67   {
68     showUrl(arg0, "jmol");
69   }
70
71   public FeatureRenderer getFeatureRenderer()
72   {
73     if (ap.av.showSequenceFeatures)
74     {
75       return ap.getFeatureRenderer();
76     }
77     else
78     {
79       return null;
80     }
81   }
82
83   public SequenceRenderer getSequenceRenderer()
84   {
85     return ap.getSequenceRenderer();
86   }
87
88   public void notifyScriptTermination(String strStatus, int msWalltime)
89   {
90     // ignore
91   }
92
93   public void sendConsoleEcho(String strEcho)
94   {
95     // ignore
96   }
97
98   public void sendConsoleMessage(String strStatus)
99   {
100     // ignore
101   }
102
103   public void showUrl(String url, String target)
104   {
105     ap.alignFrame.showURL(url, target);
106   }
107
108   public void refreshGUI()
109   {
110     // ignore
111   }
112
113   public void selectionChanged(BitSet arg0)
114   {
115     System.out.println(arg0);
116   }
117
118   public void refreshPdbEntries()
119   {
120     Vector pdbe = new Vector();
121     Hashtable fileids = new Hashtable();
122     SequenceI[] sq = ap.av.getAlignment().getSequencesArray();
123     for (int s=0;s<sq.length;s++)
124     {
125       Vector pdbids = sq[s].getPDBId();
126       if (pdbids!=null)
127       {
128         for (int pe=0,peSize=pdbids.size(); pe<peSize; pe++)
129         {
130           PDBEntry pentry = (PDBEntry) pdbids.elementAt(pe);
131           if (!fileids.containsKey(pentry.getId())) {
132             pdbe.addElement(pentry);
133           }
134         }
135       }
136     }
137     pdbentry = new PDBEntry[pdbe.size()];
138     for (int pe=0;pe<pdbe.size(); pe++)
139     {
140       pdbentry[pe] = (PDBEntry) pdbe.elementAt(pe);
141     }
142   }
143
144   @Override
145   public void showConsole(boolean show)
146   {
147     // This never gets called because we haven't overriden the associated Jmol's console
148     System.err.println("WARNING: unexpected call to ExtJmol's showConsole method. (showConsole="+show);
149   }
150
151   @Override
152   protected JmolAppConsoleInterface createJmolConsole(JmolViewer viewer2,
153           Container consolePanel, String buttonsToShow)
154   {
155     // TODO Auto-generated method stub
156     return null;
157   }
158   @Override
159   protected void releaseUIResources()
160   {
161     ap = null;
162     if (console!=null) {
163       try {
164         console.setVisible(false);
165       } catch (Error e) {} catch (Exception x) {};
166       console=null;
167     }
168     
169   }
170
171 }