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;
27 import java.awt.Dimension;
29 import java.awt.FontMetrics;
30 import java.lang.reflect.InvocationTargetException;
32 import javax.swing.SwingUtilities;
34 import org.testng.annotations.BeforeMethod;
35 import org.testng.annotations.Test;
37 import jalview.api.AlignViewportI;
38 import jalview.bin.Cache;
39 import jalview.bin.Jalview;
40 import jalview.datamodel.AlignmentAnnotation;
41 import jalview.datamodel.SequenceI;
42 import jalview.io.DataSourceType;
43 import jalview.io.FileLoader;
44 import jalview.util.Platform;
45 import jalview.viewmodel.ViewportRanges;
47 public class AlignmentPanelTest
51 @BeforeMethod(alwaysRun = true)
52 public void setUp() throws InvocationTargetException, InterruptedException
56 { "-nonews", "-props", "test/jalview/testProps.jvprops" });
58 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
59 Boolean.TRUE.toString());
60 af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
64 * ensure the panel has been repainted and so ViewportRanges set
66 SwingUtilities.invokeAndWait(new Runnable()
76 * wait for Consensus thread to complete
83 } catch (InterruptedException x)
86 } while (af.getViewport().getCalcManager().isWorking());
90 * Test side effect that end residue is set correctly by setScrollValues, with
91 * or without hidden columns
93 @Test(groups = "Functional")
94 public void testSetScrollValues()
96 ViewportRanges ranges = af.getViewport().getRanges();
97 af.alignPanel.setScrollValues(0, 0);
99 int oldres = ranges.getEndRes();
100 af.alignPanel.setScrollValues(-1, 5);
102 // setting -ve x value does not change residue
103 assertEquals(ranges.getEndRes(), oldres);
105 af.alignPanel.setScrollValues(0, 5);
107 // setting 0 as x value does not change residue
108 assertEquals(ranges.getEndRes(), oldres);
110 af.alignPanel.setScrollValues(5, 5);
111 // setting x value to 5 extends endRes by 5 residues
112 assertEquals(ranges.getEndRes(), oldres + 5);
114 // scroll to position after hidden columns sets endres to oldres (width) +
117 af.getViewport().hideColumns(30, 50);
118 af.alignPanel.setScrollValues(scrollpos, 5);
119 assertEquals(ranges.getEndRes(), oldres + scrollpos);
121 // scroll to position within hidden columns, still sets endres to oldres +
123 // not sure if this is actually correct behaviour but this is what Jalview
126 af.getViewport().showAllHiddenColumns();
127 af.getViewport().hideColumns(30, 50);
128 af.alignPanel.setScrollValues(scrollpos, 5);
129 assertEquals(ranges.getEndRes(), oldres + scrollpos);
131 // scroll to position within <width> distance of the end of the alignment
132 // endRes should be set to width of alignment - 1
134 af.getViewport().showAllHiddenColumns();
135 af.alignPanel.setScrollValues(scrollpos, 5);
136 assertEquals(ranges.getEndRes(),
137 af.getViewport().getAlignment().getWidth() - 1);
139 // now hide some columns, and scroll to position within <width>
140 // distance of the end of the alignment
141 // endRes should be set to width of alignment - 1 - the number of hidden
143 af.getViewport().hideColumns(30, 50);
144 af.alignPanel.setScrollValues(scrollpos, 5);
145 assertEquals(ranges.getEndRes(),
146 af.getViewport().getAlignment().getWidth() - 1 - 21); // 21 is the
153 * Test that update layout reverts to original (unwrapped) values for endRes
154 * when switching from wrapped back to unwrapped mode (JAL-2739)
156 @Test(groups = "Functional")
157 public void testUpdateLayout_endRes()
159 // get details of original alignment dimensions
160 ViewportRanges ranges = af.getViewport().getRanges();
161 int endres = ranges.getEndRes();
164 af.alignPanel.getAlignViewport().setWrapAlignment(true);
165 af.alignPanel.updateLayout();
167 // endRes has changed
168 assertNotEquals(ranges.getEndRes(), endres);
171 af.alignPanel.getAlignViewport().setWrapAlignment(false);
172 af.alignPanel.updateLayout();
174 // endRes back to original value
175 assertEquals(ranges.getEndRes(), endres);
179 * Test the variant of calculateIdWidth that only recomputes the width if it
180 * is not already saved in the viewport (initial value is -1)
182 @Test(groups = "Functional")
183 public void testCalculateIdWidth_noArgs()
185 AlignViewportI av = af.alignPanel.getAlignViewport();
186 av.setShowJVSuffix(true);
187 av.setFont(new Font("Courier", Font.PLAIN, 15), true);
190 Dimension d = af.alignPanel.calculateIdWidth();
191 assertEquals(d.width, 0);
192 assertEquals(d.height, 0);
195 d = af.alignPanel.calculateIdWidth();
196 assertEquals(d.width, 99);
197 assertEquals(d.height, 0);
200 * note 4 pixels padding are added to the longest sequence name width
202 av.setIdWidth(-1); // force recalculation
203 d = af.alignPanel.calculateIdWidth();
204 assertEquals(d.width, Platform.forArch(166).forWin(172).value().intValue()); // 4 + pixel width of "Q93Z60_ARATH/1-118"
205 assertEquals(d.height, 12);
206 assertEquals(d.width, av.getIdWidth());
210 * Test the variant of calculateIdWidth that computes the longest of any
211 * sequence name or annotation label width
213 @Test(groups = "Functional")
214 public void testCalculateIdWidth_withMaxWidth()
216 AlignViewportI av = af.alignPanel.getAlignViewport();
217 av.setShowJVSuffix(true);
218 av.setFont(new Font("Courier", Font.PLAIN, 15), true);
219 av.setShowAnnotation(false);
223 * note 4 pixels 'padding' are added to the longest seq name/annotation label
225 Dimension d = af.alignPanel.calculateIdWidth(2000);
226 assertEquals(d.width, Platform.forArch(166).forWin(172).value().intValue()); // 4 + pixel width of "Q93Z60_ARATH/1-118"
227 assertEquals(d.height, 12); // fixed value (not used?)
228 assertEquals(av.getIdWidth(), 18); // not changed by this method
231 * make the longest sequence name longer
233 SequenceI seq = af.viewport.getAlignment()
234 .findSequenceMatch("Q93Z60_ARATH")[0];
235 seq.setName(seq.getName() + "MMMMM");
236 d = af.alignPanel.calculateIdWidth(2000);
237 assertEquals(d.width, Platform.forArch(211).forWin(219).value().intValue()); // 4 + pixel width of "Q93Z60_ARATHMMMMM/1-118"
238 assertEquals(d.height, 12);
239 assertEquals(av.getIdWidth(), 18); // unchanged
242 * make the longest annotation name even longer
243 * note this is checked even if annotations are not shown
245 AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[0];
246 aa.label = "THIS IS A VERY LONG LABEL INDEED";
247 FontMetrics fmfor = af.alignPanel
248 .getFontMetrics(af.alignPanel.getAlabels().getFont());
249 // Assumption ID_WIDTH_PADDING == 4
250 int expwidth = 4 + fmfor.stringWidth(aa.label);
251 d = af.alignPanel.calculateIdWidth(2000);
252 assertEquals(d.width, expwidth); // 228 == ID_WIDTH_PADDING + pixel width of
253 // "THIS IS A VERY LONG LABEL INDEED"
254 assertEquals(d.height, 12);
257 * override with maxwidth
258 * note the 4 pixels padding is added to this value
260 d = af.alignPanel.calculateIdWidth(213);
261 assertEquals(d.width, 217);
262 assertEquals(d.height, 12);
265 @Test(groups = { "Functional" })
266 public void testGetVisibleWidth()
269 * width for onscreen rendering is IDPanel width
271 int w = af.alignPanel.getVisibleIdWidth(true);
272 assertEquals(w, af.alignPanel.getIdPanel().getWidth());
273 assertEquals(w, Platform.forArch(115).forWin(112).forMac(115)
274 .forLinux(114).value().intValue());
277 * width for offscreen rendering is the same
278 * if no fixed id width is specified in preferences
280 Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.FALSE.toString());
281 Cache.removeProperty("FIGURE_FIXEDIDWIDTH");
282 assertEquals(w, af.alignPanel.getVisibleIdWidth(false));
285 * preference for fixed id width - note 4 pixels padding is added
287 Cache.setProperty("FIGURE_FIXEDIDWIDTH", "120");
288 assertEquals(124, af.alignPanel.getVisibleIdWidth(false));
291 * preference for auto id width overrides fixed width
293 Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.TRUE.toString());
294 assertEquals(af.alignPanel.getVisibleIdWidth(false),
295 Platform.forArch(115).forWin(106).forMac(115).forLinux(114)
296 .value().intValue());
299 @Test(groups = "Functional")
300 public void testSetOverviewTitle()
302 OverviewPanel ov1 = this.af.openOverviewPanel(true);
303 String alignFrameTitle = af.getTitle();
304 assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle);
307 * on New View, existing overview should get " Original" added to title
308 * and new view's overview should get " View 1" added
310 af.newView_actionPerformed(null);
311 assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle + " Original");
312 OverviewPanel ov2 = this.af.openOverviewPanel(true);
313 assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1");
316 @Test(groups = "Functional")
317 public void testSetOverviewTitle_automaticOverview()
319 Cache.setProperty("SHOW_OVERVIEW", "true");
320 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
321 "examples/uniref50.fa", DataSourceType.FILE);
322 OverviewPanel ov1 = alignFrame.alignPanel.getOverviewPanel();
324 String alignFrameTitle = alignFrame.getTitle();
325 assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle);
328 * on New View, existing overview should get " Original" added to title
329 * and new view's automatic overview should have " View 1" added
331 alignFrame.newView_actionPerformed(null);
332 assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle + " Original");
333 OverviewPanel ov2 = alignFrame.alignPanel.getOverviewPanel();
335 assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1");