/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. ***********************************************************************/
  18. package org.mt4j.components.visibleComponents.widgets.progressBar;
  19. /**
  20. * The Class SampleProgressProv.
  21. */
  22. public class SampleProgressProv extends AbstractProgressThread implements Runnable{
  23. /**
  24. * Instantiates a new sample progress prov.
  25. *
  26. * @param sleepTime the sleep time
  27. */
  28. public SampleProgressProv(int sleepTime) {
  29. super(sleepTime);
  30. this.setTarget(10);
  31. }
  32. /**
  33. * Run thread loop.
  34. *
  35. * @return true, if successful
  36. */
  37. private boolean runThreadLoop(){
  38. return (this.getCurrent() < this.getTarget());
  39. }
  40. /* (non-Javadoc)
  41. * @see com.jMT.components.visibleComponents.progressBar.AbstractProgressThread#run()
  42. */
  43. @Override
  44. public void run() {
  45. while (runThreadLoop()){
  46. try {
  47. //SleepTime is the amount of time the thread waits
  48. //_at least_ to give other threads a chance to execute
  49. //smaller sleepTime -> thread runs faster, but other threads slower
  50. Thread.sleep(this.getSleepTime());
  51. } catch (InterruptedException e) {
  52. e.printStackTrace();
  53. }
  54. //DO ONE ITERATION OF THE THREADS WORK
  55. /*
  56. synchronized(das object auf das mehrere threads zugreifen wollen){
  57. mache änderungen am object;
  58. }
  59. //TODO wie funktioniert das mit notifyAll() und wait?
  60. */
  61. this.setCurrent(this.getCurrent()+1);
  62. // System.out.println(this.getName() + ": " + current);
  63. }
  64. this.setFinished(true); //richtig?
  65. // System.out.println(this.getName() + " thread exiting.");
  66. }
  67. }