From: David ‘Bombe’ Roden Date: Mon, 28 Dec 2009 21:58:55 +0000 (+0100) Subject: Factor out transfer rate calculation. X-Git-Tag: 0.9~47 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=5a876370ec1864ae54db22301aaa5cd2b0e44bf5;p=jSite.git Factor out transfer rate calculation. --- 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 //