import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
-import jalview.bin.Cache;
-import jalview.bin.Jalview;
-import jalview.datamodel.Sequence;
-import jalview.datamodel.SequenceI;
-import jalview.io.DataSourceType;
-import jalview.io.FileLoader;
-import jalview.viewmodel.ViewportRanges;
-
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
import java.lang.reflect.InvocationTargetException;
import javax.swing.SwingUtilities;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import jalview.api.AlignViewportI;
+import jalview.bin.Cache;
+import jalview.bin.Jalview;
+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
{
- SequenceI seq1 = new Sequence(
- "Seq1",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq2 = new Sequence(
- "Seq2",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq3 = new Sequence(
- "Seq3",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq4 = new Sequence(
- "Seq4",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq5 = new Sequence(
- "Seq5",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq6 = new Sequence(
- "Seq6",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq7 = new Sequence(
- "Seq7",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq8 = new Sequence(
- "Seq8",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq9 = new Sequence(
- "Seq9",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq10 = new Sequence(
- "Seq10",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq11 = new Sequence(
- "Seq11",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq12 = new Sequence(
- "Seq12",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq13 = new Sequence(
- "Seq13",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq14 = new Sequence(
- "Seq14",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq15 = new Sequence(
- "Seq15",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq16 = new Sequence(
- "Seq16",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq17 = new Sequence(
- "Seq17",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq18 = new Sequence(
- "Seq18",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq19 = new Sequence(
- "Seq19",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq20 = new Sequence(
- "Seq20",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq21 = new Sequence(
- "Seq21",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq22 = new Sequence(
- "Seq22",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
- SequenceI seq23 = new Sequence(
- "Seq23",
- "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
-
AlignFrame af;
@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",
+ "-jabaws", "none"});
- Cache.applicationProperties.setProperty("SHOW_IDENTITY",
+ Cache.setPropertyNoSave("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
*/
- synchronized (this)
+ do
{
- while (af.getViewport().getConsensusSeq() == null)
+ try
+ {
+ Thread.sleep(50);
+ } catch (InterruptedException x)
{
- try
- {
- wait(50);
- } catch (InterruptedException e)
- {
- }
}
- }
+ } while (af.getViewport().getCalcManager().isWorking());
}
-
/**
* Test side effect that end residue is set correctly by setScrollValues, with
* or without hidden columns
*/
@Test(groups = "Functional")
- public void TestSetScrollValues()
+ public void testSetScrollValues()
{
ViewportRanges ranges = af.getViewport().getRanges();
af.alignPanel.setScrollValues(0, 0);
af.alignPanel.setScrollValues(-1, 5);
// setting -ve x value does not change residue
+ // no update necessary now
assertEquals(ranges.getEndRes(), oldres);
af.alignPanel.setScrollValues(0, 5);
+ // no update necessary now
// setting 0 as x value does not change residue
+ // no update necessary now
assertEquals(ranges.getEndRes(), oldres);
af.alignPanel.setScrollValues(5, 5);
// setting x value to 5 extends endRes by 5 residues
+ System.out.println(ranges);
+ // no update necessary now
assertEquals(ranges.getEndRes(), oldres + 5);
// scroll to position after hidden columns sets endres to oldres (width) +
// position
- int scrollpos = 60;
+ int scrollpos = 53; // was 60, but this is too high to allow full scrolling
+ // in Windows
af.getViewport().hideColumns(30, 50);
af.alignPanel.setScrollValues(scrollpos, 5);
+ // no update necessary now
assertEquals(ranges.getEndRes(), oldres + scrollpos);
// scroll to position within hidden columns, still sets endres to oldres +
af.getViewport().showAllHiddenColumns();
af.getViewport().hideColumns(30, 50);
af.alignPanel.setScrollValues(scrollpos, 5);
+ // no update necessary now
assertEquals(ranges.getEndRes(), oldres + scrollpos);
// scroll to position within <width> distance of the end of the alignment
scrollpos = 130;
af.getViewport().showAllHiddenColumns();
af.alignPanel.setScrollValues(scrollpos, 5);
- assertEquals(ranges.getEndRes(), af.getViewport()
- .getAlignment().getWidth() - 1);
+ // no update necessary now
+ assertEquals(ranges.getEndRes(),
+ af.getViewport().getAlignment().getWidth() - 1);
// now hide some columns, and scroll to position within <width>
// distance of the end of the alignment
// 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
+ // no update necessary now
+ assertEquals(ranges.getEndRes(),
+ af.getViewport().getAlignment().getWidth() - 1 - 21); // 21 is the
+ // number of
+ // hidden
+ // columns
}
/**
* when switching from wrapped back to unwrapped mode (JAL-2739)
*/
@Test(groups = "Functional")
- public void TestUpdateLayout_endRes()
+ public void testUpdateLayout_endRes()
{
// get details of original alignment dimensions
ViewportRanges ranges = af.getViewport().getRanges();
// endRes back to original value
assertEquals(ranges.getEndRes(), endres);
+ }
+ /**
+ * 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()
+ {
+ AlignViewportI av = af.alignPanel.getAlignViewport();
+ av.setShowJVSuffix(true);
+ av.setFont(new Font("Courier", Font.PLAIN, 15), true);
+
+ av.setIdWidth(0);
+ Dimension d = af.alignPanel.calculateIdWidth();
+ assertEquals(d.width, 0);
+ assertEquals(d.height, 0);
+
+ av.setIdWidth(99);
+ d = af.alignPanel.calculateIdWidth();
+ assertEquals(d.width, 99);
+ assertEquals(d.height, 0);
+
+ /*
+ * note 4 pixels padding are added to the longest sequence name width
+ */
+ av.setIdWidth(-1); // force recalculation
+
+ d = af.alignPanel.calculateIdWidth();
+ assertEquals(d.width, Platform.isWin() ? 172 : 166); // 4 + pixel width of "Q93Z60_ARATH/1-118"
+ assertEquals(d.height, 12);
+ assertEquals(d.width, av.getIdWidth());
+ }
+
+ /**
+ * Test the variant of calculateIdWidth that computes the longest of any
+ * sequence name or annotation label width
+ */
+ @Test(groups = "Functional")
+ public void testCalculateIdWidth_withMaxWidth()
+ {
+ AlignViewportI av = af.alignPanel.getAlignViewport();
+ av.setShowJVSuffix(true);
+ av.setFont(new Font("Courier", Font.PLAIN, 15), true);
+ av.setShowAnnotation(false);
+ av.setIdWidth(18);
+
+ /*
+ * note 4 pixels 'padding' are added to the longest seq name/annotation label
+ */
+ Dimension d = af.alignPanel.calculateIdWidth(2000);
+ assertEquals(d.width, Platform.isWin() ? 172 : 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
+
+ /*
+ * make the longest sequence name longer
+ */
+ SequenceI seq = af.viewport.getAlignment()
+ .findSequenceMatch("Q93Z60_ARATH")[0];
+ String orig = seq.getName();
+ seq.setName(orig + "MMMMM");
+ d = af.alignPanel.calculateIdWidth(2000);
+ assertEquals(d.width, Platform.isWin() ? 219 : 211); // 4 + pixel width of "Q93Z60_ARATHMMMMM/1-118"
+ assertEquals(d.height, 12);
+ assertEquals(av.getIdWidth(), 18); // unchanged
+ // for next test:
+ seq.setName(orig);
+
+ /*
+ * make the longest annotation name even longer
+ * note this is checked even if annotations are not shown
+ */
+ 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
+ // AH! But with those added MMMM above, this was NOT the longest label!
+ int expwidth = 4 + fmfor.stringWidth(aa.label);
+ d = af.alignPanel.calculateIdWidth(2000);
+ assertEquals(d.width, expwidth); // 191 == ID_WIDTH_PADDING + pixel width of "THIS IS A VERY LONG LABEL INDEED"
+ assertEquals(d.height, 12);
+
+ /*
+ * override with maxwidth
+ * note the 4 pixels padding is added to this value
+ */
+ // BH but we have to be under the max width
+ d = af.alignPanel.calculateIdWidth(180);
+ assertEquals(d.width, 184);
+ assertEquals(d.height, 12);
+ }
+
+ @Test(groups = { "Functional", "Not-bamboo" })
+ public void testGetVisibleWidth()
+ {
+ /*
+ * width for onscreen rendering is IDPanel width
+ */
+ int w = af.alignPanel.getVisibleIdWidth(true);
+ assertEquals(w, af.alignPanel.getIdPanel().getWidth());
+ assertEquals(w, Platform.isWin() ? 112 : 115);
+
+ /*
+ * width for offscreen rendering is the same
+ * if no fixed id width is specified in preferences
+ */
+ Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.FALSE.toString());
+ Cache.removeProperty("FIGURE_FIXEDIDWIDTH");
+ assertEquals(w, af.alignPanel.getVisibleIdWidth(false));
+
+ /*
+ * preference for fixed id width - note 4 pixels padding is added
+ */
+ Cache.setProperty("FIGURE_FIXEDIDWIDTH", "120");
+ assertEquals(124, af.alignPanel.getVisibleIdWidth(false));
+
+ /*
+ * preference for auto id width overrides fixed width
+ */
+ Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.TRUE.toString());
+ assertEquals(Platform.isWin() ? 106 : 115, af.alignPanel.getVisibleIdWidth(false));
}
}