fuin.org

Small Open Source Java Tools and Libraries

File Copy Progress Monitor

Enhanced version of the well known ProgressMonitor with two progress bars instead of one.

Screenshot:
Example progress dialog

Example video:
Flash video Internal link outside layout

Example usage:
    public static void main(final String[] args) {

        // This runs in the "main" thread (outside the EDT)

        // Initialize the L&F in a thread safe way
        Utils4Swing.initSystemLookAndFeel();

        // Create an cancel tracker
        final Cancelable cancelable = new CancelableImpl();

        // Create the monitor dialog
        final FileCopyProgressMonitor monitor = new FileCopyProgressMonitor(cancelable,
                "Copy Test", 10);

        // Make the UI visible
        monitor.open();
        try {
            // Dummy loop to simulate copy...
            for (int i = 0; i < 10; i++) {
                // Check if the user canceled the copy process
                if (cancelable.isCanceled()) {
                    break;
                }

                // Create a dummy source and target name...
                final int n = i + 1;
                final String fileName = "file" + n + ".jar";
                final int fileSize = n * 10;
                final String sourceFilename = "http://www.fuin.org/demo-app/" + fileName;
                final String targetFilename = "/program files/demo app/" + fileName;

                // Update the UI with names, count and filesize
                monitor.updateFile(sourceFilename, targetFilename, n, fileSize);

                // Simulate copying a file
                // Normally this would be done with a
                // "FileCopyProgressInputStream"
                for (int j = 0; j < fileSize; j++) {

                    // Update the lower progress bar
                    monitor.updateByte(j + 1);

                    // Sleep to simulate slow copy...
                    sleep(100);
                }
            }
        } finally {
            // Hide the UI
            monitor.close();
        }

    }