39d198d00eea01050a75a4bdf8bfd47fbeae65d9
[jalview.git] / src / jalview / gui / AppJmolBinding.java
1 /**
2  * 
3  */
4 package jalview.gui;
5
6 import java.util.BitSet;
7 import java.util.Vector;
8
9 import jalview.bin.Cache;
10 import jalview.datamodel.PDBEntry;
11 import jalview.datamodel.SequenceI;
12
13 import org.jmol.popup.JmolPopup;
14
15 class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding
16 {
17
18   /**
19    * 
20    */
21   private AppJmol appJmolWindow;
22
23   public AppJmolBinding(AppJmol appJmol, PDBEntry[] pdbentry,
24           SequenceI[] seq, String[] chains, String protocol)
25   {
26     super(pdbentry, seq, chains, protocol);
27     appJmolWindow = appJmol;
28   }
29   FeatureRenderer fr=null;
30   @Override
31   public jalview.api.FeatureRenderer getFeatureRenderer()
32   {
33     if (appJmolWindow.ap.av.showSequenceFeatures)
34     {
35       if (fr == null)
36       {
37         fr = new FeatureRenderer(appJmolWindow.ap);
38       }
39
40       fr.transferSettings(appJmolWindow.ap.seqPanel.seqCanvas
41                       .getFeatureRenderer());
42     }
43
44     return fr;
45   }
46
47   @Override
48   public jalview.api.SequenceRenderer getSequenceRenderer()
49   {
50     return new SequenceRenderer(appJmolWindow.ap.av);
51   }
52
53   public void sendConsoleEcho(String strEcho)
54   {
55     if (appJmolWindow.scriptWindow != null)
56     {
57       appJmolWindow.scriptWindow.sendConsoleEcho(strEcho);
58     }
59   }
60
61   public void sendConsoleMessage(String strStatus)
62   {
63     if (appJmolWindow.scriptWindow!=null && strStatus != null
64             )
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       jalview.util.BrowserLauncher.openURL(url);
77     } catch (Exception e) {
78       Cache.log.error("Failed to launch Jmol-associated url " + url, e);
79       // TODO: 2.6 : warn user if browser was not configured.
80     }
81   }
82
83   @Override
84   public void refreshGUI()
85   {
86     // appJmolWindow.repaint();
87     appJmolWindow.updateTitleAndMenus();
88   }
89
90   public void updateColours(Object source)
91   {
92     AlignmentPanel ap = (AlignmentPanel) source;
93     if (appJmolWindow.ap.alignFrame.getCurrentView()!=ap.av)
94       return;
95     
96     colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment);
97   }
98
99   public void notifyScriptTermination(String strStatus, int msWalltime)
100   {
101     if (appJmolWindow.scriptWindow != null)
102       appJmolWindow.scriptWindow.notifyScriptTermination(strStatus, msWalltime);
103   }
104
105   public void showUrl(String url)
106   {
107     showUrl(url,"jmol");
108   }
109
110   public void newJmolPopup(boolean translateLocale, String menuName,
111           boolean asPopup)
112   {
113
114     jmolpopup = JmolPopup.newJmolPopup(viewer, translateLocale, menuName,
115             asPopup);
116   }
117   public synchronized void addSequence(SequenceI[] seq)
118   {
119     Vector v = new Vector();
120     for (int i = 0; i < sequence.length; i++)
121       v.addElement(sequence[i]);
122
123     for (int i = 0; i < seq.length; i++)
124       if (!v.contains(seq[i]))
125         v.addElement(seq[i]);
126
127     SequenceI[] tmp = new SequenceI[v.size()];
128     v.copyInto(tmp);
129     sequence = tmp;
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 }