X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FPDBViewer.java;h=868b7538817265233118e1e48297791e20155da0;hb=37a5dfc3c72a42689e90ad8a0e118e8855d9868b;hp=87c2739ca1a65ee17085b2b6924d523838b16503;hpb=196711de5050f77775a8df8f652ef6b36a88df2a;p=jalview.git diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java index 87c2739..868b753 100755 --- a/src/MCview/PDBViewer.java +++ b/src/MCview/PDBViewer.java @@ -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,17 +49,35 @@ 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()); @@ -80,24 +101,18 @@ public class PDBViewer extends JInternalFrame implements Runnable { try { - EBIFetchClient ebi = new EBIFetchClient(); - String query = "pdb:" + pdb.getId(); - String[] result = ebi.fetchData(query, "default","raw"); - if (result!=null) { - PDBfile pdbfile = new PDBfile(result); - pdbcanvas.setPDBFile(pdbfile); - } else { - throw new Exception("Empty result for WSDbFetch Query: "+query); - } - - 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) { @@ -280,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); @@ -394,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! @@ -595,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(); + } + } + } }