Add new feature from seqrch results
[jalview.git] / src / jalview / appletgui / CutAndPasteTransfer.java
index 22cfd67..173b031 100755 (executable)
@@ -1,42 +1,61 @@
 /*\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) 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
 \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 extends Panel implements ActionListener, MouseListener\r
 {\r
-  public CutAndPasteTransfer(boolean forImport)\r
+  jalview.bin.JalviewLite applet;\r
+\r
+  boolean pdbImport = false;\r
+  Sequence seq;\r
+  SeqCanvas seqcanvas;\r
+\r
+  public CutAndPasteTransfer(boolean forImport, jalview.bin.JalviewLite mainApplet)\r
   {\r
-    super();\r
+    try {\r
+        jbInit();\r
+    } catch (Exception e) {\r
+        e.printStackTrace();\r
+    }\r
+\r
+    applet = mainApplet;\r
 \r
-    if(!forImport)\r
+    if (!forImport)\r
     {\r
       buttonPanel.setVisible(false);\r
     }\r
   }\r
 \r
+  public void setPDBImport(Sequence seq, SeqCanvas seqcanvas)\r
+  {\r
+    this.seq = seq;\r
+    this.seqcanvas = seqcanvas;\r
+    pdbImport = true;\r
+  }\r
+\r
 \r
   public String getText()\r
   {\r
@@ -48,34 +67,93 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer
     textarea.setText(text);\r
   }\r
 \r
+  public void actionPerformed(ActionEvent evt)\r
+  {\r
+    if(evt.getSource()==ok)\r
+      ok_actionPerformed();\r
+    else if(evt.getSource()==cancel)\r
+      cancel_actionPerformed();\r
+  }\r
 \r
-  protected void ok_actionPerformed(ActionEvent e)\r
+  protected void ok_actionPerformed()\r
   {\r
     String text = getText();\r
-    SequenceI[] sequences = null;\r
-\r
-    String format = IdentifyFile.Identify(text, "Paste");\r
-    sequences = FormatAdapter.readFile(text, "Paste", format);\r
-\r
-    if (sequences != null)\r
+    int length = text.length();\r
+    textarea.append("\n");\r
+    if(textarea.getText().length()==length)\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
+      String warning = "\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
-    Frame frame = (Frame)this.getParent();\r
-    frame.setVisible(false);\r
-   }\r
-\r
-   protected void cancel_actionPerformed(ActionEvent e) {\r
-     Frame frame = (Frame)this.getParent();\r
-     frame.setVisible(false);\r
-   }\r
+    if(pdbImport)\r
+    {\r
+      new MCview.AppletPDBViewer(text, AppletFormatAdapter.PASTE, seq, seqcanvas);\r
+    }\r
+    else\r
+    {\r
+      SequenceI[] sequences = null;\r
+\r
+      String format = new IdentifyFile().Identify(text, AppletFormatAdapter.PASTE);\r
+      try{\r
+        sequences = new AppletFormatAdapter().readFile(text, AppletFormatAdapter.PASTE, format);\r
+      }catch(java.io.IOException ex)\r
+      {\r
+        ex.printStackTrace();\r
+      }\r
+      if (sequences != null)\r
+      {\r
+        AlignFrame af = new AlignFrame(new Alignment(sequences), applet,\r
+                                       "Cut & Paste input - " + format);\r
+        af.statusBar.setText("Successfully pasted alignment file");\r
+      }\r
+    }\r
 \r
+    ((Frame)this.getParent()).setVisible(false);\r
+  }\r
 \r
+  protected void cancel_actionPerformed()\r
+  {\r
+    ((Frame)this.getParent()).setVisible(false);\r
+  }\r
 \r
+  protected TextArea textarea = new TextArea();\r
+  Button ok = new Button();\r
+  Button cancel = new Button();\r
+  protected Panel buttonPanel = new Panel();\r
+  BorderLayout borderLayout1 = new BorderLayout();\r
+\r
+\r
+  private void jbInit() throws Exception {\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
+      ok.setLabel("OK");\r
+      ok.addActionListener(this);\r
+      cancel.setLabel("Cancel");\r
+      cancel.addActionListener(this);\r
+      this.add(buttonPanel, BorderLayout.SOUTH);\r
+      buttonPanel.add(ok, null);\r
+      buttonPanel.add(cancel, null);\r
+      this.add(textarea, java.awt.BorderLayout.CENTER);\r
+  }\r
 \r
+  public void mousePressed(MouseEvent evt) {\r
+      if (textarea.getText().startsWith("Paste your")) {\r
+          textarea.setText("");\r
+     }\r
+  }\r
+  public void mouseReleased(MouseEvent evt){}\r
+  public void mouseClicked(MouseEvent evt){}\r
+  public void mouseEntered(MouseEvent evt){}\r
+  public void mouseExited(MouseEvent evt){}\r
 }\r