StatsController.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package ui.controller;
  2. import java.util.ArrayList;
  3. import classes.AbstractCanvasObject;
  4. import classes.TrackedDataSet;
  5. import ui.model.Model;
  6. import ui.view.StatisticGraphPanel;
  7. public class StatsController {
  8. private Model model;
  9. public StatsController(Model mod) {
  10. this.model = mod;
  11. }
  12. public void setTrackingObj(ArrayList<AbstractCanvasObject> objArr) {
  13. model.setTrackingObj(objArr);
  14. }
  15. public ArrayList<AbstractCanvasObject> getTrackingObj() {
  16. return model.getTrackingObj();
  17. }
  18. public void addTrackingObj(AbstractCanvasObject obj) {
  19. model.getTrackingObj().add(obj);
  20. model.addObjectsToGraphListeners();
  21. }
  22. public void removeTrackingObj(AbstractCanvasObject obj) {
  23. ArrayList<AbstractCanvasObject> objArr = model.getTrackingObj();
  24. objArr.remove(obj);
  25. model.setTrackingObj(objArr);
  26. model.addObjectsToGraphListeners();
  27. //Remove the Object from the graph and the LegendPanel
  28. for (StatisticGraphPanel sg : model.getGraphTable().values()) {
  29. ArrayList<Integer> indexList = new ArrayList<>();
  30. for (TrackedDataSet set: sg.getStatGraph().getDataSets()) {
  31. if (obj == set.getCpsObject()) {
  32. indexList.add(sg.getStatGraph().getDataSets().indexOf(set));
  33. }
  34. }
  35. for (int i = indexList.size()-1; i >= 0; i--) {
  36. sg.getLegendPanel().remove(sg.getLegendPanel().getComponent(indexList.get(i)));
  37. sg.getStatGraph().removeObject(indexList.get(i));
  38. sg.updateUI();
  39. }
  40. }
  41. }
  42. }