/** * Update the progress bar of the currently downloaded file in main window. Only update if progess * has at least increased by one percent of the total file size of the downloaded file. * * @param downloadedBytes The current amount of downloaded bytes * @param lastProgBarUpdate The byte count at the last progress bar update * @param file The download file * @return The byte count at the last progress bar update */ private int updateProgressBar(int downloadedBytes, int lastProgBarUpdate, DownloadFile file) { int totalSize = (int) file.getTotalFileSize(); // only update progess bar if progess has at least increased by one percent int diff = downloadedBytes - lastProgBarUpdate; int onePercent = (int) totalSize / 100; if (diff >= onePercent) { final String filename = file.getFilename(); final int db = downloadedBytes; SwingUtilities.invokeLater( new Runnable() { public void run() { mainApp.updateDownloadQueue(filename, db); } }); return downloadedBytes; // prog bar updated, so return the new byte count } return lastProgBarUpdate; // no update, so return the previous byte count }