From 270f61aee660a2b8206e51f6392405b8ac30fef7 Mon Sep 17 00:00:00 2001 From: James Procter Date: Mon, 20 Mar 2023 16:26:18 +0000 Subject: [PATCH] JAL-4150 test and quick patch copying code from AlignFrame.paste() to Desktop.paste() so internal paste works from popup menu --- src/jalview/gui/Desktop.java | 40 ++++++++ test/jalview/datamodel/AlignmentTest.java | 10 ++ test/jalview/gui/DesktopTests.java | 153 +++++++++++++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 test/jalview/gui/DesktopTests.java diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 7b4af59..1521d0a 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -105,6 +105,10 @@ 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; @@ -799,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(); @@ -820,6 +859,7 @@ public class Desktop extends jalview.jbgui.GDesktop System.out.println( "Unable to paste alignment from system clipboard:\n" + ex); } + } } /** diff --git a/test/jalview/datamodel/AlignmentTest.java b/test/jalview/datamodel/AlignmentTest.java index 06be982..92db223 100644 --- a/test/jalview/datamodel/AlignmentTest.java +++ b/test/jalview/datamodel/AlignmentTest.java @@ -1591,4 +1591,14 @@ public class AlignmentTest // ? } + @Test(groups = {"Functional"}) + public void testEquals() + { + SequenceI seq1 = new Sequence("seq1", "ABCDEF--"); + SequenceI seq2 = new Sequence("seq2", "-JKLMNO--"); + SequenceI seq3 = new Sequence("seq2", "-PQR"); + AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2, seq3 }); + a.setDataset(null); + assertEquals(a.getDataset(),a.getDataset()); + } } diff --git a/test/jalview/gui/DesktopTests.java b/test/jalview/gui/DesktopTests.java new file mode 100644 index 0000000..897f28e --- /dev/null +++ b/test/jalview/gui/DesktopTests.java @@ -0,0 +1,153 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ 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. + * + * 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 Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.gui; + +import static org.junit.Assert.assertNotEquals; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotSame; +import static org.testng.Assert.assertSame; +import static org.testng.Assert.assertTrue; + +import java.awt.Color; +import java.util.Iterator; + +import javax.swing.SwingUtilities; + +import org.junit.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import jalview.api.FeatureColourI; +import jalview.bin.Cache; +import jalview.bin.Jalview; +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.HiddenColumns; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.io.DataSourceType; +import jalview.io.FileLoader; +import jalview.project.Jalview2xmlTests; +import jalview.renderer.ResidueShaderI; +import jalview.schemes.BuriedColourScheme; +import jalview.schemes.FeatureColour; +import jalview.schemes.HelixColourScheme; +import jalview.schemes.JalviewColourScheme; +import jalview.schemes.StrandColourScheme; +import jalview.schemes.TurnColourScheme; +import jalview.util.MessageManager; + +public class DesktopTests +{ + + @BeforeClass(alwaysRun = true) + public static void setUpBeforeClass() throws Exception + { + setUpJvOptionPane(); + /* + * use read-only test properties file + */ + Cache.loadProperties("test/jalview/io/testProps.jvprops"); + Jalview.main(new String[] { "-nonews" }); + } + + @AfterMethod(alwaysRun = true) + public void tearDown() + { + Desktop.instance.closeAll_actionPerformed(null); + } + + /** + * + * configure (read-only) properties for test to ensure Consensus is computed + * for colour Above PID testing + */ + public AlignFrame loadTestFile() + { + Cache.loadProperties("test/jalview/io/testProps.jvprops"); + Cache.applicationProperties.setProperty("SHOW_IDENTITY", + Boolean.TRUE.toString()); + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( + "examples/uniref50.fa", DataSourceType.FILE); + + /* + * wait for Consensus thread to complete + */ + do + { + try + { + Thread.sleep(50); + } catch (InterruptedException x) + { + } + } while (af.getViewport().getCalcManager().isWorking()); + return af; + } + + public static void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + + @Test(groups = { "Functional" }) + public void testInternalCopyPaste() + { + AlignFrame internalSource = loadTestFile(); + + try + { + SwingUtilities.invokeAndWait(new Runnable() + { + @Override + public void run() + { + internalSource.selectAllSequenceMenuItem_actionPerformed(null); + internalSource.copy_actionPerformed(); + Desktop.instance.paste(); + } + }); + } catch (Exception x) + { + Assert.fail("Unexpected exception " + x); + } + AlignFrame[] alfs = Desktop.getAlignFrames(); + Assert.assertEquals("Expect just 2 alignment frames", 2, alfs.length); + // internal paste should yield a new alignment window with shared dataset + AlignmentI dataset = internalSource.getViewport().getAlignment() + .getDataset(); + Assert.assertNotNull(dataset); + + for (AlignFrame alf : alfs) + { + Assert.assertTrue( + "Internal paste should yield alignment with same dataset.", + dataset == alf.getViewport().getAlignment().getDataset()); + } + + } +} -- 1.7.10.2