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.Container;
28 import java.awt.Dimension;
30 import java.awt.FontMetrics;
31 import java.lang.reflect.InvocationTargetException;
33 import javax.swing.SwingUtilities;
35 import org.testng.annotations.BeforeMethod;
36 import org.testng.annotations.Test;
38 import jalview.api.AlignViewportI;
39 import jalview.bin.Cache;
40 import jalview.bin.Jalview;
41 import jalview.datamodel.AlignmentAnnotation;
42 import jalview.datamodel.SequenceI;
43 import jalview.io.DataSourceType;
44 import jalview.io.FileLoader;
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, 166); // 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
212 * FIXME: JAL-4291: test needs updating for JAL-244 and JAL-4091
214 @Test(groups = "Functional",enabled=false)
215 public void testCalculateIdWidth_withMaxWidth()
217 AlignViewportI av = af.alignPanel.getAlignViewport();
218 av.setShowJVSuffix(true);
219 av.setFont(new Font("Courier", Font.PLAIN, 15), true);
220 av.setShowAnnotation(false);
223 FontMetrics fmfor = new Container()
224 .getFontMetrics(new Font(af.viewport.font.getName(),
225 Font.ITALIC, af.viewport.font.getSize()));
228 * note 4 pixels 'padding' are added to the longest seq name/annotation label
230 Dimension d = af.alignPanel.calculateIdWidth(2000);
231 // Assumption ID_WIDTH_PADDING == 4
232 int expwidth = 3 + fmfor.stringWidth("Conservation");
234 assertEquals(d.width, 166); // 4 + pixel width of "Q93Z60_ARATH/1-118"
235 assertEquals(d.height, 12); // fixed value (not used?)
236 assertEquals(av.getIdWidth(), expwidth); // not changed by this method
239 * make the longest sequence name longer
241 SequenceI seq = af.viewport.getAlignment()
242 .findSequenceMatch("Q93Z60_ARATH")[0];
243 seq.setName(seq.getName() + "MMMMM");
244 d = af.alignPanel.calculateIdWidth(2000);
245 assertEquals(d.width, 211); // 4 + pixel width of "Q93Z60_ARATHMMMMM/1-118"
246 assertEquals(d.height, 12);
247 assertEquals(av.getIdWidth(), 18); // unchanged
250 * make the longest annotation name even longer
251 * note this is checked even if annotations are not shown
253 AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[0];
254 aa.label = "THIS IS A VERY LONG LABEL INDEED";
255 d = af.alignPanel.calculateIdWidth(2000);
256 // Assumption ID_WIDTH_PADDING == 3
257 expwidth = 3 + fmfor.stringWidth(aa.label);
259 assertEquals(d.width, expwidth); // 228 == ID_WIDTH_PADDING + pixel width of
260 // "THIS IS A VERY LONG LABEL INDEED"
261 assertEquals(d.height, 12);
264 * override with maxwidth
265 * note the 4 pixels padding is added to this value
267 d = af.alignPanel.calculateIdWidth(213);
268 assertEquals(d.width, 217);
269 assertEquals(d.height, 12);
272 @Test(groups = { "Functional", "Not-bamboo" })
273 public void testGetVisibleWidth()
276 * width for onscreen rendering is IDPanel width
278 int w = af.alignPanel.getVisibleIdWidth(true);
279 assertEquals(w, af.alignPanel.getIdPanel().getWidth());
280 assertEquals(w, 115);
283 * width for offscreen rendering is the same
284 * if no fixed id width is specified in preferences
286 Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.FALSE.toString());
287 Cache.removeProperty("FIGURE_FIXEDIDWIDTH");
288 assertEquals(w, af.alignPanel.getVisibleIdWidth(false));
291 * preference for fixed id width - note 4 pixels padding is added
293 Cache.setProperty("FIGURE_FIXEDIDWIDTH", "120");
294 assertEquals(124, af.alignPanel.getVisibleIdWidth(false));
297 * preference for auto id width overrides fixed width
299 Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.TRUE.toString());
300 assertEquals(115, af.alignPanel.getVisibleIdWidth(false));
303 @Test(groups = "Functional")
304 public void testSetOverviewTitle()
306 OverviewPanel ov1 = this.af.openOverviewPanel(true);
307 String alignFrameTitle = af.getTitle();
308 assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle);
311 * on New View, existing overview should get " Original" added to title
312 * and new view's overview should get " View 1" added
314 af.newView_actionPerformed(null);
315 assertEquals(ov1.getTitle(),
316 "Overview " + alignFrameTitle + " Original");
317 OverviewPanel ov2 = this.af.openOverviewPanel(true);
318 assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1");
321 @Test(groups = "Functional")
322 public void testSetOverviewTitle_automaticOverview()
324 Cache.setProperty("SHOW_OVERVIEW", "true");
325 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
326 "examples/uniref50.fa", DataSourceType.FILE);
327 OverviewPanel ov1 = alignFrame.alignPanel.getOverviewPanel();
329 String alignFrameTitle = alignFrame.getTitle();
330 assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle);
333 * on New View, existing overview should get " Original" added to title
334 * and new view's automatic overview should have " View 1" added
336 alignFrame.newView_actionPerformed(null);
337 assertEquals(ov1.getTitle(),
338 "Overview " + alignFrameTitle + " Original");
339 OverviewPanel ov2 = alignFrame.alignPanel.getOverviewPanel();
341 assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1");