AutoSaveController.java 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package ui.controller;
  2. import ui.model.Model;
  3. /**
  4. * Autosave Controller.
  5. *
  6. * @author Gruppe14
  7. */
  8. public class AutoSaveController {
  9. private Model model;
  10. private int max = Integer.MAX_VALUE;
  11. private int numberOfSaves = 20;
  12. private int currentSave;
  13. private int count = 0;
  14. private boolean isAllowed = false;
  15. /**
  16. * Constructor.
  17. *
  18. * @param model
  19. * the Model
  20. */
  21. public AutoSaveController(Model model) {
  22. this.model = model;
  23. }
  24. /**
  25. * Increase the Auto save number.
  26. */
  27. public void increaseAutoSaveNr() {
  28. currentSave = model.getAutoSaveNr() + 1;
  29. if (count < currentSave) {
  30. count = currentSave;
  31. }
  32. if (numberOfSaves == count) {
  33. isAllowed = true;
  34. }
  35. if (currentSave > max) {
  36. currentSave = 0;
  37. }
  38. model.setAutoSaveNr(currentSave);
  39. }
  40. /**
  41. * Decrease the Autosave Number.
  42. */
  43. public void decreaseAutoSaveNr() {
  44. currentSave = model.getAutoSaveNr() - 1;
  45. // if (currentSave < 0) {
  46. // currentSave = max;
  47. // }
  48. model.setAutoSaveNr(currentSave);
  49. }
  50. /**
  51. * Return the Autosave Number.
  52. *
  53. * @return Autosave Number
  54. */
  55. public int getAutoSaveNr() {
  56. return model.getAutoSaveNr();
  57. }
  58. /**
  59. * Return isAllowed.
  60. *
  61. * @return isAllowed
  62. */
  63. public boolean allowed() {
  64. return isAllowed;
  65. }
  66. }