jmol update
[jalview.git] / src / jalview / appletgui / ExtJmol.java
1 package jalview.appletgui;
2
3 import java.awt.Container;
4 import java.util.BitSet;
5 import java.util.Hashtable;
6 import java.util.Vector;
7
8 import org.jmol.api.JmolAppConsoleInterface;
9 import org.jmol.api.JmolViewer;
10
11 import jalview.api.FeatureRenderer;
12 import jalview.api.SequenceRenderer;
13 import jalview.datamodel.PDBEntry;
14 import jalview.datamodel.SequenceI;
15 import jalview.ext.jmol.JalviewJmolBinding;
16
17 /**
18  * bind an alignment view to an external Jmol instance.
19  * @author JimP
20  *
21  */
22 public class ExtJmol extends JalviewJmolBinding
23 {
24
25   private AlignmentPanel ap;
26
27   protected ExtJmol(jalview.appletgui.AlignFrame alframe, PDBEntry[] pdbentry, SequenceI[][] seq, String[][] chains,
28           String protocol)
29   {
30     super(pdbentry, seq, chains, protocol);
31   }
32
33   public ExtJmol(JmolViewer viewer, AlignmentPanel alignPanel,
34           SequenceI[][] seqs)
35   {
36     super(viewer);
37     ap = alignPanel;
38     this.sequence = seqs;
39     notifyFileLoaded(null, null, null, null, 0);
40   }
41
42   public void updateColours(Object source)
43   {
44     
45     // TODO Auto-generated method stub
46
47   }
48
49   public void showUrl(String arg0)
50   {
51     showUrl(arg0, "jmol");
52   }
53
54   public FeatureRenderer getFeatureRenderer()
55   {
56     if (ap.av.showSequenceFeatures)
57     {
58       return ap.getFeatureRenderer();
59     }
60     else
61     {
62       return null;
63     }
64   }
65
66   public SequenceRenderer getSequenceRenderer()
67   {
68     return ap.getSequenceRenderer();
69   }
70
71   public void notifyScriptTermination(String strStatus, int msWalltime)
72   {
73     // ignore
74   }
75
76   public void sendConsoleEcho(String strEcho)
77   {
78     // ignore
79   }
80
81   public void sendConsoleMessage(String strStatus)
82   {
83     // ignore
84   }
85
86   public void showUrl(String url, String target)
87   {
88     ap.alignFrame.showURL(url, target);
89   }
90
91   public void refreshGUI()
92   {
93     // ignore
94   }
95
96   public void selectionChanged(BitSet arg0)
97   {
98     System.out.println(arg0);
99   }
100
101   public void refreshPdbEntries()
102   {
103     Vector pdbe = new Vector();
104     Hashtable fileids = new Hashtable();
105     SequenceI[] sq = ap.av.getAlignment().getSequencesArray();
106     for (int s=0;s<sq.length;s++)
107     {
108       Vector pdbids = sq[s].getPDBId();
109       if (pdbids!=null)
110       {
111         for (int pe=0,peSize=pdbids.size(); pe<peSize; pe++)
112         {
113           PDBEntry pentry = (PDBEntry) pdbids.elementAt(pe);
114           if (!fileids.containsKey(pentry.getId())) {
115             pdbe.addElement(pentry);
116           }
117         }
118       }
119     }
120     pdbentry = new PDBEntry[pdbe.size()];
121     for (int pe=0;pe<pdbe.size(); pe++)
122     {
123       pdbentry[pe] = (PDBEntry) pdbe.elementAt(pe);
124     }
125   }
126
127   @Override
128   public void showConsole(boolean show)
129   {
130     // This never gets called because we haven't overriden the associated Jmol's console
131     System.err.println("WARNING: unexpected call to ExtJmol's showConsole method. (showConsole="+show);
132   }
133
134   @Override
135   protected JmolAppConsoleInterface createJmolConsole(JmolViewer viewer2,
136           Container consolePanel, String buttonsToShow)
137   {
138     // TODO Auto-generated method stub
139     return null;
140   }
141   @Override
142   protected void releaseUIResources()
143   {
144     ap = null;
145     if (console!=null) {
146       try {
147         console.setVisible(false);
148       } catch (Error e) {} catch (Exception x) {};
149       console=null;
150     }
151     
152   }
153
154 }