1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package ui.controller;
- import java.util.ArrayList;
- import classes.AbstractCanvasObject;
- import classes.TrackedDataSet;
- import ui.model.Model;
- import ui.view.StatisticGraphPanel;
- public class StatsController {
- private Model model;
- public StatsController(Model mod) {
- this.model = mod;
- }
- public void setTrackingObj(ArrayList<AbstractCanvasObject> objArr) {
- model.setTrackingObj(objArr);
- }
- public ArrayList<AbstractCanvasObject> getTrackingObj() {
- return model.getTrackingObj();
- }
- public void addTrackingObj(AbstractCanvasObject obj) {
- model.getTrackingObj().add(obj);
- model.addObjectsToGraphListeners();
- }
- public void removeTrackingObj(AbstractCanvasObject obj) {
- ArrayList<AbstractCanvasObject> objArr = model.getTrackingObj();
- objArr.remove(obj);
- model.setTrackingObj(objArr);
- model.addObjectsToGraphListeners();
- //Remove the Object from the graph and the LegendPanel
- for (StatisticGraphPanel sg : model.getGraphTable().values()) {
- ArrayList<Integer> indexList = new ArrayList<>();
- for (TrackedDataSet set: sg.getStatGraph().getDataSets()) {
- if (obj == set.getCpsObject()) {
- indexList.add(sg.getStatGraph().getDataSets().indexOf(set));
- }
- }
- for (int i = indexList.size()-1; i >= 0; i--) {
- sg.getLegendPanel().remove(sg.getLegendPanel().getComponent(indexList.get(i)));
- sg.getStatGraph().removeObject(indexList.get(i));
- sg.updateUI();
-
- }
- }
- }
- }
|