X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FPDBViewer.java;h=e16241bdc222c1d389a08a9336b37b480fdecc42;hb=ab43013b7e357b84b4abade0dba949668dfb2a0e;hp=e586707c7a5581e214282a6673a7bf4d5a8b3bb9;hpb=0eda2ac2f334f55f6e5f137789453a9f4dfe4d73;p=jalview.git diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java index e586707..e16241b 100755 --- a/src/MCview/PDBViewer.java +++ b/src/MCview/PDBViewer.java @@ -1,38 +1,70 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 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 - * as published by the Free Software Foundation; either version 2 + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1) + * Copyright (C) 2014 The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package MCview; -import java.io.*; - -import java.awt.event.*; -import javax.swing.*; - -import jalview.datamodel.*; -import jalview.gui.*; -import jalview.io.*; -import jalview.schemes.*; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; +import jalview.gui.AlignmentPanel; +import jalview.gui.Desktop; +import jalview.gui.OOMWarning; +import jalview.gui.UserDefinedColours; +import jalview.io.JalviewFileChooser; +import jalview.io.JalviewFileView; +import jalview.schemes.BuriedColourScheme; +import jalview.schemes.HelixColourScheme; +import jalview.schemes.HydrophobicColourScheme; +import jalview.schemes.StrandColourScheme; +import jalview.schemes.TaylorColourScheme; +import jalview.schemes.TurnColourScheme; +import jalview.schemes.UserColourScheme; +import jalview.schemes.ZappoColourScheme; +import jalview.util.MessageManager; import jalview.ws.ebi.EBIFetchClient; -import java.awt.BorderLayout; - -public class PDBViewer - extends JInternalFrame implements Runnable +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.PrintWriter; + +import javax.swing.ButtonGroup; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JColorChooser; +import javax.swing.JInternalFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JRadioButtonMenuItem; +import javax.swing.SwingUtilities; + +public class PDBViewer extends JInternalFrame implements Runnable { /** @@ -41,18 +73,19 @@ public class PDBViewer PDBCanvas pdbcanvas; PDBEntry pdbentry; - SequenceI[]seq; - String[]chains; + + SequenceI[] seq; + + String[] chains; + AlignmentPanel ap; + String protocol; - String tmpPDBFile; - public PDBViewer(PDBEntry pdbentry, - SequenceI[] seq, - String[] chains, - AlignmentPanel ap, - String protocol) + String tmpPDBFile; + public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains, + AlignmentPanel ap, String protocol) { this.pdbentry = pdbentry; this.seq = seq; @@ -63,16 +96,13 @@ public class PDBViewer try { jbInit(); - } - catch (Exception ex) + } catch (Exception ex) { ex.printStackTrace(); } - - StringBuffer title = new StringBuffer(seq[0].getName() - + ":" - + pdbentry.getFile()); + StringBuffer title = new StringBuffer(seq[0].getName() + ":" + + pdbentry.getFile()); pdbcanvas = new PDBCanvas(); @@ -83,13 +113,12 @@ public class PDBViewer try { tmpPDBFile = pdbentry.getFile(); - PDBfile pdbfile = new PDBfile(tmpPDBFile, - jalview.io.AppletFormatAdapter.FILE); + PDBfile pdbfile = new PDBfile(false, false, false, tmpPDBFile, + jalview.io.AppletFormatAdapter.FILE); pdbcanvas.init(pdbentry, seq, chains, ap, protocol); - } - catch (java.io.IOException ex) + } catch (java.io.IOException ex) { ex.printStackTrace(); } @@ -100,8 +129,6 @@ public class PDBViewer worker.start(); } - - if (pdbentry.getProperty() != null) { if (pdbentry.getProperty().get("method") != null) @@ -125,20 +152,20 @@ public class PDBViewer EBIFetchClient ebi = new EBIFetchClient(); String query = "pdb:" + pdbentry.getId(); pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw") - .getAbsolutePath()); + .getAbsolutePath()); - if(pdbentry.getFile()!=null) + if (pdbentry.getFile() != null) + { pdbcanvas.init(pdbentry, seq, chains, ap, protocol); - } - catch (Exception ex) + } + } catch (Exception ex) { - pdbcanvas.errorMessage = "Error retrieving file: "+pdbentry.getId(); + pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId(); ex.printStackTrace(); } } - private void jbInit() - throws Exception + private void jbInit() throws Exception { this.addKeyListener(new KeyAdapter() { @@ -149,10 +176,10 @@ public class PDBViewer }); this.setJMenuBar(jMenuBar1); - fileMenu.setText("File"); - coloursMenu.setText("Colours"); - saveMenu.setActionCommand("Save Image"); - saveMenu.setText("Save As"); + fileMenu.setText(MessageManager.getString("action.file")); + coloursMenu.setText(MessageManager.getString("label.colours")); + saveMenu.setActionCommand(MessageManager.getString("action.save_image")); + saveMenu.setText(MessageManager.getString("action.save_as")); png.setText("PNG"); png.addActionListener(new ActionListener() { @@ -169,7 +196,7 @@ public class PDBViewer eps_actionPerformed(e); } }); - mapping.setText("View Mapping"); + mapping.setText(MessageManager.getString("label.view_mapping")); mapping.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -177,7 +204,7 @@ public class PDBViewer mapping_actionPerformed(e); } }); - wire.setText("Wireframe"); + wire.setText(MessageManager.getString("label.wireframe")); wire.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -186,7 +213,7 @@ public class PDBViewer } }); depth.setSelected(true); - depth.setText("Depthcue"); + depth.setText(MessageManager.getString("label.depthcue")); depth.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -195,7 +222,7 @@ public class PDBViewer } }); zbuffer.setSelected(true); - zbuffer.setText("Z Buffering"); + zbuffer.setText(MessageManager.getString("label.z_buffering")); zbuffer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -203,7 +230,7 @@ public class PDBViewer zbuffer_actionPerformed(e); } }); - charge.setText("Charge & Cysteine"); + charge.setText(MessageManager.getString("label.charge_cysteine")); charge.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -211,7 +238,7 @@ public class PDBViewer charge_actionPerformed(e); } }); - chain.setText("By Chain"); + chain.setText(MessageManager.getString("action.by_chain")); chain.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -220,7 +247,7 @@ public class PDBViewer } }); seqButton.setSelected(true); - seqButton.setText("By Sequence"); + seqButton.setText(MessageManager.getString("action.by_sequence")); seqButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -229,7 +256,7 @@ public class PDBViewer } }); allchains.setSelected(true); - allchains.setText("Show All Chains"); + allchains.setText(MessageManager.getString("label.show_all_chains")); allchains.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) @@ -237,7 +264,7 @@ public class PDBViewer allchains_itemStateChanged(e); } }); - zappo.setText("Zappo"); + zappo.setText(MessageManager.getString("label.zappo")); zappo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -245,7 +272,7 @@ public class PDBViewer zappo_actionPerformed(e); } }); - taylor.setText("Taylor"); + taylor.setText(MessageManager.getString("label.taylor")); taylor.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -253,7 +280,7 @@ public class PDBViewer taylor_actionPerformed(e); } }); - hydro.setText("Hydro"); + hydro.setText(MessageManager.getString("label.hydrophobicity")); hydro.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -261,7 +288,7 @@ public class PDBViewer hydro_actionPerformed(e); } }); - helix.setText("Helix"); + helix.setText(MessageManager.getString("label.helix_propensity")); helix.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -269,7 +296,7 @@ public class PDBViewer helix_actionPerformed(e); } }); - strand.setText("Strand"); + strand.setText(MessageManager.getString("label.strand_propensity")); strand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -277,7 +304,7 @@ public class PDBViewer strand_actionPerformed(e); } }); - turn.setText("Turn"); + turn.setText(MessageManager.getString("label.turn_propensity")); turn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -285,7 +312,7 @@ public class PDBViewer turn_actionPerformed(e); } }); - buried.setText("Buried"); + buried.setText(MessageManager.getString("label.buried_index")); buried.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -293,7 +320,7 @@ public class PDBViewer buried_actionPerformed(e); } }); - user.setText("User Defined..."); + user.setText(MessageManager.getString("action.user_defined")); user.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -301,8 +328,9 @@ public class PDBViewer user_actionPerformed(e); } }); - viewMenu.setText("View"); - background.setText("Background Colour..."); + viewMenu.setText(MessageManager.getString("action.view")); + background.setText(MessageManager.getString("label.background_colour") + + "..."); background.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -310,7 +338,7 @@ public class PDBViewer background_actionPerformed(e); } }); - savePDB.setText("PDB File"); + savePDB.setText(MessageManager.getString("label.pdb_file")); savePDB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -353,32 +381,34 @@ public class PDBViewer if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null) { - java.util.Enumeration userColours = jalview.gui.UserDefinedColours. - getUserColourSchemes().keys(); + java.util.Enumeration userColours = jalview.gui.UserDefinedColours + .getUserColourSchemes().keys(); while (userColours.hasMoreElements()) { final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem( - userColours. - nextElement().toString()); + userColours.nextElement().toString()); radioItem.setName("USER_DEFINED"); radioItem.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent evt) { - if (evt.isControlDown() || SwingUtilities.isRightMouseButton(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); + int option = JOptionPane.showInternalConfirmDialog( + jalview.gui.Desktop.desktop, + MessageManager + .getString("label.remove_from_default_list"), + MessageManager + .getString("label.remove_user_defined_colour"), + JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { - jalview.gui.UserDefinedColours.removeColourFromDefaults( - radioItem.getText()); + jalview.gui.UserDefinedColours + .removeColourFromDefaults(radioItem.getText()); coloursMenu.remove(radioItem); } else @@ -413,74 +443,103 @@ public class PDBViewer } JMenuBar jMenuBar1 = new JMenuBar(); + JMenu fileMenu = new JMenu(); + JMenu coloursMenu = new JMenu(); + JMenu saveMenu = new JMenu(); + JMenuItem png = new JMenuItem(); + JMenuItem eps = new JMenuItem(); + JMenuItem mapping = new JMenuItem(); + JCheckBoxMenuItem wire = new JCheckBoxMenuItem(); + JCheckBoxMenuItem depth = new JCheckBoxMenuItem(); + JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem(); + JCheckBoxMenuItem allchains = new JCheckBoxMenuItem(); JRadioButtonMenuItem charge = new JRadioButtonMenuItem(); + JRadioButtonMenuItem chain = new JRadioButtonMenuItem(); + JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem(); + 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! - * - * @param e DOCUMENT ME! + * + * @param e + * DOCUMENT ME! */ public void eps_actionPerformed(ActionEvent e) { - makePDBImage(jalview.util.ImageMaker.EPS); + makePDBImage(jalview.util.ImageMaker.TYPE.EPS); } /** * DOCUMENT ME! - * - * @param e DOCUMENT ME! + * + * @param e + * DOCUMENT ME! */ public void png_actionPerformed(ActionEvent e) { - makePDBImage(jalview.util.ImageMaker.PNG); + makePDBImage(jalview.util.ImageMaker.TYPE.PNG); } - void makePDBImage(int type) + void makePDBImage(jalview.util.ImageMaker.TYPE type) { int width = pdbcanvas.getWidth(); int height = pdbcanvas.getHeight(); jalview.util.ImageMaker im; - if (type == jalview.util.ImageMaker.PNG) + if (type == jalview.util.ImageMaker.TYPE.PNG) + { + im = new jalview.util.ImageMaker(this, + jalview.util.ImageMaker.TYPE.PNG, + "Make PNG image from view", width, height, null, null); + } + else if (type == jalview.util.ImageMaker.TYPE.EPS) { im = new jalview.util.ImageMaker(this, - jalview.util.ImageMaker.PNG, - "Make PNG image from view", - width, height, - null, null); + jalview.util.ImageMaker.TYPE.EPS, + "Make EPS file from view", width, height, null, + this.getTitle()); } else { + im = new jalview.util.ImageMaker(this, - jalview.util.ImageMaker.EPS, - "Make EPS file from view", - width, height, - null, this.getTitle()); + jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA", + width, height, null, this.getTitle()); } if (im.getGraphics() != null) @@ -551,8 +610,17 @@ public class PDBViewer public void mapping_actionPerformed(ActionEvent e) { jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer(); - Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600); - cap.setText(pdbcanvas.mappingDetails.toString()); + try + { + cap.setText(pdbcanvas.mappingDetails.toString()); + Desktop.addInternalFrame(cap, + MessageManager.getString("label.pdb_sequence_mapping"), 550, + 600); + } catch (OutOfMemoryError oom) + { + new OOMWarning("Opening sequence to structure mapping report", oom); + cap.dispose(); + } } public void allchains_itemStateChanged(ItemEvent e) @@ -560,7 +628,6 @@ public class PDBViewer pdbcanvas.setAllchainsVisible(allchains.getState()); } - public void zappo_actionPerformed(ActionEvent e) { pdbcanvas.bysequence = false; @@ -611,14 +678,15 @@ public class PDBViewer public void user_actionPerformed(ActionEvent e) { - if (e.getActionCommand().equals("User Defined...")) + if (e.getActionCommand().equals( + MessageManager.getString("action.user_defined"))) { - // new UserDefinedColours(pdbcanvas, null); + // new UserDefinedColours(pdbcanvas, null); } else { - UserColourScheme udc = (UserColourScheme) UserDefinedColours. - getUserColourSchemes().get(e.getActionCommand()); + UserColourScheme udc = (UserColourScheme) UserDefinedColours + .getUserColourSchemes().get(e.getActionCommand()); pdbcanvas.pdb.setColours(udc); pdbcanvas.redrawneeded = true; @@ -629,8 +697,8 @@ public class PDBViewer public void background_actionPerformed(ActionEvent e) { java.awt.Color col = JColorChooser.showDialog(this, - "Select Background Colour", - pdbcanvas.backgroundColour); + MessageManager.getString("label.select_backgroud_colour"), + pdbcanvas.backgroundColour); if (col != null) { @@ -643,12 +711,11 @@ public class PDBViewer public void savePDB_actionPerformed(ActionEvent e) { JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty( - "LAST_DIRECTORY")); + jalview.bin.Cache.getProperty("LAST_DIRECTORY")); chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle("Save PDB File"); - chooser.setToolTipText("Save"); + chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file")); + chooser.setToolTipText(MessageManager.getString("action.save")); int value = chooser.showSaveDialog(this); @@ -661,18 +728,16 @@ public class PDBViewer PrintWriter out = new PrintWriter(new FileOutputStream(outFile)); String data; - while ( (data = in.readLine()) != null) + while ((data = in.readLine()) != null) { - if ( - ! (data.indexOf("
") > -1 || data.indexOf("
") > -1) - ) + if (!(data.indexOf("
") > -1 || data.indexOf("
") > -1)) { out.println(data); } } out.close(); - } - catch (Exception ex) + in.close(); + } catch (Exception ex) { ex.printStackTrace(); }