setVisible replaces show
[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
287      scriptWindow.setVisible(showConsole);
288    }
289
290    public float functionXY(String functionName, int x, int y) {
291      return 0;  // for user-defined isosurface functions (testing only -- bob hanson)
292    }
293
294     }
295
296
297     class ScriptWindowAction extends AbstractAction {
298
299       public ScriptWindowAction() {
300         super("BLAH");
301       }
302
303       public void actionPerformed(ActionEvent e) {
304         if (scriptWindow != null)
305         scriptWindow.show();
306       }
307     }
308
309     /**
310      * Called when the selected atoms change
311      * @param selection bit set giving selection of atom indexes
312      */
313     public void selectionChanged(BitSet selection)
314     {
315   System.out.println("SELECTION: "+selection);
316     }
317
318
319     public JmolSimpleViewer getViewer()
320     {
321       return viewer;
322     }
323
324     final Dimension currentSize = new Dimension();
325     final Rectangle rectClip = new Rectangle();
326
327     public void paint(Graphics g)
328     {
329
330       getSize(currentSize);
331       g.getClipBounds(rectClip);
332       viewer.renderScreenImage(g, currentSize, rectClip);
333     }
334   }
335
336
337   public void run()
338   {
339     try
340     {
341       EBIFetchClient ebi = new EBIFetchClient();
342       String query = "pdb:" + pdb.getId();
343       tmpPDBFile = ebi.fetchDataAsFile(query, "default", "raw").getAbsolutePath();
344       if (tmpPDBFile != null)
345       {
346         PDBfile pdbfile = new PDBfile(tmpPDBFile,
347                                       jalview.io.AppletFormatAdapter.FILE);
348         pdbcanvas.setPDBFile(pdbfile);
349       }
350       else
351       {
352         throw new Exception("Empty result for WSDbFetch Query: " + query);
353       }
354     }
355     catch (Exception ex)
356     {
357       ex.printStackTrace();
358       showErrorMessage("Failed to retrieve PDB structure.");
359 //      this.dispose();
360     }
361   }
362
363   private void jbInit()
364       throws Exception
365   {
366     this.addKeyListener(new KeyAdapter()
367     {
368       public void keyPressed(KeyEvent evt)
369       {
370         pdbcanvas.keyPressed(evt);
371       }
372     });
373
374     this.setJMenuBar(jMenuBar1);
375     fileMenu.setText("File");
376     coloursMenu.setText("Colours");
377     saveMenu.setActionCommand("Save Image");
378     saveMenu.setText("Save As");
379     png.setText("PNG");
380     png.addActionListener(new ActionListener()
381     {
382       public void actionPerformed(ActionEvent e)
383       {
384         png_actionPerformed(e);
385       }
386     });
387     eps.setText("EPS");
388     eps.addActionListener(new ActionListener()
389     {
390       public void actionPerformed(ActionEvent e)
391       {
392         eps_actionPerformed(e);
393       }
394     });
395     mapping.setText("View Mapping");
396     mapping.addActionListener(new ActionListener()
397     {
398       public void actionPerformed(ActionEvent e)
399       {
400         mapping_actionPerformed(e);
401       }
402     });
403     wire.setText("Wireframe");
404     wire.addActionListener(new ActionListener()
405     {
406       public void actionPerformed(ActionEvent e)
407       {
408         wire_actionPerformed(e);
409       }
410     });
411     depth.setSelected(true);
412     depth.setText("Depthcue");
413     depth.addActionListener(new ActionListener()
414     {
415       public void actionPerformed(ActionEvent e)
416       {
417         depth_actionPerformed(e);
418       }
419     });
420     zbuffer.setSelected(true);
421     zbuffer.setText("Z Buffering");
422     zbuffer.addActionListener(new ActionListener()
423     {
424       public void actionPerformed(ActionEvent e)
425       {
426         zbuffer_actionPerformed(e);
427       }
428     });
429     charge.setText("Charge & Cysteine");
430     charge.addActionListener(new ActionListener()
431     {
432       public void actionPerformed(ActionEvent e)
433       {
434         charge_actionPerformed(e);
435       }
436     });
437     chain.setText("By Chain");
438     chain.addActionListener(new ActionListener()
439     {
440       public void actionPerformed(ActionEvent e)
441       {
442         chain_actionPerformed(e);
443       }
444     });
445     seqButton.setSelected(true);
446     seqButton.setText("By Sequence");
447     seqButton.addActionListener(new ActionListener()
448     {
449       public void actionPerformed(ActionEvent e)
450       {
451         seqButton_actionPerformed(e);
452       }
453     });
454     allchains.setSelected(true);
455     allchains.setText("Show All Chains");
456     allchains.addItemListener(new ItemListener()
457     {
458       public void itemStateChanged(ItemEvent e)
459       {
460         allchains_itemStateChanged(e);
461       }
462     });
463     zappo.setText("Zappo");
464     zappo.addActionListener(new ActionListener()
465     {
466       public void actionPerformed(ActionEvent e)
467       {
468         zappo_actionPerformed(e);
469       }
470     });
471     taylor.setText("Taylor");
472     taylor.addActionListener(new ActionListener()
473     {
474       public void actionPerformed(ActionEvent e)
475       {
476         taylor_actionPerformed(e);
477       }
478     });
479     hydro.setText("Hydro");
480     hydro.addActionListener(new ActionListener()
481     {
482       public void actionPerformed(ActionEvent e)
483       {
484         hydro_actionPerformed(e);
485       }
486     });
487     helix.setText("Helix");
488     helix.addActionListener(new ActionListener()
489     {
490       public void actionPerformed(ActionEvent e)
491       {
492         helix_actionPerformed(e);
493       }
494     });
495     strand.setText("Strand");
496     strand.addActionListener(new ActionListener()
497     {
498       public void actionPerformed(ActionEvent e)
499       {
500         strand_actionPerformed(e);
501       }
502     });
503     turn.setText("Turn");
504     turn.addActionListener(new ActionListener()
505     {
506       public void actionPerformed(ActionEvent e)
507       {
508         turn_actionPerformed(e);
509       }
510     });
511     buried.setText("Buried");
512     buried.addActionListener(new ActionListener()
513     {
514       public void actionPerformed(ActionEvent e)
515       {
516         buried_actionPerformed(e);
517       }
518     });
519     user.setText("User Defined...");
520     user.addActionListener(new ActionListener()
521     {
522       public void actionPerformed(ActionEvent e)
523       {
524         user_actionPerformed(e);
525       }
526     });
527     viewMenu.setText("View");
528     background.setText("Background Colour...");
529     background.addActionListener(new ActionListener()
530     {
531       public void actionPerformed(ActionEvent e)
532       {
533         background_actionPerformed(e);
534       }
535     });
536     savePDB.setText("PDB File");
537     savePDB.addActionListener(new ActionListener()
538     {
539       public void actionPerformed(ActionEvent e)
540       {
541         savePDB_actionPerformed(e);
542       }
543     });
544     jMenuBar1.add(fileMenu);
545     jMenuBar1.add(coloursMenu);
546     jMenuBar1.add(viewMenu);
547     fileMenu.add(saveMenu);
548     fileMenu.add(mapping);
549     saveMenu.add(savePDB);
550     saveMenu.add(png);
551     saveMenu.add(eps);
552     coloursMenu.add(seqButton);
553     coloursMenu.add(chain);
554     coloursMenu.add(charge);
555     coloursMenu.add(zappo);
556     coloursMenu.add(taylor);
557     coloursMenu.add(hydro);
558     coloursMenu.add(helix);
559     coloursMenu.add(strand);
560     coloursMenu.add(turn);
561     coloursMenu.add(buried);
562     coloursMenu.add(user);
563     coloursMenu.add(background);
564     ButtonGroup bg = new ButtonGroup();
565     bg.add(seqButton);
566     bg.add(chain);
567     bg.add(charge);
568     bg.add(zappo);
569     bg.add(taylor);
570     bg.add(hydro);
571     bg.add(helix);
572     bg.add(strand);
573     bg.add(turn);
574     bg.add(buried);
575     bg.add(user);
576
577     if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
578     {
579       java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
580           getUserColourSchemes().keys();
581
582       while (userColours.hasMoreElements())
583       {
584         final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
585             userColours.
586             nextElement().toString());
587         radioItem.setName("USER_DEFINED");
588         radioItem.addMouseListener(new MouseAdapter()
589         {
590           public void mousePressed(MouseEvent evt)
591           {
592             if (evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
593             {
594               radioItem.removeActionListener(radioItem.getActionListeners()[0]);
595
596               int option = JOptionPane.showInternalConfirmDialog(jalview.gui.
597                   Desktop.desktop,
598                   "Remove from default list?",
599                   "Remove user defined colour",
600                   JOptionPane.YES_NO_OPTION);
601               if (option == JOptionPane.YES_OPTION)
602               {
603                 jalview.gui.UserDefinedColours.removeColourFromDefaults(
604                     radioItem.getText());
605                 coloursMenu.remove(radioItem);
606               }
607               else
608               {
609                 radioItem.addActionListener(new ActionListener()
610                 {
611                   public void actionPerformed(ActionEvent evt)
612                   {
613                     user_actionPerformed(evt);
614                   }
615                 });
616               }
617             }
618           }
619         });
620         radioItem.addActionListener(new ActionListener()
621         {
622           public void actionPerformed(ActionEvent evt)
623           {
624             user_actionPerformed(evt);
625           }
626         });
627         coloursMenu.add(radioItem);
628         bg.add(radioItem);
629       }
630     }
631
632     viewMenu.add(wire);
633     viewMenu.add(depth);
634     viewMenu.add(zbuffer);
635     viewMenu.add(allchains);
636   }
637
638   JMenuBar jMenuBar1 = new JMenuBar();
639   JMenu fileMenu = new JMenu();
640   JMenu coloursMenu = new JMenu();
641   JMenu saveMenu = new JMenu();
642   JMenuItem png = new JMenuItem();
643   JMenuItem eps = new JMenuItem();
644   JMenuItem mapping = new JMenuItem();
645   JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
646   JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
647   JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
648   JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
649
650   JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
651   JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
652   JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
653   JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
654   JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
655   JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
656   JRadioButtonMenuItem user = new JRadioButtonMenuItem();
657   JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
658   JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
659   JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
660   JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
661   JMenu viewMenu = new JMenu();
662   JMenuItem background = new JMenuItem();
663   JMenuItem savePDB = new JMenuItem();
664
665   /**
666    * DOCUMENT ME!
667    *
668    * @param e DOCUMENT ME!
669    */
670   public void eps_actionPerformed(ActionEvent e)
671   {
672     makePDBImage(jalview.util.ImageMaker.EPS);
673   }
674
675   /**
676    * DOCUMENT ME!
677    *
678    * @param e DOCUMENT ME!
679    */
680   public void png_actionPerformed(ActionEvent e)
681   {
682     makePDBImage(jalview.util.ImageMaker.PNG);
683   }
684
685   void makePDBImage(int type)
686   {
687     int width = pdbcanvas.getWidth();
688     int height = pdbcanvas.getHeight();
689
690     jalview.util.ImageMaker im;
691
692     if (type == jalview.util.ImageMaker.PNG)
693     {
694       im = new jalview.util.ImageMaker(this,
695                                        jalview.util.ImageMaker.PNG,
696                                        "Make PNG image from view",
697                                        width, height,
698                                        null, null);
699     }
700     else
701     {
702       im = new jalview.util.ImageMaker(this,
703                                        jalview.util.ImageMaker.EPS,
704                                        "Make EPS file from view",
705                                        width, height,
706                                        null, this.getTitle());
707     }
708
709     if (im.getGraphics() != null)
710     {
711       pdbcanvas.drawAll(im.getGraphics(), width, height);
712       im.writeImage();
713     }
714   }
715
716   public void charge_actionPerformed(ActionEvent e)
717   {
718     pdbcanvas.bysequence = false;
719     pdbcanvas.pdb.setChargeColours();
720     pdbcanvas.redrawneeded = true;
721     pdbcanvas.repaint();
722   }
723
724   public void hydro_actionPerformed(ActionEvent e)
725   {
726     pdbcanvas.bysequence = false;
727     pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
728     pdbcanvas.redrawneeded = true;
729     pdbcanvas.repaint();
730   }
731
732   public void chain_actionPerformed(ActionEvent e)
733   {
734     pdbcanvas.bysequence = false;
735     pdbcanvas.pdb.setChainColours();
736     pdbcanvas.redrawneeded = true;
737     pdbcanvas.repaint();
738   }
739
740   public void zbuffer_actionPerformed(ActionEvent e)
741   {
742     pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
743     pdbcanvas.redrawneeded = true;
744     pdbcanvas.repaint();
745   }
746
747   public void molecule_actionPerformed(ActionEvent e)
748   {
749     pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
750     pdbcanvas.redrawneeded = true;
751     pdbcanvas.repaint();
752   }
753
754   public void depth_actionPerformed(ActionEvent e)
755   {
756     pdbcanvas.depthcue = !pdbcanvas.depthcue;
757     pdbcanvas.redrawneeded = true;
758     pdbcanvas.repaint();
759   }
760
761   public void wire_actionPerformed(ActionEvent e)
762   {
763     pdbcanvas.wire = !pdbcanvas.wire;
764     pdbcanvas.redrawneeded = true;
765     pdbcanvas.repaint();
766   }
767
768   public void seqButton_actionPerformed(ActionEvent e)
769   {
770     pdbcanvas.bysequence = true;
771     pdbcanvas.updateSeqColours();
772   }
773
774   public void mapping_actionPerformed(ActionEvent e)
775   {
776     jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
777   //  Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
778     cap.setText(pdbcanvas.mappingDetails.toString());
779   }
780
781   public void allchains_itemStateChanged(ItemEvent e)
782   {
783     pdbcanvas.setAllchainsVisible(allchains.getState());
784   }
785
786   void showErrorMessage(String error)
787   {
788   //  JOptionPane.showInternalMessageDialog(Desktop.desktop,
789   //                                        error, "PDB Viewer Error",
790   //                                        JOptionPane.WARNING_MESSAGE);
791   }
792
793   public void zappo_actionPerformed(ActionEvent e)
794   {
795     pdbcanvas.bysequence = false;
796     pdbcanvas.pdb.setColours(new ZappoColourScheme());
797     pdbcanvas.redrawneeded = true;
798     pdbcanvas.repaint();
799   }
800
801   public void taylor_actionPerformed(ActionEvent e)
802   {
803     pdbcanvas.bysequence = false;
804     pdbcanvas.pdb.setColours(new TaylorColourScheme());
805     pdbcanvas.redrawneeded = true;
806     pdbcanvas.repaint();
807   }
808
809   public void helix_actionPerformed(ActionEvent e)
810   {
811     pdbcanvas.bysequence = false;
812     pdbcanvas.pdb.setColours(new HelixColourScheme());
813     pdbcanvas.redrawneeded = true;
814     pdbcanvas.repaint();
815   }
816
817   public void strand_actionPerformed(ActionEvent e)
818   {
819     pdbcanvas.bysequence = false;
820     pdbcanvas.pdb.setColours(new StrandColourScheme());
821     pdbcanvas.redrawneeded = true;
822     pdbcanvas.repaint();
823   }
824
825   public void turn_actionPerformed(ActionEvent e)
826   {
827     pdbcanvas.bysequence = false;
828     pdbcanvas.pdb.setColours(new TurnColourScheme());
829     pdbcanvas.redrawneeded = true;
830     pdbcanvas.repaint();
831   }
832
833   public void buried_actionPerformed(ActionEvent e)
834   {
835     pdbcanvas.bysequence = false;
836     pdbcanvas.pdb.setColours(new BuriedColourScheme());
837     pdbcanvas.redrawneeded = true;
838     pdbcanvas.repaint();
839   }
840
841   public void user_actionPerformed(ActionEvent e)
842   {
843     if (e.getActionCommand().equals("User Defined..."))
844     {
845      // new UserDefinedColours(pdbcanvas, null);
846     }
847     else
848     {
849       UserColourScheme udc = (UserColourScheme) UserDefinedColours.
850           getUserColourSchemes().get(e.getActionCommand());
851
852       pdbcanvas.pdb.setColours(udc);
853       pdbcanvas.redrawneeded = true;
854       pdbcanvas.repaint();
855     }
856   }
857
858   public void background_actionPerformed(ActionEvent e)
859   {
860     java.awt.Color col = JColorChooser.showDialog(this,
861                                                   "Select Background Colour",
862                                                   pdbcanvas.backgroundColour);
863
864     if (col != null)
865     {
866       pdbcanvas.backgroundColour = col;
867       pdbcanvas.redrawneeded = true;
868       pdbcanvas.repaint();
869     }
870   }
871
872   public void savePDB_actionPerformed(ActionEvent e)
873   {
874     JalviewFileChooser chooser = new JalviewFileChooser(
875         jalview.bin.Cache.getProperty(
876             "LAST_DIRECTORY"));
877
878     chooser.setFileView(new JalviewFileView());
879     chooser.setDialogTitle("Save PDB File");
880     chooser.setToolTipText("Save");
881
882     int value = chooser.showSaveDialog(this);
883
884     if (value == JalviewFileChooser.APPROVE_OPTION)
885     {
886       try
887       {
888         BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
889         File outFile = chooser.getSelectedFile();
890
891         PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
892         String data;
893         while ( (data = in.readLine()) != null)
894         {
895           if (
896               ! (data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1)
897               )
898           {
899             out.println(data);
900           }
901         }
902         out.close();
903       }
904       catch (Exception ex)
905       {
906         ex.printStackTrace();
907       }
908     }
909   }
910 }