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