1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package graphical;
25 
26 import java.util.Calendar;
27 
28 /**
29  *
30  * @author ll93751
31  */
32 public class TimeHelper
33 {
34     /*
35       wait a second the caller don't need to handle the interruptexception
36       @param _nSeconds how long should we wait
37       @param _sReason  give a good reason, why we have to wait
38      */
waitInSeconds(int _nSeconds, String _sReason)39     static void waitInSeconds(int _nSeconds, String _sReason)
40         {
41             GlobalLogWriter.println("Wait 0.25 * " + String.valueOf(_nSeconds) + " sec. Reason: " + _sReason);
42             try {
43                 java.lang.Thread.sleep(_nSeconds * 250);
44             } catch (java.lang.InterruptedException e2) {}
45         }
46 
47     private int m_nSeconds;
48     private int m_nMilliSeconds;
49     private long m_nRealMilliSeconds;
50 
51     private boolean m_bIsStopped = false;
52 
TimeHelper()53     public TimeHelper()
54     {}
55 
start()56     public void start()
57         {
58             m_bIsStopped = false;
59             Calendar cal = Calendar.getInstance();
60             m_nSeconds = cal.get(Calendar.SECOND);
61             m_nMilliSeconds = cal.get(Calendar.MILLISECOND);
62         }
stop()63     public void stop()
64         {
65             Calendar cal = Calendar.getInstance();
66             m_bIsStopped = true;
67             int nSeconds = cal.get(Calendar.SECOND);
68             m_nSeconds = nSeconds - m_nSeconds;
69             if (m_nSeconds < 0)
70             {
71                 // add a minute
72                 m_nSeconds += 60;
73             }
74 
75             int nMilliSeconds = cal.get(Calendar.MILLISECOND);
76             m_nMilliSeconds = nMilliSeconds - m_nMilliSeconds;
77             m_nRealMilliSeconds = m_nSeconds * 1000 + m_nMilliSeconds;
78         }
79 
getTime()80     public String getTime()
81         {
82             return String.valueOf(m_nRealMilliSeconds);
83         }
84 
85 }
86