VmsFormManager.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package com.its.vms.domain;
  2. import lombok.Data;
  3. import java.io.Serializable;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. /**
  7. * DTO Class
  8. */
  9. @Data
  10. public class VmsFormManager implements Serializable {
  11. private static final long serialVersionUID = 1L;
  12. private int formWidth;
  13. private int formHeight;
  14. private int totalCount;
  15. private int objectCount;
  16. private List<VmsForm> objects;
  17. public VmsFormManager(int formWidth, int formHeight) {
  18. this.formWidth = formWidth;
  19. this.formHeight = formHeight;
  20. this.totalCount = 0;
  21. this.objectCount = 0;
  22. this.objects = new ArrayList<>();
  23. }
  24. public void clear() {
  25. this.objectCount = 0;
  26. this.objects.forEach(obj -> {
  27. obj.clear();
  28. });
  29. }
  30. public VmsForm getItem(int idx) {
  31. if (this.objects.size() > idx) {
  32. return this.objects.get(idx);
  33. }
  34. return null;
  35. }
  36. public int addForm(VmsForm form) {
  37. this.objects.add(form);
  38. this.objectCount = this.objects.size();
  39. return this.objectCount;
  40. }
  41. public VmsForm addForm() {
  42. VmsForm form = null;
  43. if (this.objectCount < this.totalCount) {
  44. form = getItem(this.objectCount);
  45. }
  46. else {
  47. form = new VmsForm();
  48. form.init(this.formWidth, this.formHeight);
  49. this.objects.add(form);
  50. this.totalCount++;
  51. }
  52. this.objectCount++;
  53. return form;
  54. }
  55. public int count() { return this.objectCount; }
  56. public int total() { return this.totalCount; }
  57. }