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