View Javadoc

1   /*
2    * This file is part of NetPisteur.
3    * 
4    * Copyright 2001-2002 : Olivier CORNEC, David BOUANCHEAU, Loic LOPEZ,
5    *                       Gaetan BOUDARD, Mael LE LANNOU, Julien ROBINEAU
6    * 
7    * Copyright 2002-2003 : Olivier BRIENS, Simon DEZE, Florence FRIGOULT,
8    *                       Olivier JOURNEAULT, Francois MARTINIER, Damien RAUDE-MORVAN
9    * 
10   * Copyright 2004-2007 : Damien RAUDE-MORVAN
11   * 
12   * NetPisteur is free software; you can redistribute it and/or modify
13   * it under the terms of the GNU General Public License as published by
14   * the Free Software Foundation; either version 2 of the License, or
15   * (at your option) any later version.
16   *
17   * NetPisteur is distributed in the hope that it will be useful,
18   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20   * GNU General Public License for more details.
21   *
22   * You should have received a copy of the GNU General Public License
23   * along with NetPisteur; if not, write to the Free Software
24   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
25   *
26   */
27  package com.drazzib.netpisteur.ui;
28  
29  import java.awt.event.ActionEvent;
30  import java.awt.event.ActionListener;
31  
32  /**
33   * Create a clock that count or decount time
34   * 
35   * @author NetPisteur team
36   */
37  public class Clock implements ActionListener {
38  
39  	// attributes
40  	private int sec, min, heure;
41  
42  	private String secToString, minToString, heureToString;
43  
44  	private boolean decomptage;
45  
46  	private MainFrame window;
47  
48  	// constructor
49  
50  	/**
51  	 * Create an Horloge on a mainWindow that count time
52  	 * 
53  	 * @param main :
54  	 *            the window where the clock is applicated
55  	 */
56  	public Clock(MainFrame main) {
57  		this.sec = 0;
58  		this.min = 0;
59  		this.heure = 0;
60  		this.decomptage = false;
61  		this.window = main;
62  	} // Horloge()
63  
64  	/**
65  	 * Create an Horloge on a mainWindow that decount time
66  	 * 
67  	 * @param ss :
68  	 *            seconds that will be decounted
69  	 * @param mm :
70  	 *            minutes that will be decounted
71  	 * @param hh :
72  	 *            hours that will be decounted
73  	 * @param main :
74  	 *            the window where the clock is applicated
75  	 */
76  	public Clock(int ss, int mm, int hh, MainFrame main) {
77  		this.sec = ss;
78  		this.min = mm;
79  		this.heure = hh;
80  		this.decomptage = true;
81  		this.window = main;
82  	} // Horloge()
83  
84  	/**
85  	 * Functionning of the Horloge
86  	 */
87  	public void actionPerformed(ActionEvent event) {
88  
89  		if (this.decomptage == false) {
90  			this.sec++;
91  
92  			if (this.sec == 60) {
93  				this.sec = 0;
94  				this.min++;
95  			}
96  			if (this.min == 60) {
97  				this.min = 0;
98  				this.heure++;
99  			}
100 			if (this.sec > -1 && this.sec < 10) {
101 				this.secToString = "0" + this.sec; //$NON-NLS-1$
102 			} else {
103 				this.secToString = Integer.toString(this.sec);
104 			}
105 			if (this.min > -1 && this.min < 10) {
106 				this.minToString = "0" + this.min; //$NON-NLS-1$
107 			} else {
108 				this.minToString = Integer.toString(this.min);
109 			}
110 			if (this.heure > -1 && this.heure < 10) {
111 				this.heureToString = "0" + this.heure; //$NON-NLS-1$
112 			} else {
113 				this.heureToString = Integer.toString(this.heure);
114 			}
115 			this.window.setDuree(this.heureToString
116 					+ ":" + this.minToString + ":" //$NON-NLS-1$ //$NON-NLS-2$
117 					+ this.secToString);
118 		} else {
119 			this.sec--;
120 
121 			if (this.sec == -1) {
122 				this.sec = 59;
123 				this.min--;
124 			}
125 			if (this.min == -1) {
126 				this.min = 59;
127 				this.heure--;
128 			}
129 			if (this.sec == 0 && this.min == 0 && this.heure == 0) {
130 				this.window.saveDatas();
131 			}
132 			if (this.sec > -1 && this.sec < 10) {
133 				this.secToString = "0" + this.sec; //$NON-NLS-1$
134 			} else {
135 				this.secToString = Integer.toString(this.sec);
136 			}
137 			if (this.min > -1 && this.min < 10) {
138 				this.minToString = "0" + this.min; //$NON-NLS-1$
139 			} else {
140 				this.minToString = Integer.toString(this.min);
141 			}
142 			if (this.heure > -1 && this.heure < 10) {
143 				this.heureToString = "0" + this.heure; //$NON-NLS-1$
144 			} else {
145 				this.heureToString = Integer.toString(this.heure);
146 			}
147 			this.window.setDuree(this.heureToString
148 					+ ":" + this.minToString + ":" //$NON-NLS-1$//$NON-NLS-2$
149 					+ this.secToString);
150 		}
151 	}// fin actionPerformed
152 
153 }// class Horloge
154