From 29b74ec57dfed68ee26a19edfd55987c28870241 Mon Sep 17 00:00:00 2001 From: kiramt Date: Fri, 25 Aug 2017 18:36:26 +0100 Subject: [PATCH] JAL-2587 Removed duplicate events fired to progress bar --- src/jalview/renderer/OverviewRenderer.java | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/jalview/renderer/OverviewRenderer.java b/src/jalview/renderer/OverviewRenderer.java index 416defb..1f3f663 100644 --- a/src/jalview/renderer/OverviewRenderer.java +++ b/src/jalview/renderer/OverviewRenderer.java @@ -95,6 +95,7 @@ public class OverviewRenderer int totalPixels = miniMe.getWidth() * alignmentHeight; int lastRowUpdate = 0; + int lastUpdate = 0; changeSupport.firePropertyChange(UPDATE, -1, 0); for (int alignmentRow : rows) @@ -145,8 +146,10 @@ public class OverviewRenderer } } - sendProgressUpdate((pixelCol + 1) * (endRow - pixelRow), - totalPixels, lastRowUpdate); + // store last update value + lastUpdate = sendProgressUpdate( + (pixelCol + 1) * (endRow - pixelRow), totalPixels, + lastRowUpdate, lastUpdate); pixelCol = endCol + 1; } colIndex++; @@ -154,7 +157,10 @@ public class OverviewRenderer if (pixelRow != endRow + 1) { - lastRowUpdate = sendProgressUpdate(endRow + 1, alignmentHeight, 0); + // store row offset and last update value + lastRowUpdate = sendProgressUpdate(endRow + 1, alignmentHeight, 0, + lastUpdate); + lastUpdate = lastRowUpdate; pixelRow = endRow + 1; } seqIndex++; @@ -163,28 +169,31 @@ public class OverviewRenderer // final update to progress bar if present if (redraw) { - sendProgressUpdate(pixelRow - 1, alignmentHeight, 0); + sendProgressUpdate(pixelRow - 1, alignmentHeight, 0, 0); } else { - sendProgressUpdate(alignmentHeight, miniMe.getHeight(), 0); + sendProgressUpdate(alignmentHeight, miniMe.getHeight(), 0, 0); } return miniMe; } /* * Calculate progress update value and fire event + * @param rowOffset number of rows to offset calculation by + * @return new rowOffset - return value only to be used when at end of a row */ - private int sendProgressUpdate(int position, int maximum, int offset) + private int sendProgressUpdate(int position, int maximum, int rowOffset, + int lastUpdate) { - int newUpdate = offset + int newUpdate = rowOffset + Math.round(MAX_PROGRESS * ((float) position / maximum)); - if (newUpdate > offset) + if (newUpdate > lastUpdate) { - changeSupport.firePropertyChange(UPDATE, offset, newUpdate); + changeSupport.firePropertyChange(UPDATE, rowOffset, newUpdate); return newUpdate; } - return offset; + return newUpdate; } /* -- 1.7.10.2