X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FPDBViewer.java;h=4c9351bdd3b678e318a206a90d2c096ad0257ac9;hb=3f9c1d052c8fe2e92ae0d7a1c3088ccb82c58ba5;hp=50a4a36cc6a6a1fd510249ae97fda2a5606a8522;hpb=c44b1974aea543db46790f6cb88f5ac0aae10a94;p=jalview.git diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java index 50a4a36..4c9351b 100755 --- a/src/MCview/PDBViewer.java +++ b/src/MCview/PDBViewer.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -26,19 +26,22 @@ import jalview.gui.*; import jalview.io.EBIFetchClient; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; +import java.io.*; +import jalview.io.JalviewFileChooser; +import jalview.io.JalviewFileView; public class PDBViewer extends JInternalFrame implements Runnable { PDBEntry pdb; Sequence sequence; PDBCanvas pdbcanvas; + String tmpPDBFile; public PDBViewer(PDBEntry entry, Sequence seq, SeqCanvas seqcanvas) { - /*Uncomment this to modify in Jbuilder try { jbInit(); @@ -46,27 +49,51 @@ public class PDBViewer extends JInternalFrame implements Runnable catch (Exception ex) { ex.printStackTrace(); - }*/ + } + if (entry==null) + return; pdb = entry; sequence = seq; + pdbcanvas = new PDBCanvas(seqcanvas, sequence); + + if(pdb.getFile()!=null) + { + try{ + tmpPDBFile = pdb.getFile(); + PDBfile pdbfile = new PDBfile(tmpPDBFile, + jalview.io.AppletFormatAdapter.FILE); + pdbcanvas.setPDBFile(pdbfile); + + }catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + } + else + { + Thread worker = new Thread(this); + worker.start(); + } - Thread worker = new Thread(this); - worker.start(); - pdbcanvas = new PDBCanvas(seqcanvas, seq); setContentPane(pdbcanvas); StringBuffer title = new StringBuffer(sequence.getName() + ":" + pdb.getId()); if(pdb.getProperty()!=null) { - title.append( " Method: " ); - title.append(pdb.getProperty().get("method")); - title.append( " Chain:" ); - title.append( pdb.getProperty().get("chains")); + if (pdb.getProperty().get("method")!=null) + { + title.append(" Method: "); + title.append(pdb.getProperty().get("method")); + } + if (pdb.getProperty().get("chains") != null) + { + title.append(" Chain:"); + title.append(pdb.getProperty().get("chains")); + } } - Desktop.addInternalFrame(this,title.toString(),400, 400); } @@ -74,25 +101,24 @@ public class PDBViewer extends JInternalFrame implements Runnable { try { - EBIFetchClient ebi = new EBIFetchClient(); - String[] result = ebi.fetchData("pdb:" + pdb.getId(), "default","raw"); - - PDBfile pdbfile = new PDBfile(result); - - pdbcanvas.setPDBFile(pdbfile); - - try - { - jbInit(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } + EBIFetchClient ebi = new EBIFetchClient(); + String query = "pdb:" + pdb.getId(); + tmpPDBFile = ebi.fetchDataAsFile(query, "default", "raw").getAbsolutePath(); + if (tmpPDBFile != null) + { + PDBfile pdbfile = new PDBfile(tmpPDBFile, jalview.io.AppletFormatAdapter.FILE); + pdbcanvas.setPDBFile(pdbfile); + } + else + { + throw new Exception("Empty result for WSDbFetch Query: " + query); + } } catch (Exception ex) { ex.printStackTrace(); + showErrorMessage("Failed to retrieve PDB structure."); +// this.dispose(); } } @@ -261,11 +287,28 @@ public class PDBViewer extends JInternalFrame implements Runnable } }); viewMenu.setText("View"); + background.setText("Background Colour..."); + background.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + background_actionPerformed(e); + } + }); + savePDB.setText("PDB File"); + savePDB.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + savePDB_actionPerformed(e); + } + }); jMenuBar1.add(fileMenu); jMenuBar1.add(coloursMenu); jMenuBar1.add(viewMenu); fileMenu.add(saveMenu); fileMenu.add(mapping); + saveMenu.add(savePDB); saveMenu.add(png); saveMenu.add(eps); coloursMenu.add(seqButton); @@ -279,6 +322,7 @@ public class PDBViewer extends JInternalFrame implements Runnable coloursMenu.add(turn); coloursMenu.add(buried); coloursMenu.add(user); + coloursMenu.add(background); ButtonGroup bg = new ButtonGroup(); bg.add(seqButton); bg.add(chain); @@ -373,6 +417,8 @@ public class PDBViewer extends JInternalFrame implements Runnable JRadioButtonMenuItem strand = new JRadioButtonMenuItem(); JRadioButtonMenuItem helix = new JRadioButtonMenuItem(); JMenu viewMenu = new JMenu(); + JMenuItem background = new JMenuItem(); + JMenuItem savePDB = new JMenuItem(); /** * DOCUMENT ME! @@ -490,6 +536,12 @@ public class PDBViewer extends JInternalFrame implements Runnable { pdbcanvas.setAllchainsVisible(allchains.getState()); } + void showErrorMessage(String error) + { + JOptionPane.showInternalMessageDialog(Desktop.desktop, + error, "PDB Viewer Error", JOptionPane.WARNING_MESSAGE); + } + public void zappo_actionPerformed(ActionEvent e) { @@ -555,4 +607,54 @@ public class PDBViewer extends JInternalFrame implements Runnable pdbcanvas.repaint(); } } + + public void background_actionPerformed(ActionEvent e) + { + java.awt.Color col = JColorChooser.showDialog(this, "Select Background Colour", + pdbcanvas.backgroundColour); + + if(col!=null) + { + pdbcanvas.backgroundColour = col; + pdbcanvas.redrawneeded = true; + pdbcanvas.repaint(); + } + } + + public void savePDB_actionPerformed(ActionEvent e) + { + JalviewFileChooser chooser = new JalviewFileChooser( + jalview.bin.Cache.getProperty( + "LAST_DIRECTORY")); + + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle("Save PDB File"); + chooser.setToolTipText("Save"); + + int value = chooser.showSaveDialog(this); + + if (value == JalviewFileChooser.APPROVE_OPTION) + { + try + { + BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile)); + File outFile = chooser.getSelectedFile(); + + PrintWriter out = new PrintWriter(new FileOutputStream(outFile)); + String data; + while ( (data = in.readLine()) != null) + { + if ( + !( data.indexOf("
") > -1 || data.indexOf("
") > -1) + ) + out.println(data); + } + out.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + } }