/*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
-*\r
-* This program is free software; you can redistribute it and/or\r
-* modify it under the terms of the GNU General Public License\r
-* as published by the Free Software Foundation; either version 2\r
-* of the License, or (at your option) any later version.\r
-*\r
-* This program is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with this program; if not, write to the Free Software\r
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
-*/\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+ */\r
\r
package jalview.appletgui;\r
\r
-import jalview.jbappletgui.GCutAndPasteTransfer;\r
-import jalview.datamodel.*;\r
-import jalview.io.*;\r
import java.awt.*;\r
import java.awt.event.*;\r
\r
-public class CutAndPasteTransfer extends GCutAndPasteTransfer\r
+import jalview.datamodel.*;\r
+import jalview.io.*;\r
+\r
+public class CutAndPasteTransfer\r
+ extends Panel implements ActionListener, MouseListener\r
{\r
- public CutAndPasteTransfer(boolean forImport)\r
+ boolean pdbImport = false;\r
+ boolean treeImport = false;\r
+ boolean annotationImport = false;\r
+ Sequence seq;\r
+ AlignFrame alignFrame;\r
+\r
+ public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame)\r
{\r
- super();\r
+ try\r
+ {\r
+ jbInit();\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ e.printStackTrace();\r
+ }\r
+\r
+ this.alignFrame = alignFrame;\r
\r
- if(!forImport)\r
+ if (!forImport)\r
{\r
buttonPanel.setVisible(false);\r
}\r
}\r
\r
-\r
public String getText()\r
{\r
return textarea.getText();\r
textarea.setText(text);\r
}\r
\r
+ public void setPDBImport(Sequence seq)\r
+ {\r
+ this.seq = seq;\r
+ accept.setLabel("Accept");\r
+ addSequences.setVisible(false);\r
+ pdbImport = true;\r
+ }\r
+\r
+ public void setTreeImport()\r
+ {\r
+ treeImport = true;\r
+ accept.setLabel("Accept");\r
+ addSequences.setVisible(false);\r
+ }\r
\r
- protected void ok_actionPerformed(ActionEvent e)\r
+ public void setAnnotationImport()\r
+ {\r
+ annotationImport = true;\r
+ accept.setLabel("Accept");\r
+ addSequences.setVisible(false);\r
+ }\r
+\r
+ public void actionPerformed(ActionEvent evt)\r
+ {\r
+ if (evt.getSource() == accept)\r
+ {\r
+ ok(true);\r
+ }\r
+ else if (evt.getSource() == addSequences)\r
+ {\r
+ ok(false);\r
+ }\r
+ else if (evt.getSource() == cancel)\r
+ {\r
+ cancel();\r
+ }\r
+ }\r
+\r
+ protected void ok(boolean newWindow)\r
{\r
String text = getText();\r
- SequenceI[] sequences = null;\r
+ int length = text.length();\r
+ textarea.append("\n");\r
+ if (textarea.getText().length() == length)\r
+ {\r
+ String warning =\r
+ "\n\n#################################################\n"\r
+ + "WARNING!! THIS IS THE MAXIMUM SIZE OF TEXTAREA!!\n"\r
+ + "\nCAN'T INPUT FULL ALIGNMENT"\r
+ + "\n\nYOU MUST DELETE THIS WARNING TO CONTINUE"\r
+ + "\n\nMAKE SURE LAST SEQUENCE PASTED IS COMPLETE"\r
+ + "\n#################################################\n";\r
+ textarea.setText(text.substring(0, text.length() - warning.length())\r
+ + warning);\r
+\r
+ textarea.setCaretPosition(text.length());\r
+ }\r
+\r
+ if (pdbImport)\r
+ {\r
+ PDBEntry pdb = new PDBEntry();\r
+ pdb.setFile(text);\r
+\r
+ if ( alignFrame.alignPanel.av.applet.jmolAvailable )\r
+ new jalview.appletgui.AppletJmol(pdb,\r
+ new Sequence[]\r
+ {seq},\r
+ alignFrame.alignPanel,\r
+ AppletFormatAdapter.PASTE);\r
+ else\r
\r
- String format = IdentifyFile.Identify(text, "Paste");\r
- sequences = FormatAdapter.readFile(text, "Paste", format);\r
+ new MCview.AppletPDBViewer(pdb,\r
+ new Sequence[]\r
+ {seq},\r
+ alignFrame.alignPanel,\r
+ AppletFormatAdapter.PASTE);\r
\r
- if (sequences != null)\r
+ }\r
+ else if (treeImport)\r
{\r
- AlignFrame af = new AlignFrame(new Alignment(sequences));\r
- jalview.bin.JalviewLite.addFrame(af, "Cut & Paste input - " + format,\r
- AlignFrame.NEW_WINDOW_WIDTH,\r
- AlignFrame.NEW_WINDOW_HEIGHT);\r
- af.statusBar.setText("Successfully pasted alignment file");\r
+ try\r
+ {\r
+ jalview.io.NewickFile fin = new jalview.io.NewickFile(textarea.getText(),\r
+ "Paste");\r
+\r
+ fin.parse();\r
+ if (fin.getTree() != null)\r
+ {\r
+ alignFrame.loadTree(fin, "Pasted tree file");\r
+ }\r
+\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ textarea.setText("Could not parse Newick file!\n" + ex);\r
+ return;\r
+ }\r
}\r
+ else if (annotationImport)\r
+ {\r
+ if (new AnnotationFile().readAnnotationFile(\r
+ alignFrame.viewport.alignment, textarea.getText(),\r
+ jalview.io.AppletFormatAdapter.PASTE))\r
+ {\r
+ alignFrame.alignPanel.fontChanged();\r
+ alignFrame.alignPanel.setScrollValues(0, 0);\r
+\r
+ }\r
+ else\r
+ {\r
+ alignFrame.parseFeaturesFile(textarea.getText(),\r
+ jalview.io.AppletFormatAdapter.PASTE);\r
+ }\r
+ }\r
+ else if (alignFrame != null)\r
+ {\r
+ Alignment al = null;\r
\r
- Frame frame = (Frame)this.getParent();\r
- frame.setVisible(false);\r
- }\r
+ String format = new IdentifyFile().Identify(text,\r
+ AppletFormatAdapter.PASTE);\r
+ try\r
+ {\r
+ al = new AppletFormatAdapter().readFile(text, AppletFormatAdapter.PASTE,\r
+ format);\r
+ }\r
+ catch (java.io.IOException ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+\r
+ if (al != null)\r
+ {\r
+ if (newWindow)\r
+ {\r
+ AlignFrame af = new AlignFrame(al, alignFrame.viewport.applet,\r
+ "Cut & Paste input - " + format,\r
+ false);\r
+ af.statusBar.setText("Successfully pasted alignment file");\r
+ }\r
+ else\r
+ {\r
+ alignFrame.addSequences(al.getSequencesArray());\r
+ }\r
+ }\r
+ }\r
+\r
+ if (this.getParent() instanceof Frame)\r
+ {\r
+ ( (Frame)this.getParent()).setVisible(false);\r
+ }\r
+ else\r
+ {\r
+ ( (Dialog)this.getParent()).setVisible(false);\r
+ }\r
+ }\r
\r
- protected void cancel_actionPerformed(ActionEvent e) {\r
- Frame frame = (Frame)this.getParent();\r
- frame.setVisible(false);\r
- }\r
+ protected void cancel()\r
+ {\r
+ textarea.setText("");\r
+ if (this.getParent() instanceof Frame)\r
+ {\r
+ ( (Frame)this.getParent()).setVisible(false);\r
+ }\r
+ else\r
+ {\r
+ ( (Dialog)this.getParent()).setVisible(false);\r
+ }\r
+ }\r
+\r
+ protected TextArea textarea = new TextArea();\r
+ Button accept = new Button("New Window");\r
+ Button addSequences = new Button("Add to Current Alignment");\r
+ Button cancel = new Button("Close");\r
+\r
+ protected Panel buttonPanel = new Panel();\r
+ BorderLayout borderLayout1 = new BorderLayout();\r
+\r
+ private void jbInit()\r
+ throws Exception\r
+ {\r
+ textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10));\r
+ textarea.setText("Paste your alignment file here");\r
+ textarea.addMouseListener(this);\r
+ this.setLayout(borderLayout1);\r
+ accept.addActionListener(this);\r
+ addSequences.addActionListener(this);\r
+ cancel.addActionListener(this);\r
+ this.add(buttonPanel, BorderLayout.SOUTH);\r
+ buttonPanel.add(accept, null);\r
+ buttonPanel.add(addSequences);\r
+ buttonPanel.add(cancel, null);\r
+ this.add(textarea, java.awt.BorderLayout.CENTER);\r
+ }\r
+\r
+ public void mousePressed(MouseEvent evt)\r
+ {\r
+ if (textarea.getText().startsWith("Paste your"))\r
+ {\r
+ textarea.setText("");\r
+ }\r
+ }\r
\r
+ public void mouseReleased(MouseEvent evt)\r
+ {}\r
\r
+ public void mouseClicked(MouseEvent evt)\r
+ {}\r
\r
+ public void mouseEntered(MouseEvent evt)\r
+ {}\r
\r
+ public void mouseExited(MouseEvent evt)\r
+ {}\r
}\r