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.viewmodel.ViewportRanges;
46 public class AlignmentPanelTest
50 @BeforeMethod(alwaysRun = true)
51 public void setUp() throws InvocationTargetException, InterruptedException
55 { "-nonews", "-props", "test/jalview/testProps.jvprops" });
57 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
58 Boolean.TRUE.toString());
59 af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
63 * ensure the panel has been repainted and so ViewportRanges set
65 SwingUtilities.invokeAndWait(new Runnable()
75 * wait for Consensus thread to complete
82 } catch (InterruptedException x)
85 } while (af.getViewport().getCalcManager().isWorking());
89 * Test side effect that end residue is set correctly by setScrollValues, with
90 * or without hidden columns
92 @Test(groups = "Functional")
93 public void testSetScrollValues()
95 ViewportRanges ranges = af.getViewport().getRanges();
96 af.alignPanel.setScrollValues(0, 0);
98 int oldres = ranges.getEndRes();
99 af.alignPanel.setScrollValues(-1, 5);
101 // setting -ve x value does not change residue
102 assertEquals(ranges.getEndRes(), oldres);
104 af.alignPanel.setScrollValues(0, 5);
106 // setting 0 as x value does not change residue
107 assertEquals(ranges.getEndRes(), oldres);
109 af.alignPanel.setScrollValues(5, 5);
110 // setting x value to 5 extends endRes by 5 residues
111 assertEquals(ranges.getEndRes(), oldres + 5);
113 // scroll to position after hidden columns sets endres to oldres (width) +
116 af.getViewport().hideColumns(30, 50);
117 af.alignPanel.setScrollValues(scrollpos, 5);
118 assertEquals(ranges.getEndRes(), oldres + scrollpos);
120 // scroll to position within hidden columns, still sets endres to oldres +
122 // not sure if this is actually correct behaviour but this is what Jalview
125 af.getViewport().showAllHiddenColumns();
126 af.getViewport().hideColumns(30, 50);
127 af.alignPanel.setScrollValues(scrollpos, 5);
128 assertEquals(ranges.getEndRes(), oldres + scrollpos);
130 // scroll to position within <width> distance of the end of the alignment
131 // endRes should be set to width of alignment - 1
133 af.getViewport().showAllHiddenColumns();
134 af.alignPanel.setScrollValues(scrollpos, 5);
135 assertEquals(ranges.getEndRes(),
136 af.getViewport().getAlignment().getWidth() - 1);
138 // now hide some columns, and scroll to position within <width>
139 // distance of the end of the alignment
140 // endRes should be set to width of alignment - 1 - the number of hidden
142 af.getViewport().hideColumns(30, 50);
143 af.alignPanel.setScrollValues(scrollpos, 5);
144 assertEquals(ranges.getEndRes(),
145 af.getViewport().getAlignment().getWidth() - 1 - 21); // 21 is the
152 * Test that update layout reverts to original (unwrapped) values for endRes
153 * when switching from wrapped back to unwrapped mode (JAL-2739)
155 @Test(groups = "Functional")
156 public void testUpdateLayout_endRes()
158 // get details of original alignment dimensions
159 ViewportRanges ranges = af.getViewport().getRanges();
160 int endres = ranges.getEndRes();
163 af.alignPanel.getAlignViewport().setWrapAlignment(true);
164 af.alignPanel.updateLayout();
166 // endRes has changed
167 assertNotEquals(ranges.getEndRes(), endres);
170 af.alignPanel.getAlignViewport().setWrapAlignment(false);
171 af.alignPanel.updateLayout();
173 // endRes back to original value
174 assertEquals(ranges.getEndRes(), endres);
178 * Test the variant of calculateIdWidth that only recomputes the width if it
179 * is not already saved in the viewport (initial value is -1)
181 @Test(groups = "Functional")
182 public void testCalculateIdWidth_noArgs()
184 AlignViewportI av = af.alignPanel.getAlignViewport();
185 av.setShowJVSuffix(true);
186 av.setFont(new Font("Courier", Font.PLAIN, 15), true);
189 Dimension d = af.alignPanel.calculateIdWidth();
190 assertEquals(d.width, 0);
191 assertEquals(d.height, 0);
194 d = af.alignPanel.calculateIdWidth();
195 assertEquals(d.width, 99);
196 assertEquals(d.height, 0);
199 * note 4 pixels padding are added to the longest sequence name width
201 av.setIdWidth(-1); // force recalculation
202 d = af.alignPanel.calculateIdWidth();
203 assertEquals(d.width, 166); // 4 + pixel width of "Q93Z60_ARATH/1-118"
204 assertEquals(d.height, 12);
205 assertEquals(d.width, av.getIdWidth());
209 * Test the variant of calculateIdWidth that computes the longest of any
210 * sequence name or annotation label width
212 @Test(groups = "Functional")
213 public void testCalculateIdWidth_withMaxWidth()
215 AlignViewportI av = af.alignPanel.getAlignViewport();
216 av.setShowJVSuffix(true);
217 av.setFont(new Font("Courier", Font.PLAIN, 15), true);
218 av.setShowAnnotation(false);
222 * note 4 pixels 'padding' are added to the longest seq name/annotation label
224 Dimension d = af.alignPanel.calculateIdWidth(2000);
225 assertEquals(d.width, 166); // 4 + pixel width of "Q93Z60_ARATH/1-118"
226 assertEquals(d.height, 12); // fixed value (not used?)
227 assertEquals(av.getIdWidth(), 18); // not changed by this method
230 * make the longest sequence name longer
232 SequenceI seq = af.viewport.getAlignment()
233 .findSequenceMatch("Q93Z60_ARATH")[0];
234 seq.setName(seq.getName() + "MMMMM");
235 d = af.alignPanel.calculateIdWidth(2000);
236 assertEquals(d.width, 211); // 4 + pixel width of "Q93Z60_ARATHMMMMM/1-118"
237 assertEquals(d.height, 12);
238 assertEquals(av.getIdWidth(), 18); // unchanged
241 * make the longest annotation name even longer
242 * note this is checked even if annotations are not shown
244 AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[0];
245 aa.label = "THIS IS A VERY LONG LABEL INDEED";
246 FontMetrics fmfor = af.alignPanel
247 .getFontMetrics(af.alignPanel.getAlabels().getFont());
248 // Assumption ID_WIDTH_PADDING == 4
249 int expwidth = 4 + fmfor.stringWidth(aa.label);
250 d = af.alignPanel.calculateIdWidth(2000);
251 assertEquals(d.width, expwidth); // 228 == ID_WIDTH_PADDING + pixel width of
252 // "THIS IS A VERY LONG LABEL INDEED"
253 assertEquals(d.height, 12);
256 * override with maxwidth
257 * note the 4 pixels padding is added to this value
259 d = af.alignPanel.calculateIdWidth(213);
260 assertEquals(d.width, 217);
261 assertEquals(d.height, 12);
264 @Test(groups = { "Functional", "Not-bamboo" })
265 public void testGetVisibleWidth()
268 * width for onscreen rendering is IDPanel width
270 int w = af.alignPanel.getVisibleIdWidth(true);
271 assertEquals(w, af.alignPanel.getIdPanel().getWidth());
272 assertEquals(w, 115);
275 * width for offscreen rendering is the same
276 * if no fixed id width is specified in preferences
278 Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.FALSE.toString());
279 Cache.removeProperty("FIGURE_FIXEDIDWIDTH");
280 assertEquals(w, af.alignPanel.getVisibleIdWidth(false));
283 * preference for fixed id width - note 4 pixels padding is added
285 Cache.setProperty("FIGURE_FIXEDIDWIDTH", "120");
286 assertEquals(124, af.alignPanel.getVisibleIdWidth(false));
289 * preference for auto id width overrides fixed width
291 Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.TRUE.toString());
292 assertEquals(115, af.alignPanel.getVisibleIdWidth(false));
295 @Test(groups = "Functional")
296 public void testSetOverviewTitle()
298 OverviewPanel ov1 = this.af.openOverviewPanel(true);
299 String alignFrameTitle = af.getTitle();
300 assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle);
303 * on New View, existing overview should get " Original" added to title
304 * and new view's overview should get " View 1" added
306 af.newView_actionPerformed(null);
307 assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle + " Original");
308 OverviewPanel ov2 = this.af.openOverviewPanel(true);
309 assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1");
312 @Test(groups = "Functional")
313 public void testSetOverviewTitle_automaticOverview()
315 Cache.setProperty("SHOW_OVERVIEW", "true");
316 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
317 "examples/uniref50.fa", DataSourceType.FILE);
318 OverviewPanel ov1 = alignFrame.alignPanel.getOverviewPanel();
320 String alignFrameTitle = alignFrame.getTitle();
321 assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle);
324 * on New View, existing overview should get " Original" added to title
325 * and new view's automatic overview should have " View 1" added
327 alignFrame.newView_actionPerformed(null);
328 assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle + " Original");
329 OverviewPanel ov2 = alignFrame.alignPanel.getOverviewPanel();
331 assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1");