Package oop13.space.controller

Source Code of oop13.space.controller.AchievementsController

package oop13.space.controller;

import java.io.File;
import java.util.List;

import oop13.space.model.Achievement;
import oop13.space.model.IModel;
import oop13.space.utilities.ListIOManager;
import oop13.space.views.AchievementsGUI;
import oop13.space.views.AchievementsGUI.AchievementsObserver;
import oop13.space.views.AchievementsInterface;
import oop13.space.views.MainFrameInterface;

/**
* Controller handling the interaction with the {@link oop13.space.model.Achievement} view.
*
* @author Mattia Capucci
*/
public class AchievementsController implements AchievementsObserver {

  private MainFrameInterface mainFrame;
  private IModel model;
  private AchievementsInterface achievements;

  /**
   * Creates a new AchievementsController with the parameters provided in input.
   *
   * @param mainFrame - The {@link oop13.space.views.MainFrameInterface}
   * to use for changing the current panel displayed
   *
   * @param model - The data used by the controller
   */
  public AchievementsController(MainFrameInterface mainFrame, IModel model) {
    this.mainFrame = mainFrame;
    this.model = model;
  }

  /**
   * Sets the {@link oop13.space.views.AchievementsInterface} view
   * the controller has to observe.
   *
   * @param achievements - The {@link oop13.space.views.AchievementsInterface}
   * to observe
   *
   */
  public void setView(AchievementsInterface achievements) {
    this.achievements = achievements;
    this.achievements.attachObserver(this);
  }

  @Override
  public void backCmd() {
    this.mainFrame.replacePanel(this.mainFrame.getMainMenu());

  }

  @Override
  public void resetAchievements() {
    File achFile = this.model.getAchievementsFile();
    ListIOManager<Achievement> achManager = new ListIOManager<>(achFile);
    List<Achievement> achList = this.model.getAchievementsList();
    achManager.reset();
    AchievementsGUI achGUI = new AchievementsGUI(achList);
    this.setView(achGUI);
    this.mainFrame.replacePanel(achGUI);
  }

}
TOP

Related Classes of oop13.space.controller.AchievementsController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.