1 /*
2  * ************************************************************************
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org.  If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  * ***********************************************************************
28  */
29 
30 package graphical;
31 
32 import java.util.Calendar;
33 
34 /**
35  *
36  * @author ll93751
37  */
38 public class TimeHelper
39 {
40     /*
41       wait a second the caller don't need to handle the interruptexception
42       @param _nSeconds how long should we wait
43       @param _sReason  give a good reason, why we have to wait
44      */
45     static void waitInSeconds(int _nSeconds, String _sReason)
46         {
47             GlobalLogWriter.println("Wait 0.25 * " + String.valueOf(_nSeconds) + " sec. Reason: " + _sReason);
48             try {
49                 java.lang.Thread.sleep(_nSeconds * 250);
50             } catch (java.lang.InterruptedException e2) {}
51         }
52 
53     private int m_nSeconds;
54     private int m_nMilliSeconds;
55     private long m_nRealMilliSeconds;
56 
57     private boolean m_bIsStopped = false;
58 
59     public TimeHelper()
60     {}
61 
62     public void start()
63         {
64             m_bIsStopped = false;
65             Calendar cal = Calendar.getInstance();
66             m_nSeconds = cal.get(Calendar.SECOND);
67             m_nMilliSeconds = cal.get(Calendar.MILLISECOND);
68         }
69     public void stop()
70         {
71             Calendar cal = Calendar.getInstance();
72             m_bIsStopped = true;
73             int nSeconds = cal.get(Calendar.SECOND);
74             m_nSeconds = nSeconds - m_nSeconds;
75             if (m_nSeconds < 0)
76             {
77                 // add a minute
78                 m_nSeconds += 60;
79             }
80 
81             int nMilliSeconds = cal.get(Calendar.MILLISECOND);
82             m_nMilliSeconds = nMilliSeconds - m_nMilliSeconds;
83             m_nRealMilliSeconds = m_nSeconds * 1000 + m_nMilliSeconds;
84         }
85 
86     public String getTime()
87         {
88             return String.valueOf(m_nRealMilliSeconds);
89         }
90 
91 }
92