From 5a876370ec1864ae54db22301aaa5cd2b0e44bf5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 28 Dec 2009 22:58:55 +0100 Subject: [PATCH] Factor out transfer rate calculation. --- src/de/todesbaum/jsite/gui/ProjectInsertPage.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/de/todesbaum/jsite/gui/ProjectInsertPage.java b/src/de/todesbaum/jsite/gui/ProjectInsertPage.java index 04241c2..843499a 100644 --- a/src/de/todesbaum/jsite/gui/ProjectInsertPage.java +++ b/src/de/todesbaum/jsite/gui/ProjectInsertPage.java @@ -80,6 +80,9 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl /** The start time of the insert. */ private long startTime = 0; + /** The number of inserted blocks. */ + private volatile int insertedBlocks; + /** * Creates a new progress insert wizard page. * @@ -290,6 +293,7 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl * {@inheritDoc} */ public void projectInsertProgress(Project project, final int succeeded, final int failed, final int fatal, final int total, final boolean finalized) { + insertedBlocks = succeeded; SwingUtilities.invokeLater(new Runnable() { @SuppressWarnings("synthetic-access") @@ -301,7 +305,7 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl progressString.append(progress).append("% ("); progressString.append(succeeded + failed + fatal).append('/').append(total); progressString.append(") ("); - progressString.append(formatNumber(succeeded * 32.0 / ((System.currentTimeMillis() - startTime) / 1000), 1)); + progressString.append(getTransferRate()); progressString.append(' ').append(I18n.getMessage("jsite.insert.k-per-s")).append(')'); progressBar.setString(progressString.toString()); if (finalized) { @@ -374,6 +378,15 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl return formattedNumber; } + /** + * Returns the formatted transfer rate at this point. + * + * @return The formatted transfer rate + */ + private String getTransferRate() { + return formatNumber(insertedBlocks * 32.0 / ((System.currentTimeMillis() - startTime) / 1000), 1); + } + // // INTERFACE ClipboardOwner // -- 2.7.4