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