JAL-4150 test and quick patch copying code from AlignFrame.paste() to Desktop.paste...
[jalview.git] / src / jalview / gui / Desktop.java
index 06afe81..1521d0a 100644 (file)
@@ -102,8 +102,13 @@ import org.stackoverflowusers.file.WindowsShortcut;
 
 import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
+import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.HiddenColumns;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
 import jalview.gui.ImageExporter.ImageWriterI;
 import jalview.gui.QuitHandler.QResponse;
 import jalview.io.BackupFiles;
@@ -502,11 +507,15 @@ public class Desktop extends jalview.jbgui.GDesktop
     // This line prevents Windows Look&Feel resizing all new windows to maximum
     // if previous window was maximised
     desktop.setDesktopManager(new MyDesktopManager(
-            (Platform.isWindowsAndNotJS() ? new DefaultDesktopManager()
-                    : Platform.isAMacAndNotJS()
-                            ? new AquaInternalFrameManager(
-                                    desktop.getDesktopManager())
-                            : desktop.getDesktopManager())));
+            Platform.isJS() ? desktop.getDesktopManager()
+                    : new DefaultDesktopManager()));
+    /*
+    (Platform.isWindowsAndNotJS() ? new DefaultDesktopManager()
+            : Platform.isAMacAndNotJS()
+                    ? new AquaInternalFrameManager(
+                            desktop.getDesktopManager())
+                    : desktop.getDesktopManager())));
+                    */
 
     Rectangle dims = getLastKnownDimensions("");
     if (dims != null)
@@ -794,6 +803,41 @@ public class Desktop extends jalview.jbgui.GDesktop
 
   public void paste()
   {
+    // quick patch for JAL-4150 - needs some more work and test coverage
+    // TODO - unify below and AlignFrame.paste()
+    // TODO - write tests and fix AlignFrame.paste() which doesn't track if
+    // clipboard has come from a different alignment window than the one where
+    // paste has been called! JAL-4151
+    
+    if (Desktop.jalviewClipboard != null)
+    {
+      // The clipboard was filled from within Jalview, we must use the
+      // sequences
+      // And dataset from the copied alignment
+      SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
+      // be doubly sure that we create *new* sequence objects.
+      SequenceI[] sequences = new SequenceI[newseq.length];
+      for (int i = 0; i < newseq.length; i++)
+      {
+        sequences[i] = new Sequence(newseq[i]);
+      }
+      Alignment alignment = new Alignment(sequences);
+      // dataset is inherited
+      alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
+      AlignFrame af = new AlignFrame(alignment, AlignFrame.DEFAULT_WIDTH,
+              AlignFrame.DEFAULT_HEIGHT);
+      String newtitle = new String("Copied sequences");
+
+      if (Desktop.jalviewClipboard[2] != null)
+      {
+        HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
+        af.viewport.setHiddenColumns(hc);
+      }
+
+      Desktop.addInternalFrame(af, newtitle, AlignFrame.DEFAULT_WIDTH,
+            AlignFrame.DEFAULT_HEIGHT);
+
+    } else {
     try
     {
       Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
@@ -815,6 +859,7 @@ public class Desktop extends jalview.jbgui.GDesktop
       System.out.println(
               "Unable to paste alignment from system clipboard:\n" + ex);
     }
+    }
   }
 
   /**
@@ -1377,6 +1422,8 @@ public class Desktop extends jalview.jbgui.GDesktop
         storeLastKnownDimensions("JALVIEW_RSS_WINDOW_", jvnews.getBounds());
       }
 
+      // Frames should all close automatically. Keeping external
+      // viewers open should already be decided by user.
       closeAll_actionPerformed(null);
 
       // check for aborted quit
@@ -1551,17 +1598,11 @@ public class Desktop extends jalview.jbgui.GDesktop
   {
     // TODO show a progress bar while closing?
     JInternalFrame[] frames = desktop.getAllFrames();
-    boolean quitting = QuitHandler.quitting();
     for (int i = 0; i < frames.length; i++)
     {
       try
       {
         frames[i].setClosed(true);
-        // check for cancelled quit
-        if (quitting && QuitHandler.quitCancelled())
-        {
-          return;
-        }
       } catch (java.beans.PropertyVetoException ex)
       {
       }
@@ -1581,6 +1622,22 @@ public class Desktop extends jalview.jbgui.GDesktop
     }
   }
 
+  public int structureViewersStillRunningCount()
+  {
+    int count = 0;
+    JInternalFrame[] frames = desktop.getAllFrames();
+    for (int i = 0; i < frames.length; i++)
+    {
+      if (frames[i] != null
+              && frames[i] instanceof JalviewStructureDisplayI)
+      {
+        if (((JalviewStructureDisplayI) frames[i]).stillRunning())
+          count++;
+      }
+    }
+    return count;
+  }
+
   @Override
   public void raiseRelated_actionPerformed(ActionEvent e)
   {