You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EierUhrController.java 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package EierUhrKomponente;
  7. import java.util.concurrent.CopyOnWriteArrayList;
  8. import java.util.concurrent.Flow;
  9. import java.util.concurrent.Flow.Subscriber;
  10. import java.util.logging.Logger;
  11. import ohmlogger.OhmLogger;
  12. /**
  13. *
  14. * @author chris
  15. */
  16. public class EierUhrController implements Flow.Subscriber<Integer>
  17. {
  18. private EierUhrView view;
  19. private EierUhrModel model;
  20. private EierUhr eierUhr;
  21. private Flow.Subscription sub;
  22. private static Logger lg = OhmLogger.getLogger();
  23. public EierUhrController(EierUhrView view, EierUhrModel model, EierUhr eierUhr)
  24. {
  25. this.view = view;
  26. this.model = model;
  27. this.eierUhr = eierUhr;
  28. addSubscription();
  29. }
  30. public void setZahl(int zahl)
  31. {
  32. view.setZahl(zahl);
  33. }
  34. public int getZahl()
  35. {
  36. return view.getZahl();
  37. }
  38. public void start(int zahl)
  39. {
  40. lg.info("Controller Start");
  41. model.initZahl(zahl);
  42. }
  43. private void addSubscription()
  44. {
  45. model.addSubscription(this);
  46. }
  47. @Override
  48. public void onSubscribe(Flow.Subscription subscription)
  49. {
  50. this.sub = subscription;
  51. sub.request(1);
  52. }
  53. @Override
  54. public void onNext(Integer item)
  55. {
  56. int zahl = view.getZahl();
  57. sub.request(1);
  58. view.setZahl(item);
  59. eierUhr.firePropertyChange("zahl", zahl, view.getZahl());
  60. if(item == 0)
  61. {
  62. eierUhr.fireEierUhrEvent(new EierUhrEvent(this));
  63. }
  64. }
  65. @Override
  66. public void onError(Throwable thrwbl)
  67. {
  68. }
  69. @Override
  70. public void onComplete()
  71. {
  72. }
  73. }