No longer use ref to seqcanvas for painting
[jalview.git] / src / MCview / PDBViewer.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 MCview;
20
21 import java.io.*;
22
23 import java.awt.*;
24 import java.awt.event.*;
25 import javax.swing.*;
26 import java.util.BitSet;
27
28 import jalview.datamodel.*;
29 import jalview.gui.*;
30 import jalview.io.*;
31 import jalview.schemes.*;
32
33 import org.jmol.api.*;
34 import org.jmol.adapter.smarter.SmarterJmolAdapter;
35 import org.jmol.util.Logger;
36 import org.jmol.popup.*;
37
38 public class PDBViewer
39     extends JInternalFrame implements Runnable
40 {
41   PDBEntry pdb;
42   /**
43    * The associated sequence in an alignment
44    */
45   Sequence sequence;
46   PDBCanvas pdbcanvas;
47   String tmpPDBFile;
48
49   public PDBViewer(PDBEntry entry,
50                    Sequence seq,
51                    SeqCanvas seqcanvas)
52   {
53    /* try
54     {
55       jbInit();
56     }
57     catch (Exception ex)
58     {
59       ex.printStackTrace();
60     }
61
62     if (entry == null)
63     {
64       return;
65     }
66     pdb = entry;
67     sequence = seq;
68     pdbcanvas = new PDBCanvas(seqcanvas, sequence);
69
70     if (pdb.getFile() != null)
71     {
72       try
73       {
74         tmpPDBFile = pdb.getFile();
75         PDBfile pdbfile = new PDBfile(tmpPDBFile,
76                                       jalview.io.AppletFormatAdapter.FILE);
77         pdbcanvas.setPDBFile(pdbfile);
78
79       }
80       catch (java.io.IOException ex)
81       {
82         ex.printStackTrace();
83       }
84     }
85     else
86     {
87       Thread worker = new Thread(this);
88       worker.start();
89     }
90
91       public void run()
92       {
93         try
94         {
95           EBIFetchClient ebi = new EBIFetchClient();
96           String query = "pdb:" + pdb.getId();
97           tmpPDBFile = ebi.fetchDataAsFile(query, "default", "raw").getAbsolutePath();
98           if (tmpPDBFile != null)
99           {
100             PDBfile pdbfile = new PDBfile(tmpPDBFile,
101                                           jalview.io.AppletFormatAdapter.FILE);
102             pdbcanvas.setPDBFile(pdbfile);
103           }
104           else
105           {
106             throw new Exception("Empty result for WSDbFetch Query: " + query);
107           }
108         }
109         catch (Exception ex)
110         {
111           ex.printStackTrace();
112           showErrorMessage("Failed to retrieve PDB structure.");
113 //      this.dispose();
114         }
115       }
116
117
118     setContentPane(pdbcanvas);
119     StringBuffer title = new StringBuffer(sequence.getName() + ":" + pdb.getId());
120     if (pdb.getProperty() != null)
121     {
122       if (pdb.getProperty().get("method") != null)
123       {
124         title.append(" Method: ");
125         title.append(pdb.getProperty().get("method"));
126       }
127       if (pdb.getProperty().get("chains") != null)
128       {
129         title.append(" Chain:");
130         title.append(pdb.getProperty().get("chains"));
131       }
132     }
133     */
134
135      Container contentPane = getContentPane();
136      JmolPanel jmolPanel = new JmolPanel();
137      contentPane.add(jmolPanel);
138
139      JmolViewer viewer = jmolPanel.viewer;
140
141
142      System.out.println(entry.getFile()+" "+entry.getId());
143      viewer.openFile(entry.getFile());
144
145
146      StringBuffer string = new StringBuffer();
147
148      for(int i=0; i<seq.getLength(); i++)
149      {
150        Color col = seqcanvas.getSequenceRenderer().getResidueBoxColour(seq, i);
151
152        string.append("select " + i + "B; color [" +
153                      col.getRed()+","
154                      +col.getGreen()+","
155                      +col.getBlue()+"]; ");
156      }
157     System.out.println(string);
158
159     viewer.evalString(string.toString());
160
161
162      String strError = viewer.getOpenFileError();
163      if (strError != null)
164        Logger.error(strError);
165
166
167   //   Desktop.addInternalFrame(this,
168    //                           seq.getName() + ":1GAQ"
169    //                           , 400, 400);
170
171   }
172
173
174
175
176   static class JmolPanel
177       extends JPanel implements JmolSelectionListener
178   {
179     JmolViewer viewer;
180     JmolAdapter adapter;
181     JmolPanel()
182     {
183       adapter = new SmarterJmolAdapter(null);
184       viewer = org.jmol.viewer.Viewer.allocateViewer(this, adapter);
185       viewer.addSelectionListener(this);
186
187       MyStatusListener myStatusListener;
188       myStatusListener = new MyStatusListener();
189       viewer.setJmolStatusListener(myStatusListener);
190
191       JFrame frame = new JFrame("script window");
192      // scriptWindow = new ScriptWindow(viewer, frame);
193
194       myStatusListener.jmolpopup = JmolPopup.newJmolPopup(viewer);
195     }
196      public ScriptWindow scriptWindow;
197  class MyStatusListener implements JmolStatusListener
198  {
199
200    JmolPopup jmolpopup ;
201
202
203    public String eval(String strEval) {
204      return "# 'eval' is implemented only for the applet.";
205    }
206
207    public void createImage(String file, String type, int quality) {
208    System.out.println("CREATE IMAGE");
209      // ImageCreator c = new ImageCreator(viewer, status);
210    //  c.createImage(file, type, quality);
211    }
212
213    public void setCallbackFunction(String callbackType, String callbackFunction) {
214      // applet only?
215    }
216
217    public void notifyFileLoaded(String fullPathName, String fileName,
218                                 String modelName, Object clientFile,
219                                 String errorMsg) {
220
221    }
222
223    public void notifyFrameChanged(int frameNo) {
224      // Note: twos-complement. To get actual frame number, use
225      // Math.max(frameNo, -2 - frameNo)
226      // -1 means all frames are now displayed
227
228      boolean isAnimationRunning = (frameNo <= -2);
229
230    }
231
232    public void notifyScriptStart(String statusMessage, String additionalInfo) {
233      //System.out.println("notifyScriptStart:" + statusMessage + (additionalInfo == "" ? "" : additionalInfo));
234    }
235
236    public void sendConsoleEcho(String strEcho) {
237      if (scriptWindow != null)
238        scriptWindow.sendConsoleEcho(strEcho);
239    }
240
241    public void sendConsoleMessage(String strStatus) {
242      if (scriptWindow != null)
243        scriptWindow.sendConsoleMessage(strStatus);
244    }
245
246    public void notifyScriptTermination(String strStatus, int msWalltime) {
247      if (scriptWindow != null)
248        scriptWindow.notifyScriptTermination(strStatus, msWalltime);
249    }
250
251    public void handlePopupMenu(int x, int y) {
252      jmolpopup.show(x, y);
253    }
254
255    public void notifyNewPickingModeMeasurement(int iatom, String strMeasure) {
256      notifyAtomPicked(iatom, strMeasure);
257    }
258
259    public void notifyNewDefaultModeMeasurement(int count, String strInfo) {
260    //  measurementTable.updateTables();
261    }
262
263    public void notifyAtomPicked(int atomIndex, String strInfo) {
264
265      System.out.println("ATOM PICKED "+atomIndex+" "+strInfo);
266      if (scriptWindow != null) {
267        scriptWindow.sendConsoleMessage(strInfo);
268        scriptWindow.sendConsoleMessage("\n");
269      }
270    }
271
272    public void notifyAtomHovered(int atomIndex, String strInfo) {
273 System.out.println("HOVER "+atomIndex+" "+strInfo);
274    }
275
276    public void sendSyncScript(String script, String appletName) {
277    }
278
279    public void showUrl(String url) {
280    }
281
282    public void showConsole(boolean showConsole) {
283      System.out.println("SHOW CONSOLE" +(scriptWindow==null));
284      if (scriptWindow == null)
285        return;
286      if (showConsole)
287        scriptWindow.show();
288      else
289        scriptWindow.hide();
290    }
291
292    public float functionXY(String functionName, int x, int y) {
293      return 0;  // for user-defined isosurface functions (testing only -- bob hanson)
294    }
295
296     }
297
298
299     class ScriptWindowAction extends AbstractAction {
300
301       public ScriptWindowAction() {
302         super("BLAH");
303       }
304
305       public void actionPerformed(ActionEvent e) {
306         if (scriptWindow != null)
307         scriptWindow.show();
308       }
309     }
310
311     /**
312      * Called when the selected atoms change
313      * @param selection bit set giving selection of atom indexes
314      */
315     public void selectionChanged(BitSet selection)
316     {
317   System.out.println("SELECTION: "+selection);
318     }
319
320
321     public JmolSimpleViewer getViewer()
322     {
323       return viewer;
324     }
325
326     final Dimension currentSize = new Dimension();
327     final Rectangle rectClip = new Rectangle();
328
329     public void paint(Graphics g)
330     {
331
332       getSize(currentSize);
333       g.getClipBounds(rectClip);
334       viewer.renderScreenImage(g, currentSize, rectClip);
335     }
336   }
337
338
339   public void run()
340   {
341     try
342     {
343       EBIFetchClient ebi = new EBIFetchClient();
344       String query = "pdb:" + pdb.getId();
345       tmpPDBFile = ebi.fetchDataAsFile(query, "default", "raw").getAbsolutePath();
346       if (tmpPDBFile != null)
347       {
348         PDBfile pdbfile = new PDBfile(tmpPDBFile,
349                                       jalview.io.AppletFormatAdapter.FILE);
350         pdbcanvas.setPDBFile(pdbfile);
351       }
352       else
353       {
354         throw new Exception("Empty result for WSDbFetch Query: " + query);
355       }
356     }
357     catch (Exception ex)
358     {
359       ex.printStackTrace();
360       showErrorMessage("Failed to retrieve PDB structure.");
361 //      this.dispose();
362     }
363   }
364
365   private void jbInit()
366       throws Exception
367   {
368     this.addKeyListener(new KeyAdapter()
369     {
370       public void keyPressed(KeyEvent evt)
371       {
372         pdbcanvas.keyPressed(evt);
373       }
374     });
375
376     this.setJMenuBar(jMenuBar1);
377     fileMenu.setText("File");
378     coloursMenu.setText("Colours");
379     saveMenu.setActionCommand("Save Image");
380     saveMenu.setText("Save As");
381     png.setText("PNG");
382     png.addActionListener(new ActionListener()
383     {
384       public void actionPerformed(ActionEvent e)
385       {
386         png_actionPerformed(e);
387       }
388     });
389     eps.setText("EPS");
390     eps.addActionListener(new ActionListener()
391     {
392       public void actionPerformed(ActionEvent e)
393       {
394         eps_actionPerformed(e);
395       }
396     });
397     mapping.setText("View Mapping");
398     mapping.addActionListener(new ActionListener()
399     {
400       public void actionPerformed(ActionEvent e)
401       {
402         mapping_actionPerformed(e);
403       }
404     });
405     wire.setText("Wireframe");
406     wire.addActionListener(new ActionListener()
407     {
408       public void actionPerformed(ActionEvent e)
409       {
410         wire_actionPerformed(e);
411       }
412     });
413     depth.setSelected(true);
414     depth.setText("Depthcue");
415     depth.addActionListener(new ActionListener()
416     {
417       public void actionPerformed(ActionEvent e)
418       {
419         depth_actionPerformed(e);
420       }
421     });
422     zbuffer.setSelected(true);
423     zbuffer.setText("Z Buffering");
424     zbuffer.addActionListener(new ActionListener()
425     {
426       public void actionPerformed(ActionEvent e)
427       {
428         zbuffer_actionPerformed(e);
429       }
430     });
431     charge.setText("Charge & Cysteine");
432     charge.addActionListener(new ActionListener()
433     {
434       public void actionPerformed(ActionEvent e)
435       {
436         charge_actionPerformed(e);
437       }
438     });
439     chain.setText("By Chain");
440     chain.addActionListener(new ActionListener()
441     {
442       public void actionPerformed(ActionEvent e)
443       {
444         chain_actionPerformed(e);
445       }
446     });
447     seqButton.setSelected(true);
448     seqButton.setText("By Sequence");
449     seqButton.addActionListener(new ActionListener()
450     {
451       public void actionPerformed(ActionEvent e)
452       {
453         seqButton_actionPerformed(e);
454       }
455     });
456     allchains.setSelected(true);
457     allchains.setText("Show All Chains");
458     allchains.addItemListener(new ItemListener()
459     {
460       public void itemStateChanged(ItemEvent e)
461       {
462         allchains_itemStateChanged(e);
463       }
464     });
465     zappo.setText("Zappo");
466     zappo.addActionListener(new ActionListener()
467     {
468       public void actionPerformed(ActionEvent e)
469       {
470         zappo_actionPerformed(e);
471       }
472     });
473     taylor.setText("Taylor");
474     taylor.addActionListener(new ActionListener()
475     {
476       public void actionPerformed(ActionEvent e)
477       {
478         taylor_actionPerformed(e);
479       }
480     });
481     hydro.setText("Hydro");
482     hydro.addActionListener(new ActionListener()
483     {
484       public void actionPerformed(ActionEvent e)
485       {
486         hydro_actionPerformed(e);
487       }
488     });
489     helix.setText("Helix");
490     helix.addActionListener(new ActionListener()
491     {
492       public void actionPerformed(ActionEvent e)
493       {
494         helix_actionPerformed(e);
495       }
496     });
497     strand.setText("Strand");
498     strand.addActionListener(new ActionListener()
499     {
500       public void actionPerformed(ActionEvent e)
501       {
502         strand_actionPerformed(e);
503       }
504     });
505     turn.setText("Turn");
506     turn.addActionListener(new ActionListener()
507     {
508       public void actionPerformed(ActionEvent e)
509       {
510         turn_actionPerformed(e);
511       }
512     });
513     buried.setText("Buried");
514     buried.addActionListener(new ActionListener()
515     {
516       public void actionPerformed(ActionEvent e)
517       {
518         buried_actionPerformed(e);
519       }
520     });
521     user.setText("User Defined...");
522     user.addActionListener(new ActionListener()
523     {
524       public void actionPerformed(ActionEvent e)
525       {
526         user_actionPerformed(e);
527       }
528     });
529     viewMenu.setText("View");
530     background.setText("Background Colour...");
531     background.addActionListener(new ActionListener()
532     {
533       public void actionPerformed(ActionEvent e)
534       {
535         background_actionPerformed(e);
536       }
537     });
538     savePDB.setText("PDB File");
539     savePDB.addActionListener(new ActionListener()
540     {
541       public void actionPerformed(ActionEvent e)
542       {
543         savePDB_actionPerformed(e);
544       }
545     });
546     jMenuBar1.add(fileMenu);
547     jMenuBar1.add(coloursMenu);
548     jMenuBar1.add(viewMenu);
549     fileMenu.add(saveMenu);
550     fileMenu.add(mapping);
551     saveMenu.add(savePDB);
552     saveMenu.add(png);
553     saveMenu.add(eps);
554     coloursMenu.add(seqButton);
555     coloursMenu.add(chain);
556     coloursMenu.add(charge);
557     coloursMenu.add(zappo);
558     coloursMenu.add(taylor);
559     coloursMenu.add(hydro);
560     coloursMenu.add(helix);
561     coloursMenu.add(strand);
562     coloursMenu.add(turn);
563     coloursMenu.add(buried);
564     coloursMenu.add(user);
565     coloursMenu.add(background);
566     ButtonGroup bg = new ButtonGroup();
567     bg.add(seqButton);
568     bg.add(chain);
569     bg.add(charge);
570     bg.add(zappo);
571     bg.add(taylor);
572     bg.add(hydro);
573     bg.add(helix);
574     bg.add(strand);
575     bg.add(turn);
576     bg.add(buried);
577     bg.add(user);
578
579     if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
580     {
581       java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
582           getUserColourSchemes().keys();
583
584       while (userColours.hasMoreElements())
585       {
586         final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
587             userColours.
588             nextElement().toString());
589         radioItem.setName("USER_DEFINED");
590         radioItem.addMouseListener(new MouseAdapter()
591         {
592           public void mousePressed(MouseEvent evt)
593           {
594             if (evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
595             {
596               radioItem.removeActionListener(radioItem.getActionListeners()[0]);
597
598               int option = JOptionPane.showInternalConfirmDialog(jalview.gui.
599                   Desktop.desktop,
600                   "Remove from default list?",
601                   "Remove user defined colour",
602                   JOptionPane.YES_NO_OPTION);
603               if (option == JOptionPane.YES_OPTION)
604               {
605                 jalview.gui.UserDefinedColours.removeColourFromDefaults(
606                     radioItem.getText());
607                 coloursMenu.remove(radioItem);
608               }
609               else
610               {
611                 radioItem.addActionListener(new ActionListener()
612                 {
613                   public void actionPerformed(ActionEvent evt)
614                   {
615                     user_actionPerformed(evt);
616                   }
617                 });
618               }
619             }
620           }
621         });
622         radioItem.addActionListener(new ActionListener()
623         {
624           public void actionPerformed(ActionEvent evt)
625           {
626             user_actionPerformed(evt);
627           }
628         });
629         coloursMenu.add(radioItem);
630         bg.add(radioItem);
631       }
632     }
633
634     viewMenu.add(wire);
635     viewMenu.add(depth);
636     viewMenu.add(zbuffer);
637     viewMenu.add(allchains);
638   }
639
640   JMenuBar jMenuBar1 = new JMenuBar();
641   JMenu fileMenu = new JMenu();
642   JMenu coloursMenu = new JMenu();
643   JMenu saveMenu = new JMenu();
644   JMenuItem png = new JMenuItem();
645   JMenuItem eps = new JMenuItem();
646   JMenuItem mapping = new JMenuItem();
647   JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
648   JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
649   JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
650   JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
651
652   JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
653   JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
654   JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
655   JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
656   JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
657   JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
658   JRadioButtonMenuItem user = new JRadioButtonMenuItem();
659   JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
660   JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
661   JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
662   JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
663   JMenu viewMenu = new JMenu();
664   JMenuItem background = new JMenuItem();
665   JMenuItem savePDB = new JMenuItem();
666
667   /**
668    * DOCUMENT ME!
669    *
670    * @param e DOCUMENT ME!
671    */
672   public void eps_actionPerformed(ActionEvent e)
673   {
674     makePDBImage(jalview.util.ImageMaker.EPS);
675   }
676
677   /**
678    * DOCUMENT ME!
679    *
680    * @param e DOCUMENT ME!
681    */
682   public void png_actionPerformed(ActionEvent e)
683   {
684     makePDBImage(jalview.util.ImageMaker.PNG);
685   }
686
687   void makePDBImage(int type)
688   {
689     int width = pdbcanvas.getWidth();
690     int height = pdbcanvas.getHeight();
691
692     jalview.util.ImageMaker im;
693
694     if (type == jalview.util.ImageMaker.PNG)
695     {
696       im = new jalview.util.ImageMaker(this,
697                                        jalview.util.ImageMaker.PNG,
698                                        "Make PNG image from view",
699                                        width, height,
700                                        null, null);
701     }
702     else
703     {
704       im = new jalview.util.ImageMaker(this,
705                                        jalview.util.ImageMaker.EPS,
706                                        "Make EPS file from view",
707                                        width, height,
708                                        null, this.getTitle());
709     }
710
711     if (im.getGraphics() != null)
712     {
713       pdbcanvas.drawAll(im.getGraphics(), width, height);
714       im.writeImage();
715     }
716   }
717
718   public void charge_actionPerformed(ActionEvent e)
719   {
720     pdbcanvas.bysequence = false;
721     pdbcanvas.pdb.setChargeColours();
722     pdbcanvas.redrawneeded = true;
723     pdbcanvas.repaint();
724   }
725
726   public void hydro_actionPerformed(ActionEvent e)
727   {
728     pdbcanvas.bysequence = false;
729     pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
730     pdbcanvas.redrawneeded = true;
731     pdbcanvas.repaint();
732   }
733
734   public void chain_actionPerformed(ActionEvent e)
735   {
736     pdbcanvas.bysequence = false;
737     pdbcanvas.pdb.setChainColours();
738     pdbcanvas.redrawneeded = true;
739     pdbcanvas.repaint();
740   }
741
742   public void zbuffer_actionPerformed(ActionEvent e)
743   {
744     pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
745     pdbcanvas.redrawneeded = true;
746     pdbcanvas.repaint();
747   }
748
749   public void molecule_actionPerformed(ActionEvent e)
750   {
751     pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
752     pdbcanvas.redrawneeded = true;
753     pdbcanvas.repaint();
754   }
755
756   public void depth_actionPerformed(ActionEvent e)
757   {
758     pdbcanvas.depthcue = !pdbcanvas.depthcue;
759     pdbcanvas.redrawneeded = true;
760     pdbcanvas.repaint();
761   }
762
763   public void wire_actionPerformed(ActionEvent e)
764   {
765     pdbcanvas.wire = !pdbcanvas.wire;
766     pdbcanvas.redrawneeded = true;
767     pdbcanvas.repaint();
768   }
769
770   public void seqButton_actionPerformed(ActionEvent e)
771   {
772     pdbcanvas.bysequence = true;
773     pdbcanvas.updateSeqColours();
774   }
775
776   public void mapping_actionPerformed(ActionEvent e)
777   {
778     jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
779   //  Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
780     cap.setText(pdbcanvas.mappingDetails.toString());
781   }
782
783   public void allchains_itemStateChanged(ItemEvent e)
784   {
785     pdbcanvas.setAllchainsVisible(allchains.getState());
786   }
787
788   void showErrorMessage(String error)
789   {
790   //  JOptionPane.showInternalMessageDialog(Desktop.desktop,
791   //                                        error, "PDB Viewer Error",
792   //                                        JOptionPane.WARNING_MESSAGE);
793   }
794
795   public void zappo_actionPerformed(ActionEvent e)
796   {
797     pdbcanvas.bysequence = false;
798     pdbcanvas.pdb.setColours(new ZappoColourScheme());
799     pdbcanvas.redrawneeded = true;
800     pdbcanvas.repaint();
801   }
802
803   public void taylor_actionPerformed(ActionEvent e)
804   {
805     pdbcanvas.bysequence = false;
806     pdbcanvas.pdb.setColours(new TaylorColourScheme());
807     pdbcanvas.redrawneeded = true;
808     pdbcanvas.repaint();
809   }
810
811   public void helix_actionPerformed(ActionEvent e)
812   {
813     pdbcanvas.bysequence = false;
814     pdbcanvas.pdb.setColours(new HelixColourScheme());
815     pdbcanvas.redrawneeded = true;
816     pdbcanvas.repaint();
817   }
818
819   public void strand_actionPerformed(ActionEvent e)
820   {
821     pdbcanvas.bysequence = false;
822     pdbcanvas.pdb.setColours(new StrandColourScheme());
823     pdbcanvas.redrawneeded = true;
824     pdbcanvas.repaint();
825   }
826
827   public void turn_actionPerformed(ActionEvent e)
828   {
829     pdbcanvas.bysequence = false;
830     pdbcanvas.pdb.setColours(new TurnColourScheme());
831     pdbcanvas.redrawneeded = true;
832     pdbcanvas.repaint();
833   }
834
835   public void buried_actionPerformed(ActionEvent e)
836   {
837     pdbcanvas.bysequence = false;
838     pdbcanvas.pdb.setColours(new BuriedColourScheme());
839     pdbcanvas.redrawneeded = true;
840     pdbcanvas.repaint();
841   }
842
843   public void user_actionPerformed(ActionEvent e)
844   {
845     if (e.getActionCommand().equals("User Defined..."))
846     {
847       new UserDefinedColours(pdbcanvas, null);
848     }
849     else
850     {
851       UserColourScheme udc = (UserColourScheme) UserDefinedColours.
852           getUserColourSchemes().get(e.getActionCommand());
853
854       pdbcanvas.pdb.setColours(udc);
855       pdbcanvas.redrawneeded = true;
856       pdbcanvas.repaint();
857     }
858   }
859
860   public void background_actionPerformed(ActionEvent e)
861   {
862     java.awt.Color col = JColorChooser.showDialog(this,
863                                                   "Select Background Colour",
864                                                   pdbcanvas.backgroundColour);
865
866     if (col != null)
867     {
868       pdbcanvas.backgroundColour = col;
869       pdbcanvas.redrawneeded = true;
870       pdbcanvas.repaint();
871     }
872   }
873
874   public void savePDB_actionPerformed(ActionEvent e)
875   {
876     JalviewFileChooser chooser = new JalviewFileChooser(
877         jalview.bin.Cache.getProperty(
878             "LAST_DIRECTORY"));
879
880     chooser.setFileView(new JalviewFileView());
881     chooser.setDialogTitle("Save PDB File");
882     chooser.setToolTipText("Save");
883
884     int value = chooser.showSaveDialog(this);
885
886     if (value == JalviewFileChooser.APPROVE_OPTION)
887     {
888       try
889       {
890         BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
891         File outFile = chooser.getSelectedFile();
892
893         PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
894         String data;
895         while ( (data = in.readLine()) != null)
896         {
897           if (
898               ! (data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1)
899               )
900           {
901             out.println(data);
902           }
903         }
904         out.close();
905       }
906       catch (Exception ex)
907       {
908         ex.printStackTrace();
909       }
910     }
911   }
912 }