babffedf90ffb124a6d04cb9aa1ea620d20a262a
[jalview.git] / src / jalview / gui / AppJmolBinding.java
1 /**
2  * 
3  */
4 package jalview.gui;
5
6 import java.awt.Container;
7 import java.util.BitSet;
8
9 import javax.swing.JPanel;
10
11 import jalview.bin.Cache;
12 import jalview.datamodel.PDBEntry;
13 import jalview.datamodel.SequenceI;
14
15 import org.jmol.api.JmolAppConsoleInterface;
16 import org.jmol.api.JmolViewer;
17 import org.jmol.popup.JmolPopup;
18 import org.openscience.jmol.app.jmolpanel.AppConsole;
19
20 public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding
21 {
22
23   /**
24    * 
25    */
26   private AppJmol appJmolWindow;
27
28   public AppJmolBinding(AppJmol appJmol, PDBEntry[] pdbentry,
29           SequenceI[][] sequenceIs, String[][] chains, String protocol)
30   {
31     super(pdbentry, sequenceIs, chains, protocol);
32     appJmolWindow = appJmol;
33   }
34
35   FeatureRenderer fr = null;
36
37   @Override
38   public jalview.api.FeatureRenderer getFeatureRenderer()
39   {
40     if (appJmolWindow.ap.av.showSequenceFeatures)
41     {
42       if (fr == null)
43       {
44         fr = new FeatureRenderer(appJmolWindow.ap);
45       }
46
47       fr.transferSettings(appJmolWindow.ap.seqPanel.seqCanvas
48               .getFeatureRenderer());
49     }
50
51     return fr;
52   }
53
54   @Override
55   public jalview.api.SequenceRenderer getSequenceRenderer()
56   {
57     return new SequenceRenderer(appJmolWindow.ap.av);
58   }
59
60   public void sendConsoleEcho(String strEcho)
61   {
62     if (console != null)
63     {
64       console.sendConsoleEcho(strEcho);
65     }
66   }
67
68   public void sendConsoleMessage(String strStatus)
69   {
70     if (console != null && strStatus != null)
71     // && !strStatus.equals("Script completed"))
72     // should we squash the script completed string ?
73     {
74       console.sendConsoleMessage(strStatus);
75     }
76   }
77
78   @Override
79   public void showUrl(String url, String target)
80   {
81     try
82     {
83       jalview.util.BrowserLauncher.openURL(url);
84     } catch (Exception e)
85     {
86       Cache.log.error("Failed to launch Jmol-associated url " + url, e);
87       // TODO: 2.6 : warn user if browser was not configured.
88     }
89   }
90
91   @Override
92   public void refreshGUI()
93   {
94     // appJmolWindow.repaint();
95     javax.swing.SwingUtilities.invokeLater(new Runnable() {
96       public void run() {
97         appJmolWindow.updateTitleAndMenus();
98         appJmolWindow.revalidate();
99       }});
100   }
101
102   public void updateColours(Object source)
103   {
104     AlignmentPanel ap = (AlignmentPanel) source;
105     if (appJmolWindow.ap.alignFrame.getCurrentView() != ap.av)
106       return;
107
108     colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment);
109   }
110
111   public void notifyScriptTermination(String strStatus, int msWalltime)
112   {
113     // todo - script termination doesn't happen ?
114     //if (console != null)
115       //console.notifyScriptTermination(strStatus,
116       //        msWalltime);
117   }
118
119   public void showUrl(String url)
120   {
121     showUrl(url, "jmol");
122   }
123
124   public void newJmolPopup(boolean translateLocale, String menuName,
125           boolean asPopup)
126   {
127
128     jmolpopup = JmolPopup.newJmolPopup(viewer, translateLocale, menuName,
129             asPopup);
130   }
131
132   public void selectionChanged(BitSet arg0)
133   {
134     // TODO Auto-generated method stub
135
136   }
137
138   public void refreshPdbEntries()
139   {
140     // TODO Auto-generated method stub
141
142   }
143
144   public void showConsole(boolean b) {
145     appJmolWindow.showConsole(b);
146   }
147
148   /**
149    * add the given sequences to the mapping scope for the given pdb file handle
150    * 
151    * @param pdbFile
152    *          - pdbFile identifier
153    * @param seq
154    *          - set of sequences it can be mapped to
155    */
156   public void addSequenceForStructFile(String pdbFile, SequenceI[] seq)
157   {
158     for (int pe = 0; pe < pdbentry.length; pe++)
159     {
160       if (pdbentry[pe].getFile().equals(pdbFile))
161       {
162         addSequence(pe, seq);
163       }
164     }
165   }
166
167   @Override
168   protected JmolAppConsoleInterface createJmolConsole(JmolViewer viewer2,
169           Container consolePanel, String buttonsToShow)
170   {
171     return new AppConsole(viewer, null, consolePanel, buttonsToShow);
172   }
173 }