1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
void UpdateProgressBar()
{
Thread oUpdateThread = new Thread()
{
public void run()
{
FTPManager oFTP = new FTPManager();
// While the instance is existing
long iSize = new File(m_oNewMovie.GetLocalPath()).length();
while(m_oNewMovie.GetState() != StateMovie.ID_STATE_OK && m_oNewMovie.GetState() != StateMovie.ID_STATE_INVALID && m_oNewMovie.GetState() != StateMovie.ID_STATE_ERROR && m_oNewMovie.GetState() != StateMovie.ID_STATE_ABORD)
{
if(m_oNewMovie.GetState() == StateMovie.ID_STATE_RUNNING || m_oNewMovie.GetState() == StateMovie.ID_STATE_RETRY)
{
long iCurrentSize = 0;
try
{
iCurrentSize = oFTP.FTPGetFileSize(m_oNewMovie);
if(iCurrentSize > 0)
{
float iValue = (float)iCurrentSize/iSize;
m_oDataLoad.setValue((int)(iValue * 1000));
m_oDataLoad.setString((int)(iValue * 100) + " %");
m_oDataLoad.validate();
m_oDataLoad.repaint();
}
}
catch (IOException e)
{
System.out.println("FTP : Impossible d'obtenir la taille");
}
}
}
// To be sure the last "list" stop the progresbar at 99%
if(m_oNewMovie.GetState() == StateMovie.ID_STATE_OK)
{
m_oDataLoad.setValue(1000);
m_oDataLoad.setString("100 %");
}
if(m_oNewMovie.GetState() == StateMovie.ID_STATE_ABORD)
{
try {
oFTP.FTPDisconnect();
} catch (IOException e) {
System.out.println("dÈco : "+e);
}
}
}
};
// Set the Thread as deamon
oUpdateThread.setDaemon(true);
// and go!
oUpdateThread.setPriority(Thread.MAX_PRIORITY);
oUpdateThread.start();
} |
Partager