2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2005 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 public class PDBViewer extends JInternalFrame implements Runnable
37 public PDBViewer(PDBEntry entry,
41 /*Uncomment this to modify in Jbuilder
56 Thread worker = new Thread(this);
59 pdbcanvas = new PDBCanvas(seqcanvas, seq);
61 setContentPane(pdbcanvas);
62 StringBuffer title = new StringBuffer(sequence.getName() + ":" + pdb.getId());
63 if(pdb.getProperty()!=null)
65 if (pdb.getProperty().get("method")!=null)
67 title.append(" Method: ");
68 title.append(pdb.getProperty().get("method"));
70 if (pdb.getProperty().get("chains") != null)
72 title.append(" Chain:");
73 title.append(pdb.getProperty().get("chains"));
76 Desktop.addInternalFrame(this,title.toString(),400, 400);
83 EBIFetchClient ebi = new EBIFetchClient();
84 String query = "pdb:" + pdb.getId();
85 String[] result = ebi.fetchData(query, "default","raw");
87 PDBfile pdbfile = new PDBfile(result);
88 pdbcanvas.setPDBFile(pdbfile);
90 throw new Exception("Empty result for WSDbFetch Query: "+query);
104 ex.printStackTrace();
105 showErrorMessage("Failed to retrieve PDB structure.");
110 private void jbInit()
113 this.addKeyListener(new KeyAdapter()
115 public void keyPressed(KeyEvent evt)
117 pdbcanvas.keyPressed(evt);
121 this.setJMenuBar(jMenuBar1);
122 fileMenu.setText("File");
123 coloursMenu.setText("Colours");
124 saveMenu.setActionCommand("Save Image");
125 saveMenu.setText("Save As");
127 png.addActionListener(new ActionListener()
129 public void actionPerformed(ActionEvent e)
131 png_actionPerformed(e);
135 eps.addActionListener(new ActionListener()
137 public void actionPerformed(ActionEvent e)
139 eps_actionPerformed(e);
142 mapping.setText("View Mapping");
143 mapping.addActionListener(new ActionListener()
145 public void actionPerformed(ActionEvent e)
147 mapping_actionPerformed(e);
150 wire.setText("Wireframe");
151 wire.addActionListener(new ActionListener()
153 public void actionPerformed(ActionEvent e)
155 wire_actionPerformed(e);
158 depth.setSelected(true);
159 depth.setText("Depthcue");
160 depth.addActionListener(new ActionListener()
162 public void actionPerformed(ActionEvent e)
164 depth_actionPerformed(e);
167 zbuffer.setSelected(true);
168 zbuffer.setText("Z Buffering");
169 zbuffer.addActionListener(new ActionListener()
171 public void actionPerformed(ActionEvent e)
173 zbuffer_actionPerformed(e);
176 charge.setText("Charge & Cysteine");
177 charge.addActionListener(new ActionListener()
179 public void actionPerformed(ActionEvent e)
181 charge_actionPerformed(e);
184 chain.setText("By Chain");
185 chain.addActionListener(new ActionListener()
187 public void actionPerformed(ActionEvent e)
189 chain_actionPerformed(e);
192 seqButton.setSelected(true);
193 seqButton.setText("By Sequence");
194 seqButton.addActionListener(new ActionListener()
196 public void actionPerformed(ActionEvent e)
198 seqButton_actionPerformed(e);
201 allchains.setSelected(true);
202 allchains.setText("Show All Chains");
203 allchains.addItemListener(new ItemListener()
205 public void itemStateChanged(ItemEvent e)
207 allchains_itemStateChanged(e);
210 zappo.setText("Zappo");
211 zappo.addActionListener(new ActionListener()
213 public void actionPerformed(ActionEvent e)
215 zappo_actionPerformed(e);
218 taylor.setText("Taylor");
219 taylor.addActionListener(new ActionListener()
221 public void actionPerformed(ActionEvent e)
223 taylor_actionPerformed(e);
226 hydro.setText("Hydro");
227 hydro.addActionListener(new ActionListener()
229 public void actionPerformed(ActionEvent e)
231 hydro_actionPerformed(e);
234 helix.setText("Helix");
235 helix.addActionListener(new ActionListener()
237 public void actionPerformed(ActionEvent e)
239 helix_actionPerformed(e);
242 strand.setText("Strand");
243 strand.addActionListener(new ActionListener()
245 public void actionPerformed(ActionEvent e)
247 strand_actionPerformed(e);
250 turn.setText("Turn");
251 turn.addActionListener(new ActionListener()
253 public void actionPerformed(ActionEvent e)
255 turn_actionPerformed(e);
258 buried.setText("Buried");
259 buried.addActionListener(new ActionListener()
261 public void actionPerformed(ActionEvent e)
263 buried_actionPerformed(e);
266 user.setText("User Defined...");
267 user.addActionListener(new ActionListener()
269 public void actionPerformed(ActionEvent e)
271 user_actionPerformed(e);
274 viewMenu.setText("View");
275 jMenuBar1.add(fileMenu);
276 jMenuBar1.add(coloursMenu);
277 jMenuBar1.add(viewMenu);
278 fileMenu.add(saveMenu);
279 fileMenu.add(mapping);
282 coloursMenu.add(seqButton);
283 coloursMenu.add(chain);
284 coloursMenu.add(charge);
285 coloursMenu.add(zappo);
286 coloursMenu.add(taylor);
287 coloursMenu.add(hydro);
288 coloursMenu.add(helix);
289 coloursMenu.add(strand);
290 coloursMenu.add(turn);
291 coloursMenu.add(buried);
292 coloursMenu.add(user);
293 ButtonGroup bg = new ButtonGroup();
307 if(jalview.gui.UserDefinedColours.getUserColourSchemes()!=null)
309 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
310 getUserColourSchemes().keys();
312 while (userColours.hasMoreElements())
314 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
315 nextElement().toString());
316 radioItem.setName("USER_DEFINED");
317 radioItem.addMouseListener(new MouseAdapter()
319 public void mousePressed(MouseEvent evt)
321 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
323 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
325 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
326 "Remove from default list?",
327 "Remove user defined colour",
328 JOptionPane.YES_NO_OPTION);
329 if(option == JOptionPane.YES_OPTION)
331 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
332 coloursMenu.remove(radioItem);
335 radioItem.addActionListener(new ActionListener()
337 public void actionPerformed(ActionEvent evt)
339 user_actionPerformed(evt);
345 radioItem.addActionListener(new ActionListener()
347 public void actionPerformed(ActionEvent evt)
349 user_actionPerformed(evt);
352 coloursMenu.add(radioItem);
359 viewMenu.add(zbuffer);
360 viewMenu.add(allchains);
363 JMenuBar jMenuBar1 = new JMenuBar();
364 JMenu fileMenu = new JMenu();
365 JMenu coloursMenu = new JMenu();
366 JMenu saveMenu = new JMenu();
367 JMenuItem png = new JMenuItem();
368 JMenuItem eps = new JMenuItem();
369 JMenuItem mapping = new JMenuItem();
370 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
371 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
372 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
373 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
375 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
376 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
377 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
378 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
379 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
380 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
381 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
382 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
383 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
384 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
385 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
386 JMenu viewMenu = new JMenu();
391 * @param e DOCUMENT ME!
393 public void eps_actionPerformed(ActionEvent e)
395 makePDBImage(jalview.util.ImageMaker.EPS);
401 * @param e DOCUMENT ME!
403 public void png_actionPerformed(ActionEvent e)
405 makePDBImage(jalview.util.ImageMaker.PNG);
408 void makePDBImage(int type)
410 int width = pdbcanvas.getWidth();
411 int height = pdbcanvas.getHeight();
413 jalview.util.ImageMaker im;
415 if (type == jalview.util.ImageMaker.PNG)
416 im = new jalview.util.ImageMaker(this,
417 jalview.util.ImageMaker.PNG,
418 "Make PNG image from view",
422 im = new jalview.util.ImageMaker(this,
423 jalview.util.ImageMaker.EPS,
424 "Make EPS file from view",
426 null, this.getTitle());
428 if (im.getGraphics() != null)
430 pdbcanvas.drawAll(im.getGraphics(), width, height);
434 public void charge_actionPerformed(ActionEvent e)
436 pdbcanvas.bysequence = false;
437 pdbcanvas.pdb.setChargeColours();
438 pdbcanvas.redrawneeded=true;
442 public void hydro_actionPerformed(ActionEvent e)
444 pdbcanvas.bysequence = false;
445 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
446 pdbcanvas.redrawneeded=true;
450 public void chain_actionPerformed(ActionEvent e)
452 pdbcanvas.bysequence = false;
453 pdbcanvas.pdb.setChainColours();
454 pdbcanvas.redrawneeded=true;
458 public void zbuffer_actionPerformed(ActionEvent e)
460 pdbcanvas.zbuffer = ! pdbcanvas.zbuffer;
461 pdbcanvas.redrawneeded=true;
465 public void molecule_actionPerformed(ActionEvent e)
467 pdbcanvas.bymolecule = ! pdbcanvas.bymolecule;
468 pdbcanvas.redrawneeded=true;
472 public void depth_actionPerformed(ActionEvent e)
474 pdbcanvas.depthcue = ! pdbcanvas.depthcue;
475 pdbcanvas.redrawneeded=true;
479 public void wire_actionPerformed(ActionEvent e)
481 pdbcanvas.wire = ! pdbcanvas.wire;
482 pdbcanvas.redrawneeded=true;
486 public void seqButton_actionPerformed(ActionEvent e)
488 pdbcanvas.bysequence = true;
489 pdbcanvas.updateSeqColours();
493 public void mapping_actionPerformed(ActionEvent e)
495 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
496 Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
497 cap.setText(pdbcanvas.mappingDetails.toString());
500 public void allchains_itemStateChanged(ItemEvent e)
502 pdbcanvas.setAllchainsVisible(allchains.getState());
504 void showErrorMessage(String error)
506 JOptionPane.showInternalMessageDialog(Desktop.desktop,
507 error, "PDB Viewer Error", JOptionPane.WARNING_MESSAGE);
511 public void zappo_actionPerformed(ActionEvent e)
513 pdbcanvas.bysequence = false;
514 pdbcanvas.pdb.setColours(new ZappoColourScheme());
515 pdbcanvas.redrawneeded=true;
519 public void taylor_actionPerformed(ActionEvent e)
521 pdbcanvas.bysequence = false;
522 pdbcanvas.pdb.setColours(new TaylorColourScheme());
523 pdbcanvas.redrawneeded=true;
527 public void helix_actionPerformed(ActionEvent e)
529 pdbcanvas.bysequence = false;
530 pdbcanvas.pdb.setColours(new HelixColourScheme());
531 pdbcanvas.redrawneeded=true;
535 public void strand_actionPerformed(ActionEvent e)
537 pdbcanvas.bysequence = false;
538 pdbcanvas.pdb.setColours(new StrandColourScheme());
539 pdbcanvas.redrawneeded=true;
543 public void turn_actionPerformed(ActionEvent e)
545 pdbcanvas.bysequence = false;
546 pdbcanvas.pdb.setColours(new TurnColourScheme());
547 pdbcanvas.redrawneeded=true;
551 public void buried_actionPerformed(ActionEvent e)
553 pdbcanvas.bysequence = false;
554 pdbcanvas.pdb.setColours(new BuriedColourScheme());
555 pdbcanvas.redrawneeded=true;
559 public void user_actionPerformed(ActionEvent e)
561 if (e.getActionCommand().equals("User Defined..."))
563 new UserDefinedColours(pdbcanvas, null);
567 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
568 getUserColourSchemes().get(e.getActionCommand());
570 pdbcanvas.pdb.setColours(udc);
571 pdbcanvas.redrawneeded=true;