- Timestamp:
- 2017-05-18T20:38:56+12:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/download/DownloadProgressBar.java
r22103 r31692 128 128 JPanel button_pane = new JPanel(); 129 129 130 // our "pause" button never paused before, it always did a process.destroy() on being pressed. 131 // See http://trac.greenstone.org/browser/trunk/gli/src/org/greenstone/gatherer/download/DownloadJob.java?rev=13594 132 // However, now we additionally ensure that the wget launched by the perl is stopped before 133 // process.destroy(), so at least it cleans up better. I'm therefore changing it to a "Stop" button. 130 134 stop_start_button = new GLIButton(Dictionary.get("Mirroring.DownloadJob.Pause"),Dictionary.get("Mirroring.DownloadJob.Pause_Tooltip")); 135 //stop_start_button = new GLIButton(Dictionary.get("Mirroring.DownloadJob.Stop"),Dictionary.get("Mirroring.DownloadJob.Stop_Tooltip")); 131 136 stop_start_button.addActionListener(this); 132 137 stop_start_button.addActionListener(owner); … … 166 171 // Make the labels, etc update. 167 172 refresh(); 173 } 174 175 // internally thread-safe 176 public void enableCancelJob(boolean isEnabled) { 177 synchronized(stop_start_button) { 178 stop_start_button.setEnabled(isEnabled); 179 } 180 synchronized(stop_start_button) { 181 close_button.setEnabled(isEnabled); 182 } 168 183 } 169 184 … … 212 227 * @param url The url String of the file that is being downloaded. 213 228 */ 214 public void addDownload(String url) {229 public synchronized void addDownload(String url) { 215 230 current_url = url; 216 231 file_size = 0; … … 221 236 * is called to enlighten the DownloadProgressBar of this fact. 222 237 */ 223 public void downloadComplete() {238 public synchronized void downloadComplete() { 224 239 current_url = null; 225 240 file_count++; … … 232 247 } 233 248 234 public void downloadFailed() {249 public synchronized void downloadFailed() { 235 250 err_count++; 236 251 if(total_count < (file_count + err_count + warning_count)) { … … 240 255 } 241 256 242 public void downloadWarning() {257 public synchronized void downloadWarning() { 243 258 warning_count++; 244 259 if(total_count < (file_count + err_count + warning_count)) { … … 248 263 } 249 264 250 public void setTotalDownload(int total_download) { 265 // need to make these methods synchronized too, as they modify variables 266 // that other synchronized methods work with. And if any methods that modify 267 // such variables were to remain unsynchronized, can end up with race conditions 268 // http://stackoverflow.com/questions/574240/is-there-an-advantage-to-use-a-synchronized-method-instead-of-a-synchronized-blo 269 // "Not only do synchronized methods not lock the whole class, but they don't lock the whole instance either. Unsynchronized methods in the class may still proceed on the instance." 270 // "Only the syncronized methods are locked. If there are fields you use within synced methods that are accessed by unsynced methods, you can run into race conditions." 271 public synchronized void setTotalDownload(int total_download) { 251 272 total_count = total_download; 252 273 refresh(); … … 257 278 } 258 279 259 public void increaseFileCount() {280 public synchronized void increaseFileCount() { 260 281 file_count++; 261 282 refresh(); 262 283 } 263 284 264 public void increaseFileCount(int amount) {285 public synchronized void increaseFileCount(int amount) { 265 286 file_count += amount; 266 287 refresh(); 267 288 } 268 289 269 public void resetFileCount() {290 public synchronized void resetFileCount() { 270 291 file_count = 0; 271 292 refresh(); … … 278 299 * reset to zero. 279 300 */ 280 public void mirrorBegun(boolean reset, boolean simple) {301 public synchronized void mirrorBegun(boolean reset, boolean simple) { 281 302 if(reset) { 282 303 this.file_count = 0; … … 301 322 * components. 302 323 */ 303 public void mirrorComplete() {324 public synchronized void mirrorComplete() { 304 325 current_action = DownloadJob.COMPLETE; 305 326 current_url = null; … … 319 340 * the amount of the current file downloaded. 320 341 */ 321 public void updateProgress(long current, long expected) {342 public synchronized void updateProgress(long current, long expected) { 322 343 file_size = file_size + current; 323 344 if(!progress.isIndeterminate()) {
Note:
See TracChangeset
for help on using the changeset viewer.