d3dad58f982edccc05f422578f0e94b0eae4b445
[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  * 
37  * @author JimP
38  * 
39  */
40 public class ExtJmol extends JalviewJmolBinding
41 {
42
43   private AlignmentPanel ap;
44
45   protected ExtJmol(jalview.appletgui.AlignFrame alframe,
46           PDBEntry[] pdbentry, SequenceI[][] seq, String[][] chains,
47           String protocol)
48   {
49     super(pdbentry, seq, chains, protocol);
50   }
51
52   public ExtJmol(JmolViewer viewer, AlignmentPanel alignPanel,
53           SequenceI[][] seqs)
54   {
55     super(viewer);
56     ap = alignPanel;
57     this.sequence = seqs;
58     notifyFileLoaded(null, null, null, null, 0);
59   }
60
61   public void updateColours(Object source)
62   {
63
64     // TODO Auto-generated method stub
65
66   }
67
68   public void showUrl(String arg0)
69   {
70     showUrl(arg0, "jmol");
71   }
72
73   public FeatureRenderer getFeatureRenderer()
74   {
75     if (ap.av.showSequenceFeatures)
76     {
77       return ap.getFeatureRenderer();
78     }
79     else
80     {
81       return null;
82     }
83   }
84
85   public SequenceRenderer getSequenceRenderer()
86   {
87     return ap.getSequenceRenderer();
88   }
89
90   public void notifyScriptTermination(String strStatus, int msWalltime)
91   {
92     // ignore
93   }
94
95   public void sendConsoleEcho(String strEcho)
96   {
97     // ignore
98   }
99
100   public void sendConsoleMessage(String strStatus)
101   {
102     // ignore
103   }
104
105   public void showUrl(String url, String target)
106   {
107     ap.alignFrame.showURL(url, target);
108   }
109
110   public void refreshGUI()
111   {
112     // ignore
113   }
114
115   public void selectionChanged(BitSet arg0)
116   {
117     System.out.println(arg0);
118   }
119
120   public void refreshPdbEntries()
121   {
122     Vector pdbe = new Vector();
123     Hashtable fileids = new Hashtable();
124     SequenceI[] sq = ap.av.getAlignment().getSequencesArray();
125     for (int s = 0; s < sq.length; s++)
126     {
127       Vector pdbids = sq[s].getPDBId();
128       if (pdbids != null)
129       {
130         for (int pe = 0, peSize = pdbids.size(); pe < peSize; pe++)
131         {
132           PDBEntry pentry = (PDBEntry) pdbids.elementAt(pe);
133           if (!fileids.containsKey(pentry.getId()))
134           {
135             pdbe.addElement(pentry);
136           }
137         }
138       }
139     }
140     pdbentry = new PDBEntry[pdbe.size()];
141     for (int pe = 0; pe < pdbe.size(); pe++)
142     {
143       pdbentry[pe] = (PDBEntry) pdbe.elementAt(pe);
144     }
145   }
146
147   @Override
148   public void showConsole(boolean show)
149   {
150     // This never gets called because we haven't overriden the associated Jmol's
151     // console
152     System.err
153             .println("WARNING: unexpected call to ExtJmol's showConsole method. (showConsole="
154                     + show);
155   }
156
157   @Override
158   protected JmolAppConsoleInterface createJmolConsole(JmolViewer viewer2,
159           Container consolePanel, String buttonsToShow)
160   {
161     // TODO Auto-generated method stub
162     return null;
163   }
164
165   @Override
166   protected void releaseUIResources()
167   {
168     ap = null;
169     if (console != null)
170     {
171       try
172       {
173         console.setVisible(false);
174       } catch (Error e)
175       {
176       } catch (Exception x)
177       {
178       }
179       ;
180       console = null;
181     }
182
183   }
184
185 }