From 0654aaeaf0f2788912dc9814ffd352dd72dc5115 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 18 Apr 2024 16:01:46 +0100 Subject: [PATCH] JAL-4397 fixed testresetIdWidth() test on macos --- src/jalview/gui/IdCanvas.java | 2 +- test/jalview/gui/AlignmentPanelTest.java | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index 76020c7..7a4cf84 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -312,7 +312,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI if (alignViewport.getWrapAlignment()) { drawIdsWrapped(g, alignViewport, startSeq, getHeight(), - manuallyAdjusted ? panelWidth : -1, forGUI); + isManuallyAdjusted() ? panelWidth : -1, forGUI); return; } diff --git a/test/jalview/gui/AlignmentPanelTest.java b/test/jalview/gui/AlignmentPanelTest.java index a221bd1..d69f57f 100644 --- a/test/jalview/gui/AlignmentPanelTest.java +++ b/test/jalview/gui/AlignmentPanelTest.java @@ -29,6 +29,7 @@ import java.awt.Container; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; +import java.awt.event.MouseEvent; import java.lang.reflect.InvocationTargetException; import javax.swing.SwingUtilities; @@ -308,23 +309,35 @@ public class AlignmentPanelTest * width for onscreen rendering is IDPanel width */ int w = af.alignPanel.getVisibleIdWidth(true); - assertEquals(w, af.alignPanel.getIdPanel().getWidth()); + int actual = af.alignPanel.getIdPanel().getWidth(); + assertEquals(w, actual); assertEquals(w, 115); // manually adjust af.viewport.setIdWidth(200); + // fake mouse drag sets manuallyAdjusted to true (0,0 not moving mouse) + MouseEvent drag = new MouseEvent(af.alignPanel, + MouseEvent.MOUSE_DRAGGED, System.currentTimeMillis(), 0, 0, 0, + MouseEvent.BUTTON1, false); + af.alignPanel.idwidthAdjuster.mouseDragged(drag); + af.alignPanel.paintComponent(af.alignPanel.getGraphics()); w = af.alignPanel.calculateIdWidth().width; assertTrue( af.alignPanel.getIdPanel().getIdCanvas().isManuallyAdjusted()); - assertEquals(w, af.alignPanel.getIdPanel().getWidth()); + actual = af.alignPanel.getIdPanel().getWidth(); + assertEquals(w, actual); af.viewport.setIdWidth(-1); af.alignPanel.getIdPanel().getIdCanvas().setManuallyAdjusted(false); w = af.alignPanel.calculateIdWidth().width; + af.alignPanel.paintComponent(af.alignPanel.getGraphics()); - assertEquals(w, af.alignPanel.getIdPanel().getWidth()); + actual = af.alignPanel.getIdPanel().getWidth(); + assertEquals(w, actual); - assertNotEquals(w, 115); + // setting a negative IdWidth and then running calculateIdWidth resets width + // to optimal id width + assertEquals(w, 115); } @Test(groups = "Functional") -- 1.7.10.2