fixed column selection cut/paste and self paste.
[jalview.git] / src / jalview / gui / AppJMol.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer
3  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.gui;
20
21 import java.util.regex.*;
22 import java.util.*;
23 import java.awt.*;
24 import javax.swing.*;
25 import javax.swing.event.*;
26 import java.awt.event.*;
27 import java.io.*;
28
29 import jalview.jbgui.GStructureViewer;
30 import jalview.datamodel.*;
31 import jalview.gui.*;
32 import jalview.structure.*;
33 import jalview.datamodel.PDBEntry;
34 import jalview.io.*;
35 import jalview.schemes.*;
36
37 import org.jmol.api.*;
38 import org.jmol.adapter.smarter.SmarterJmolAdapter;
39 import org.jmol.popup.*;
40
41
42 public class AppJMol
43     extends GStructureViewer
44     implements StructureListener, JmolStatusListener, Runnable
45
46 {
47   JmolViewer viewer;
48   JmolPopup jmolpopup;
49   ScriptWindow scriptWindow;
50   PDBEntry pdbentry;
51   SequenceI[] sequence;
52   StructureSelectionManager ssm;
53   JSplitPane splitPane;
54   RenderPanel renderPanel;
55   AlignmentPanel ap;
56   String fileLoadingError;
57   boolean colourBySequence = true;
58   boolean loadingFromArchive = false;
59   Vector atomsPicked = new Vector();
60
61   public AppJMol(String file, String id,
62                  SequenceI[] seq,
63                  AlignmentPanel ap,
64                  String loadStatus,
65                  Rectangle bounds)
66   {
67     loadingFromArchive = true;
68     pdbentry = new PDBEntry();
69     pdbentry.setFile(file);
70     pdbentry.setId(id);
71     this.sequence = seq;
72     this.ap = ap;
73     this.setBounds(bounds);
74
75     colourBySequence = false;
76     seqColour.setSelected(false);
77
78     jalview.gui.Desktop.addInternalFrame(this, "Loading File",
79                                          bounds.width,bounds.height);
80
81     initJmol(loadStatus);
82
83     this.addInternalFrameListener(new InternalFrameAdapter()
84     {
85       public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
86       {
87         closeViewer();
88       }
89     });
90   }
91
92 public synchronized void addSequence(SequenceI [] seq)
93    {
94     Vector v = new Vector();
95      for(int i=0; i<sequence.length; i++)
96        v.addElement(sequence[i]);
97
98      for(int i=0; i<seq.length; i++)
99       if(!v.contains(seq[i]))
100           v.addElement(seq[i]);
101
102      SequenceI [] tmp = new SequenceI[v.size()];
103      v.copyInto(tmp);
104      sequence = tmp;
105    }
106
107   public AppJMol(PDBEntry pdbentry, SequenceI[] seq, AlignmentPanel ap)
108   {
109     //////////////////////////////////
110     //Is the pdb file already loaded?
111     String alreadyMapped = StructureSelectionManager
112         .getStructureSelectionManager()
113         .alreadyMappedToFile(pdbentry.getId());
114
115     if (alreadyMapped != null)
116     {
117       int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
118           pdbentry.getId() + " is already displayed."
119           + "\nDo you want to map sequences to the visible structure?",
120           "Map Sequences to Visible Window: " + pdbentry.getId(),
121           JOptionPane.YES_NO_OPTION);
122
123       if (option == JOptionPane.YES_OPTION)
124       {
125         StructureSelectionManager.getStructureSelectionManager()
126             .setMapping(seq, alreadyMapped, AppletFormatAdapter.FILE);
127         if (ap.seqPanel.seqCanvas.fr!=null) {
128           ap.seqPanel.seqCanvas.fr.featuresAdded();
129           ap.paintAlignment(true);
130         }
131         return;
132       }
133     }
134     ///////////////////////////////////
135
136     this.ap = ap;
137     this.pdbentry = pdbentry;
138     this.sequence = seq;
139
140     jalview.gui.Desktop.addInternalFrame(this, "Loading File", 400, 400);
141
142     if (pdbentry.getFile() != null)
143     {
144       initJmol("load \""+pdbentry.getFile()+"\"");
145     }
146     else
147     {
148       Thread worker = new Thread(this);
149       worker.start();
150     }
151
152     this.addInternalFrameListener(new InternalFrameAdapter()
153     {
154       public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
155       {
156         closeViewer();
157       }
158     });
159   }
160
161
162   void initJmol(String command)
163   {
164     renderPanel = new RenderPanel();
165
166     this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
167
168     StringBuffer title = new StringBuffer(sequence[0].getName() + ":" +
169                                           pdbentry.getId());
170
171     if (pdbentry.getProperty() != null)
172     {
173       if (pdbentry.getProperty().get("method") != null)
174       {
175         title.append(" Method: ");
176         title.append(pdbentry.getProperty().get("method"));
177       }
178       if (pdbentry.getProperty().get("chains") != null)
179       {
180         title.append(" Chain:");
181         title.append(pdbentry.getProperty().get("chains"));
182       }
183     }
184
185     this.setTitle(title.toString());
186
187     viewer = org.jmol.api.JmolViewer.allocateViewer(renderPanel,
188         new SmarterJmolAdapter());
189
190
191     viewer.setAppletContext("", null, null, "");
192
193     viewer.setJmolStatusListener(this);
194
195     jmolpopup = JmolPopup.newJmolPopup(viewer);
196
197     viewer.evalStringQuiet(command);
198
199     colourBySequence = true;
200   }
201
202
203   void setChainMenuItems(Vector chains)
204   {
205     chainMenu.removeAll();
206
207     JMenuItem menuItem = new JMenuItem("All");
208     menuItem.addActionListener(new ActionListener()
209         {
210           public void actionPerformed(ActionEvent evt)
211           {
212             allChainsSelected = true;
213             for(int i=0; i<chainMenu.getItemCount(); i++)
214             {
215               if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
216                 ( (JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
217             }
218             centerViewer();
219             allChainsSelected = false;
220           }
221         });
222
223     chainMenu.add(menuItem);
224
225     for (int c = 0; c < chains.size(); c++)
226     {
227       menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
228       menuItem.addItemListener(new ItemListener()
229       {
230         public void itemStateChanged(ItemEvent evt)
231         {
232           if (!allChainsSelected)
233             centerViewer();
234         }
235       });
236
237       chainMenu.add(menuItem);
238     }
239   }
240
241   boolean allChainsSelected = false;
242   void centerViewer()
243   {
244     StringBuffer cmd = new StringBuffer();
245     for(int i=0; i<chainMenu.getItemCount(); i++)
246     {
247       if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
248       {
249        JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
250        if(item.isSelected())
251          cmd.append(":"+item.getText()+" or ");
252       }
253     }
254
255     if (cmd.length() > 0)
256       cmd.setLength(cmd.length() - 4);
257
258     viewer.evalStringQuiet("select *;restrict "
259                       +cmd+";cartoon;center "+cmd);
260   }
261
262   void closeViewer()
263   {
264     viewer.setModeMouse(org.jmol.viewer.JmolConstants.MOUSE_NONE);
265     viewer.evalStringQuiet("zap");
266     viewer.setJmolStatusListener(null);
267     viewer = null;
268
269     //We'll need to find out what other
270     // listeners need to be shut down in Jmol
271     StructureSelectionManager
272         .getStructureSelectionManager()
273         .removeStructureViewerListener(this, pdbentry.getFile());
274   }
275
276   public void run()
277   {
278     try
279     {
280       EBIFetchClient ebi = new EBIFetchClient();
281       String query = "pdb:" + pdbentry.getId();
282       pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
283                        .getAbsolutePath());
284       initJmol("load "+pdbentry.getFile());
285     }
286     catch (Exception ex)
287     {
288       ex.printStackTrace();
289     }
290   }
291
292   public void pdbFile_actionPerformed(ActionEvent actionEvent)
293   {
294     JalviewFileChooser chooser = new JalviewFileChooser(
295         jalview.bin.Cache.getProperty(
296             "LAST_DIRECTORY"));
297
298     chooser.setFileView(new JalviewFileView());
299     chooser.setDialogTitle("Save PDB File");
300     chooser.setToolTipText("Save");
301
302     int value = chooser.showSaveDialog(this);
303
304     if (value == JalviewFileChooser.APPROVE_OPTION)
305     {
306       try
307       {
308         BufferedReader in = new BufferedReader(new FileReader(pdbentry.getFile()));
309         File outFile = chooser.getSelectedFile();
310
311         PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
312         String data;
313         while ( (data = in.readLine()) != null)
314         {
315           if (
316               ! (data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1)
317               )
318           {
319             out.println(data);
320           }
321         }
322         out.close();
323       }
324       catch (Exception ex)
325       {
326         ex.printStackTrace();
327       }
328     }
329   }
330
331   public void viewMapping_actionPerformed(ActionEvent actionEvent)
332   {
333     jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
334     jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550,
335                                          600);
336     cap.setText(
337         StructureSelectionManager.getStructureSelectionManager().printMapping(
338             pdbentry.getFile())
339         );
340   }
341
342   /**
343    * DOCUMENT ME!
344    *
345    * @param e DOCUMENT ME!
346    */
347   public void eps_actionPerformed(ActionEvent e)
348   {
349     makePDBImage(jalview.util.ImageMaker.EPS);
350   }
351
352   /**
353    * DOCUMENT ME!
354    *
355    * @param e DOCUMENT ME!
356    */
357   public void png_actionPerformed(ActionEvent e)
358   {
359     makePDBImage(jalview.util.ImageMaker.PNG);
360   }
361
362   void makePDBImage(int type)
363   {
364     int width = getWidth();
365     int height = getHeight();
366
367     jalview.util.ImageMaker im;
368
369     if (type == jalview.util.ImageMaker.PNG)
370     {
371       im = new jalview.util.ImageMaker(this,
372                                        jalview.util.ImageMaker.PNG,
373                                        "Make PNG image from view",
374                                        width, height,
375                                        null, null);
376     }
377     else
378     {
379       im = new jalview.util.ImageMaker(this,
380                                        jalview.util.ImageMaker.EPS,
381                                        "Make EPS file from view",
382                                        width, height,
383                                        null, this.getTitle());
384     }
385
386     if (im.getGraphics() != null)
387     {
388       Rectangle rect = new Rectangle(width, height);
389       viewer.renderScreenImage(im.getGraphics(),
390                                rect.getSize(), rect);
391       im.writeImage();
392     }
393   }
394
395
396   public void seqColour_actionPerformed(ActionEvent actionEvent)
397   {
398     colourBySequence = seqColour.isSelected();
399     colourBySequence(ap);
400   }
401
402   public void chainColour_actionPerformed(ActionEvent actionEvent)
403   {
404     colourBySequence = false;
405     seqColour.setSelected(false);
406     viewer.evalStringQuiet("select *;color chain");
407   }
408
409   public void chargeColour_actionPerformed(ActionEvent actionEvent)
410   {
411     colourBySequence = false;
412     seqColour.setSelected(false);
413     viewer.evalStringQuiet("select *;color white;select ASP,GLU;color red;"
414                       +"select LYS,ARG;color blue;select CYS;color yellow");
415   }
416
417   public void zappoColour_actionPerformed(ActionEvent actionEvent)
418   {
419     setJalviewColourScheme(new ZappoColourScheme());
420   }
421
422   public void taylorColour_actionPerformed(ActionEvent actionEvent)
423   {
424     setJalviewColourScheme(new TaylorColourScheme());
425   }
426
427   public void hydroColour_actionPerformed(ActionEvent actionEvent)
428   {
429     setJalviewColourScheme(new HydrophobicColourScheme());
430   }
431
432   public void helixColour_actionPerformed(ActionEvent actionEvent)
433   {
434     setJalviewColourScheme(new HelixColourScheme());
435   }
436
437   public void strandColour_actionPerformed(ActionEvent actionEvent)
438   {
439     setJalviewColourScheme(new StrandColourScheme());
440   }
441
442   public void turnColour_actionPerformed(ActionEvent actionEvent)
443   {
444     setJalviewColourScheme(new TurnColourScheme());
445   }
446
447   public void buriedColour_actionPerformed(ActionEvent actionEvent)
448   {
449     setJalviewColourScheme(new BuriedColourScheme());
450   }
451
452   public void setJalviewColourScheme(ColourSchemeI cs)
453   {
454     colourBySequence = false;
455     seqColour.setSelected(false);
456
457     if(cs==null)
458       return;
459
460     String res;
461     int index;
462     Color col;
463
464     Enumeration en = ResidueProperties.aa3Hash.keys();
465     StringBuffer command = new StringBuffer("select *;color white;");
466     while(en.hasMoreElements())
467     {
468       res = en.nextElement().toString();
469       index = ((Integer) ResidueProperties.aa3Hash.get(res)).intValue();
470       if(index>20)
471         continue;
472
473       col = cs.findColour(ResidueProperties.aa[index].charAt(0));
474
475       command.append("select "+res+";color["
476                         + col.getRed() + ","
477                         + col.getGreen() + ","
478                         + col.getBlue() + "];");
479     }
480
481     viewer.evalStringQuiet(command.toString());
482   }
483
484   public void userColour_actionPerformed(ActionEvent actionEvent)
485   {
486     new UserDefinedColours(this, null);
487   }
488
489   public void backGround_actionPerformed(ActionEvent actionEvent)
490   {
491     java.awt.Color col = JColorChooser.showDialog(this,
492                                                   "Select Background Colour",
493                                                   null);
494
495     if (col != null)
496     {
497       viewer.evalStringQuiet("background ["
498                         + col.getRed() + ","
499                         + col.getGreen() + ","
500                         + col.getBlue() + "];");
501     }
502   }
503
504
505   public void jmolHelp_actionPerformed(ActionEvent actionEvent)
506   {
507        try{
508          jalview.util.BrowserLauncher.openURL(
509              "http://jmol.sourceforge.net/docs/JmolUserGuide/");
510        }catch(Exception ex){}
511    }
512
513
514   //////////////////////////////////
515   ///StructureListener
516   public String getPdbFile()
517   {
518     return pdbentry.getFile();
519   }
520
521   Pattern pattern = Pattern.compile(
522       "\\[(.*)\\]([0-9]+)(:[a-zA-Z]*)?\\.([a-zA-Z]+)(/[0-9]*)?"
523       );
524
525   String lastMessage;
526   public void mouseOverStructure(int atomIndex, String strInfo)
527   {
528     Matcher matcher = pattern.matcher(strInfo);
529     matcher.find();
530     matcher.group(1);
531     int pdbResNum = Integer.parseInt(matcher.group(2));
532     String chainId = matcher.group(3);
533
534     if (chainId != null)
535       chainId = chainId.substring(1, chainId.length());
536     else
537     {
538       chainId = " ";
539     }
540
541     if (lastMessage == null || !lastMessage.equals(strInfo))
542       ssm.mouseOverStructure(pdbResNum, chainId, pdbentry.getFile());
543
544     lastMessage = strInfo;
545   }
546
547   StringBuffer resetLastRes = new StringBuffer();
548   StringBuffer eval = new StringBuffer();
549
550   public void highlightAtom(int atomIndex, int pdbResNum, String chain, String pdbfile)
551   {
552     if (!pdbfile.equals(pdbentry.getFile()))
553       return;
554
555     if (resetLastRes.length() > 0)
556     {
557       viewer.evalStringQuiet(resetLastRes.toString());
558     }
559
560     eval.setLength(0);
561     eval.append("select " + pdbResNum);
562
563     resetLastRes.setLength(0);
564     resetLastRes.append("select " + pdbResNum);
565
566     if (!chain.equals(" "))
567     {
568       eval.append(":" + chain);
569       resetLastRes.append(":" + chain);
570     }
571
572     eval.append(";color gold;wireframe 100");
573
574     Color col = new Color(viewer.getAtomArgb(atomIndex));
575
576     resetLastRes.append(";color["
577                         + col.getRed() + ","
578                         + col.getGreen() + ","
579                         + col.getBlue() + "];wireframe 0");
580
581     viewer.evalStringQuiet(eval.toString());
582
583   }
584
585   public void updateColours(Object source)
586   {
587     colourBySequence( (AlignmentPanel) source);
588   }
589
590
591 //End StructureListener
592 ////////////////////////////
593
594   FeatureRenderer fr=null;
595   public void colourBySequence(AlignmentPanel ap)
596   {
597     if(!colourBySequence)
598       return;
599
600
601     StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile());
602
603     if (mapping.length < 1)
604       return;
605
606     SequenceRenderer sr = ap.seqPanel.seqCanvas.getSequenceRenderer();
607
608     boolean showFeatures = false;
609
610     if (ap.av.showSequenceFeatures)
611     {
612       showFeatures = true;
613       if (fr == null)
614       {
615         fr = new jalview.gui.FeatureRenderer(ap);
616       }
617
618       fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
619     }
620
621     StringBuffer command = new StringBuffer();
622
623     int lastPos = -1;
624     for (int s = 0; s < sequence.length; s++)
625     {
626       for (int m = 0; m < mapping.length; m++)
627       {
628         if (mapping[m].getSequence() == sequence[s]
629             && ap.av.alignment.findIndex(sequence[s])>-1)
630         {
631           for (int r = 0; r < sequence[s].getLength(); r++)
632           {
633             int pos = mapping[m].getPDBResNum(
634                 sequence[s].findPosition(r));
635
636             if (pos < 1 || pos==lastPos)
637               continue;
638
639             lastPos = pos;
640
641             Color col = sr.getResidueBoxColour(sequence[s], r);
642
643             if (showFeatures)
644               col = fr.findFeatureColour(col, sequence[s], r);
645
646             if (command.toString().endsWith(":" + mapping[m].getChain()+
647                                             ";color["
648                                             + col.getRed() + ","
649                                             + col.getGreen() + ","
650                                             + col.getBlue() + "]"))
651             {
652               command = condenseCommand(command, pos);
653               continue;
654             }
655
656             command.append(";select " + pos);
657
658             if (!mapping[m].getChain().equals(" "))
659             {
660               command.append(":" + mapping[m].getChain());
661             }
662
663             command.append(";color["
664                              + col.getRed() + ","
665                              + col.getGreen() + ","
666                              + col.getBlue() + "]");
667
668           }
669           break;
670         }
671       }
672     }
673
674     viewer.evalStringQuiet(command.toString());
675   }
676
677   StringBuffer condenseCommand(StringBuffer command, int pos)
678   {
679     StringBuffer sb = new StringBuffer(command.substring(0, command.lastIndexOf("select")+7));
680
681     command.delete(0, sb.length());
682
683     String start;
684
685     if (command.indexOf("-") > -1)
686     {
687       start = command.substring(0,command.indexOf("-"));
688     }
689     else
690     {
691       start = command.substring(0, command.indexOf(":"));
692     }
693
694     sb.append(start+"-"+pos+command.substring(command.indexOf(":")));
695
696     return sb;
697   }
698
699   /////////////////////////////////
700   //JmolStatusListener
701
702   public String eval(String strEval)
703   {
704    // System.out.println(strEval);
705    //"# 'eval' is implemented only for the applet.";
706     return null;
707   }
708
709   public void createImage(String file, String type, int quality)
710   {
711     System.out.println("JMOL CREATE IMAGE");
712   }
713
714   public void setCallbackFunction(String callbackType,
715                                   String callbackFunction)
716   {}
717
718   public void notifyFileLoaded(String fullPathName, String fileName,
719                                String modelName, Object clientFile,
720                                String errorMsg)
721   {
722     if(errorMsg!=null)
723     {
724       fileLoadingError = errorMsg;
725       repaint();
726       return;
727     }
728
729     fileLoadingError = null;
730
731     if (fileName != null)
732     {
733
734       //FILE LOADED OK
735       ssm = StructureSelectionManager.getStructureSelectionManager();
736       MCview.PDBfile pdbFile = ssm.setMapping(sequence, pdbentry.getFile(), AppletFormatAdapter.FILE);
737       ssm.addStructureViewerListener(this);
738       Vector chains = new Vector();
739       for(int i=0; i<pdbFile.chains.size(); i++)
740       {
741         chains.addElement(((MCview.PDBChain)pdbFile.chains.elementAt(i)).id);
742       }
743       setChainMenuItems(chains);
744
745       jmolpopup.updateComputedMenus();
746
747       if(!loadingFromArchive)
748       {
749         viewer.evalStringQuiet(
750              "select backbone;restrict;cartoon;wireframe off;spacefill off");
751
752         colourBySequence(ap);
753       }
754       if (fr!=null)
755         fr.featuresAdded();
756
757       loadingFromArchive = false;
758     }
759     else
760       return;
761   }
762
763   public void notifyFrameChanged(int frameNo)
764   {
765     boolean isAnimationRunning = (frameNo <= -2);
766   }
767
768   public void notifyScriptStart(String statusMessage, String additionalInfo)
769   {}
770
771   public void sendConsoleEcho(String strEcho)
772   {
773     if (scriptWindow != null)
774       scriptWindow.sendConsoleEcho(strEcho);
775   }
776
777   public void sendConsoleMessage(String strStatus)
778   {
779     if (scriptWindow != null)
780       scriptWindow.sendConsoleMessage(strStatus);
781   }
782
783   public void notifyScriptTermination(String strStatus, int msWalltime)
784   {
785     if (scriptWindow != null)
786       scriptWindow.notifyScriptTermination(strStatus, msWalltime);
787   }
788
789   public void handlePopupMenu(int x, int y)
790   {
791     jmolpopup.show(x, y);
792   }
793
794   public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
795   {
796     notifyAtomPicked(iatom, strMeasure);
797   }
798
799   public void notifyNewDefaultModeMeasurement(int count, String strInfo)
800   {}
801
802   public void notifyAtomPicked(int atomIndex, String strInfo)
803   {
804     Matcher matcher = pattern.matcher(strInfo);
805     matcher.find();
806
807     matcher.group(1);
808     String resnum = new String(matcher.group(2));
809     String chainId = matcher.group(3);
810
811     String picked = resnum;
812
813     if (chainId != null)
814       picked+=(":"+chainId.substring(1, chainId.length()));
815
816     picked+=".C";
817
818     if (!atomsPicked.contains(picked))
819     {
820       if(chainId!=null)
821       viewer.evalString("select "+picked+";label %n %r:%c");
822     else
823       viewer.evalString("select "+picked+";label %n %r");
824       atomsPicked.addElement(picked);
825     }
826     else
827     {
828       viewer.evalString("select "+picked+";label off");
829       atomsPicked.removeElement(picked);
830     }
831
832     if (scriptWindow != null)
833     {
834       scriptWindow.sendConsoleMessage(strInfo);
835       scriptWindow.sendConsoleMessage("\n");
836     }
837   }
838
839   public void notifyAtomHovered(int atomIndex, String strInfo)
840   {
841     mouseOverStructure(atomIndex, strInfo);
842   }
843
844   public void sendSyncScript(String script, String appletName)
845   {}
846
847   public void showUrl(String url)
848   {}
849
850   public void showConsole(boolean showConsole)
851   {
852     if (scriptWindow == null)
853       scriptWindow = new ScriptWindow(this);
854
855     if(showConsole)
856     {
857       if(splitPane==null)
858       {
859         splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
860         splitPane.setTopComponent(renderPanel);
861         splitPane.setBottomComponent(scriptWindow);
862         this.getContentPane().add(splitPane, BorderLayout.CENTER);
863       }
864
865       splitPane.setDividerLocation(getHeight()-200);
866       splitPane.validate();
867     }
868     else
869     {
870       if (splitPane != null)
871         splitPane.setVisible(false);
872
873       splitPane = null;
874
875       this.getContentPane().add(renderPanel, BorderLayout.CENTER);
876     }
877
878     validate();
879   }
880
881   public float functionXY(String functionName, int x, int y)
882   {
883     return 0;
884   }
885
886   ///End JmolStatusListener
887   ///////////////////////////////
888
889
890   class RenderPanel
891       extends JPanel
892   {
893     final Dimension currentSize = new Dimension();
894     final Rectangle rectClip = new Rectangle();
895
896     public void paintComponent(Graphics g)
897     {
898       getSize(currentSize);
899       g.getClipBounds(rectClip);
900
901       if (viewer == null)
902       {
903         g.setColor(Color.black);
904         g.fillRect(0, 0, currentSize.width, currentSize.height);
905         g.setColor(Color.white);
906         g.setFont(new Font("Verdana", Font.BOLD, 14));
907         g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
908       }
909       else if(fileLoadingError!=null)
910       {
911         g.setColor(Color.black);
912         g.fillRect(0, 0, currentSize.width, currentSize.height);
913         g.setColor(Color.white);
914         g.setFont(new Font("Verdana", Font.BOLD, 14));
915         g.drawString("Error loading file..." + pdbentry.getId(), 20,
916                      currentSize.height / 2);
917       }
918       else
919       {
920         viewer.renderScreenImage(g, currentSize, rectClip);
921       }
922     }
923   }
924
925 }