package cse1030.test3; import java.util.List; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** * A simple controller for the sample test. * * @author CSE1030_F13_14 * */ public class Controller implements ActionListener { private View view; private Model model; /** * Creates a controller with no view or model. */ public Controller() { this.view = null; this.model = null; } /** * Sets the view for this controller. * * @param v * the view */ public void setView(View v) { this.view = v; } /** * Sets the model for this controller. * * @param m * the model */ public void setModel(Model m) { this.model = m; } /** * Responds to events emitted from the view. In this case, there is only one * possible event having the action command "GO". * * @param event * the event to respond to * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ @Override public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (command.equals("GO")) { String elements = this.view.getListElements(); List t = this.model.toList(elements); this.view.setList(t); Integer min = IntegerLists.minimum(t); int idx = IntegerLists.indexOf(min, t); this.view.setMinimum(min); this.view.setIndexOfMinimum(idx); IntegerLists.sort(t); this.view.setSortedList(t); } } }