Coverage Report - com.timjohnstondev.timer.TimerApplication
 
Classes in this File Line Coverage Branch Coverage Complexity
TimerApplication
66%
16/24
N/A
1.286
TimerApplication$1
0%
0/5
N/A
1.286
TimerApplication$TimerAction
16%
1/6
0%
0/4
1.286
 
 1  
 package com.timjohnstondev.timer;
 2  
 
 3  
 import java.awt.Dimension;
 4  
 import java.awt.Image;
 5  
 import java.awt.Window;
 6  
 import java.awt.event.ActionEvent;
 7  
 import java.awt.event.ActionListener;
 8  
 import java.net.URL;
 9  
 import javax.swing.BoxLayout;
 10  
 import javax.swing.ImageIcon;
 11  
 import javax.swing.JFrame;
 12  
 import javax.swing.SwingUtilities;
 13  
 import javax.swing.Timer;
 14  
 import com.sun.awt.AWTUtilities;
 15  
 
 16  0
 public class TimerApplication extends JFrame
 17  
 {
 18  
   private static final String TIMER_TITLE = "   Timer   ";
 19  
   private static Window window;
 20  2
   private final CountDownPanel countDownPanel = new CountDownPanel();
 21  2
   private final TopPanel topPanel = new TopPanel(countDownPanel);
 22  2
   private final Timer displayUpdater = new Timer(1000, new TimerAction());
 23  
 
 24  
   public TimerApplication()
 25  
   {
 26  2
     super(TIMER_TITLE);
 27  2
     setSize(new Dimension(280, 140));
 28  2
     setLocationRelativeTo(null);
 29  2
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 30  2
     setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
 31  2
     setResizable(false);
 32  
 
 33  2
     add(topPanel);
 34  2
     add(countDownPanel);
 35  2
     setAlwaysOnTop(true);
 36  2
     setIconImage(getImage());
 37  2
   }
 38  
 
 39  
   public static void main(final String[] args)
 40  
   {
 41  0
     SwingUtilities.invokeLater(new Runnable()
 42  0
     {
 43  
       @Override
 44  
       public void run()
 45  
       {
 46  0
         window = new TimerApplication();
 47  0
         window.setVisible(true);
 48  0
         AWTUtilities.setWindowOpacity(window, 0.7f);
 49  0
       }
 50  
     });
 51  0
   }
 52  
 
 53  
   public final void startDispayTimer()
 54  
   {
 55  0
     displayUpdater.start();
 56  0
   }
 57  
 
 58  
   public final void stopDispayTimer()
 59  
   {
 60  0
     new TimerAction();
 61  0
     displayUpdater.stop();
 62  0
   }
 63  
 
 64  2
   public class TimerAction implements ActionListener
 65  
   {
 66  
     public final void actionPerformed(final ActionEvent ae)
 67  
     {
 68  0
       if (countDownPanel.getRemainingSeconds() == 0)
 69  
       {
 70  0
         final int newValue = topPanel.getSliderValue() > 50 ? 0 : 100;
 71  0
         topPanel.setSliderValue(newValue);
 72  
       }
 73  0
       countDownPanel.updateRemainingTimeDisplay();
 74  0
     }
 75  
   }
 76  
 
 77  
   private Image getImage()
 78  
   {
 79  
 
 80  2
     final URL imgURL = getClass().getResource("images/T-96x96.png");
 81  2
     return new ImageIcon(imgURL).getImage();
 82  
   }
 83  
 }