2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertNotEquals;
25 import static org.testng.Assert.assertNotNull;
26 import static org.testng.Assert.assertTrue;
28 import java.awt.Container;
29 import java.awt.Dimension;
31 import java.awt.FontMetrics;
32 import java.lang.reflect.InvocationTargetException;
34 import javax.swing.SwingUtilities;
36 import org.testng.annotations.BeforeMethod;
37 import org.testng.annotations.Test;
39 import jalview.api.AlignViewportI;
40 import jalview.bin.Cache;
41 import jalview.bin.Jalview;
42 import jalview.datamodel.AlignmentAnnotation;
43 import jalview.datamodel.SequenceI;
44 import jalview.io.DataSourceType;
45 import jalview.io.FileLoader;
46 import jalview.viewmodel.ViewportRanges;
48 public class AlignmentPanelTest
52 @BeforeMethod(alwaysRun = true)
53 public void setUp() throws InvocationTargetException, InterruptedException
57 { "--nonews", "--props", "test/jalview/testProps.jvprops" });
59 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
60 Boolean.TRUE.toString());
61 af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
65 * ensure the panel has been repainted and so ViewportRanges set
67 SwingUtilities.invokeAndWait(new Runnable()
77 * wait for Consensus thread to complete
84 } catch (InterruptedException x)
87 } while (af.getViewport().getCalcManager().isWorking());
91 * Test side effect that end residue is set correctly by setScrollValues, with
92 * or without hidden columns
94 @Test(groups = "Functional")
95 public void testSetScrollValues()
97 ViewportRanges ranges = af.getViewport().getRanges();
98 af.alignPanel.setScrollValues(0, 0);
100 int oldres = ranges.getEndRes();
101 af.alignPanel.setScrollValues(-1, 5);
103 // setting -ve x value does not change residue
104 assertEquals(ranges.getEndRes(), oldres);
106 af.alignPanel.setScrollValues(0, 5);
108 // setting 0 as x value does not change residue
109 assertEquals(ranges.getEndRes(), oldres);
111 af.alignPanel.setScrollValues(5, 5);
112 // setting x value to 5 extends endRes by 5 residues
113 assertEquals(ranges.getEndRes(), oldres + 5);
115 // scroll to position after hidden columns sets endres to oldres (width) +
118 af.getViewport().hideColumns(30, 50);
119 af.alignPanel.setScrollValues(scrollpos, 5);
120 assertEquals(ranges.getEndRes(), oldres + scrollpos);
122 // scroll to position within hidden columns, still sets endres to oldres +
124 // not sure if this is actually correct behaviour but this is what Jalview
127 af.getViewport().showAllHiddenColumns();
128 af.getViewport().hideColumns(30, 50);
129 af.alignPanel.setScrollValues(scrollpos, 5);
130 assertEquals(ranges.getEndRes(), oldres + scrollpos);
132 // scroll to position within <width> distance of the end of the alignment
133 // endRes should be set to width of alignment - 1
135 af.getViewport().showAllHiddenColumns();
136 af.alignPanel.setScrollValues(scrollpos, 5);
137 assertEquals(ranges.getEndRes(),
138 af.getViewport().getAlignment().getWidth() - 1);
140 // now hide some columns, and scroll to position within <width>
141 // distance of the end of the alignment
142 // endRes should be set to width of alignment - 1 - the number of hidden
144 af.getViewport().hideColumns(30, 50);
145 af.alignPanel.setScrollValues(scrollpos, 5);
146 assertEquals(ranges.getEndRes(),
147 af.getViewport().getAlignment().getWidth() - 1 - 21); // 21 is the
154 * Test that update layout reverts to original (unwrapped) values for endRes
155 * when switching from wrapped back to unwrapped mode (JAL-2739)
157 @Test(groups = "Functional")
158 public void testUpdateLayout_endRes()
160 // get details of original alignment dimensions
161 ViewportRanges ranges = af.getViewport().getRanges();
162 int endres = ranges.getEndRes();
165 af.alignPanel.getAlignViewport().setWrapAlignment(true);
166 af.alignPanel.updateLayout();
168 // endRes has changed
169 assertNotEquals(ranges.getEndRes(), endres);
172 af.alignPanel.getAlignViewport().setWrapAlignment(false);
173 af.alignPanel.updateLayout();
175 // endRes back to original value
176 assertEquals(ranges.getEndRes(), endres);
180 * Test the variant of calculateIdWidth that only recomputes the width if it
181 * is not already saved in the viewport (initial value is -1)
183 @Test(groups = "Functional")
184 public void testCalculateIdWidth_noArgs()
186 AlignViewportI av = af.alignPanel.getAlignViewport();
187 av.setShowJVSuffix(true);
188 av.setFont(new Font("Courier", Font.PLAIN, 15), true);
191 Dimension d = af.alignPanel.calculateIdWidth();
192 assertEquals(d.width, 0);
193 assertEquals(d.height, 0);
196 d = af.alignPanel.calculateIdWidth();
197 assertEquals(d.width, 99);
198 assertEquals(d.height, 0);
201 * note 4 pixels padding are added to the longest sequence name width
203 av.setIdWidth(-1); // force recalculation
204 d = af.alignPanel.calculateIdWidth();
205 assertEquals(d.width, 166); // 4 + pixel width of "Q93Z60_ARATH/1-118"
206 assertEquals(d.height, 12);
207 assertEquals(d.width, av.getIdWidth());
211 * Test the variant of calculateIdWidth that computes the longest of any
212 * sequence name or annotation label width FIXME: JAL-4291: test needs
213 * updating for JAL-244 and JAL-4091
215 @Test(groups = "Functional", enabled = false)
216 public void testCalculateIdWidth_withMaxWidth()
218 AlignViewportI av = af.alignPanel.getAlignViewport();
219 av.setShowJVSuffix(true);
220 av.setFont(new Font("Courier", Font.PLAIN, 15), true);
221 av.setShowAnnotation(false);
224 FontMetrics fmfor = new Container()
225 .getFontMetrics(new Font(af.viewport.font.getName(),
226 Font.ITALIC, af.viewport.font.getSize()));
229 * note 4 pixels 'padding' are added to the longest seq name/annotation label
231 Dimension d = af.alignPanel.calculateIdWidth(2000);
232 // Assumption ID_WIDTH_PADDING == 4
233 int expwidth = 3 + fmfor.stringWidth("Conservation");
235 assertEquals(d.width, 166); // 4 + pixel width of "Q93Z60_ARATH/1-118"
236 assertEquals(d.height, 12); // fixed value (not used?)
237 assertEquals(av.getIdWidth(), expwidth); // not changed by this method
240 * make the longest sequence name longer
242 SequenceI seq = af.viewport.getAlignment()
243 .findSequenceMatch("Q93Z60_ARATH")[0];
244 seq.setName(seq.getName() + "MMMMM");
245 d = af.alignPanel.calculateIdWidth(2000);
246 assertEquals(d.width, 211); // 4 + pixel width of "Q93Z60_ARATHMMMMM/1-118"
247 assertEquals(d.height, 12);
248 assertEquals(av.getIdWidth(), 18); // unchanged
251 * make the longest annotation name even longer
252 * note this is checked even if annotations are not shown
254 AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[0];
255 aa.label = "THIS IS A VERY LONG LABEL INDEED";
256 d = af.alignPanel.calculateIdWidth(2000);
257 // Assumption ID_WIDTH_PADDING == 3
258 expwidth = 3 + fmfor.stringWidth(aa.label);
260 assertEquals(d.width, expwidth); // 228 == ID_WIDTH_PADDING + pixel width of
261 // "THIS IS A VERY LONG LABEL INDEED"
262 assertEquals(d.height, 12);
265 * override with maxwidth
266 * note the 4 pixels padding is added to this value
268 d = af.alignPanel.calculateIdWidth(213);
269 assertEquals(d.width, 217);
270 assertEquals(d.height, 12);
273 @Test(groups = { "Functional", "Not-bamboo" })
274 public void testGetVisibleWidth()
277 * width for onscreen rendering is IDPanel width
279 int w = af.alignPanel.getVisibleIdWidth(true);
280 assertEquals(w, af.alignPanel.getIdPanel().getWidth());
281 assertEquals(w, 115);
284 * width for offscreen rendering is the same
285 * if no fixed id width is specified in preferences
287 Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.FALSE.toString());
288 Cache.removeProperty("FIGURE_FIXEDIDWIDTH");
289 assertEquals(w, af.alignPanel.getVisibleIdWidth(false));
292 * preference for fixed id width - note 4 pixels padding is added
294 Cache.setProperty("FIGURE_FIXEDIDWIDTH", "120");
295 assertEquals(124, af.alignPanel.getVisibleIdWidth(false));
298 * preference for auto id width overrides fixed width
300 Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.TRUE.toString());
301 assertEquals(115, af.alignPanel.getVisibleIdWidth(false));
304 @Test(groups = { "Functional", "Not-bamboo" })
305 public void testresetIdWidth()
308 * width for onscreen rendering is IDPanel width
310 int w = af.alignPanel.getVisibleIdWidth(true);
311 assertEquals(w, af.alignPanel.getIdPanel().getWidth());
312 assertEquals(w, 115);
315 af.viewport.setIdWidth(200);
316 w = af.alignPanel.calculateIdWidth().width;
318 af.alignPanel.getIdPanel().getIdCanvas().isManuallyAdjusted());
319 assertEquals(w, af.alignPanel.getIdPanel().getWidth());
321 af.viewport.setIdWidth(-1);
322 af.alignPanel.getIdPanel().getIdCanvas().setManuallyAdjusted(false);
323 w = af.alignPanel.calculateIdWidth().width;
325 assertEquals(w, af.alignPanel.getIdPanel().getWidth());
327 assertNotEquals(w, 115);
330 @Test(groups = "Functional")
331 public void testSetOverviewTitle()
333 OverviewPanel ov1 = this.af.openOverviewPanel(true);
334 String alignFrameTitle = af.getTitle();
335 assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle);
338 * on New View, existing overview should get " Original" added to title
339 * and new view's overview should get " View 1" added
341 af.newView_actionPerformed(null);
342 assertEquals(ov1.getTitle(),
343 "Overview " + alignFrameTitle + " Original");
344 OverviewPanel ov2 = this.af.openOverviewPanel(true);
345 assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1");
348 @Test(groups = "Functional")
349 public void testSetOverviewTitle_automaticOverview()
351 Cache.setProperty("SHOW_OVERVIEW", "true");
352 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
353 "examples/uniref50.fa", DataSourceType.FILE);
354 OverviewPanel ov1 = alignFrame.alignPanel.getOverviewPanel();
356 String alignFrameTitle = alignFrame.getTitle();
357 assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle);
360 * on New View, existing overview should get " Original" added to title
361 * and new view's automatic overview should have " View 1" added
363 alignFrame.newView_actionPerformed(null);
364 assertEquals(ov1.getTitle(),
365 "Overview " + alignFrameTitle + " Original");
366 OverviewPanel ov2 = alignFrame.alignPanel.getOverviewPanel();
368 assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1");