/*
 * 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dblpconverter;

/**
 * @author Gersk
 * 
 * Temporized is a timer of the conversion process.
 */

import javax.swing.*;    

public class Temporized extends JTextField implements Runnable
{

    private Window window;
    private boolean stop;
    private int seconds, minutes, hours;
    private String secondsStr = "", minutesStr = "", hoursStr = "";
   
    public Temporized(Window window)
    {
        
        this.window = window;
        this.setText("00:00:00");
        this.setEditable(false);
    }

    public void run()
    {
        this.setText("00:00:00");
        
        seconds = 0; 
        minutes = 0; 
        hours = 0;
        stop = false;
        while(!stop)
        {
            seconds++;
            try {
                Thread.sleep(1000);
            } catch(InterruptedException e) {
                window.append("Error in timer thread: " + e);
            }

            if(seconds == 60)
            {
                minutes++;
                seconds = 0;
            }
            if(minutes == 60) 
            {
                hours++;
                minutes = 0;
            }    
            
            if(seconds < 10)
                secondsStr = "0" + Integer.toString(seconds);
            else
                secondsStr = Integer.toString(seconds);
            if(minutes < 10)
                minutesStr = "0" + Integer.toString(minutes);
            else
                minutesStr = Integer.toString(minutes);
            if(hours < 10)
                hoursStr = "0" + Integer.toString(hours);
            else
                hoursStr = Integer.toString(hours);
            
            this.setText(hoursStr + ":" + minutesStr + ":" + secondsStr); 
        }
    }
    public String getHours()
    {
        return hoursStr;
    }
    
    public String getMinutes()
    {
        return minutesStr;
    }
    
    public String getSeconds()
    {
        return secondsStr;
    }
    
    public void stop() 
    {
        stop = true;
    }
    
}
