14acb143f38bd13de38137e6e61dd3a08bd5c6af
[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
200
201   void setChainMenuItems(Vector chains)
202   {
203     chainMenu.removeAll();
204
205     JMenuItem menuItem = new JMenuItem("All");
206     menuItem.addActionListener(new ActionListener()
207         {
208           public void actionPerformed(ActionEvent evt)
209           {
210             allChainsSelected = true;
211             for(int i=0; i<chainMenu.getItemCount(); i++)
212             {
213               if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
214                 ( (JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
215             }
216             centerViewer();
217             allChainsSelected = false;
218           }
219         });
220
221     chainMenu.add(menuItem);
222
223     for (int c = 0; c < chains.size(); c++)
224     {
225       menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
226       menuItem.addItemListener(new ItemListener()
227       {
228         public void itemStateChanged(ItemEvent evt)
229         {
230           if (!allChainsSelected)
231             centerViewer();
232         }
233       });
234
235       chainMenu.add(menuItem);
236     }
237   }
238
239   boolean allChainsSelected = false;
240   void centerViewer()
241   {
242     StringBuffer cmd = new StringBuffer();
243     for(int i=0; i<chainMenu.getItemCount(); i++)
244     {
245       if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
246       {
247        JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
248        if(item.isSelected())
249          cmd.append(":"+item.getText()+" or ");
250       }
251     }
252
253     if (cmd.length() > 0)
254       cmd.setLength(cmd.length() - 4);
255
256     viewer.evalStringQuiet("select *;restrict "
257                       +cmd+";cartoon;center "+cmd);
258   }
259
260   void closeViewer()
261   {
262     viewer.setModeMouse(org.jmol.viewer.JmolConstants.MOUSE_NONE);
263     viewer.evalStringQuiet("zap");
264     viewer.setJmolStatusListener(null);
265     viewer = null;
266
267     //We'll need to find out what other
268     // listeners need to be shut down in Jmol
269     StructureSelectionManager
270         .getStructureSelectionManager()
271         .removeStructureViewerListener(this, pdbentry.getFile());
272   }
273
274   public void run()
275   {
276     try
277     {
278       EBIFetchClient ebi = new EBIFetchClient();
279       String query = "pdb:" + pdbentry.getId();
280       pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
281                        .getAbsolutePath());
282       initJmol("load "+pdbentry.getFile());
283     }
284     catch (Exception ex)
285     {
286       ex.printStackTrace();
287     }
288   }
289
290   public void pdbFile_actionPerformed(ActionEvent actionEvent)
291   {
292     JalviewFileChooser chooser = new JalviewFileChooser(
293         jalview.bin.Cache.getProperty(
294             "LAST_DIRECTORY"));
295
296     chooser.setFileView(new JalviewFileView());
297     chooser.setDialogTitle("Save PDB File");
298     chooser.setToolTipText("Save");
299
300     int value = chooser.showSaveDialog(this);
301
302     if (value == JalviewFileChooser.APPROVE_OPTION)
303     {
304       try
305       {
306         BufferedReader in = new BufferedReader(new FileReader(pdbentry.getFile()));
307         File outFile = chooser.getSelectedFile();
308
309         PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
310         String data;
311         while ( (data = in.readLine()) != null)
312         {
313           if (
314               ! (data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1)
315               )
316           {
317             out.println(data);
318           }
319         }
320         out.close();
321       }
322       catch (Exception ex)
323       {
324         ex.printStackTrace();
325       }
326     }
327   }
328
329   public void viewMapping_actionPerformed(ActionEvent actionEvent)
330   {
331     jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
332     jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550,
333                                          600);
334     cap.setText(
335         StructureSelectionManager.getStructureSelectionManager().printMapping(
336             pdbentry.getFile())
337         );
338   }
339
340   /**
341    * DOCUMENT ME!
342    *
343    * @param e DOCUMENT ME!
344    */
345   public void eps_actionPerformed(ActionEvent e)
346   {
347     makePDBImage(jalview.util.ImageMaker.EPS);
348   }
349
350   /**
351    * DOCUMENT ME!
352    *
353    * @param e DOCUMENT ME!
354    */
355   public void png_actionPerformed(ActionEvent e)
356   {
357     makePDBImage(jalview.util.ImageMaker.PNG);
358   }
359
360   void makePDBImage(int type)
361   {
362     int width = getWidth();
363     int height = getHeight();
364
365     jalview.util.ImageMaker im;
366
367     if (type == jalview.util.ImageMaker.PNG)
368     {
369       im = new jalview.util.ImageMaker(this,
370                                        jalview.util.ImageMaker.PNG,
371                                        "Make PNG image from view",
372                                        width, height,
373                                        null, null);
374     }
375     else
376     {
377       im = new jalview.util.ImageMaker(this,
378                                        jalview.util.ImageMaker.EPS,
379                                        "Make EPS file from view",
380                                        width, height,
381                                        null, this.getTitle());
382     }
383
384     if (im.getGraphics() != null)
385     {
386       Rectangle rect = new Rectangle(width, height);
387       viewer.renderScreenImage(im.getGraphics(),
388                                rect.getSize(), rect);
389       im.writeImage();
390     }
391   }
392
393
394   public void seqColour_actionPerformed(ActionEvent actionEvent)
395   {
396     colourBySequence = seqColour.isSelected();
397     colourBySequence(ap);
398   }
399
400   public void chainColour_actionPerformed(ActionEvent actionEvent)
401   {
402     colourBySequence = false;
403     seqColour.setSelected(false);
404     viewer.evalStringQuiet("select *;color chain");
405   }
406
407   public void chargeColour_actionPerformed(ActionEvent actionEvent)
408   {
409     colourBySequence = false;
410     seqColour.setSelected(false);
411     viewer.evalStringQuiet("select *;color white;select ASP,GLU;color red;"
412                       +"select LYS,ARG;color blue;select CYS;color yellow");
413   }
414
415   public void zappoColour_actionPerformed(ActionEvent actionEvent)
416   {
417     setJalviewColourScheme(new ZappoColourScheme());
418   }
419
420   public void taylorColour_actionPerformed(ActionEvent actionEvent)
421   {
422     setJalviewColourScheme(new TaylorColourScheme());
423   }
424
425   public void hydroColour_actionPerformed(ActionEvent actionEvent)
426   {
427     setJalviewColourScheme(new HydrophobicColourScheme());
428   }
429
430   public void helixColour_actionPerformed(ActionEvent actionEvent)
431   {
432     setJalviewColourScheme(new HelixColourScheme());
433   }
434
435   public void strandColour_actionPerformed(ActionEvent actionEvent)
436   {
437     setJalviewColourScheme(new StrandColourScheme());
438   }
439
440   public void turnColour_actionPerformed(ActionEvent actionEvent)
441   {
442     setJalviewColourScheme(new TurnColourScheme());
443   }
444
445   public void buriedColour_actionPerformed(ActionEvent actionEvent)
446   {
447     setJalviewColourScheme(new BuriedColourScheme());
448   }
449
450   public void setJalviewColourScheme(ColourSchemeI cs)
451   {
452     colourBySequence = false;
453     seqColour.setSelected(false);
454
455     if(cs==null)
456       return;
457
458     String res;
459     int index;
460     Color col;
461
462     Enumeration en = ResidueProperties.aa3Hash.keys();
463     StringBuffer command = new StringBuffer("select *;color white;");
464     while(en.hasMoreElements())
465     {
466       res = en.nextElement().toString();
467       index = ((Integer) ResidueProperties.aa3Hash.get(res)).intValue();
468       if(index>20)
469         continue;
470
471       col = cs.findColour(ResidueProperties.aa[index].charAt(0));
472
473       command.append("select "+res+";color["
474                         + col.getRed() + ","
475                         + col.getGreen() + ","
476                         + col.getBlue() + "];");
477     }
478
479     viewer.evalStringQuiet(command.toString());
480   }
481
482   public void userColour_actionPerformed(ActionEvent actionEvent)
483   {
484     new UserDefinedColours(this, null);
485   }
486
487   public void backGround_actionPerformed(ActionEvent actionEvent)
488   {
489     java.awt.Color col = JColorChooser.showDialog(this,
490                                                   "Select Background Colour",
491                                                   null);
492
493     if (col != null)
494     {
495       viewer.evalStringQuiet("background ["
496                         + col.getRed() + ","
497                         + col.getGreen() + ","
498                         + col.getBlue() + "];");
499     }
500   }
501
502
503   public void jmolHelp_actionPerformed(ActionEvent actionEvent)
504   {
505        try{
506          jalview.util.BrowserLauncher.openURL(
507              "http://jmol.sourceforge.net/docs/JmolUserGuide/");
508        }catch(Exception ex){}
509    }
510
511
512   //////////////////////////////////
513   ///StructureListener
514   public String getPdbFile()
515   {
516     return pdbentry.getFile();
517   }
518
519   Pattern pattern = Pattern.compile(
520       "\\[(.*)\\]([0-9]+)(:[a-zA-Z]*)?\\.([a-zA-Z]+)(/[0-9]*)?"
521       );
522
523   String lastMessage;
524   public void mouseOverStructure(int atomIndex, String strInfo)
525   {
526     Matcher matcher = pattern.matcher(strInfo);
527     matcher.find();
528     matcher.group(1);
529     int pdbResNum = Integer.parseInt(matcher.group(2));
530     String chainId = matcher.group(3);
531
532     if (chainId != null)
533       chainId = chainId.substring(1, chainId.length());
534     else
535     {
536       chainId = " ";
537     }
538
539     if (lastMessage == null || !lastMessage.equals(strInfo))
540       ssm.mouseOverStructure(pdbResNum, chainId, pdbentry.getFile());
541
542     lastMessage = strInfo;
543   }
544
545   StringBuffer resetLastRes = new StringBuffer();
546   StringBuffer eval = new StringBuffer();
547
548   public void highlightAtom(int atomIndex, int pdbResNum, String chain, String pdbfile)
549   {
550     if (!pdbfile.equals(pdbentry.getFile()))
551       return;
552
553     if (resetLastRes.length() > 0)
554     {
555       viewer.evalStringQuiet(resetLastRes.toString());
556     }
557
558     eval.setLength(0);
559     eval.append("select " + pdbResNum);
560
561     resetLastRes.setLength(0);
562     resetLastRes.append("select " + pdbResNum);
563
564     if (!chain.equals(" "))
565     {
566       eval.append(":" + chain);
567       resetLastRes.append(":" + chain);
568     }
569
570     eval.append(";color gold;wireframe 100");
571
572     Color col = new Color(viewer.getAtomArgb(atomIndex));
573
574     resetLastRes.append(";color["
575                         + col.getRed() + ","
576                         + col.getGreen() + ","
577                         + col.getBlue() + "];wireframe 0");
578
579     viewer.evalStringQuiet(eval.toString());
580
581   }
582
583   public void updateColours(Object source)
584   {
585     colourBySequence( (AlignmentPanel) source);
586   }
587
588
589 //End StructureListener
590 ////////////////////////////
591
592   FeatureRenderer fr=null;
593   public void colourBySequence(AlignmentPanel ap)
594   {
595     if(!colourBySequence)
596       return;
597
598
599     StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile());
600
601     if (mapping.length < 1)
602       return;
603
604     SequenceRenderer sr = ap.seqPanel.seqCanvas.getSequenceRenderer();
605
606     boolean showFeatures = false;
607     if (ap.av.showSequenceFeatures)
608     {
609       showFeatures = true;
610       if (fr == null)
611       {
612         fr = new jalview.gui.FeatureRenderer(ap.av);
613       }
614
615       fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
616     }
617
618     StringBuffer command = new StringBuffer();
619
620     int lastPos = -1;
621     for (int s = 0; s < sequence.length; s++)
622     {
623       for (int m = 0; m < mapping.length; m++)
624       {
625         if (mapping[m].getSequence() == sequence[s])
626         {
627           for (int r = 0; r < sequence[s].getLength(); r++)
628           {
629             int pos = mapping[m].getPDBResNum(
630                 sequence[s].findPosition(r));
631
632             if (pos < 1 || pos==lastPos)
633               continue;
634
635             lastPos = pos;
636
637             Color col = sr.getResidueBoxColour(sequence[s], r);
638
639             if (showFeatures)
640               col = fr.findFeatureColour(col, sequence[s], r);
641
642             if (command.toString().endsWith(":" + mapping[m].getChain()+
643                                             ";color["
644                                             + col.getRed() + ","
645                                             + col.getGreen() + ","
646                                             + col.getBlue() + "]"))
647             {
648               command = condenseCommand(command, pos);
649               continue;
650             }
651
652             command.append(";select " + pos);
653
654             if (!mapping[m].getChain().equals(" "))
655             {
656               command.append(":" + mapping[m].getChain());
657             }
658
659             command.append(";color["
660                              + col.getRed() + ","
661                              + col.getGreen() + ","
662                              + col.getBlue() + "]");
663
664           }
665           break;
666         }
667       }
668     }
669
670     viewer.evalStringQuiet(command.toString());
671   }
672
673   StringBuffer condenseCommand(StringBuffer command, int pos)
674   {
675     StringBuffer sb = new StringBuffer(command.substring(0, command.lastIndexOf("select")+7));
676
677     command.delete(0, sb.length());
678
679     String start;
680
681     if (command.indexOf("-") > -1)
682     {
683       start = command.substring(0,command.indexOf("-"));
684     }
685     else
686     {
687       start = command.substring(0, command.indexOf(":"));
688     }
689
690     sb.append(start+"-"+pos+command.substring(command.indexOf(":")));
691
692     return sb;
693   }
694
695   /////////////////////////////////
696   //JmolStatusListener
697
698   public String eval(String strEval)
699   {
700    // System.out.println(strEval);
701    //"# 'eval' is implemented only for the applet.";
702     return null;
703   }
704
705   public void createImage(String file, String type, int quality)
706   {
707     System.out.println("JMOL CREATE IMAGE");
708   }
709
710   public void setCallbackFunction(String callbackType,
711                                   String callbackFunction)
712   {}
713
714   public void notifyFileLoaded(String fullPathName, String fileName,
715                                String modelName, Object clientFile,
716                                String errorMsg)
717   {
718     if(errorMsg!=null)
719     {
720       fileLoadingError = errorMsg;
721       repaint();
722       return;
723     }
724
725     fileLoadingError = null;
726
727     if (fileName != null)
728     {
729
730       //FILE LOADED OK
731       ssm = StructureSelectionManager.getStructureSelectionManager();
732       MCview.PDBfile pdbFile = ssm.setMapping(sequence, pdbentry.getFile(), AppletFormatAdapter.FILE);
733       ssm.addStructureViewerListener(this);
734       Vector chains = new Vector();
735       for(int i=0; i<pdbFile.chains.size(); i++)
736       {
737         chains.addElement(((MCview.PDBChain)pdbFile.chains.elementAt(i)).id);
738       }
739       setChainMenuItems(chains);
740
741       jmolpopup.updateComputedMenus();
742
743       if(!loadingFromArchive)
744       {
745         viewer.evalStringQuiet(
746              "select backbone;restrict;cartoon;wireframe off;spacefill off");
747
748         colourBySequence(ap);
749       }
750       if (fr!=null)
751         fr.featuresAdded();
752
753       loadingFromArchive = false;
754     }
755     else
756       return;
757   }
758
759   public void notifyFrameChanged(int frameNo)
760   {
761     boolean isAnimationRunning = (frameNo <= -2);
762   }
763
764   public void notifyScriptStart(String statusMessage, String additionalInfo)
765   {}
766
767   public void sendConsoleEcho(String strEcho)
768   {
769     if (scriptWindow != null)
770       scriptWindow.sendConsoleEcho(strEcho);
771   }
772
773   public void sendConsoleMessage(String strStatus)
774   {
775     if (scriptWindow != null)
776       scriptWindow.sendConsoleMessage(strStatus);
777   }
778
779   public void notifyScriptTermination(String strStatus, int msWalltime)
780   {
781     if (scriptWindow != null)
782       scriptWindow.notifyScriptTermination(strStatus, msWalltime);
783   }
784
785   public void handlePopupMenu(int x, int y)
786   {
787     jmolpopup.show(x, y);
788   }
789
790   public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
791   {
792     notifyAtomPicked(iatom, strMeasure);
793   }
794
795   public void notifyNewDefaultModeMeasurement(int count, String strInfo)
796   {}
797
798   public void notifyAtomPicked(int atomIndex, String strInfo)
799   {
800     Matcher matcher = pattern.matcher(strInfo);
801     matcher.find();
802
803     matcher.group(1);
804     String resnum = new String(matcher.group(2));
805     String chainId = matcher.group(3);
806
807     String picked = resnum;
808
809     if (chainId != null)
810       picked+=(":"+chainId.substring(1, chainId.length()));
811
812     picked+=".C";
813
814     if (!atomsPicked.contains(picked))
815     {
816       if(chainId!=null)
817       viewer.evalString("select "+picked+";label %n %r:%c");
818     else
819       viewer.evalString("select "+picked+";label %n %r");
820       atomsPicked.addElement(picked);
821     }
822     else
823     {
824       viewer.evalString("select "+picked+";label off");
825       atomsPicked.removeElement(picked);
826     }
827
828     if (scriptWindow != null)
829     {
830       scriptWindow.sendConsoleMessage(strInfo);
831       scriptWindow.sendConsoleMessage("\n");
832     }
833   }
834
835   public void notifyAtomHovered(int atomIndex, String strInfo)
836   {
837     mouseOverStructure(atomIndex, strInfo);
838   }
839
840   public void sendSyncScript(String script, String appletName)
841   {}
842
843   public void showUrl(String url)
844   {}
845
846   public void showConsole(boolean showConsole)
847   {
848     if (scriptWindow == null)
849       scriptWindow = new ScriptWindow(this);
850
851     if(showConsole)
852     {
853       if(splitPane==null)
854       {
855         splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
856         splitPane.setTopComponent(renderPanel);
857         splitPane.setBottomComponent(scriptWindow);
858         this.getContentPane().add(splitPane, BorderLayout.CENTER);
859       }
860
861       splitPane.setDividerLocation(getHeight()-200);
862       splitPane.validate();
863     }
864     else
865     {
866       if (splitPane != null)
867         splitPane.setVisible(false);
868
869       splitPane = null;
870
871       this.getContentPane().add(renderPanel, BorderLayout.CENTER);
872     }
873
874     validate();
875   }
876
877   public float functionXY(String functionName, int x, int y)
878   {
879     return 0;
880   }
881
882   ///End JmolStatusListener
883   ///////////////////////////////
884
885
886   class RenderPanel
887       extends JPanel
888   {
889     final Dimension currentSize = new Dimension();
890     final Rectangle rectClip = new Rectangle();
891
892     public void paintComponent(Graphics g)
893     {
894       getSize(currentSize);
895       g.getClipBounds(rectClip);
896
897       if (viewer == null)
898       {
899         g.setColor(Color.black);
900         g.fillRect(0, 0, currentSize.width, currentSize.height);
901         g.setColor(Color.white);
902         g.setFont(new Font("Verdana", Font.BOLD, 14));
903         g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
904       }
905       else if(fileLoadingError!=null)
906       {
907         g.setColor(Color.black);
908         g.fillRect(0, 0, currentSize.width, currentSize.height);
909         g.setColor(Color.white);
910         g.setFont(new Font("Verdana", Font.BOLD, 14));
911         g.drawString("Error loading file..." + pdbentry.getId(), 20,
912                      currentSize.height / 2);
913       }
914       else
915       {
916         viewer.renderScreenImage(g, currentSize, rectClip);
917       }
918     }
919   }
920
921 }