1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
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; |
27 |
|
|
28 |
|
import java.awt.Container; |
29 |
|
import java.awt.Dimension; |
30 |
|
import java.awt.Font; |
31 |
|
import java.awt.FontMetrics; |
32 |
|
import java.awt.event.MouseEvent; |
33 |
|
import java.lang.reflect.InvocationTargetException; |
34 |
|
|
35 |
|
import javax.swing.SwingUtilities; |
36 |
|
|
37 |
|
import org.testng.annotations.BeforeMethod; |
38 |
|
import org.testng.annotations.Test; |
39 |
|
|
40 |
|
import jalview.api.AlignViewportI; |
41 |
|
import jalview.bin.Cache; |
42 |
|
import jalview.bin.Jalview; |
43 |
|
import jalview.datamodel.AlignmentAnnotation; |
44 |
|
import jalview.datamodel.SequenceI; |
45 |
|
import jalview.io.DataSourceType; |
46 |
|
import jalview.io.FileLoader; |
47 |
|
import jalview.util.Platform; |
48 |
|
import jalview.viewmodel.ViewportRanges; |
49 |
|
|
|
|
| 52.2% |
Uncovered Elements: 76 (159) |
Complexity: 16 |
Complexity Density: 0.12 |
|
50 |
|
public class AlignmentPanelTest |
51 |
|
{ |
52 |
|
AlignFrame af; |
53 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
54 |
5 |
@BeforeMethod(alwaysRun = true)... |
55 |
|
public void setUp() throws InvocationTargetException, InterruptedException |
56 |
|
{ |
57 |
5 |
Jalview.main( |
58 |
|
new String[] |
59 |
|
{ "--nonews", "--props", "test/jalview/testProps.jvprops" }); |
60 |
|
|
61 |
5 |
Cache.applicationProperties.setProperty("SHOW_IDENTITY", |
62 |
|
Boolean.TRUE.toString()); |
63 |
5 |
af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa", |
64 |
|
DataSourceType.FILE); |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
5 |
SwingUtilities.invokeAndWait(new Runnable() |
70 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
5 |
@Override... |
72 |
|
public void run() |
73 |
|
{ |
74 |
5 |
af.repaint(); |
75 |
|
} |
76 |
|
}); |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
5 |
do |
82 |
|
{ |
83 |
5 |
try |
84 |
|
{ |
85 |
5 |
Thread.sleep(50); |
86 |
|
} catch (InterruptedException x) |
87 |
|
{ |
88 |
|
} |
89 |
5 |
} while (af.getViewport().getCalcManager().isWorking()); |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
96 |
1 |
@Test(groups = "Functional")... |
97 |
|
public void testSetScrollValues() |
98 |
|
{ |
99 |
1 |
ViewportRanges ranges = af.getViewport().getRanges(); |
100 |
1 |
af.alignPanel.setScrollValues(0, 0); |
101 |
|
|
102 |
1 |
int oldres = ranges.getEndRes(); |
103 |
1 |
af.alignPanel.setScrollValues(-1, 5); |
104 |
|
|
105 |
|
|
106 |
1 |
assertEquals(ranges.getEndRes(), oldres); |
107 |
|
|
108 |
1 |
af.alignPanel.setScrollValues(0, 5); |
109 |
|
|
110 |
|
|
111 |
1 |
assertEquals(ranges.getEndRes(), oldres); |
112 |
|
|
113 |
1 |
af.alignPanel.setScrollValues(5, 5); |
114 |
|
|
115 |
1 |
assertEquals(ranges.getEndRes(), oldres + 5); |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
1 |
int scrollpos = 60; |
120 |
1 |
af.getViewport().hideColumns(30, 50); |
121 |
1 |
af.alignPanel.setScrollValues(scrollpos, 5); |
122 |
1 |
assertEquals(ranges.getEndRes(), oldres + scrollpos); |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
1 |
scrollpos = 40; |
129 |
1 |
af.getViewport().showAllHiddenColumns(); |
130 |
1 |
af.getViewport().hideColumns(30, 50); |
131 |
1 |
af.alignPanel.setScrollValues(scrollpos, 5); |
132 |
1 |
assertEquals(ranges.getEndRes(), oldres + scrollpos); |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
1 |
scrollpos = 130; |
137 |
1 |
af.getViewport().showAllHiddenColumns(); |
138 |
1 |
af.alignPanel.setScrollValues(scrollpos, 5); |
139 |
1 |
assertEquals(ranges.getEndRes(), |
140 |
|
af.getViewport().getAlignment().getWidth() - 1); |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
1 |
af.getViewport().hideColumns(30, 50); |
147 |
1 |
af.alignPanel.setScrollValues(scrollpos, 5); |
148 |
1 |
assertEquals(ranges.getEndRes(), |
149 |
|
af.getViewport().getAlignment().getWidth() - 1 - 21); |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
159 |
1 |
@Test(groups = "Functional")... |
160 |
|
public void testUpdateLayout_endRes() |
161 |
|
{ |
162 |
|
|
163 |
1 |
ViewportRanges ranges = af.getViewport().getRanges(); |
164 |
1 |
int endres = ranges.getEndRes(); |
165 |
|
|
166 |
|
|
167 |
1 |
af.alignPanel.getAlignViewport().setWrapAlignment(true); |
168 |
1 |
af.alignPanel.updateLayout(); |
169 |
|
|
170 |
|
|
171 |
1 |
assertNotEquals(ranges.getEndRes(), endres); |
172 |
|
|
173 |
|
|
174 |
1 |
af.alignPanel.getAlignViewport().setWrapAlignment(false); |
175 |
1 |
af.alignPanel.updateLayout(); |
176 |
|
|
177 |
|
|
178 |
1 |
assertEquals(ranges.getEndRes(), endres); |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
185 |
1 |
@Test(groups = "Functional")... |
186 |
|
public void testCalculateIdWidth_noArgs() |
187 |
|
{ |
188 |
1 |
AlignViewportI av = af.alignPanel.getAlignViewport(); |
189 |
1 |
av.setShowJVSuffix(true); |
190 |
1 |
av.setFont(new Font("Courier", Font.PLAIN, 15), true); |
191 |
|
|
192 |
1 |
av.setIdWidth(0); |
193 |
1 |
Dimension d = af.alignPanel.calculateIdWidth(); |
194 |
1 |
assertEquals(d.width, 0); |
195 |
1 |
assertEquals(d.height, 0); |
196 |
|
|
197 |
1 |
av.setIdWidth(99); |
198 |
1 |
d = af.alignPanel.calculateIdWidth(); |
199 |
1 |
assertEquals(d.width, 99); |
200 |
1 |
assertEquals(d.height, 0); |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
1 |
av.setIdWidth(-1); |
206 |
1 |
d = af.alignPanel.calculateIdWidth(); |
207 |
1 |
assertEquals(d.width, 166); |
208 |
1 |
assertEquals(d.height, 12); |
209 |
1 |
assertEquals(d.width, av.getIdWidth()); |
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
217 |
0 |
@Test(groups = "Functional", enabled = false)... |
218 |
|
public void testCalculateIdWidth_withMaxWidth() |
219 |
|
{ |
220 |
0 |
AlignViewportI av = af.alignPanel.getAlignViewport(); |
221 |
0 |
av.setShowJVSuffix(true); |
222 |
0 |
av.setFont(new Font("Courier", Font.PLAIN, 15), true); |
223 |
0 |
av.setShowAnnotation(false); |
224 |
0 |
av.setIdWidth(18); |
225 |
|
|
226 |
0 |
FontMetrics fmfor = new Container() |
227 |
|
.getFontMetrics(new Font(af.viewport.font.getName(), |
228 |
|
Font.ITALIC, af.viewport.font.getSize())); |
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
0 |
Dimension d = af.alignPanel.calculateIdWidth(2000); |
234 |
|
|
235 |
0 |
int expwidth = 3 + fmfor.stringWidth("Conservation"); |
236 |
|
|
237 |
0 |
assertEquals(d.width, 166); |
238 |
0 |
assertEquals(d.height, 12); |
239 |
0 |
assertEquals(av.getIdWidth(), expwidth); |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
0 |
SequenceI seq = af.viewport.getAlignment() |
245 |
|
.findSequenceMatch("Q93Z60_ARATH")[0]; |
246 |
0 |
seq.setName(seq.getName() + "MMMMM"); |
247 |
0 |
d = af.alignPanel.calculateIdWidth(2000); |
248 |
0 |
assertEquals(d.width, 211); |
249 |
0 |
assertEquals(d.height, 12); |
250 |
0 |
assertEquals(av.getIdWidth(), 18); |
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
0 |
AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[0]; |
257 |
0 |
aa.label = "THIS IS A VERY LONG LABEL INDEED"; |
258 |
0 |
d = af.alignPanel.calculateIdWidth(2000); |
259 |
|
|
260 |
0 |
expwidth = 3 + fmfor.stringWidth(aa.label); |
261 |
|
|
262 |
0 |
assertEquals(d.width, expwidth); |
263 |
|
|
264 |
0 |
assertEquals(d.height, 12); |
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
0 |
d = af.alignPanel.calculateIdWidth(213); |
271 |
0 |
assertEquals(d.width, 217); |
272 |
0 |
assertEquals(d.height, 12); |
273 |
|
} |
274 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 3 |
Complexity Density: 0.21 |
1PASS
|
|
275 |
0 |
@Test(groups = { "Functional", "Not-bamboo" })... |
276 |
|
public void testGetVisibleWidth() |
277 |
|
{ |
278 |
0 |
double scaling = jalview.gui.JvSwingUtilsTest.getScaling(af.alignPanel); |
279 |
|
|
280 |
|
|
281 |
|
|
282 |
0 |
int w = af.alignPanel.getVisibleIdWidth(true); |
283 |
0 |
assertEquals(w, af.alignPanel.getIdPanel().getWidth()); |
284 |
|
|
285 |
|
|
286 |
0 |
int expectedWidth = scaling == 1.0 ? 112 : Platform.isMac() ? 115 : 107; |
287 |
0 |
assertEquals(w, expectedWidth); |
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
0 |
Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.FALSE.toString()); |
294 |
0 |
Cache.removeProperty("FIGURE_FIXEDIDWIDTH"); |
295 |
0 |
assertEquals(w, af.alignPanel.getVisibleIdWidth(false)); |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
0 |
Cache.setProperty("FIGURE_FIXEDIDWIDTH", "120"); |
301 |
0 |
assertEquals(124, af.alignPanel.getVisibleIdWidth(false)); |
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
0 |
Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.TRUE.toString()); |
307 |
0 |
w = af.alignPanel.getVisibleIdWidth(false); |
308 |
|
|
309 |
0 |
assertTrue(w > 105 && w < 120); |
310 |
|
|
311 |
0 |
assertEquals(w, expectedWidth); |
312 |
|
} |
313 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 3 |
Complexity Density: 0.12 |
1PASS
|
|
314 |
0 |
@Test(groups = { "Functional", "Not-bamboo" })... |
315 |
|
public void testresetIdWidth() |
316 |
|
{ |
317 |
0 |
double scaling = jalview.gui.JvSwingUtilsTest.getScaling(af.alignPanel); |
318 |
|
|
319 |
|
|
320 |
|
|
321 |
0 |
int w = af.alignPanel.getVisibleIdWidth(true); |
322 |
0 |
int actual = af.alignPanel.getIdPanel().getWidth(); |
323 |
0 |
assertEquals(w, actual); |
324 |
|
|
325 |
0 |
assertTrue(w > 105 && w < 120); |
326 |
|
|
327 |
0 |
int expectedWidth = scaling == 1.0 ? 112 : Platform.isMac() ? 115 : 107; |
328 |
0 |
assertEquals(w, expectedWidth); |
329 |
|
|
330 |
|
|
331 |
0 |
af.viewport.setIdWidth(200); |
332 |
|
|
333 |
0 |
MouseEvent drag = new MouseEvent(af.alignPanel, |
334 |
|
MouseEvent.MOUSE_DRAGGED, System.currentTimeMillis(), 0, 0, 0, |
335 |
|
MouseEvent.BUTTON1, false); |
336 |
0 |
af.alignPanel.idwidthAdjuster.mouseDragged(drag); |
337 |
0 |
af.alignPanel.paintComponent(af.alignPanel.getGraphics()); |
338 |
0 |
w = af.alignPanel.calculateIdWidth().width; |
339 |
0 |
assertTrue( |
340 |
|
af.alignPanel.getIdPanel().getIdCanvas().isManuallyAdjusted()); |
341 |
0 |
actual = af.alignPanel.getIdPanel().getWidth(); |
342 |
0 |
assertEquals(w, actual); |
343 |
|
|
344 |
0 |
af.viewport.setIdWidth(-1); |
345 |
0 |
af.alignPanel.calculateIdWidth(); |
346 |
0 |
af.alignPanel.getIdPanel().getIdCanvas().setManuallyAdjusted(false); |
347 |
0 |
w = af.alignPanel.calculateIdWidth().width; |
348 |
0 |
af.alignPanel.paintComponent(af.alignPanel.getGraphics()); |
349 |
|
|
350 |
0 |
actual = af.alignPanel.getIdPanel().getWidth(); |
351 |
0 |
assertEquals(w, actual); |
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
0 |
assertTrue(w > 105 && w < 120); |
357 |
|
|
358 |
0 |
assertEquals(w, expectedWidth); |
359 |
|
} |
360 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
361 |
1 |
@Test(groups = "Functional")... |
362 |
|
public void testSetOverviewTitle() |
363 |
|
{ |
364 |
1 |
OverviewPanel ov1 = this.af.openOverviewPanel(true); |
365 |
1 |
String alignFrameTitle = af.getTitle(); |
366 |
1 |
assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle); |
367 |
|
|
368 |
|
|
369 |
|
|
370 |
|
|
371 |
|
|
372 |
1 |
af.newView_actionPerformed(null); |
373 |
1 |
assertEquals(ov1.getTitle(), |
374 |
|
"Overview " + alignFrameTitle + " Original"); |
375 |
1 |
OverviewPanel ov2 = this.af.openOverviewPanel(true); |
376 |
1 |
assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1"); |
377 |
|
} |
378 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
379 |
1 |
@Test(groups = "Functional")... |
380 |
|
public void testSetOverviewTitle_automaticOverview() |
381 |
|
{ |
382 |
1 |
Cache.setProperty("SHOW_OVERVIEW", "true"); |
383 |
1 |
AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded( |
384 |
|
"examples/uniref50.fa", DataSourceType.FILE); |
385 |
1 |
OverviewPanel ov1 = alignFrame.alignPanel.getOverviewPanel(); |
386 |
1 |
assertNotNull(ov1); |
387 |
1 |
String alignFrameTitle = alignFrame.getTitle(); |
388 |
1 |
assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle); |
389 |
|
|
390 |
|
|
391 |
|
|
392 |
|
|
393 |
|
|
394 |
1 |
alignFrame.newView_actionPerformed(null); |
395 |
1 |
assertEquals(ov1.getTitle(), |
396 |
|
"Overview " + alignFrameTitle + " Original"); |
397 |
1 |
OverviewPanel ov2 = alignFrame.alignPanel.getOverviewPanel(); |
398 |
1 |
assertNotNull(ov2); |
399 |
1 |
assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1"); |
400 |
|
} |
401 |
|
} |