2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
21 import javax.swing.*;
\r
22 import java.awt.event.*;
\r
23 import jalview.datamodel.*;
\r
24 import jalview.schemes.*;
\r
25 import jalview.gui.*;
\r
26 import jalview.io.EBIFetchClient;
\r
27 import java.awt.event.ActionListener;
\r
28 import java.awt.event.ActionEvent;
\r
30 import jalview.io.JalviewFileChooser;
\r
31 import jalview.io.JalviewFileView;
\r
33 public class PDBViewer extends JInternalFrame implements Runnable
\r
37 PDBCanvas pdbcanvas;
\r
41 public PDBViewer(PDBEntry entry,
\r
43 SeqCanvas seqcanvas)
\r
49 catch (Exception ex)
\r
51 ex.printStackTrace();
\r
59 pdbcanvas = new PDBCanvas(seqcanvas, sequence);
\r
61 if(pdb.getFile()!=null)
\r
64 tmpPDBFile = pdb.getFile();
\r
65 PDBfile pdbfile = new PDBfile(tmpPDBFile,
\r
66 jalview.io.AppletFormatAdapter.FILE);
\r
67 pdbcanvas.setPDBFile(pdbfile);
\r
69 }catch(java.io.IOException ex)
\r
71 ex.printStackTrace();
\r
76 Thread worker = new Thread(this);
\r
82 setContentPane(pdbcanvas);
\r
83 StringBuffer title = new StringBuffer(sequence.getName() + ":" + pdb.getId());
\r
84 if(pdb.getProperty()!=null)
\r
86 if (pdb.getProperty().get("method")!=null)
\r
88 title.append(" Method: ");
\r
89 title.append(pdb.getProperty().get("method"));
\r
91 if (pdb.getProperty().get("chains") != null)
\r
93 title.append(" Chain:");
\r
94 title.append(pdb.getProperty().get("chains"));
\r
97 Desktop.addInternalFrame(this,title.toString(),400, 400);
\r
104 EBIFetchClient ebi = new EBIFetchClient();
\r
105 String query = "pdb:" + pdb.getId();
\r
106 tmpPDBFile = ebi.fetchDataAsFile(query, "default", "raw").getAbsolutePath();
\r
107 if (tmpPDBFile != null)
\r
109 PDBfile pdbfile = new PDBfile(tmpPDBFile, jalview.io.AppletFormatAdapter.FILE);
\r
110 pdbcanvas.setPDBFile(pdbfile);
\r
114 throw new Exception("Empty result for WSDbFetch Query: " + query);
\r
117 catch (Exception ex)
\r
119 ex.printStackTrace();
\r
120 showErrorMessage("Failed to retrieve PDB structure.");
\r
125 private void jbInit()
\r
128 this.addKeyListener(new KeyAdapter()
\r
130 public void keyPressed(KeyEvent evt)
\r
132 pdbcanvas.keyPressed(evt);
\r
136 this.setJMenuBar(jMenuBar1);
\r
137 fileMenu.setText("File");
\r
138 coloursMenu.setText("Colours");
\r
139 saveMenu.setActionCommand("Save Image");
\r
140 saveMenu.setText("Save As");
\r
141 png.setText("PNG");
\r
142 png.addActionListener(new ActionListener()
\r
144 public void actionPerformed(ActionEvent e)
\r
146 png_actionPerformed(e);
\r
149 eps.setText("EPS");
\r
150 eps.addActionListener(new ActionListener()
\r
152 public void actionPerformed(ActionEvent e)
\r
154 eps_actionPerformed(e);
\r
157 mapping.setText("View Mapping");
\r
158 mapping.addActionListener(new ActionListener()
\r
160 public void actionPerformed(ActionEvent e)
\r
162 mapping_actionPerformed(e);
\r
165 wire.setText("Wireframe");
\r
166 wire.addActionListener(new ActionListener()
\r
168 public void actionPerformed(ActionEvent e)
\r
170 wire_actionPerformed(e);
\r
173 depth.setSelected(true);
\r
174 depth.setText("Depthcue");
\r
175 depth.addActionListener(new ActionListener()
\r
177 public void actionPerformed(ActionEvent e)
\r
179 depth_actionPerformed(e);
\r
182 zbuffer.setSelected(true);
\r
183 zbuffer.setText("Z Buffering");
\r
184 zbuffer.addActionListener(new ActionListener()
\r
186 public void actionPerformed(ActionEvent e)
\r
188 zbuffer_actionPerformed(e);
\r
191 charge.setText("Charge & Cysteine");
\r
192 charge.addActionListener(new ActionListener()
\r
194 public void actionPerformed(ActionEvent e)
\r
196 charge_actionPerformed(e);
\r
199 chain.setText("By Chain");
\r
200 chain.addActionListener(new ActionListener()
\r
202 public void actionPerformed(ActionEvent e)
\r
204 chain_actionPerformed(e);
\r
207 seqButton.setSelected(true);
\r
208 seqButton.setText("By Sequence");
\r
209 seqButton.addActionListener(new ActionListener()
\r
211 public void actionPerformed(ActionEvent e)
\r
213 seqButton_actionPerformed(e);
\r
216 allchains.setSelected(true);
\r
217 allchains.setText("Show All Chains");
\r
218 allchains.addItemListener(new ItemListener()
\r
220 public void itemStateChanged(ItemEvent e)
\r
222 allchains_itemStateChanged(e);
\r
225 zappo.setText("Zappo");
\r
226 zappo.addActionListener(new ActionListener()
\r
228 public void actionPerformed(ActionEvent e)
\r
230 zappo_actionPerformed(e);
\r
233 taylor.setText("Taylor");
\r
234 taylor.addActionListener(new ActionListener()
\r
236 public void actionPerformed(ActionEvent e)
\r
238 taylor_actionPerformed(e);
\r
241 hydro.setText("Hydro");
\r
242 hydro.addActionListener(new ActionListener()
\r
244 public void actionPerformed(ActionEvent e)
\r
246 hydro_actionPerformed(e);
\r
249 helix.setText("Helix");
\r
250 helix.addActionListener(new ActionListener()
\r
252 public void actionPerformed(ActionEvent e)
\r
254 helix_actionPerformed(e);
\r
257 strand.setText("Strand");
\r
258 strand.addActionListener(new ActionListener()
\r
260 public void actionPerformed(ActionEvent e)
\r
262 strand_actionPerformed(e);
\r
265 turn.setText("Turn");
\r
266 turn.addActionListener(new ActionListener()
\r
268 public void actionPerformed(ActionEvent e)
\r
270 turn_actionPerformed(e);
\r
273 buried.setText("Buried");
\r
274 buried.addActionListener(new ActionListener()
\r
276 public void actionPerformed(ActionEvent e)
\r
278 buried_actionPerformed(e);
\r
281 user.setText("User Defined...");
\r
282 user.addActionListener(new ActionListener()
\r
284 public void actionPerformed(ActionEvent e)
\r
286 user_actionPerformed(e);
\r
289 viewMenu.setText("View");
\r
290 background.setText("Background Colour...");
\r
291 background.addActionListener(new ActionListener()
\r
293 public void actionPerformed(ActionEvent e)
\r
295 background_actionPerformed(e);
\r
298 savePDB.setText("PDB File");
\r
299 savePDB.addActionListener(new ActionListener()
\r
301 public void actionPerformed(ActionEvent e)
\r
303 savePDB_actionPerformed(e);
\r
306 jMenuBar1.add(fileMenu);
\r
307 jMenuBar1.add(coloursMenu);
\r
308 jMenuBar1.add(viewMenu);
\r
309 fileMenu.add(saveMenu);
\r
310 fileMenu.add(mapping);
\r
311 saveMenu.add(savePDB);
\r
314 coloursMenu.add(seqButton);
\r
315 coloursMenu.add(chain);
\r
316 coloursMenu.add(charge);
\r
317 coloursMenu.add(zappo);
\r
318 coloursMenu.add(taylor);
\r
319 coloursMenu.add(hydro);
\r
320 coloursMenu.add(helix);
\r
321 coloursMenu.add(strand);
\r
322 coloursMenu.add(turn);
\r
323 coloursMenu.add(buried);
\r
324 coloursMenu.add(user);
\r
325 coloursMenu.add(background);
\r
326 ButtonGroup bg = new ButtonGroup();
\r
340 if(jalview.gui.UserDefinedColours.getUserColourSchemes()!=null)
\r
342 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
\r
343 getUserColourSchemes().keys();
\r
345 while (userColours.hasMoreElements())
\r
347 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
\r
348 nextElement().toString());
\r
349 radioItem.setName("USER_DEFINED");
\r
350 radioItem.addMouseListener(new MouseAdapter()
\r
352 public void mousePressed(MouseEvent evt)
\r
354 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
\r
356 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
\r
358 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
\r
359 "Remove from default list?",
\r
360 "Remove user defined colour",
\r
361 JOptionPane.YES_NO_OPTION);
\r
362 if(option == JOptionPane.YES_OPTION)
\r
364 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
\r
365 coloursMenu.remove(radioItem);
\r
368 radioItem.addActionListener(new ActionListener()
\r
370 public void actionPerformed(ActionEvent evt)
\r
372 user_actionPerformed(evt);
\r
378 radioItem.addActionListener(new ActionListener()
\r
380 public void actionPerformed(ActionEvent evt)
\r
382 user_actionPerformed(evt);
\r
385 coloursMenu.add(radioItem);
\r
390 viewMenu.add(wire);
\r
391 viewMenu.add(depth);
\r
392 viewMenu.add(zbuffer);
\r
393 viewMenu.add(allchains);
\r
396 JMenuBar jMenuBar1 = new JMenuBar();
\r
397 JMenu fileMenu = new JMenu();
\r
398 JMenu coloursMenu = new JMenu();
\r
399 JMenu saveMenu = new JMenu();
\r
400 JMenuItem png = new JMenuItem();
\r
401 JMenuItem eps = new JMenuItem();
\r
402 JMenuItem mapping = new JMenuItem();
\r
403 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
\r
404 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
\r
405 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
\r
406 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
\r
408 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
\r
409 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
\r
410 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
\r
411 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
\r
412 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
\r
413 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
\r
414 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
\r
415 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
\r
416 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
\r
417 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
\r
418 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
\r
419 JMenu viewMenu = new JMenu();
\r
420 JMenuItem background = new JMenuItem();
\r
421 JMenuItem savePDB = new JMenuItem();
\r
426 * @param e DOCUMENT ME!
\r
428 public void eps_actionPerformed(ActionEvent e)
\r
430 makePDBImage(jalview.util.ImageMaker.EPS);
\r
436 * @param e DOCUMENT ME!
\r
438 public void png_actionPerformed(ActionEvent e)
\r
440 makePDBImage(jalview.util.ImageMaker.PNG);
\r
443 void makePDBImage(int type)
\r
445 int width = pdbcanvas.getWidth();
\r
446 int height = pdbcanvas.getHeight();
\r
448 jalview.util.ImageMaker im;
\r
450 if (type == jalview.util.ImageMaker.PNG)
\r
451 im = new jalview.util.ImageMaker(this,
\r
452 jalview.util.ImageMaker.PNG,
\r
453 "Make PNG image from view",
\r
457 im = new jalview.util.ImageMaker(this,
\r
458 jalview.util.ImageMaker.EPS,
\r
459 "Make EPS file from view",
\r
461 null, this.getTitle());
\r
463 if (im.getGraphics() != null)
\r
465 pdbcanvas.drawAll(im.getGraphics(), width, height);
\r
469 public void charge_actionPerformed(ActionEvent e)
\r
471 pdbcanvas.bysequence = false;
\r
472 pdbcanvas.pdb.setChargeColours();
\r
473 pdbcanvas.redrawneeded=true;
\r
474 pdbcanvas.repaint();
\r
477 public void hydro_actionPerformed(ActionEvent e)
\r
479 pdbcanvas.bysequence = false;
\r
480 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
\r
481 pdbcanvas.redrawneeded=true;
\r
482 pdbcanvas.repaint();
\r
485 public void chain_actionPerformed(ActionEvent e)
\r
487 pdbcanvas.bysequence = false;
\r
488 pdbcanvas.pdb.setChainColours();
\r
489 pdbcanvas.redrawneeded=true;
\r
490 pdbcanvas.repaint();
\r
493 public void zbuffer_actionPerformed(ActionEvent e)
\r
495 pdbcanvas.zbuffer = ! pdbcanvas.zbuffer;
\r
496 pdbcanvas.redrawneeded=true;
\r
497 pdbcanvas.repaint();
\r
500 public void molecule_actionPerformed(ActionEvent e)
\r
502 pdbcanvas.bymolecule = ! pdbcanvas.bymolecule;
\r
503 pdbcanvas.redrawneeded=true;
\r
504 pdbcanvas.repaint();
\r
507 public void depth_actionPerformed(ActionEvent e)
\r
509 pdbcanvas.depthcue = ! pdbcanvas.depthcue;
\r
510 pdbcanvas.redrawneeded=true;
\r
511 pdbcanvas.repaint();
\r
514 public void wire_actionPerformed(ActionEvent e)
\r
516 pdbcanvas.wire = ! pdbcanvas.wire;
\r
517 pdbcanvas.redrawneeded=true;
\r
518 pdbcanvas.repaint();
\r
521 public void seqButton_actionPerformed(ActionEvent e)
\r
523 pdbcanvas.bysequence = true;
\r
524 pdbcanvas.updateSeqColours();
\r
528 public void mapping_actionPerformed(ActionEvent e)
\r
530 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
\r
531 Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
\r
532 cap.setText(pdbcanvas.mappingDetails.toString());
\r
535 public void allchains_itemStateChanged(ItemEvent e)
\r
537 pdbcanvas.setAllchainsVisible(allchains.getState());
\r
539 void showErrorMessage(String error)
\r
541 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
542 error, "PDB Viewer Error", JOptionPane.WARNING_MESSAGE);
\r
546 public void zappo_actionPerformed(ActionEvent e)
\r
548 pdbcanvas.bysequence = false;
\r
549 pdbcanvas.pdb.setColours(new ZappoColourScheme());
\r
550 pdbcanvas.redrawneeded=true;
\r
551 pdbcanvas.repaint();
\r
554 public void taylor_actionPerformed(ActionEvent e)
\r
556 pdbcanvas.bysequence = false;
\r
557 pdbcanvas.pdb.setColours(new TaylorColourScheme());
\r
558 pdbcanvas.redrawneeded=true;
\r
559 pdbcanvas.repaint();
\r
562 public void helix_actionPerformed(ActionEvent e)
\r
564 pdbcanvas.bysequence = false;
\r
565 pdbcanvas.pdb.setColours(new HelixColourScheme());
\r
566 pdbcanvas.redrawneeded=true;
\r
567 pdbcanvas.repaint();
\r
570 public void strand_actionPerformed(ActionEvent e)
\r
572 pdbcanvas.bysequence = false;
\r
573 pdbcanvas.pdb.setColours(new StrandColourScheme());
\r
574 pdbcanvas.redrawneeded=true;
\r
575 pdbcanvas.repaint();
\r
578 public void turn_actionPerformed(ActionEvent e)
\r
580 pdbcanvas.bysequence = false;
\r
581 pdbcanvas.pdb.setColours(new TurnColourScheme());
\r
582 pdbcanvas.redrawneeded=true;
\r
583 pdbcanvas.repaint();
\r
586 public void buried_actionPerformed(ActionEvent e)
\r
588 pdbcanvas.bysequence = false;
\r
589 pdbcanvas.pdb.setColours(new BuriedColourScheme());
\r
590 pdbcanvas.redrawneeded=true;
\r
591 pdbcanvas.repaint();
\r
594 public void user_actionPerformed(ActionEvent e)
\r
596 if (e.getActionCommand().equals("User Defined..."))
\r
598 new UserDefinedColours(pdbcanvas, null);
\r
602 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
\r
603 getUserColourSchemes().get(e.getActionCommand());
\r
605 pdbcanvas.pdb.setColours(udc);
\r
606 pdbcanvas.redrawneeded=true;
\r
607 pdbcanvas.repaint();
\r
611 public void background_actionPerformed(ActionEvent e)
\r
613 java.awt.Color col = JColorChooser.showDialog(this, "Select Background Colour",
\r
614 pdbcanvas.backgroundColour);
\r
618 pdbcanvas.backgroundColour = col;
\r
619 pdbcanvas.redrawneeded = true;
\r
620 pdbcanvas.repaint();
\r
624 public void savePDB_actionPerformed(ActionEvent e)
\r
626 JalviewFileChooser chooser = new JalviewFileChooser(
\r
627 jalview.bin.Cache.getProperty(
\r
628 "LAST_DIRECTORY"));
\r
630 chooser.setFileView(new JalviewFileView());
\r
631 chooser.setDialogTitle("Save PDB File");
\r
632 chooser.setToolTipText("Save");
\r
634 int value = chooser.showSaveDialog(this);
\r
636 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
640 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
\r
641 File outFile = chooser.getSelectedFile();
\r
643 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
\r
645 while ( (data = in.readLine()) != null)
\r
648 !( data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1)
\r
654 catch (Exception ex)
\r
656 ex.printStackTrace();
\r