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