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