| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.renderer; |
| 22 |
|
|
| 23 |
|
import jalview.api.AlignmentColsCollectionI; |
| 24 |
|
import jalview.api.AlignmentRowsCollectionI; |
| 25 |
|
import jalview.api.RendererListenerI; |
| 26 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 27 |
|
import jalview.datamodel.AlignmentI; |
| 28 |
|
import jalview.datamodel.Annotation; |
| 29 |
|
import jalview.datamodel.SequenceGroup; |
| 30 |
|
import jalview.datamodel.SequenceI; |
| 31 |
|
import jalview.renderer.seqfeatures.FeatureColourFinder; |
| 32 |
|
import jalview.renderer.seqfeatures.FeatureRenderer; |
| 33 |
|
import jalview.viewmodel.OverviewDimensions; |
| 34 |
|
|
| 35 |
|
import java.awt.AlphaComposite; |
| 36 |
|
import java.awt.Color; |
| 37 |
|
import java.awt.Graphics; |
| 38 |
|
import java.awt.Graphics2D; |
| 39 |
|
import java.awt.image.BufferedImage; |
| 40 |
|
import java.beans.PropertyChangeSupport; |
| 41 |
|
|
| |
|
| 68.1% |
Uncovered Elements: 53 (166) |
Complexity: 32 |
Complexity Density: 0.28 |
|
| 42 |
|
public class OverviewRenderer |
| 43 |
|
{ |
| 44 |
|
|
| 45 |
|
private final float TRANSPARENCY = 0.5f; |
| 46 |
|
|
| 47 |
|
public static final String UPDATE = "OverviewUpdate"; |
| 48 |
|
|
| 49 |
|
private static final int MAX_PROGRESS = 100; |
| 50 |
|
|
| 51 |
|
private PropertyChangeSupport changeSupport = new PropertyChangeSupport( |
| 52 |
|
this); |
| 53 |
|
|
| 54 |
|
private FeatureColourFinder finder; |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
private BufferedImage miniMe; |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
private float pixelsPerCol; |
| 61 |
|
|
| 62 |
|
|
| 63 |
|
private float pixelsPerSeq; |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
private int graphHeight; |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
private volatile boolean redraw = false; |
| 70 |
|
|
| 71 |
|
|
| 72 |
|
private AlignmentI al; |
| 73 |
|
|
| 74 |
|
private ResidueShaderI shader; |
| 75 |
|
|
| 76 |
|
private OverviewResColourFinder resColFinder; |
| 77 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 78 |
394 |
public OverviewRenderer(FeatureRenderer fr, OverviewDimensions od,... |
| 79 |
|
AlignmentI alignment, ResidueShaderI resshader, |
| 80 |
|
OverviewResColourFinder colFinder) |
| 81 |
|
{ |
| 82 |
394 |
finder = new FeatureColourFinder(fr); |
| 83 |
394 |
resColFinder = colFinder; |
| 84 |
|
|
| 85 |
394 |
al = alignment; |
| 86 |
394 |
shader = resshader; |
| 87 |
|
|
| 88 |
394 |
pixelsPerCol = od.getPixelsPerCol(); |
| 89 |
394 |
pixelsPerSeq = od.getPixelsPerSeq(); |
| 90 |
394 |
graphHeight = od.getGraphHeight(); |
| 91 |
394 |
miniMe = new BufferedImage(od.getWidth(), od.getHeight(), |
| 92 |
|
BufferedImage.TYPE_INT_RGB); |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
@param |
| 99 |
|
|
| 100 |
|
@param |
| 101 |
|
|
| 102 |
|
@return |
| 103 |
|
|
| |
|
| 96.2% |
Uncovered Elements: 2 (52) |
Complexity: 8 |
Complexity Density: 0.21 |
|
| 104 |
394 |
public BufferedImage draw(AlignmentRowsCollectionI rows,... |
| 105 |
|
AlignmentColsCollectionI cols) |
| 106 |
|
{ |
| 107 |
394 |
int rgbcolor = Color.white.getRGB(); |
| 108 |
394 |
int seqIndex = 0; |
| 109 |
394 |
int pixelRow = 0; |
| 110 |
394 |
int alignmentHeight = miniMe.getHeight() - graphHeight; |
| 111 |
394 |
int totalPixels = miniMe.getWidth() * alignmentHeight; |
| 112 |
|
|
| 113 |
394 |
int lastRowUpdate = 0; |
| 114 |
394 |
int lastUpdate = 0; |
| 115 |
394 |
changeSupport.firePropertyChange(UPDATE, -1, 0); |
| 116 |
|
|
| 117 |
394 |
for (int alignmentRow : rows) |
| 118 |
|
{ |
| 119 |
3399 |
if (redraw) |
| 120 |
|
{ |
| 121 |
161 |
break; |
| 122 |
|
} |
| 123 |
|
|
| 124 |
|
|
| 125 |
3238 |
SequenceI seq = rows.getSequence(alignmentRow); |
| 126 |
|
|
| 127 |
|
|
| 128 |
3238 |
SequenceGroup[] allGroups = al.findAllGroups(seq); |
| 129 |
|
|
| 130 |
|
|
| 131 |
3238 |
int endRow = Math.min(Math.round((seqIndex + 1) * pixelsPerSeq) - 1, |
| 132 |
|
miniMe.getHeight() - 1); |
| 133 |
|
|
| 134 |
3238 |
int colIndex = 0; |
| 135 |
3238 |
int pixelCol = 0; |
| 136 |
3238 |
for (int alignmentCol : cols) |
| 137 |
|
{ |
| 138 |
471743 |
if (redraw) |
| 139 |
|
{ |
| 140 |
134 |
break; |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
|
| 144 |
471572 |
int endCol = Math.min(Math.round((colIndex + 1) * pixelsPerCol) - 1, |
| 145 |
|
miniMe.getWidth() - 1); |
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| 150 |
471483 |
if (pixelCol <= endCol) |
| 151 |
|
{ |
| 152 |
471443 |
rgbcolor = getColumnColourFromSequence(allGroups, seq, |
| 153 |
|
alignmentCol); |
| 154 |
|
|
| 155 |
|
|
| 156 |
1645602 |
for (int row = pixelRow; row <= endRow; ++row) |
| 157 |
|
{ |
| 158 |
4041542 |
for (int col = pixelCol; col <= endCol; ++col) |
| 159 |
|
{ |
| 160 |
2867688 |
miniMe.setRGB(col, row, rgbcolor); |
| 161 |
|
} |
| 162 |
|
} |
| 163 |
|
|
| 164 |
|
|
| 165 |
471476 |
lastUpdate = sendProgressUpdate( |
| 166 |
|
(pixelCol + 1) * (endRow - pixelRow), totalPixels, |
| 167 |
|
lastRowUpdate, lastUpdate); |
| 168 |
|
|
| 169 |
471422 |
pixelCol = endCol + 1; |
| 170 |
|
} |
| 171 |
471531 |
colIndex++; |
| 172 |
|
} |
| 173 |
|
|
| 174 |
3238 |
if (pixelRow != endRow + 1) |
| 175 |
|
{ |
| 176 |
|
|
| 177 |
3238 |
lastRowUpdate = sendProgressUpdate(endRow + 1, alignmentHeight, 0, |
| 178 |
|
lastUpdate); |
| 179 |
3238 |
lastUpdate = lastRowUpdate; |
| 180 |
3238 |
pixelRow = endRow + 1; |
| 181 |
|
} |
| 182 |
3238 |
seqIndex++; |
| 183 |
|
} |
| 184 |
|
|
| 185 |
394 |
overlayHiddenRegions(rows, cols); |
| 186 |
|
|
| 187 |
394 |
if (redraw) |
| 188 |
|
{ |
| 189 |
177 |
sendProgressUpdate(pixelRow - 1, alignmentHeight, 0, 0); |
| 190 |
|
} |
| 191 |
|
else |
| 192 |
|
{ |
| 193 |
217 |
sendProgressUpdate(alignmentHeight, miniMe.getHeight(), 0, 0); |
| 194 |
|
} |
| 195 |
394 |
return miniMe; |
| 196 |
|
} |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
@param |
| 201 |
|
@return |
| 202 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 203 |
475015 |
private int sendProgressUpdate(int position, int maximum, int rowOffset,... |
| 204 |
|
int lastUpdate) |
| 205 |
|
{ |
| 206 |
475092 |
int newUpdate = rowOffset |
| 207 |
|
+ Math.round(MAX_PROGRESS * ((float) position / maximum)); |
| 208 |
475197 |
if (newUpdate > lastUpdate) |
| 209 |
|
{ |
| 210 |
16528 |
changeSupport.firePropertyChange(UPDATE, rowOffset, newUpdate); |
| 211 |
16528 |
return newUpdate; |
| 212 |
|
} |
| 213 |
458710 |
return newUpdate; |
| 214 |
|
} |
| 215 |
|
|
| 216 |
|
|
| 217 |
|
|
| 218 |
|
|
| 219 |
|
@param |
| 220 |
|
|
| 221 |
|
@param |
| 222 |
|
|
| 223 |
|
@return |
| 224 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 225 |
471351 |
int getColumnColourFromSequence(SequenceGroup[] allGroups, SequenceI seq,... |
| 226 |
|
int lastcol) |
| 227 |
|
{ |
| 228 |
471410 |
Color color = resColFinder.gapColour; |
| 229 |
|
|
| 230 |
471367 |
if ((seq != null) && (seq.getLength() > lastcol)) |
| 231 |
|
{ |
| 232 |
469183 |
color = resColFinder.getResidueColour(true, shader, allGroups, seq, |
| 233 |
|
lastcol, finder); |
| 234 |
|
} |
| 235 |
|
|
| 236 |
471131 |
return color.getRGB(); |
| 237 |
|
} |
| 238 |
|
|
| 239 |
|
|
| 240 |
|
|
| 241 |
|
|
| 242 |
|
@param |
| 243 |
|
|
| 244 |
|
@param |
| 245 |
|
|
| 246 |
|
|
| |
|
| 28.6% |
Uncovered Elements: 5 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 247 |
394 |
private void overlayHiddenRegions(AlignmentRowsCollectionI rows,... |
| 248 |
|
AlignmentColsCollectionI cols) |
| 249 |
|
{ |
| 250 |
394 |
if (cols.hasHidden() || rows.hasHidden()) |
| 251 |
|
{ |
| 252 |
0 |
BufferedImage mask = buildHiddenImage(rows, cols, miniMe.getWidth(), |
| 253 |
|
miniMe.getHeight()); |
| 254 |
|
|
| 255 |
0 |
Graphics2D g = (Graphics2D) miniMe.getGraphics(); |
| 256 |
0 |
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, |
| 257 |
|
TRANSPARENCY)); |
| 258 |
0 |
g.drawImage(mask, 0, 0, miniMe.getWidth(), miniMe.getHeight(), null); |
| 259 |
|
} |
| 260 |
|
} |
| 261 |
|
|
| 262 |
|
|
| 263 |
|
|
| 264 |
|
|
| 265 |
|
|
| 266 |
|
@param |
| 267 |
|
|
| 268 |
|
@param |
| 269 |
|
|
| 270 |
|
@param |
| 271 |
|
|
| 272 |
|
@param |
| 273 |
|
|
| 274 |
|
@return |
| 275 |
|
|
| |
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 6 |
Complexity Density: 0.21 |
|
| 276 |
0 |
private BufferedImage buildHiddenImage(AlignmentRowsCollectionI rows,... |
| 277 |
|
AlignmentColsCollectionI cols, int width, int height) |
| 278 |
|
{ |
| 279 |
|
|
| 280 |
0 |
BufferedImage hiddenImage = new BufferedImage(width, height, |
| 281 |
|
BufferedImage.TYPE_INT_ARGB); |
| 282 |
|
|
| 283 |
0 |
int colIndex = 0; |
| 284 |
0 |
int pixelCol = 0; |
| 285 |
|
|
| 286 |
0 |
Color hidden = resColFinder.getHiddenColour(); |
| 287 |
|
|
| 288 |
0 |
Graphics2D g2d = (Graphics2D) hiddenImage.getGraphics(); |
| 289 |
|
|
| 290 |
|
|
| 291 |
|
|
| 292 |
|
|
| 293 |
|
|
| 294 |
|
|
| 295 |
0 |
g2d.setComposite(AlphaComposite.Src); |
| 296 |
|
|
| 297 |
0 |
for (int alignmentCol : cols) |
| 298 |
|
{ |
| 299 |
0 |
if (redraw) |
| 300 |
|
{ |
| 301 |
0 |
break; |
| 302 |
|
} |
| 303 |
|
|
| 304 |
|
|
| 305 |
0 |
int endCol = Math.min(Math.round((colIndex + 1) * pixelsPerCol) - 1, |
| 306 |
|
hiddenImage.getWidth() - 1); |
| 307 |
|
|
| 308 |
0 |
if (pixelCol <= endCol) |
| 309 |
|
{ |
| 310 |
|
|
| 311 |
0 |
if (cols.isHidden(alignmentCol)) |
| 312 |
|
{ |
| 313 |
0 |
g2d.setColor(hidden); |
| 314 |
0 |
g2d.fillRect(pixelCol, 0, endCol - pixelCol + 1, height); |
| 315 |
|
} |
| 316 |
|
|
| 317 |
0 |
pixelCol = endCol + 1; |
| 318 |
|
} |
| 319 |
0 |
colIndex++; |
| 320 |
|
|
| 321 |
|
} |
| 322 |
|
|
| 323 |
0 |
int seqIndex = 0; |
| 324 |
0 |
int pixelRow = 0; |
| 325 |
0 |
for (int alignmentRow : rows) |
| 326 |
|
{ |
| 327 |
0 |
if (redraw) |
| 328 |
|
{ |
| 329 |
0 |
break; |
| 330 |
|
} |
| 331 |
|
|
| 332 |
|
|
| 333 |
0 |
int endRow = Math.min(Math.round((seqIndex + 1) * pixelsPerSeq) - 1, |
| 334 |
|
miniMe.getHeight() - 1); |
| 335 |
|
|
| 336 |
|
|
| 337 |
0 |
if (rows.isHidden(alignmentRow)) |
| 338 |
|
{ |
| 339 |
0 |
g2d.setColor(hidden); |
| 340 |
0 |
g2d.fillRect(0, pixelRow, width, endRow - pixelRow + 1); |
| 341 |
|
} |
| 342 |
0 |
pixelRow = endRow + 1; |
| 343 |
0 |
seqIndex++; |
| 344 |
|
} |
| 345 |
|
|
| 346 |
0 |
return hiddenImage; |
| 347 |
|
} |
| 348 |
|
|
| 349 |
|
|
| 350 |
|
|
| 351 |
|
|
| 352 |
|
@param |
| 353 |
|
|
| 354 |
|
@param |
| 355 |
|
|
| 356 |
|
@param |
| 357 |
|
|
| 358 |
|
@param |
| 359 |
|
|
| 360 |
|
|
| |
|
| 79.4% |
Uncovered Elements: 7 (34) |
Complexity: 6 |
Complexity Density: 0.25 |
|
| 361 |
383 |
public void drawGraph(Graphics g, AlignmentAnnotation anno, int y,... |
| 362 |
|
AlignmentColsCollectionI cols) |
| 363 |
|
{ |
| 364 |
383 |
Annotation[] annotations = anno.annotations; |
| 365 |
383 |
g.setColor(Color.white); |
| 366 |
383 |
g.fillRect(0, 0, miniMe.getWidth(), y); |
| 367 |
|
|
| 368 |
383 |
int height; |
| 369 |
383 |
int colIndex = 0; |
| 370 |
383 |
int pixelCol = 0; |
| 371 |
383 |
for (int alignmentCol : cols) |
| 372 |
|
{ |
| 373 |
29620 |
if (redraw) |
| 374 |
|
{ |
| 375 |
172 |
changeSupport.firePropertyChange(UPDATE, MAX_PROGRESS - 1, 0); |
| 376 |
172 |
break; |
| 377 |
|
} |
| 378 |
|
|
| 379 |
29449 |
if (alignmentCol >= annotations.length) |
| 380 |
|
{ |
| 381 |
0 |
break; |
| 382 |
|
} |
| 383 |
|
else |
| 384 |
|
{ |
| 385 |
29450 |
int endCol = Math.min(Math.round((colIndex + 1) * pixelsPerCol) - 1, |
| 386 |
|
miniMe.getWidth() - 1); |
| 387 |
|
|
| 388 |
29452 |
if (annotations[alignmentCol] != null) |
| 389 |
|
{ |
| 390 |
29452 |
if (annotations[alignmentCol].colour == null) |
| 391 |
|
{ |
| 392 |
0 |
g.setColor(Color.black); |
| 393 |
|
} |
| 394 |
|
else |
| 395 |
|
{ |
| 396 |
29453 |
g.setColor(annotations[alignmentCol].colour); |
| 397 |
|
} |
| 398 |
|
|
| 399 |
29451 |
height = (int) ((annotations[alignmentCol].value / anno.graphMax) |
| 400 |
|
* y); |
| 401 |
29453 |
if (height > y) |
| 402 |
|
{ |
| 403 |
0 |
height = y; |
| 404 |
|
} |
| 405 |
|
|
| 406 |
29451 |
g.fillRect(pixelCol, y - height, endCol - pixelCol + 1, height); |
| 407 |
|
} |
| 408 |
|
|
| 409 |
29448 |
pixelCol = endCol + 1; |
| 410 |
29452 |
colIndex++; |
| 411 |
|
} |
| 412 |
|
} |
| 413 |
383 |
changeSupport.firePropertyChange(UPDATE, MAX_PROGRESS - 1, |
| 414 |
|
MAX_PROGRESS); |
| 415 |
|
} |
| 416 |
|
|
| 417 |
|
|
| 418 |
|
|
| 419 |
|
|
| 420 |
|
@param |
| 421 |
|
|
| 422 |
|
|
| 423 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 424 |
251 |
public void setRedraw(boolean b)... |
| 425 |
|
{ |
| 426 |
251 |
synchronized (this) |
| 427 |
|
{ |
| 428 |
251 |
redraw = b; |
| 429 |
|
} |
| 430 |
|
} |
| 431 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 432 |
394 |
public void addPropertyChangeListener(RendererListenerI listener)... |
| 433 |
|
{ |
| 434 |
394 |
changeSupport.addPropertyChangeListener(listener); |
| 435 |
|
} |
| 436 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 437 |
379 |
public void removePropertyChangeListener(RendererListenerI listener)... |
| 438 |
|
{ |
| 439 |
379 |
changeSupport.removePropertyChangeListener(listener); |
| 440 |
|
} |
| 441 |
|
} |