001/** 002 * 003 * Copyright (c) 2010 The Regents of the University of California. 004 * All rights reserved. 005 * 006 * Permission is hereby granted, without written agreement and without 007 * license or royalty fees, to use, copy, modify, and distribute this 008 * software and its documentation for any purpose, provided that the 009 * above copyright notice and the following two paragraphs appear in 010 * all copies of this software. 011 * 012 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 013 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 014 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 015 * IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY 016 * OF SUCH DAMAGE. 017 * 018 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 019 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 020 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 021 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY 022 * OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 023 * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 024 */ 025 026package org.kepler.modulemanager.gui; 027 028import java.awt.Container; 029import java.io.InputStream; 030 031import javax.swing.ProgressMonitor; 032 033import org.kepler.modulemanager.ModuleManagerEventListener; 034 035public class ModuleDownloadProgressMonitor implements ModuleManagerEventListener 036{ 037 private Container parent = null; 038 private ProgressMonitor progressMonitor; 039 040 /** 041 * constructor 042 * @param parent the parent gui object 043 */ 044 public ModuleDownloadProgressMonitor(Container parent) 045 { 046 this.parent = parent; 047 } 048 049 /** 050 * update progress for the progress monitor 051 */ 052 public void updateProgress(int totalSize, int bufferSize, int readCount, InputStream is) 053 { 054 progressMonitor.setProgress(readCount*bufferSize); 055 //System.out.println("downloaded " + (readCount * bufferSize) + " of " + totalSize); 056 } 057 058 /** 059 * close the progress monitor at the end of the DL. 060 */ 061 public void downloadEnd() 062 { 063 progressMonitor.close(); 064 } 065 066 /** 067 * start up a new progress monitor at the beginning of a download. 068 */ 069 public void downloadBegin(int totalSize, String moduleName) 070 { 071 progressMonitor = new ProgressMonitor(parent, "Downloading module " + moduleName, "", 0, totalSize); 072 progressMonitor.setMillisToDecideToPopup(500); 073 progressMonitor.setMillisToPopup(500); 074 } 075 076 /** 077 * create a new progress bar when an unzip begins 078 */ 079 public void unzipBegin(long totalSize, String moduleName) 080 { 081 progressMonitor = new ProgressMonitor(parent, "Unzipping module " + moduleName, "", 0, (int)totalSize); 082 progressMonitor.setMillisToDecideToPopup(500); 083 progressMonitor.setMillisToPopup(500); 084 } 085 086 /** 087 * get rid of the unzip progress bar 088 */ 089 public void unzipEnd() 090 { 091 progressMonitor.close(); 092 } 093 094 /** 095 * update the progress of an unzip 096 */ 097 public void unzipUpdateProgress(long totalSize, int bufferSize, int readCount) 098 { 099 progressMonitor.setProgress(readCount*bufferSize); 100 //System.out.println("unzipped " + (readCount * bufferSize) + " of " + totalSize); 101 } 102}