d2efb932ffbf582358ee7564e4ba85dd20fc2938
[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     appJmolWindow.updateTitleAndMenus();
90   }
91
92   public void updateColours(Object source)
93   {
94     AlignmentPanel ap = (AlignmentPanel) source;
95     if (appJmolWindow.ap.alignFrame.getCurrentView() != ap.av)
96       return;
97
98     colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment);
99   }
100
101   public void notifyScriptTermination(String strStatus, int msWalltime)
102   {
103     if (appJmolWindow.scriptWindow != null)
104       appJmolWindow.scriptWindow.notifyScriptTermination(strStatus,
105               msWalltime);
106   }
107
108   public void showUrl(String url)
109   {
110     showUrl(url, "jmol");
111   }
112
113   public void newJmolPopup(boolean translateLocale, String menuName,
114           boolean asPopup)
115   {
116
117     jmolpopup = JmolPopup.newJmolPopup(viewer, translateLocale, menuName,
118             asPopup);
119   }
120
121   public void selectionChanged(BitSet arg0)
122   {
123     // TODO Auto-generated method stub
124
125   }
126
127   public void refreshPdbEntries()
128   {
129     // TODO Auto-generated method stub
130
131   }
132
133
134   /**
135    * add the given sequences to the mapping scope for the given pdb file handle
136    * 
137    * @param pdbFile
138    *          - pdbFile identifier
139    * @param seq
140    *          - set of sequences it can be mapped to
141    */
142   public void addSequenceForStructFile(String pdbFile, SequenceI[] seq)
143   {
144     for (int pe = 0; pe < pdbentry.length; pe++)
145     {
146       if (pdbentry[pe].getFile().equals(pdbFile))
147       {
148         addSequence(pe, seq);
149       }
150     }
151   }
152
153 }