org.openstreetmap.josm.gui.io
Class DownloadFileTask

java.lang.Object
  extended by org.openstreetmap.josm.gui.PleaseWaitRunnable
      extended by org.openstreetmap.josm.gui.io.DownloadFileTask
All Implemented Interfaces:
java.lang.Runnable, ProgressMonitor.CancelListener

public class DownloadFileTask
extends PleaseWaitRunnable

Asynchronous task for downloading andnd unpacking arbitrary file lists Shows progress bar when donloading


Nested Class Summary
private static class DownloadFileTask.DownloadException
           
 
Field Summary
private  java.lang.String address
           
private  boolean canceled
           
private  java.net.URLConnection downloadConnection
           
private  java.io.File file
           
private  boolean mkdir
           
private  boolean unpack
           
 
Fields inherited from class org.openstreetmap.josm.gui.PleaseWaitRunnable
progressMonitor
 
Constructor Summary
DownloadFileTask(java.awt.Component parent, java.lang.String address, java.io.File file, boolean mkdir, boolean unpack)
          Creates the download task
 
Method Summary
protected  void cancel()
          User pressed cancel button.
private  void closeConnectionIfNeeded()
           
 void download()
           
protected  void finish()
          Finish up the data work.
 boolean isCanceled()
          Replies true if the task was canceled by the user
protected  void realRun()
          Called in the worker thread to do the actual work.
static void unzipFileRecursively(java.io.File file, java.lang.String dir)
          Recursive unzipping function TODO: May be placed somewhere else - Tools.Utils?
 
Methods inherited from class org.openstreetmap.josm.gui.PleaseWaitRunnable
afterFinish, canRunInBackground, getProgressMonitor, operationCanceled, run
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

address

private final java.lang.String address

file

private final java.io.File file

mkdir

private final boolean mkdir

unpack

private final boolean unpack

canceled

private boolean canceled

downloadConnection

private java.net.URLConnection downloadConnection
Constructor Detail

DownloadFileTask

public DownloadFileTask(java.awt.Component parent,
                        java.lang.String address,
                        java.io.File file,
                        boolean mkdir,
                        boolean unpack)
Creates the download task

Parameters:
parent - the parent component relative to which the PleaseWaitDialog is displayed
title - the title to display in the PleaseWaitDialog
Throws:
java.lang.IllegalArgumentException - thrown if toUpdate is null
Method Detail

closeConnectionIfNeeded

private void closeConnectionIfNeeded()

cancel

protected void cancel()
Description copied from class: PleaseWaitRunnable
User pressed cancel button.

Specified by:
cancel in class PleaseWaitRunnable

finish

protected void finish()
Description copied from class: PleaseWaitRunnable
Finish up the data work. Is guaranteed to be called if realRun is called. Finish is called in the gui thread just after the dialog disappeared.

Specified by:
finish in class PleaseWaitRunnable

download

public void download()
              throws DownloadFileTask.DownloadException
Throws:
DownloadFileTask.DownloadException

realRun

protected void realRun()
                throws org.xml.sax.SAXException,
                       java.io.IOException
Description copied from class: PleaseWaitRunnable
Called in the worker thread to do the actual work. When any of the exception is thrown, a message box will be displayed and closeDialog is called. finish() is called in any case.

Specified by:
realRun in class PleaseWaitRunnable
Throws:
org.xml.sax.SAXException
java.io.IOException

isCanceled

public boolean isCanceled()
Replies true if the task was canceled by the user

Returns:

unzipFileRecursively

public static void unzipFileRecursively(java.io.File file,
                                        java.lang.String dir)
                                 throws java.io.IOException
Recursive unzipping function TODO: May be placed somewhere else - Tools.Utils?

Parameters:
file -
dir -
Throws:
java.io.IOException


JOSM