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