X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fgui%2FAlignmentPanelTest.java;h=caa4e2294c433ed8979c5213548bc70c28332af1;hb=e83ce5d8ef826fc0b509a51f154abdf734501077;hp=a6bce20dee816922ba54216366ab2a2c7310ca9c;hpb=8df2de111af18978bb5254650cab7ba28bc84e82;p=jalview.git diff --git a/test/jalview/gui/AlignmentPanelTest.java b/test/jalview/gui/AlignmentPanelTest.java index a6bce20..caa4e22 100644 --- a/test/jalview/gui/AlignmentPanelTest.java +++ b/test/jalview/gui/AlignmentPanelTest.java @@ -23,10 +23,13 @@ package jalview.gui; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotEquals; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +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; @@ -41,6 +44,7 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.SequenceI; import jalview.io.DataSourceType; import jalview.io.FileLoader; +import jalview.util.Platform; import jalview.viewmodel.ViewportRanges; public class AlignmentPanelTest @@ -50,22 +54,26 @@ public class AlignmentPanelTest @BeforeMethod(alwaysRun = true) public void setUp() throws InvocationTargetException, InterruptedException { - Jalview.main(new String[] { "-nonews", "-props", - "test/jalview/testProps.jvprops" }); + Jalview.main( + new String[] + { "--nonews", "--props", "test/jalview/testProps.jvprops" }); Cache.applicationProperties.setProperty("SHOW_IDENTITY", Boolean.TRUE.toString()); af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa", DataSourceType.FILE); - + /* * ensure the panel has been repainted and so ViewportRanges set */ - SwingUtilities.invokeAndWait(new Runnable() { - @Override - public void run() { - af.repaint(); - }}); + SwingUtilities.invokeAndWait(new Runnable() + { + @Override + public void run() + { + af.repaint(); + } + }); /* * wait for Consensus thread to complete @@ -128,8 +136,8 @@ public class AlignmentPanelTest scrollpos = 130; af.getViewport().showAllHiddenColumns(); af.alignPanel.setScrollValues(scrollpos, 5); - assertEquals(ranges.getEndRes(), af.getViewport() - .getAlignment().getWidth() - 1); + assertEquals(ranges.getEndRes(), + af.getViewport().getAlignment().getWidth() - 1); // now hide some columns, and scroll to position within // distance of the end of the alignment @@ -137,9 +145,11 @@ public class AlignmentPanelTest // columns af.getViewport().hideColumns(30, 50); af.alignPanel.setScrollValues(scrollpos, 5); - assertEquals(ranges.getEndRes(), af.getViewport() - .getAlignment().getWidth() - 1 - 21); // 21 is the number of hidden - // columns + assertEquals(ranges.getEndRes(), + af.getViewport().getAlignment().getWidth() - 1 - 21); // 21 is the + // number of + // hidden + // columns } /** @@ -169,8 +179,8 @@ public class AlignmentPanelTest } /** - * Test the variant of calculateIdWidth that only recomputes the width if it is - * not already saved in the viewport (initial value is -1) + * Test the variant of calculateIdWidth that only recomputes the width if it + * is not already saved in the viewport (initial value is -1) */ @Test(groups = "Functional") public void testCalculateIdWidth_noArgs() @@ -201,9 +211,10 @@ public class AlignmentPanelTest /** * Test the variant of calculateIdWidth that computes the longest of any - * sequence name or annotation label width + * sequence name or annotation label width FIXME: JAL-4291: test needs + * updating for JAL-244 and JAL-4091 */ - @Test(groups = "Functional") + @Test(groups = "Functional", enabled = false) public void testCalculateIdWidth_withMaxWidth() { AlignViewportI av = af.alignPanel.getAlignViewport(); @@ -212,13 +223,20 @@ public class AlignmentPanelTest av.setShowAnnotation(false); av.setIdWidth(18); + FontMetrics fmfor = new Container() + .getFontMetrics(new Font(af.viewport.font.getName(), + Font.ITALIC, af.viewport.font.getSize())); + /* * note 4 pixels 'padding' are added to the longest seq name/annotation label */ Dimension d = af.alignPanel.calculateIdWidth(2000); + // Assumption ID_WIDTH_PADDING == 4 + int expwidth = 3 + fmfor.stringWidth("Conservation"); + assertEquals(d.width, 166); // 4 + pixel width of "Q93Z60_ARATH/1-118" assertEquals(d.height, 12); // fixed value (not used?) - assertEquals(av.getIdWidth(), 18); // not changed by this method + assertEquals(av.getIdWidth(), expwidth); // not changed by this method /* * make the longest sequence name longer @@ -237,12 +255,12 @@ public class AlignmentPanelTest */ AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[0]; aa.label = "THIS IS A VERY LONG LABEL INDEED"; - FontMetrics fmfor = af.alignPanel - .getFontMetrics(af.alignPanel.getAlabels().getFont()); - // Assumption ID_WIDTH_PADDING == 4 - int expwidth = 4 + fmfor.stringWidth(aa.label); d = af.alignPanel.calculateIdWidth(2000); - assertEquals(d.width, expwidth); // 228 == ID_WIDTH_PADDING + pixel width of "THIS IS A VERY LONG LABEL INDEED" + // Assumption ID_WIDTH_PADDING == 3 + expwidth = 3 + fmfor.stringWidth(aa.label); + + assertEquals(d.width, expwidth); // 228 == ID_WIDTH_PADDING + pixel width of + // "THIS IS A VERY LONG LABEL INDEED" assertEquals(d.height, 12); /* @@ -257,12 +275,16 @@ public class AlignmentPanelTest @Test(groups = { "Functional", "Not-bamboo" }) public void testGetVisibleWidth() { + double scaling = jalview.gui.JvSwingUtilsTest.getScaling(af.alignPanel); /* * width for onscreen rendering is IDPanel width */ int w = af.alignPanel.getVisibleIdWidth(true); assertEquals(w, af.alignPanel.getIdPanel().getWidth()); - assertEquals(w, 115); + + // different scaling (1.0, 2.0) gives different results + int expectedWidth = scaling == 1.0 ? 112 : Platform.isMac() ? 115 : 107; + assertEquals(w, expectedWidth); /* * width for offscreen rendering is the same @@ -282,43 +304,96 @@ public class AlignmentPanelTest * preference for auto id width overrides fixed width */ Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.TRUE.toString()); - assertEquals(115, af.alignPanel.getVisibleIdWidth(false)); + w = af.alignPanel.getVisibleIdWidth(false); + // allow some leeway for different OS renderings + assertTrue(w > 105 && w < 120); + // different scaling (1.0, 2.0) gives different results + assertEquals(w, expectedWidth); } - + + @Test(groups = { "Functional", "Not-bamboo" }) + public void testresetIdWidth() + { + double scaling = jalview.gui.JvSwingUtilsTest.getScaling(af.alignPanel); + /* + * width for onscreen rendering is IDPanel width + */ + int w = af.alignPanel.getVisibleIdWidth(true); + int actual = af.alignPanel.getIdPanel().getWidth(); + assertEquals(w, actual); + // allow some leeway for different OS renderings + assertTrue(w > 105 && w < 120); + // different scaling (1.0, 2.0) gives different results + int expectedWidth = scaling == 1.0 ? 112 : Platform.isMac() ? 115 : 107; + assertEquals(w, expectedWidth); + + // 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()); + actual = af.alignPanel.getIdPanel().getWidth(); + assertEquals(w, actual); + + af.viewport.setIdWidth(-1); + af.alignPanel.calculateIdWidth(); + af.alignPanel.getIdPanel().getIdCanvas().setManuallyAdjusted(false); + w = af.alignPanel.calculateIdWidth().width; + af.alignPanel.paintComponent(af.alignPanel.getGraphics()); + + actual = af.alignPanel.getIdPanel().getWidth(); + assertEquals(w, actual); + + // setting a negative IdWidth and then running calculateIdWidth resets width + // to optimal id width + // allow some leeway for different OS renderings + assertTrue(w > 105 && w < 120); + // different scaling (1.0, 2.0) gives different results + assertEquals(w, expectedWidth); + } + @Test(groups = "Functional") public void testSetOverviewTitle() { OverviewPanel ov1 = this.af.openOverviewPanel(true); String alignFrameTitle = af.getTitle(); assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle); - + /* * on New View, existing overview should get " Original" added to title * and new view's overview should get " View 1" added */ af.newView_actionPerformed(null); - assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle + " Original"); + assertEquals(ov1.getTitle(), + "Overview " + alignFrameTitle + " Original"); OverviewPanel ov2 = this.af.openOverviewPanel(true); assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1"); } - + @Test(groups = "Functional") public void testSetOverviewTitle_automaticOverview() { - Cache.setProperty("SHOW_OVERVIEW", "true"); + Cache.setProperty("SHOW_OVERVIEW", "true"); AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); OverviewPanel ov1 = alignFrame.alignPanel.getOverviewPanel(); assertNotNull(ov1); String alignFrameTitle = alignFrame.getTitle(); assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle); - + /* * on New View, existing overview should get " Original" added to title * and new view's automatic overview should have " View 1" added */ alignFrame.newView_actionPerformed(null); - assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle + " Original"); + assertEquals(ov1.getTitle(), + "Overview " + alignFrameTitle + " Original"); OverviewPanel ov2 = alignFrame.alignPanel.getOverviewPanel(); assertNotNull(ov2); assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1");