mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-16 23:25:03 +00:00
tweak progress bar
This commit is contained in:
parent
71a152bf18
commit
f1095a2eb2
@ -27,8 +27,8 @@ import java.lang.*;
|
||||
|
||||
public class CPGeneratorProgress extends ProgressApplet
|
||||
{
|
||||
final static String DOWNLOAD_STRING = "Downloading:";
|
||||
final static String UNJAR_STRING = "Uncompressing:";
|
||||
final static String DOWNLOAD_STRING = "Downloading...";
|
||||
final static String UNJAR_STRING = "Uncompressing...";
|
||||
final static String DONE_STRING = "Done...";
|
||||
final static String CONTACTING_SERVER = "Contacting registration server...";
|
||||
final static String SENDING = "Sending registration information...";
|
||||
@ -37,14 +37,8 @@ public class CPGeneratorProgress extends ProgressApplet
|
||||
final static String ABORT = "There were problems with the server connection...";
|
||||
final static String DIALING_STRING = "Calling registration server...";
|
||||
|
||||
protected int getState()
|
||||
{
|
||||
if ( ServerDownload.getState() == ServerDownload.IDLE )
|
||||
return CPGenerator.getState();
|
||||
else
|
||||
return ServerDownload.getState();
|
||||
}
|
||||
|
||||
final static double PEG_DOWNLOAD = 0.90;
|
||||
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
@ -61,14 +55,14 @@ public class CPGeneratorProgress extends ProgressApplet
|
||||
|
||||
int lastState = CPGenerator.DONE;
|
||||
int thisState = CPGenerator.DONE;
|
||||
String lastString = "";
|
||||
String thisString = "";
|
||||
//String lastString = "";
|
||||
//String thisString = "";
|
||||
|
||||
while ( CPGenerator.done == false )
|
||||
{
|
||||
//Trace.TRACE( "CPGenerator not done" );
|
||||
thisState = getState();
|
||||
thisString = new String( CPGenerator.currentFile );
|
||||
thisState = CPGenerator.getState();
|
||||
//thisString = new String( CPGenerator.currentFile );
|
||||
|
||||
if ( thisState != lastState )
|
||||
{
|
||||
@ -76,53 +70,76 @@ public class CPGeneratorProgress extends ProgressApplet
|
||||
|
||||
switch ( thisState )
|
||||
{
|
||||
case ServerDownload.DOWNLOADING:
|
||||
buffer = DOWNLOAD_STRING;
|
||||
case CPGenerator.IDLE:
|
||||
buffer = "";
|
||||
break;
|
||||
|
||||
case ServerDownload.UNJARRING:
|
||||
buffer = UNJAR_STRING;
|
||||
case CPGenerator.DOWNLOADING:
|
||||
buffer = DOWNLOAD_STRING;
|
||||
break;
|
||||
|
||||
case CPGenerator.UNJARRING:
|
||||
buffer = UNJAR_STRING;
|
||||
break;
|
||||
|
||||
case CPGenerator.CONTACTING_SERVER:
|
||||
buffer = CONTACTING_SERVER;
|
||||
buffer = CONTACTING_SERVER;
|
||||
break;
|
||||
|
||||
case CPGenerator.SENDING:
|
||||
buffer = SENDING;
|
||||
buffer = SENDING;
|
||||
break;
|
||||
|
||||
case CPGenerator.WAITING:
|
||||
buffer = WAITING;
|
||||
buffer = WAITING;
|
||||
break;
|
||||
|
||||
case CPGenerator.RECEIVING_RESPONSE:
|
||||
buffer = RECEIVING_RESPONSE;
|
||||
buffer = RECEIVING_RESPONSE;
|
||||
break;
|
||||
|
||||
case CPGenerator.DONE:
|
||||
buffer = DONE_STRING;
|
||||
buffer = DONE_STRING;
|
||||
break;
|
||||
|
||||
case CPGenerator.ABORT:
|
||||
buffer = ABORT;
|
||||
buffer = ABORT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
status.setText( buffer );
|
||||
lastState = thisState;
|
||||
}
|
||||
|
||||
if ( thisString.compareTo( lastString ) != 0 )
|
||||
{
|
||||
progress.setText( thisString );
|
||||
lastString = thisString;
|
||||
}
|
||||
//if ( thisString.compareTo( lastString ) != 0 )
|
||||
//{
|
||||
// progress.setText( thisString );
|
||||
// lastString = thisString;
|
||||
//}
|
||||
|
||||
if ( ServerDownload.getBytesDownloaded() == 0 || CPGenerator.totalBytes == 0 )
|
||||
progressBar.setPercent( 0.0 );
|
||||
else
|
||||
progressBar.setPercent( (double)ServerDownload.getBytesDownloaded() / (double)CPGenerator.totalBytes );
|
||||
{
|
||||
double percent;
|
||||
|
||||
if ( thisState == CPGenerator.DOWNLOADING )
|
||||
{
|
||||
percent = (double)ServerDownload.getBytesDownloaded() /
|
||||
(double)CPGenerator.totalBytes;
|
||||
|
||||
percent = percent * PEG_DOWNLOAD;
|
||||
}
|
||||
else
|
||||
{
|
||||
percent = (double)ServerDownload.getBytesUnjarred() /
|
||||
(double)CPGenerator.totalBytes;
|
||||
percent = ( 1.0 - PEG_DOWNLOAD ) * percent;
|
||||
percent = percent + PEG_DOWNLOAD;
|
||||
}
|
||||
|
||||
progressBar.setPercent( percent );
|
||||
}
|
||||
|
||||
repaint();
|
||||
Thread.yield();
|
||||
|
@ -30,6 +30,9 @@ import netscape.security.*;
|
||||
|
||||
public class CPGenerator
|
||||
{
|
||||
public static final int IDLE = 1;
|
||||
public static final int DOWNLOADING = 2;
|
||||
public static final int UNJARRING = 3;
|
||||
public static final int SENDING = 4;
|
||||
public static final int RECEIVING_RESPONSE = 5;
|
||||
public static final int WAITING = 6;
|
||||
@ -63,7 +66,7 @@ public class CPGenerator
|
||||
|
||||
//static CPGeneratorProgress progress = null;
|
||||
|
||||
// static final String regservMimeData = "http://seaspace.netscape.com:8080/programs/ias5/regserv/docs/reg.cgi";
|
||||
// static final String regservMimeData = "http://seaspace.netscape.com:8080/programs/ias5/regserv/docs/reg.cgi";
|
||||
|
||||
public static int getState()
|
||||
{
|
||||
@ -604,6 +607,8 @@ public class CPGenerator
|
||||
|
||||
private static void downloadAndUnzipMetadata( String rootURL ) throws Throwable
|
||||
{
|
||||
state = DOWNLOADING;
|
||||
|
||||
String zipFileURL = rootURL + "metadata.jar";
|
||||
String localFileName = getLocalPath() + "metadata.jar";
|
||||
|
||||
@ -613,6 +618,8 @@ public class CPGenerator
|
||||
|
||||
private static void downloadJarFiles( Vector ispList, String rootURL ) throws Throwable
|
||||
{
|
||||
state = DOWNLOADING;
|
||||
|
||||
// * download the ".jar" for each ISP
|
||||
for ( int i = 0; i < ispList.size(); i++ )
|
||||
{
|
||||
@ -627,7 +634,7 @@ public class CPGenerator
|
||||
|
||||
String ispLocalFileName = getJarFilePath( ispData );
|
||||
|
||||
currentFile = new String( ispData.name );
|
||||
currentFile = new String( ispData.getName() );
|
||||
|
||||
Trace.TRACE( "downloading: " + zipFileURL );
|
||||
ServerDownload.downloadURL( zipFileURL, ispLocalFileName );
|
||||
@ -636,6 +643,8 @@ public class CPGenerator
|
||||
|
||||
private static void decompressJarFiles( Vector ispList ) throws Throwable
|
||||
{
|
||||
state = UNJARRING;
|
||||
|
||||
// * decompress the ".jar" for each ISP
|
||||
for ( int i = 0; i < ispList.size(); i++ )
|
||||
{
|
||||
@ -681,7 +690,7 @@ public class CPGenerator
|
||||
nvSet.setValue( ispDirectorySymbol, new String( ispData.language + "/" + ispData.name + "/client_data" ) );
|
||||
parseFeatureSet( nvSet, featureMappings );
|
||||
returnSets.addElement( nvSet );
|
||||
//nvSet.printNameValueSet();
|
||||
//nvSet.printNameValueSet();
|
||||
}
|
||||
return returnSets;
|
||||
}
|
||||
@ -690,7 +699,8 @@ public class CPGenerator
|
||||
String sRootURL, String metadataMode, String reggieData[] )
|
||||
{
|
||||
done = false;
|
||||
|
||||
state = IDLE;
|
||||
|
||||
Trace.TRACE( "Hello" );
|
||||
|
||||
NameValueSet featureMappings = null;
|
||||
@ -698,6 +708,10 @@ public class CPGenerator
|
||||
|
||||
localPath = new String( inLocalPath );
|
||||
|
||||
|
||||
ServerDownload.resetBytesDownloaded();
|
||||
ServerDownload.resetBytesUnjarred();
|
||||
|
||||
try
|
||||
{
|
||||
//if ( progress == null )
|
||||
@ -713,12 +727,7 @@ public class CPGenerator
|
||||
if ( metadataMode.toLowerCase().compareTo( "no" ) != 0 )
|
||||
downloadAndUnzipMetadata( sRootURL );
|
||||
|
||||
ServerDownload.resetBytesDownloaded();
|
||||
|
||||
downloadJarFiles( ispList, sRootURL );
|
||||
|
||||
ServerDownload.resetBytesDownloaded();
|
||||
|
||||
decompressJarFiles( ispList );
|
||||
|
||||
//Trace.TRACE( "features.cfg settings: " );
|
||||
@ -754,55 +763,51 @@ public class CPGenerator
|
||||
bufferedReader.close();
|
||||
|
||||
done = true;
|
||||
Thread.yield();
|
||||
result = true;
|
||||
state = IDLE;
|
||||
//System.in.read(); // prevent console window from going away
|
||||
}
|
||||
|
||||
catch ( MalformedURLException e )
|
||||
{
|
||||
done = true;
|
||||
result = false;
|
||||
Trace.TRACE( e.getMessage() );
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch ( ConnectException e )
|
||||
{
|
||||
done = true;
|
||||
result = false;
|
||||
Trace.TRACE( e.getMessage() );
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch ( UnknownHostException e )
|
||||
{
|
||||
done = true;
|
||||
result = false;
|
||||
Trace.TRACE( e.getMessage() );
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch ( FileNotFoundException e )
|
||||
{
|
||||
done = true;
|
||||
result = false;
|
||||
Trace.TRACE( e.getMessage() );
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
done = true;
|
||||
result = false;
|
||||
Trace.TRACE( e.getMessage() );
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch ( Throwable e )
|
||||
{
|
||||
done = true;
|
||||
result = false;
|
||||
Trace.TRACE( "caught an exception" );
|
||||
Trace.TRACE( e.getMessage() );
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
finally
|
||||
{
|
||||
done = true;
|
||||
state = IDLE;
|
||||
}
|
||||
|
||||
Trace.TRACE( "returning result: " + result );
|
||||
done = false;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -42,23 +42,25 @@ class UnjarException extends Exception
|
||||
public class ServerDownload
|
||||
{
|
||||
public static final boolean SLEEP = false;
|
||||
public static final int IDLE = 0;
|
||||
public static final int DOWNLOADING = 1;
|
||||
public static final int UNJARRING = 2;
|
||||
|
||||
static int state = IDLE;
|
||||
static int bytesDownloaded = 0;
|
||||
|
||||
public static int getState()
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
static int bytesUnjarred = 0;
|
||||
|
||||
public static int getBytesDownloaded()
|
||||
{
|
||||
return bytesDownloaded;
|
||||
}
|
||||
|
||||
|
||||
public static int getBytesUnjarred()
|
||||
{
|
||||
return bytesUnjarred;
|
||||
}
|
||||
|
||||
public static void resetBytesUnjarred()
|
||||
{
|
||||
bytesUnjarred = 0;
|
||||
}
|
||||
|
||||
public static void resetBytesDownloaded()
|
||||
{
|
||||
bytesDownloaded = 0;
|
||||
@ -106,8 +108,6 @@ public class ServerDownload
|
||||
public static boolean unjarURL( String sURL, String sLocalFolder, boolean bDelTempFile )
|
||||
throws Exception
|
||||
{
|
||||
state = IDLE;
|
||||
|
||||
boolean bResult = false;
|
||||
|
||||
// * downloaded file name: append filename to provided local folder
|
||||
@ -156,8 +156,6 @@ public class ServerDownload
|
||||
|
||||
//Trace.TRACE( "downloading " + sURL );
|
||||
|
||||
state = ServerDownload.DOWNLOADING;
|
||||
|
||||
urlSrc = new URL( sURL );
|
||||
|
||||
// This is a really gross fix to a stupid little problem:
|
||||
@ -220,7 +218,6 @@ public class ServerDownload
|
||||
|
||||
bResult = true;
|
||||
|
||||
state = IDLE;
|
||||
return bResult;
|
||||
}
|
||||
|
||||
@ -234,8 +231,6 @@ public class ServerDownload
|
||||
public static boolean unJarFile( String sCompFile, boolean bDeleteJarFile )
|
||||
throws Exception
|
||||
{
|
||||
state = UNJARRING;
|
||||
|
||||
boolean bResult = false;
|
||||
final int nBuffSize = 500;
|
||||
|
||||
@ -284,7 +279,7 @@ public class ServerDownload
|
||||
fileout = new FileOutputStream( zEntryFile.getPath() );
|
||||
while ( ( nBytesRead = inflaterin.read( buffer, 0, nBuffSize ) ) != -1 )
|
||||
{
|
||||
bytesDownloaded += nBytesRead;
|
||||
bytesUnjarred += nBytesRead;
|
||||
fileout.write( buffer, 0, nBytesRead );
|
||||
|
||||
if ( SLEEP )
|
||||
@ -314,7 +309,6 @@ public class ServerDownload
|
||||
inflaterin.close();
|
||||
}
|
||||
|
||||
state = IDLE;
|
||||
return bResult;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user