X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FPDBViewer.java;h=868b7538817265233118e1e48297791e20155da0;hb=37a5dfc3c72a42689e90ad8a0e118e8855d9868b;hp=817e59da52b89c9e737861e50314ec5a39125e62;hpb=daeacba9a61069114333b550a987242d8e47e7f7;p=jalview.git diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java index 817e59d..868b753 100755 --- a/src/MCview/PDBViewer.java +++ b/src/MCview/PDBViewer.java @@ -21,29 +21,27 @@ package MCview; import javax.swing.*; import java.awt.event.*; import jalview.datamodel.*; +import jalview.schemes.*; 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) { - - pdb = entry; - sequence = seq; - - Thread worker = new Thread(this); - worker.start(); - try { jbInit(); @@ -53,18 +51,49 @@ public class PDBViewer extends JInternalFrame implements Runnable ex.printStackTrace(); } - pdbcanvas = new PDBCanvas(seqcanvas, seq); + + 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(); + } + + 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); } @@ -72,17 +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); - + 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(); } } @@ -160,14 +196,6 @@ public class PDBViewer extends JInternalFrame implements Runnable charge_actionPerformed(e); } }); - hydro.setText("Hydrophobicity"); - hydro.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - hydro_actionPerformed(e); - } - }); chain.setText("By Chain"); chain.addActionListener(new ActionListener() { @@ -185,14 +213,6 @@ public class PDBViewer extends JInternalFrame implements Runnable seqButton_actionPerformed(e); } }); - molecule.setText("By Molecule"); - molecule.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - molecule_actionPerformed(e); - } - }); allchains.setSelected(true); allchains.setText("Show All Chains"); allchains.addItemListener(new ItemListener() @@ -202,27 +222,175 @@ public class PDBViewer extends JInternalFrame implements Runnable allchains_itemStateChanged(e); } }); + zappo.setText("Zappo"); + zappo.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + zappo_actionPerformed(e); + } + }); + taylor.setText("Taylor"); + taylor.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + taylor_actionPerformed(e); + } + }); + hydro.setText("Hydro"); + hydro.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + hydro_actionPerformed(e); + } + }); + helix.setText("Helix"); + helix.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + helix_actionPerformed(e); + } + }); + strand.setText("Strand"); + strand.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + strand_actionPerformed(e); + } + }); + turn.setText("Turn"); + turn.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + turn_actionPerformed(e); + } + }); + buried.setText("Buried"); + buried.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + buried_actionPerformed(e); + } + }); + user.setText("User Defined..."); + user.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + user_actionPerformed(e); + } + }); + 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); coloursMenu.add(chain); - coloursMenu.add(hydro); coloursMenu.add(charge); - coloursMenu.addSeparator(); - coloursMenu.add(wire); - coloursMenu.add(depth); - coloursMenu.add(zbuffer); - coloursMenu.add(molecule); - coloursMenu.add(allchains); + coloursMenu.add(zappo); + coloursMenu.add(taylor); + coloursMenu.add(hydro); + coloursMenu.add(helix); + coloursMenu.add(strand); + coloursMenu.add(turn); + coloursMenu.add(buried); + coloursMenu.add(user); + coloursMenu.add(background); ButtonGroup bg = new ButtonGroup(); bg.add(seqButton); bg.add(chain); - bg.add(hydro); bg.add(charge); + bg.add(zappo); + bg.add(taylor); + bg.add(hydro); + bg.add(helix); + bg.add(strand); + bg.add(turn); + bg.add(buried); + bg.add(user); + + + if(jalview.gui.UserDefinedColours.getUserColourSchemes()!=null) + { + java.util.Enumeration userColours = jalview.gui.UserDefinedColours. + getUserColourSchemes().keys(); + + while (userColours.hasMoreElements()) + { + final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours. + nextElement().toString()); + radioItem.setName("USER_DEFINED"); + radioItem.addMouseListener(new MouseAdapter() + { + public void mousePressed(MouseEvent evt) + { + if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt)) + { + radioItem.removeActionListener(radioItem.getActionListeners()[0]); + + int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop, + "Remove from default list?", + "Remove user defined colour", + JOptionPane.YES_NO_OPTION); + if(option == JOptionPane.YES_OPTION) + { + jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText()); + coloursMenu.remove(radioItem); + } + else + radioItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent evt) + { + user_actionPerformed(evt); + } + }); + } + } + }); + radioItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent evt) + { + user_actionPerformed(evt); + } + }); + coloursMenu.add(radioItem); + bg.add(radioItem); + } + } + + viewMenu.add(wire); + viewMenu.add(depth); + viewMenu.add(zbuffer); + viewMenu.add(allchains); } JMenuBar jMenuBar1 = new JMenuBar(); @@ -235,12 +403,22 @@ public class PDBViewer extends JInternalFrame implements Runnable JCheckBoxMenuItem wire = new JCheckBoxMenuItem(); JCheckBoxMenuItem depth = new JCheckBoxMenuItem(); JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem(); + JCheckBoxMenuItem allchains = new JCheckBoxMenuItem(); + JRadioButtonMenuItem charge = new JRadioButtonMenuItem(); - JRadioButtonMenuItem hydro = new JRadioButtonMenuItem(); JRadioButtonMenuItem chain = new JRadioButtonMenuItem(); JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem(); - JCheckBoxMenuItem molecule = new JCheckBoxMenuItem(); - JCheckBoxMenuItem allchains = new JCheckBoxMenuItem(); + JRadioButtonMenuItem hydro = new JRadioButtonMenuItem(); + JRadioButtonMenuItem taylor = new JRadioButtonMenuItem(); + JRadioButtonMenuItem zappo = new JRadioButtonMenuItem(); + JRadioButtonMenuItem user = new JRadioButtonMenuItem(); + JRadioButtonMenuItem buried = new JRadioButtonMenuItem(); + JRadioButtonMenuItem turn = new JRadioButtonMenuItem(); + JRadioButtonMenuItem strand = new JRadioButtonMenuItem(); + JRadioButtonMenuItem helix = new JRadioButtonMenuItem(); + JMenu viewMenu = new JMenu(); + JMenuItem background = new JMenuItem(); + JMenuItem savePDB = new JMenuItem(); /** * DOCUMENT ME! @@ -290,7 +468,7 @@ public class PDBViewer extends JInternalFrame implements Runnable } public void charge_actionPerformed(ActionEvent e) { - clearButtonGroup(); + pdbcanvas.bysequence = false; pdbcanvas.pdb.setChargeColours(); pdbcanvas.redrawneeded=true; pdbcanvas.repaint(); @@ -298,15 +476,15 @@ public class PDBViewer extends JInternalFrame implements Runnable public void hydro_actionPerformed(ActionEvent e) { - clearButtonGroup(); - pdbcanvas.pdb.setHydrophobicityColours(); + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setColours(new HydrophobicColourScheme()); pdbcanvas.redrawneeded=true; pdbcanvas.repaint(); } public void chain_actionPerformed(ActionEvent e) { - clearButtonGroup(); + pdbcanvas.bysequence = false; pdbcanvas.pdb.setChainColours(); pdbcanvas.redrawneeded=true; pdbcanvas.repaint(); @@ -342,16 +520,10 @@ public class PDBViewer extends JInternalFrame implements Runnable public void seqButton_actionPerformed(ActionEvent e) { - clearButtonGroup(); - pdbcanvas.bysequence = seqButton.isSelected(); + pdbcanvas.bysequence = true; pdbcanvas.updateSeqColours(); } - void clearButtonGroup() - { - pdbcanvas.bysequence = false; - pdbcanvas.bymolecule = false; - } public void mapping_actionPerformed(ActionEvent e) { @@ -364,4 +536,125 @@ 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) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setColours(new ZappoColourScheme()); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void taylor_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setColours(new TaylorColourScheme()); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void helix_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setColours(new HelixColourScheme()); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void strand_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setColours(new StrandColourScheme()); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void turn_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setColours(new TurnColourScheme()); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void buried_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setColours(new BuriedColourScheme()); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void user_actionPerformed(ActionEvent e) + { + if (e.getActionCommand().equals("User Defined...")) + { + new UserDefinedColours(pdbcanvas, null); + } + else + { + UserColourScheme udc = (UserColourScheme) UserDefinedColours. + getUserColourSchemes().get(e.getActionCommand()); + + pdbcanvas.pdb.setColours(udc); + pdbcanvas.redrawneeded=true; + 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(); + } + } + } }