| 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 |
|
|
| |
|
| 53.5% |
Uncovered Elements: 73 (157) |
Complexity: 15 |
Complexity Density: 0.11 |
|
| 50 |
|
public class AlignmentPanelTest |
| 51 |
|
{ |
| 52 |
|
AlignFrame af; |
| 53 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (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 |
7 |
try |
| 84 |
|
{ |
| 85 |
7 |
Thread.sleep(50); |
| 86 |
|
} catch (InterruptedException x) |
| 87 |
|
{ |
| 88 |
|
} |
| 89 |
7 |
} 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: 5 (5) |
Complexity: 3 |
Complexity Density: 3 |
|
| 275 |
0 |
private int computeExpectedWidth(double scaling)... |
| 276 |
|
{ |
| 277 |
0 |
return Platform.isMac() ? 115 : scaling == 1.0 ? 112 : 107; |
| 278 |
|
} |
| 279 |
|
|
| 280 |
|
|
| |
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
| 281 |
0 |
@Test(groups = { "Functional", "Not-bamboo" })... |
| 282 |
|
public void testGetVisibleWidth() |
| 283 |
|
{ |
| 284 |
0 |
double scaling = jalview.gui.JvSwingUtilsTest.getScaling(af.alignPanel); |
| 285 |
|
|
| 286 |
|
|
| 287 |
|
|
| 288 |
0 |
int w = af.alignPanel.getVisibleIdWidth(true); |
| 289 |
0 |
assertEquals(w, af.alignPanel.getIdPanel().getWidth()); |
| 290 |
|
|
| 291 |
|
|
| 292 |
0 |
int expectedWidth = computeExpectedWidth(scaling); |
| 293 |
0 |
assertEquals(w, expectedWidth); |
| 294 |
|
|
| 295 |
|
|
| 296 |
|
|
| 297 |
|
|
| 298 |
|
|
| 299 |
0 |
Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.FALSE.toString()); |
| 300 |
0 |
Cache.removeProperty("FIGURE_FIXEDIDWIDTH"); |
| 301 |
0 |
assertEquals(w, af.alignPanel.getVisibleIdWidth(false)); |
| 302 |
|
|
| 303 |
|
|
| 304 |
|
|
| 305 |
|
|
| 306 |
0 |
Cache.setProperty("FIGURE_FIXEDIDWIDTH", "120"); |
| 307 |
0 |
assertEquals(124, af.alignPanel.getVisibleIdWidth(false)); |
| 308 |
|
|
| 309 |
|
|
| 310 |
|
|
| 311 |
|
|
| 312 |
0 |
Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.TRUE.toString()); |
| 313 |
0 |
w = af.alignPanel.getVisibleIdWidth(false); |
| 314 |
|
|
| 315 |
0 |
assertTrue(w > 105 && w < 120); |
| 316 |
|
|
| 317 |
0 |
assertEquals(w, expectedWidth); |
| 318 |
|
} |
| 319 |
|
|
| 320 |
|
|
| |
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
| 321 |
0 |
@Test(groups = { "Functional", "Not-bamboo" })... |
| 322 |
|
public void testresetIdWidth() |
| 323 |
|
{ |
| 324 |
0 |
double scaling = jalview.gui.JvSwingUtilsTest.getScaling(af.alignPanel); |
| 325 |
|
|
| 326 |
|
|
| 327 |
|
|
| 328 |
0 |
int w = af.alignPanel.getVisibleIdWidth(true); |
| 329 |
0 |
int actual = af.alignPanel.getIdPanel().getWidth(); |
| 330 |
0 |
assertEquals(w, actual); |
| 331 |
|
|
| 332 |
0 |
assertTrue(w > 105 && w < 120); |
| 333 |
|
|
| 334 |
0 |
int expectedWidth = computeExpectedWidth(scaling); |
| 335 |
0 |
assertEquals(w, expectedWidth); |
| 336 |
|
|
| 337 |
|
|
| 338 |
0 |
af.viewport.setIdWidth(200); |
| 339 |
|
|
| 340 |
0 |
MouseEvent drag = new MouseEvent(af.alignPanel, |
| 341 |
|
MouseEvent.MOUSE_DRAGGED, System.currentTimeMillis(), 0, 0, 0, |
| 342 |
|
MouseEvent.BUTTON1, false); |
| 343 |
0 |
af.alignPanel.idwidthAdjuster.mouseDragged(drag); |
| 344 |
0 |
af.alignPanel.paintComponent(af.alignPanel.getGraphics()); |
| 345 |
0 |
w = af.alignPanel.calculateIdWidth().width; |
| 346 |
0 |
assertTrue( |
| 347 |
|
af.alignPanel.getIdPanel().getIdCanvas().isManuallyAdjusted()); |
| 348 |
0 |
actual = af.alignPanel.getIdPanel().getWidth(); |
| 349 |
0 |
assertEquals(w, actual); |
| 350 |
|
|
| 351 |
0 |
af.viewport.setIdWidth(-1); |
| 352 |
0 |
af.alignPanel.calculateIdWidth(); |
| 353 |
0 |
af.alignPanel.getIdPanel().getIdCanvas().setManuallyAdjusted(false); |
| 354 |
0 |
w = af.alignPanel.calculateIdWidth().width; |
| 355 |
0 |
af.alignPanel.paintComponent(af.alignPanel.getGraphics()); |
| 356 |
|
|
| 357 |
0 |
actual = af.alignPanel.getIdPanel().getWidth(); |
| 358 |
0 |
assertEquals(w, actual); |
| 359 |
|
|
| 360 |
|
|
| 361 |
|
|
| 362 |
|
|
| 363 |
0 |
assertTrue(w > 105 && w < 120); |
| 364 |
|
|
| 365 |
0 |
assertEquals(w, expectedWidth); |
| 366 |
|
} |
| 367 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 368 |
1 |
@Test(groups = "Functional")... |
| 369 |
|
public void testSetOverviewTitle() |
| 370 |
|
{ |
| 371 |
1 |
OverviewPanel ov1 = this.af.openOverviewPanel(true); |
| 372 |
1 |
String alignFrameTitle = af.getTitle(); |
| 373 |
1 |
assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle); |
| 374 |
|
|
| 375 |
|
|
| 376 |
|
|
| 377 |
|
|
| 378 |
|
|
| 379 |
1 |
af.newView_actionPerformed(null); |
| 380 |
1 |
assertEquals(ov1.getTitle(), |
| 381 |
|
"Overview " + alignFrameTitle + " Original"); |
| 382 |
1 |
OverviewPanel ov2 = this.af.openOverviewPanel(true); |
| 383 |
1 |
assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1"); |
| 384 |
|
} |
| 385 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
| 386 |
1 |
@Test(groups = "Functional")... |
| 387 |
|
public void testSetOverviewTitle_automaticOverview() |
| 388 |
|
{ |
| 389 |
1 |
Cache.setProperty("SHOW_OVERVIEW", "true"); |
| 390 |
1 |
AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded( |
| 391 |
|
"examples/uniref50.fa", DataSourceType.FILE); |
| 392 |
1 |
OverviewPanel ov1 = alignFrame.alignPanel.getOverviewPanel(); |
| 393 |
1 |
assertNotNull(ov1); |
| 394 |
1 |
String alignFrameTitle = alignFrame.getTitle(); |
| 395 |
1 |
assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle); |
| 396 |
|
|
| 397 |
|
|
| 398 |
|
|
| 399 |
|
|
| 400 |
|
|
| 401 |
1 |
alignFrame.newView_actionPerformed(null); |
| 402 |
1 |
assertEquals(ov1.getTitle(), |
| 403 |
|
"Overview " + alignFrameTitle + " Original"); |
| 404 |
1 |
OverviewPanel ov2 = alignFrame.alignPanel.getOverviewPanel(); |
| 405 |
1 |
assertNotNull(ov2); |
| 406 |
1 |
assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1"); |
| 407 |
|
} |
| 408 |
|
} |