[MRM-63] add a progress bar for the checksum

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@370761 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2006-01-20 09:10:14 +00:00
parent 5db9f4bdb2
commit 8abd8e4ba8
2 changed files with 40 additions and 22 deletions

View File

@ -17,7 +17,10 @@ package org.apache.maven.repository.applet;
* *
*/ */
import javax.swing.*;
import java.applet.Applet; import java.applet.Applet;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -25,7 +28,6 @@ import java.security.AccessController;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Properties;
/** /**
* TODO: Description. * TODO: Description.
@ -39,14 +41,23 @@ public class ChecksumApplet
private static final int BYTE_MASK = 0xFF; private static final int BYTE_MASK = 0xFF;
private JProgressBar progressBar;
public void init() public void init()
{ {
super.init(); setLayout( new BorderLayout() );
progressBar = new JProgressBar();
progressBar.setStringPainted( true );
add( progressBar, BorderLayout.CENTER );
JLabel label = new JLabel( "Checksum progress: " );
add( label, BorderLayout.WEST );
setVisible( false );
} }
public String generateMd5( final String file ) public String generateMd5( final String file )
throws IOException, NoSuchAlgorithmException throws IOException, NoSuchAlgorithmException
{ {
setVisible( true );
return (String) AccessController.doPrivileged( new PrivilegedAction() return (String) AccessController.doPrivileged( new PrivilegedAction()
{ {
public Object run() public Object run()
@ -55,6 +66,8 @@ public class ChecksumApplet
{ {
MessageDigest digest = MessageDigest.getInstance( "MD5" ); MessageDigest digest = MessageDigest.getInstance( "MD5" );
long total = new File( file ).length();
long totalRead = 0;
InputStream fis = new FileInputStream( file ); InputStream fis = new FileInputStream( file );
try try
{ {
@ -66,6 +79,8 @@ public class ChecksumApplet
if ( numRead > 0 ) if ( numRead > 0 )
{ {
digest.update( buffer, 0, numRead ); digest.update( buffer, 0, numRead );
totalRead += numRead;
progressBar.setValue( (int) ( totalRead * progressBar.getMaximum() / total ) );
} }
} }
while ( numRead != -1 ); while ( numRead != -1 );

View File

@ -23,6 +23,7 @@
</script> </script>
<p>Search by MD5 (select an artifact): <p>Search by MD5 (select an artifact):
<form action="search.action" <form action="search.action"
onsubmit="this.md5.value = doSomething(this.file.value); this.file.disabled = true;"> onsubmit="this.md5.value = doSomething(this.file.value); this.file.disabled = true;">
<input name="md5" type="hidden"/> <input name="md5" type="hidden"/>
@ -47,18 +48,19 @@
</comment> </comment>
<script language="JavaScript" type="text/javascript"><!-- <script language="JavaScript" type="text/javascript"><!--
if (_ie == true) document.writeln('<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = "1" HEIGHT = "1" NAME = "ChecksumApplet" codebase="http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=5,0,0,5"><noembed><xmp>'); if (_ie == true) document.writeln('<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = "400" HEIGHT = "20" NAME = "ChecksumApplet" codebase="http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=5,0,0,5"><noembed><xmp>');
else if (_ns == true && _ns6 == false) document.writeln('<embed ' + else if (_ns == true && _ns6 == false) document.writeln('<embed ' +
'type="application/x-java-applet;version=1.5" \ 'type="application/x-java-applet;version=1.5" \
CODE = "org/apache/maven/repository/applet/ChecksumApplet.class" \ CODE = "org/apache/maven/repository/applet/ChecksumApplet.class" \
ARCHIVE = "maven-repository-artifact-applet.jar" \ ARCHIVE = "maven-repository-artifact-applet.jar" \
NAME = "ChecksumApplet" \ NAME = "ChecksumApplet" \
WIDTH = "1" \ WIDTH = "400" \
HEIGHT = "1" ' + HEIGHT = "20" ' +
'scriptable=false ' + 'scriptable=false ' +
'pluginspage="http://java.sun.com/products/plugin/index.html#download"><noembed><xmp>'); 'pluginspage="http://java.sun.com/products/plugin/index.html#download"><noembed><xmp>');
//--></script> //--></script>
<applet CODE = "org/apache/maven/repository/applet/ChecksumApplet.class" ARCHIVE = "maven-repository-artifact-applet.jar" WIDTH = "1" HEIGHT = "1" NAME = "ChecksumApplet"></xmp> <applet CODE="org/apache/maven/repository/applet/ChecksumApplet.class" ARCHIVE="maven-repository-artifact-applet.jar"
WIDTH="400" HEIGHT="20" NAME="ChecksumApplet"></xmp>
<PARAM NAME=CODE VALUE="org/apache/maven/repository/applet/ChecksumApplet.class"> <PARAM NAME=CODE VALUE="org/apache/maven/repository/applet/ChecksumApplet.class">
<PARAM NAME=ARCHIVE VALUE="maven-repository-artifact-applet.jar"> <PARAM NAME=ARCHIVE VALUE="maven-repository-artifact-applet.jar">
<PARAM NAME=NAME VALUE="ChecksumApplet"> <PARAM NAME=NAME VALUE="ChecksumApplet">
@ -73,7 +75,8 @@
</object> </object>
<!-- <!--
<APPLET CODE = "org/apache/maven/repository/applet/ChecksumApplet.class" ARCHIVE = "maven-repository-artifact-applet.jar" WIDTH = "1" HEIGHT = "1" NAME = "ChecksumApplet"> <APPLET CODE = "org/apache/maven/repository/applet/ChecksumApplet.class" ARCHIVE =
"maven-repository-artifact-applet.jar" WIDTH = "400" HEIGHT = "20" NAME = "ChecksumApplet">
</APPLET> </APPLET>