X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FMCview%2FPDBViewer.java;h=4c9351bdd3b678e318a206a90d2c096ad0257ac9;hb=c20e9d4ae9c98b093e74a10bf965e6d20d80fadf;hp=69a131c9a8ccddcf10c110104209df3cd65b3af3;hpb=4d23c07766621f358d8e64112f5399478886d3b1;p=jalview.git diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java index 69a131c..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,12 +26,16 @@ 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, @@ -57,7 +61,8 @@ public class PDBViewer extends JInternalFrame implements Runnable if(pdb.getFile()!=null) { try{ - PDBfile pdbfile = new PDBfile(pdb.getFile(), + tmpPDBFile = pdb.getFile(); + PDBfile pdbfile = new PDBfile(tmpPDBFile, jalview.io.AppletFormatAdapter.FILE); pdbcanvas.setPDBFile(pdbfile); @@ -98,10 +103,10 @@ public class PDBViewer extends JInternalFrame implements Runnable { EBIFetchClient ebi = new EBIFetchClient(); String query = "pdb:" + pdb.getId(); - String file = ebi.fetchDataAsFile(query, "default", "raw").getAbsolutePath(); - if (file != null) + tmpPDBFile = ebi.fetchDataAsFile(query, "default", "raw").getAbsolutePath(); + if (tmpPDBFile != null) { - PDBfile pdbfile = new PDBfile(file, jalview.io.AppletFormatAdapter.FILE); + PDBfile pdbfile = new PDBfile(tmpPDBFile, jalview.io.AppletFormatAdapter.FILE); pdbcanvas.setPDBFile(pdbfile); } else @@ -290,11 +295,20 @@ public class PDBViewer extends JInternalFrame implements Runnable 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); @@ -404,6 +418,7 @@ public class PDBViewer extends JInternalFrame implements Runnable JRadioButtonMenuItem helix = new JRadioButtonMenuItem(); JMenu viewMenu = new JMenu(); JMenuItem background = new JMenuItem(); + JMenuItem savePDB = new JMenuItem(); /** * DOCUMENT ME! @@ -605,4 +620,41 @@ public class PDBViewer extends JInternalFrame implements Runnable 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(); + } + } + } }