// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Clock.java

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.PrintStream;

class Clock extends Thread
{
    class GraphicalClock extends Canvas
    {

        private String fill(long l)
        {
            return (l >= 10L ? "" : "0") + l;
        }

        private String time()
        {
            long l;
            return (l >= 10L ? "" : "0") + l + ":" + (((l = seconds % 60L) >= 10L ? "" : "0") + l);
        }

        public void paint(Graphics g)
        {
            FontMetrics fontmetrics = g.getFontMetrics();
            char ac[] = {
                '8', '8', ':', '8', '8'
            };
            height = 10 + fontmetrics.getAscent();
            width = 10 + fontmetrics.charsWidth(ac, 0, 5);
            if(master.timing())
            {
                g.setColor(new Color(200, 200, 200));
                g.fillRect(0, 0, getBounds().width, getBounds().height);
                g.setColor(Color.black);
                long l;
                g.drawString(((l = seconds / 60L) >= 10L ? "" : "0") + l + ":" + (((l = seconds % 60L) >= 10L ? "" : "0") + l), 5, (fontmetrics.getAscent() - 1) + 5);
                g.drawRect(0, 0, width, height);
            }
        }

        void incrementSecond()
        {
            seconds++;
            repaint();
        }

        void decrementSecond()
        {
            seconds--;
            repaint();
        }

        void setAlarm(long l)
        {
            seconds = l;
            repaint();
        }

        long seconds;
        Clock master;
        Container where;
        int width;
        int height;

        GraphicalClock(Clock clock1, Container container, Rectangle rectangle)
        {
            setBounds(rectangle);
            master = clock1;
            where = container;
        }
    }


    public boolean timing()
    {
        return timing;
    }

    Clock(Container container, Rectangle rectangle)
    {
        timing = false;
        toolkit = Toolkit.getDefaultToolkit();
        eventQueue = toolkit.getSystemEventQueue();
        gClock = new GraphicalClock(this, container, rectangle);
        start();
    }

    Clock(Container container, Rectangle rectangle, ActionListener actionlistener)
    {
        timing = false;
        toolkit = Toolkit.getDefaultToolkit();
        eventQueue = toolkit.getSystemEventQueue();
        gClock = new GraphicalClock(this, container, rectangle);
        addActionListener(actionlistener);
        start();
    }

    public void addActionListener(ActionListener actionlistener)
    {
        al = actionlistener;
    }

    public void clear()
    {
        if(!timing)
        {
            System.out.println("ERROR -- Clock stopped when not timing.");
            return;
        } else
        {
            timing = false;
            gClock.setAlarm(0L);
            alarm = 0L;
            return;
        }
    }

    public void run()
    {
        setPriority(1);
        do
        {
            for(int i = 0; (long)i < 0x93a80L; i++)
            {
                for(int j = 0; (long)j < 0x15180L; j++)
                {
                    for(int k = 0; (long)k < 3600L; k++)
                    {
                        for(int l = 0; (long)l < 60L; l++)
                        {
                            for(int i1 = 0; (long)i1 < 1L; i1++)
                            {
                                if(timing && alarm == 0L)
                                {
                                    timing = false;
                                    al.actionPerformed(new ActionEvent(this, 2005, "time"));
                                }
                                try
                                {
                                    Thread.sleep(1000L);
                                }
                                catch(Exception _ex) { }
                                gClock.decrementSecond();
                                if(timing)
                                    alarm--;
                            }

                            al.actionPerformed(new ActionEvent(this, 2000, "time"));
                        }

                        al.actionPerformed(new ActionEvent(this, 2001, "time"));
                    }

                    al.actionPerformed(new ActionEvent(this, 2002, "time"));
                }

                al.actionPerformed(new ActionEvent(this, 2003, "time"));
            }

            al.actionPerformed(new ActionEvent(this, 2004, "time"));
        } while(true);
    }

    public void setAlarm(long l)
    {
        if(timing)
        {
            System.out.println("ERROR -- Alarm set when already timing.");
            return;
        } else
        {
            alarm = l;
            gClock.setAlarm(l);
            timing = true;
            return;
        }
    }

    ActionListener al;
    private boolean badalarm;
    private boolean timing;
    Toolkit toolkit;
    EventQueue eventQueue;
    private final long second = 1L;
    private final long minute = 60L;
    private final long hour = 3600L;
    private final long day = 0x15180L;
    private final long week = 0x93a80L;
    public static final int SECOND_EVENT = 2000;
    public static final int MINUTE_EVENT = 2001;
    public static final int HOUR_EVENT = 2002;
    public static final int DAY_EVENT = 2003;
    public static final int WEEK_EVENT = 2004;
    private long alarm;
    public static final int ALARM_EVENT = 2005;
    GraphicalClock gClock;
}
