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