2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
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.
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.
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
22 import java.awt.event.*;
23 import jalview.datamodel.*;
24 import jalview.schemes.*;
26 import jalview.io.EBIFetchClient;
27 import java.awt.event.ActionListener;
28 import java.awt.event.ActionEvent;
30 import jalview.io.JalviewFileChooser;
31 import jalview.io.JalviewFileView;
33 public class PDBViewer extends JInternalFrame implements Runnable
37 * The associated sequence in an alignment
44 public PDBViewer(PDBEntry entry,
62 pdbcanvas = new PDBCanvas(seqcanvas, sequence);
64 if(pdb.getFile()!=null)
67 tmpPDBFile = pdb.getFile();
68 PDBfile pdbfile = new PDBfile(tmpPDBFile,
69 jalview.io.AppletFormatAdapter.FILE);
70 pdbcanvas.setPDBFile(pdbfile);
72 }catch(java.io.IOException ex)
79 Thread worker = new Thread(this);
85 setContentPane(pdbcanvas);
86 StringBuffer title = new StringBuffer(sequence.getName() + ":" + pdb.getId());
87 if(pdb.getProperty()!=null)
89 if (pdb.getProperty().get("method")!=null)
91 title.append(" Method: ");
92 title.append(pdb.getProperty().get("method"));
94 if (pdb.getProperty().get("chains") != null)
96 title.append(" Chain:");
97 title.append(pdb.getProperty().get("chains"));
100 Desktop.addInternalFrame(this,title.toString(),400, 400);
107 EBIFetchClient ebi = new EBIFetchClient();
108 String query = "pdb:" + pdb.getId();
109 tmpPDBFile = ebi.fetchDataAsFile(query, "default", "raw").getAbsolutePath();
110 if (tmpPDBFile != null)
112 PDBfile pdbfile = new PDBfile(tmpPDBFile, jalview.io.AppletFormatAdapter.FILE);
113 pdbcanvas.setPDBFile(pdbfile);
117 throw new Exception("Empty result for WSDbFetch Query: " + query);
122 ex.printStackTrace();
123 showErrorMessage("Failed to retrieve PDB structure.");
128 private void jbInit()
131 this.addKeyListener(new KeyAdapter()
133 public void keyPressed(KeyEvent evt)
135 pdbcanvas.keyPressed(evt);
139 this.setJMenuBar(jMenuBar1);
140 fileMenu.setText("File");
141 coloursMenu.setText("Colours");
142 saveMenu.setActionCommand("Save Image");
143 saveMenu.setText("Save As");
145 png.addActionListener(new ActionListener()
147 public void actionPerformed(ActionEvent e)
149 png_actionPerformed(e);
153 eps.addActionListener(new ActionListener()
155 public void actionPerformed(ActionEvent e)
157 eps_actionPerformed(e);
160 mapping.setText("View Mapping");
161 mapping.addActionListener(new ActionListener()
163 public void actionPerformed(ActionEvent e)
165 mapping_actionPerformed(e);
168 wire.setText("Wireframe");
169 wire.addActionListener(new ActionListener()
171 public void actionPerformed(ActionEvent e)
173 wire_actionPerformed(e);
176 depth.setSelected(true);
177 depth.setText("Depthcue");
178 depth.addActionListener(new ActionListener()
180 public void actionPerformed(ActionEvent e)
182 depth_actionPerformed(e);
185 zbuffer.setSelected(true);
186 zbuffer.setText("Z Buffering");
187 zbuffer.addActionListener(new ActionListener()
189 public void actionPerformed(ActionEvent e)
191 zbuffer_actionPerformed(e);
194 charge.setText("Charge & Cysteine");
195 charge.addActionListener(new ActionListener()
197 public void actionPerformed(ActionEvent e)
199 charge_actionPerformed(e);
202 chain.setText("By Chain");
203 chain.addActionListener(new ActionListener()
205 public void actionPerformed(ActionEvent e)
207 chain_actionPerformed(e);
210 seqButton.setSelected(true);
211 seqButton.setText("By Sequence");
212 seqButton.addActionListener(new ActionListener()
214 public void actionPerformed(ActionEvent e)
216 seqButton_actionPerformed(e);
219 allchains.setSelected(true);
220 allchains.setText("Show All Chains");
221 allchains.addItemListener(new ItemListener()
223 public void itemStateChanged(ItemEvent e)
225 allchains_itemStateChanged(e);
228 zappo.setText("Zappo");
229 zappo.addActionListener(new ActionListener()
231 public void actionPerformed(ActionEvent e)
233 zappo_actionPerformed(e);
236 taylor.setText("Taylor");
237 taylor.addActionListener(new ActionListener()
239 public void actionPerformed(ActionEvent e)
241 taylor_actionPerformed(e);
244 hydro.setText("Hydro");
245 hydro.addActionListener(new ActionListener()
247 public void actionPerformed(ActionEvent e)
249 hydro_actionPerformed(e);
252 helix.setText("Helix");
253 helix.addActionListener(new ActionListener()
255 public void actionPerformed(ActionEvent e)
257 helix_actionPerformed(e);
260 strand.setText("Strand");
261 strand.addActionListener(new ActionListener()
263 public void actionPerformed(ActionEvent e)
265 strand_actionPerformed(e);
268 turn.setText("Turn");
269 turn.addActionListener(new ActionListener()
271 public void actionPerformed(ActionEvent e)
273 turn_actionPerformed(e);
276 buried.setText("Buried");
277 buried.addActionListener(new ActionListener()
279 public void actionPerformed(ActionEvent e)
281 buried_actionPerformed(e);
284 user.setText("User Defined...");
285 user.addActionListener(new ActionListener()
287 public void actionPerformed(ActionEvent e)
289 user_actionPerformed(e);
292 viewMenu.setText("View");
293 background.setText("Background Colour...");
294 background.addActionListener(new ActionListener()
296 public void actionPerformed(ActionEvent e)
298 background_actionPerformed(e);
301 savePDB.setText("PDB File");
302 savePDB.addActionListener(new ActionListener()
304 public void actionPerformed(ActionEvent e)
306 savePDB_actionPerformed(e);
309 jMenuBar1.add(fileMenu);
310 jMenuBar1.add(coloursMenu);
311 jMenuBar1.add(viewMenu);
312 fileMenu.add(saveMenu);
313 fileMenu.add(mapping);
314 saveMenu.add(savePDB);
317 coloursMenu.add(seqButton);
318 coloursMenu.add(chain);
319 coloursMenu.add(charge);
320 coloursMenu.add(zappo);
321 coloursMenu.add(taylor);
322 coloursMenu.add(hydro);
323 coloursMenu.add(helix);
324 coloursMenu.add(strand);
325 coloursMenu.add(turn);
326 coloursMenu.add(buried);
327 coloursMenu.add(user);
328 coloursMenu.add(background);
329 ButtonGroup bg = new ButtonGroup();
343 if(jalview.gui.UserDefinedColours.getUserColourSchemes()!=null)
345 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
346 getUserColourSchemes().keys();
348 while (userColours.hasMoreElements())
350 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
351 nextElement().toString());
352 radioItem.setName("USER_DEFINED");
353 radioItem.addMouseListener(new MouseAdapter()
355 public void mousePressed(MouseEvent evt)
357 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
359 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
361 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
362 "Remove from default list?",
363 "Remove user defined colour",
364 JOptionPane.YES_NO_OPTION);
365 if(option == JOptionPane.YES_OPTION)
367 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
368 coloursMenu.remove(radioItem);
371 radioItem.addActionListener(new ActionListener()
373 public void actionPerformed(ActionEvent evt)
375 user_actionPerformed(evt);
381 radioItem.addActionListener(new ActionListener()
383 public void actionPerformed(ActionEvent evt)
385 user_actionPerformed(evt);
388 coloursMenu.add(radioItem);
395 viewMenu.add(zbuffer);
396 viewMenu.add(allchains);
399 JMenuBar jMenuBar1 = new JMenuBar();
400 JMenu fileMenu = new JMenu();
401 JMenu coloursMenu = new JMenu();
402 JMenu saveMenu = new JMenu();
403 JMenuItem png = new JMenuItem();
404 JMenuItem eps = new JMenuItem();
405 JMenuItem mapping = new JMenuItem();
406 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
407 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
408 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
409 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
411 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
412 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
413 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
414 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
415 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
416 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
417 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
418 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
419 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
420 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
421 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
422 JMenu viewMenu = new JMenu();
423 JMenuItem background = new JMenuItem();
424 JMenuItem savePDB = new JMenuItem();
429 * @param e DOCUMENT ME!
431 public void eps_actionPerformed(ActionEvent e)
433 makePDBImage(jalview.util.ImageMaker.EPS);
439 * @param e DOCUMENT ME!
441 public void png_actionPerformed(ActionEvent e)
443 makePDBImage(jalview.util.ImageMaker.PNG);
446 void makePDBImage(int type)
448 int width = pdbcanvas.getWidth();
449 int height = pdbcanvas.getHeight();
451 jalview.util.ImageMaker im;
453 if (type == jalview.util.ImageMaker.PNG)
454 im = new jalview.util.ImageMaker(this,
455 jalview.util.ImageMaker.PNG,
456 "Make PNG image from view",
460 im = new jalview.util.ImageMaker(this,
461 jalview.util.ImageMaker.EPS,
462 "Make EPS file from view",
464 null, this.getTitle());
466 if (im.getGraphics() != null)
468 pdbcanvas.drawAll(im.getGraphics(), width, height);
472 public void charge_actionPerformed(ActionEvent e)
474 pdbcanvas.bysequence = false;
475 pdbcanvas.pdb.setChargeColours();
476 pdbcanvas.redrawneeded=true;
480 public void hydro_actionPerformed(ActionEvent e)
482 pdbcanvas.bysequence = false;
483 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
484 pdbcanvas.redrawneeded=true;
488 public void chain_actionPerformed(ActionEvent e)
490 pdbcanvas.bysequence = false;
491 pdbcanvas.pdb.setChainColours();
492 pdbcanvas.redrawneeded=true;
496 public void zbuffer_actionPerformed(ActionEvent e)
498 pdbcanvas.zbuffer = ! pdbcanvas.zbuffer;
499 pdbcanvas.redrawneeded=true;
503 public void molecule_actionPerformed(ActionEvent e)
505 pdbcanvas.bymolecule = ! pdbcanvas.bymolecule;
506 pdbcanvas.redrawneeded=true;
510 public void depth_actionPerformed(ActionEvent e)
512 pdbcanvas.depthcue = ! pdbcanvas.depthcue;
513 pdbcanvas.redrawneeded=true;
517 public void wire_actionPerformed(ActionEvent e)
519 pdbcanvas.wire = ! pdbcanvas.wire;
520 pdbcanvas.redrawneeded=true;
524 public void seqButton_actionPerformed(ActionEvent e)
526 pdbcanvas.bysequence = true;
527 pdbcanvas.updateSeqColours();
531 public void mapping_actionPerformed(ActionEvent e)
533 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
534 Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
535 cap.setText(pdbcanvas.mappingDetails.toString());
538 public void allchains_itemStateChanged(ItemEvent e)
540 pdbcanvas.setAllchainsVisible(allchains.getState());
542 void showErrorMessage(String error)
544 JOptionPane.showInternalMessageDialog(Desktop.desktop,
545 error, "PDB Viewer Error", JOptionPane.WARNING_MESSAGE);
549 public void zappo_actionPerformed(ActionEvent e)
551 pdbcanvas.bysequence = false;
552 pdbcanvas.pdb.setColours(new ZappoColourScheme());
553 pdbcanvas.redrawneeded=true;
557 public void taylor_actionPerformed(ActionEvent e)
559 pdbcanvas.bysequence = false;
560 pdbcanvas.pdb.setColours(new TaylorColourScheme());
561 pdbcanvas.redrawneeded=true;
565 public void helix_actionPerformed(ActionEvent e)
567 pdbcanvas.bysequence = false;
568 pdbcanvas.pdb.setColours(new HelixColourScheme());
569 pdbcanvas.redrawneeded=true;
573 public void strand_actionPerformed(ActionEvent e)
575 pdbcanvas.bysequence = false;
576 pdbcanvas.pdb.setColours(new StrandColourScheme());
577 pdbcanvas.redrawneeded=true;
581 public void turn_actionPerformed(ActionEvent e)
583 pdbcanvas.bysequence = false;
584 pdbcanvas.pdb.setColours(new TurnColourScheme());
585 pdbcanvas.redrawneeded=true;
589 public void buried_actionPerformed(ActionEvent e)
591 pdbcanvas.bysequence = false;
592 pdbcanvas.pdb.setColours(new BuriedColourScheme());
593 pdbcanvas.redrawneeded=true;
597 public void user_actionPerformed(ActionEvent e)
599 if (e.getActionCommand().equals("User Defined..."))
601 new UserDefinedColours(pdbcanvas, null);
605 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
606 getUserColourSchemes().get(e.getActionCommand());
608 pdbcanvas.pdb.setColours(udc);
609 pdbcanvas.redrawneeded=true;
614 public void background_actionPerformed(ActionEvent e)
616 java.awt.Color col = JColorChooser.showDialog(this, "Select Background Colour",
617 pdbcanvas.backgroundColour);
621 pdbcanvas.backgroundColour = col;
622 pdbcanvas.redrawneeded = true;
627 public void savePDB_actionPerformed(ActionEvent e)
629 JalviewFileChooser chooser = new JalviewFileChooser(
630 jalview.bin.Cache.getProperty(
633 chooser.setFileView(new JalviewFileView());
634 chooser.setDialogTitle("Save PDB File");
635 chooser.setToolTipText("Save");
637 int value = chooser.showSaveDialog(this);
639 if (value == JalviewFileChooser.APPROVE_OPTION)
643 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
644 File outFile = chooser.getSelectedFile();
646 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
648 while ( (data = in.readLine()) != null)
651 !( data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1)
659 ex.printStackTrace();