From 284dc3090d93f4b149b38bb5106d93eb1a4ae7b2 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 27 Jul 2006 10:29:45 +0000 Subject: [PATCH] Save PDB file to disk --- src/MCview/PDBViewer.java | 58 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java index 69a131c..1f1f94d 100755 --- a/src/MCview/PDBViewer.java +++ b/src/MCview/PDBViewer.java @@ -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,39 @@ 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(); + } + } + } } -- 1.7.10.2