PageRenderTime 38ms CodeModel.GetById 31ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/org/mt4j/components/visibleComponents/widgets/progressBar/SampleProgressProv.java

http://mt4j.googlecode.com/
Java | 78 lines | 22 code | 11 blank | 45 comment | 1 complexity | a5ca7864266541344aaa411d91aedc0b MD5 | raw file
 1/***********************************************************************
 2 * mt4j Copyright (c) 2008 - 2009, C.Ruff, Fraunhofer-Gesellschaft All rights reserved.
 3 *  
 4 *   This program is free software: you can redistribute it and/or modify
 5 *   it under the terms of the GNU General Public License as published by
 6 *   the Free Software Foundation, either version 3 of the License, or
 7 *   (at your option) any later version.
 8 *
 9 *   This program is distributed in the hope that it will be useful,
10 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *   GNU General Public License for more details.
13 *
14 *   You should have received a copy of the GNU General Public License
15 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 *
17 ***********************************************************************/
18package org.mt4j.components.visibleComponents.widgets.progressBar;
19
20
21
22/**
23 * The Class SampleProgressProv.
24 */
25public class SampleProgressProv extends AbstractProgressThread implements Runnable{
26
27	/**
28	 * Instantiates a new sample progress prov.
29	 * 
30	 * @param sleepTime the sleep time
31	 */
32	public SampleProgressProv(int sleepTime) {
33		super(sleepTime);
34		
35		this.setTarget(10);
36	}
37
38	/**
39	 * Run thread loop.
40	 * 
41	 * @return true, if successful
42	 */
43	private boolean runThreadLoop(){
44		return (this.getCurrent() < this.getTarget());
45	}
46	
47	/* (non-Javadoc)
48	 * @see com.jMT.components.visibleComponents.progressBar.AbstractProgressThread#run()
49	 */
50	@Override
51	public void run() {
52		while (runThreadLoop()){
53			try {
54				//SleepTime is the amount of time the thread waits 
55				//_at least_ to give other threads a chance to execute
56				//smaller sleepTime -> thread runs faster, but other threads slower
57				Thread.sleep(this.getSleepTime()); 
58			} catch (InterruptedException e) {
59				e.printStackTrace();
60			}
61			
62			//DO ONE ITERATION OF THE THREADS WORK
63		    /*
64				synchronized(das object auf das mehrere threads zugreifen wollen){
65					mache änderungen am object;
66				}
67				//TODO wie funktioniert das mit notifyAll() und wait?
68		     */
69			this.setCurrent(this.getCurrent()+1);
70			
71//			System.out.println(this.getName() + ": " + current);
72		}
73		
74		this.setFinished(true); //richtig?
75//		System.out.println(this.getName() + " thread exiting.");
76	}
77
78}