From 17dbe9d0029460ccd1f21f516e8ca7b8cd1bc449 Mon Sep 17 00:00:00 2001 From: kiramt Date: Fri, 25 Aug 2017 12:54:05 +0100 Subject: [PATCH] JAL-2587 Update overview progress bar while drawing rows too --- src/jalview/gui/OverviewCanvas.java | 23 +++++++++++++-- src/jalview/gui/OverviewPanel.java | 23 +++++++++------ src/jalview/renderer/OverviewRenderer.java | 42 +++++++++++++++++++--------- 3 files changed, 65 insertions(+), 23 deletions(-) diff --git a/src/jalview/gui/OverviewCanvas.java b/src/jalview/gui/OverviewCanvas.java index 997d214..57070f2 100644 --- a/src/jalview/gui/OverviewCanvas.java +++ b/src/jalview/gui/OverviewCanvas.java @@ -37,7 +37,7 @@ import javax.swing.Timer; public class OverviewCanvas extends JComponent { - private static final long RUNNING_TIME = 2000; + private static final long RUNNING_TIME = 1000; private static final int SPEED = 40; @@ -49,6 +49,8 @@ public class OverviewCanvas extends JComponent private volatile boolean updaterunning = false; + private boolean dispose = false; + private BufferedImage miniMe; private BufferedImage lastMiniMe = null; @@ -194,10 +196,14 @@ public class OverviewCanvas extends JComponent System.gc(); or.removePropertyChangeListener(progressPanel); + or = null; if (restart) { restart = false; - draw(showSequenceFeatures, showAnnotation, transferRenderer); + if (!dispose) + { + draw(showSequenceFeatures, showAnnotation, transferRenderer); + } } else { @@ -298,4 +304,17 @@ public class OverviewCanvas extends JComponent g.setColor(Color.red); od.drawBox(g); } + + public void dispose() + { + dispose = true; + synchronized (this) + { + restart = true; + if (or != null) + { + or.setRedraw(true); + } + } + } } diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 74c2112..593f7ae 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -308,11 +308,14 @@ public class OverviewPanel extends JPanel implements Runnable, @Override public void run() { - oviewCanvas.draw(av.isShowSequenceFeatures(), - (av.isShowAnnotation() && av - .getAlignmentConservationAnnotation() != null), ap - .getSeqPanel().seqCanvas.getFeatureRenderer()); - setBoxPosition(); + if (oviewCanvas != null) + { + oviewCanvas.draw(av.isShowSequenceFeatures(), + (av.isShowAnnotation() + && av.getAlignmentConservationAnnotation() != null), + ap.getSeqPanel().seqCanvas.getFeatureRenderer()); + setBoxPosition(); + } } /** @@ -322,9 +325,12 @@ public class OverviewPanel extends JPanel implements Runnable, */ private void setBoxPosition() { - od.setBoxPosition(av.getAlignment().getHiddenSequences(), av - .getAlignment().getHiddenColumns()); - repaint(); + if (od != null) + { + od.setBoxPosition(av.getAlignment().getHiddenSequences(), + av.getAlignment().getHiddenColumns()); + repaint(); + } } @Override @@ -341,6 +347,7 @@ public class OverviewPanel extends JPanel implements Runnable, try { av.getRanges().removePropertyChangeListener(this); + oviewCanvas.dispose(); } finally { progressPanel = null; diff --git a/src/jalview/renderer/OverviewRenderer.java b/src/jalview/renderer/OverviewRenderer.java index b9d57a4..416defb 100644 --- a/src/jalview/renderer/OverviewRenderer.java +++ b/src/jalview/renderer/OverviewRenderer.java @@ -39,7 +39,9 @@ public class OverviewRenderer { public static final String UPDATE = "OverviewUpdate"; - protected PropertyChangeSupport changeSupport = new PropertyChangeSupport( + private static final int MAX_PROGRESS = 100; + + private PropertyChangeSupport changeSupport = new PropertyChangeSupport( this); private FeatureColourFinder finder; @@ -90,7 +92,9 @@ public class OverviewRenderer int seqIndex = 0; int pixelRow = 0; int alignmentHeight = miniMe.getHeight() - graphHeight; + int totalPixels = miniMe.getWidth() * alignmentHeight; + int lastRowUpdate = 0; changeSupport.firePropertyChange(UPDATE, -1, 0); for (int alignmentRow : rows) @@ -141,6 +145,8 @@ public class OverviewRenderer } } + sendProgressUpdate((pixelCol + 1) * (endRow - pixelRow), + totalPixels, lastRowUpdate); pixelCol = endCol + 1; } colIndex++; @@ -148,10 +154,7 @@ public class OverviewRenderer if (pixelRow != endRow + 1) { - changeSupport.firePropertyChange(UPDATE, - Math.round(100 * (float) pixelRow / alignmentHeight), - Math.round( - 100 * ((float) (endRow + 1) / alignmentHeight))); + lastRowUpdate = sendProgressUpdate(endRow + 1, alignmentHeight, 0); pixelRow = endRow + 1; } seqIndex++; @@ -160,20 +163,31 @@ public class OverviewRenderer // final update to progress bar if present if (redraw) { - changeSupport.firePropertyChange(UPDATE, - Math.round(100 * (float) (pixelRow - 1) / alignmentHeight), - 0); + sendProgressUpdate(pixelRow - 1, alignmentHeight, 0); } else { - changeSupport.firePropertyChange(UPDATE, - Math.round(100 * alignmentHeight / miniMe.getHeight() - 1), - Math.round(100 * alignmentHeight / miniMe.getHeight())); + sendProgressUpdate(alignmentHeight, miniMe.getHeight(), 0); } return miniMe; } /* + * Calculate progress update value and fire event + */ + private int sendProgressUpdate(int position, int maximum, int offset) + { + int newUpdate = offset + + Math.round(MAX_PROGRESS * ((float) position / maximum)); + if (newUpdate > offset) + { + changeSupport.firePropertyChange(UPDATE, offset, newUpdate); + return newUpdate; + } + return offset; + } + + /* * Find the colour of a sequence at a specified column position */ private int getColumnColourFromSequence(jalview.datamodel.SequenceI seq, @@ -222,7 +236,7 @@ public class OverviewRenderer { if (redraw) { - changeSupport.firePropertyChange(UPDATE, 99, 0); + changeSupport.firePropertyChange(UPDATE, MAX_PROGRESS - 1, 0); break; } @@ -255,11 +269,13 @@ public class OverviewRenderer g.fillRect(pixelCol, y - height, endCol - pixelCol + 1, height); } + pixelCol = endCol + 1; colIndex++; } } - changeSupport.firePropertyChange(UPDATE, 99, 100); + changeSupport.firePropertyChange(UPDATE, MAX_PROGRESS - 1, + MAX_PROGRESS); } public void setRedraw(boolean b) -- 1.7.10.2