JAL-1645 source formatting and organise imports
[jalview.git] / src / jalview / appletgui / CutAndPasteTransfer.java
index d33e0cc..5617c64 100644 (file)
  */
 package jalview.appletgui;
 
-import java.awt.BorderLayout;
-import java.awt.Button;
-import java.awt.Dialog;
-import java.awt.Font;
-import java.awt.Frame;
-import java.awt.Label;
-import java.awt.Panel;
-import java.awt.TextArea;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-
 import jalview.analysis.AlignmentUtils;
+import jalview.api.ComplexAlignFile;
 import jalview.bin.JalviewLite;
-import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.io.AnnotationFile;
 import jalview.io.AppletFormatAdapter;
+import jalview.io.FileParse;
 import jalview.io.IdentifyFile;
 import jalview.io.NewickFile;
 import jalview.io.TCoffeeScoreFile;
+import jalview.schemes.ColourSchemeI;
 import jalview.schemes.TCoffeeColourScheme;
 import jalview.util.MessageManager;
 
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Dialog;
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.Label;
+import java.awt.Panel;
+import java.awt.TextArea;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+
 public class CutAndPasteTransfer extends Panel implements ActionListener,
         MouseListener
 {
@@ -60,6 +63,8 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
 
   AlignFrame alignFrame;
 
+  FileParse source = null;
+
   public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame)
   {
     try
@@ -163,7 +168,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
     }
     else if (alignFrame != null)
     {
-      loadAlignment(text, newWindow);
+      loadAlignment(text, newWindow, alignFrame.getAlignViewport());
     }
 
     // TODO: dialog should indicate if data was parsed correctly or not - see
@@ -199,8 +204,8 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
       // TODO: JAL-1102 - should have a warning message in dialog, not simply
       // overwrite the broken input data with the exception
       textarea.setText(MessageManager.formatMessage(
-              "label.could_not_parse_newick_file", new Object[]
-              { ex.getMessage() }));
+              "label.could_not_parse_newick_file",
+              new Object[] { ex.getMessage() }));
       return false;
     }
     return false;
@@ -212,16 +217,18 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
    * @param text
    * @param newWindow
    */
-  protected void loadAlignment(String text, boolean newWindow)
+  protected void loadAlignment(String text, boolean newWindow,
+          AlignViewport viewport)
   {
-    Alignment al = null;
+    AlignmentI al = null;
 
     String format = new IdentifyFile().Identify(text,
             AppletFormatAdapter.PASTE);
+    AppletFormatAdapter afa = new AppletFormatAdapter(alignFrame.alignPanel);
     try
     {
-      al = new AppletFormatAdapter().readFile(text,
-              AppletFormatAdapter.PASTE, format);
+      al = afa.readFile(text, AppletFormatAdapter.PASTE, format);
+      source = afa.getAlignFile();
     } catch (java.io.IOException ex)
     {
       ex.printStackTrace();
@@ -242,8 +249,29 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
       }
       if (newWindow)
       {
-        AlignFrame af = new AlignFrame(al, alignFrame.viewport.applet,
-                "Cut & Paste input - " + format, false);
+        AlignFrame af;
+
+        if (source instanceof ComplexAlignFile)
+        {
+          ColumnSelection colSel = ((ComplexAlignFile) source)
+                  .getColumnSelection();
+          SequenceI[] hiddenSeqs = ((ComplexAlignFile) source)
+                  .getHiddenSequences();
+          boolean showSeqFeatures = ((ComplexAlignFile) source)
+                  .isShowSeqFeatures();
+          ColourSchemeI cs = ((ComplexAlignFile) source).getColourScheme();
+          af = new AlignFrame(al, hiddenSeqs, colSel,
+                  alignFrame.viewport.applet, "Cut & Paste input - "
+                          + format, false);
+          af.getAlignViewport().setShowSequenceFeatures(showSeqFeatures);
+          af.changeColour(cs);
+        }
+        else
+        {
+          af = new AlignFrame(al, alignFrame.viewport.applet,
+                  "Cut & Paste input - " + format, false);
+        }
+
         af.statusBar
                 .setText(MessageManager
                         .getString("label.successfully_pasted_annotation_to_alignment"));
@@ -265,9 +293,10 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
    * @param al
    * @return
    */
-  protected boolean openSplitFrame(Alignment al, String format)
+  protected boolean openSplitFrame(AlignmentI al, String format)
   {
-    final AlignmentI thisAlignment = this.alignFrame.getAlignViewport().getAlignment();
+    final AlignmentI thisAlignment = this.alignFrame.getAlignViewport()
+            .getAlignment();
     if (thisAlignment.isNucleotide() == al.isNucleotide())
     {
       // both nucleotide or both protein
@@ -296,7 +325,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
     dialog.setMainPanel(question);
     dialog.setVisible(true);
     dialog.toFront();
-    
+
     if (!dialog.accept)
     {
       return false;
@@ -313,8 +342,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
     AlignFrame newFrame = new AlignFrame(al, alignFrame.viewport.applet,
             "Cut & Paste input - " + format, false, false);
     AlignFrame dnaFrame = al.isNucleotide() ? newFrame : copyFrame;
-    AlignFrame proteinFrame = al.isNucleotide() ? copyFrame
-            : newFrame;
+    AlignFrame proteinFrame = al.isNucleotide() ? copyFrame : newFrame;
     SplitFrame sf = new SplitFrame(dnaFrame, proteinFrame);
     sf.addToDisplay(false, applet);
     return true;
@@ -333,8 +361,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
               jalview.io.AppletFormatAdapter.PASTE);
       if (tcf.isValid())
       {
-        if (tcf.annotateAlignment(alignFrame.viewport.getAlignment(),
-                true))
+        if (tcf.annotateAlignment(alignFrame.viewport.getAlignment(), true))
         {
           alignFrame.tcoffeeColour.setEnabled(true);
           alignFrame.alignPanel.fontChanged();
@@ -349,8 +376,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
           // file valid but didn't get added to alignment for some reason
           alignFrame.statusBar.setText(MessageManager.formatMessage(
                   "label.failed_add_tcoffee_scores",
-                  new Object[]
-                  { (tcf.getWarningMessage() != null ? tcf
+                  new Object[] { (tcf.getWarningMessage() != null ? tcf
                           .getWarningMessage() : "") }));
         }
       }
@@ -365,8 +391,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
     if (tcf == null)
     {
       if (new AnnotationFile().annotateAlignmentView(alignFrame.viewport,
-              textarea.getText(),
-              jalview.io.AppletFormatAdapter.PASTE))
+              textarea.getText(), jalview.io.AppletFormatAdapter.PASTE))
       {
         alignFrame.alignPanel.fontChanged();
         alignFrame.alignPanel.setScrollValues(0, 0);
@@ -401,13 +426,13 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
 
     if (alignFrame.alignPanel.av.applet.jmolAvailable)
     {
-      new jalview.appletgui.AppletJmol(pdb, new SequenceI[]
-      { seq }, null, alignFrame.alignPanel, AppletFormatAdapter.PASTE);
+      new jalview.appletgui.AppletJmol(pdb, new SequenceI[] { seq }, null,
+              alignFrame.alignPanel, AppletFormatAdapter.PASTE);
     }
     else
     {
-      new MCview.AppletPDBViewer(pdb, new SequenceI[]
-      { seq }, null, alignFrame.alignPanel, AppletFormatAdapter.PASTE);
+      new MCview.AppletPDBViewer(pdb, new SequenceI[] { seq }, null,
+              alignFrame.alignPanel, AppletFormatAdapter.PASTE);
     }
   }