diff --git a/src/commandSystem/ElevatorListener.java b/src/commandSystem/ElevatorListener.java index 9af97ea..6b0f032 100644 --- a/src/commandSystem/ElevatorListener.java +++ b/src/commandSystem/ElevatorListener.java @@ -5,4 +5,6 @@ public interface ElevatorListener { public void elevatorCall(int floor); public void floorCall(int floor, Direction direction); public void floorChange(Direction direction); + public void emergency(); + public void cancelEmergency(); } diff --git a/src/gui/ElevatorPanel.java b/src/gui/ElevatorPanel.java index 99b78af..b393d56 100644 --- a/src/gui/ElevatorPanel.java +++ b/src/gui/ElevatorPanel.java @@ -9,6 +9,7 @@ import commandSystem.ElevatorListener; @SuppressWarnings("serial") class ElevatorPanel extends JPanel { private JButton emergencyStop = new JButton("Emergency stop."); + private JButton cancelEmergencyStop = new JButton("Cancel emergency stop."); private JButton[] buttons; public ElevatorPanel(int nbFloors, ElevatorListener l) { @@ -26,10 +27,17 @@ class ElevatorPanel extends JPanel { }); this.add(buttons[i]); } + emergencyStop.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + l.emergency(); + } + }); add(emergencyStop); - } - - public void addEmergencyStopListener(ActionListener l) { - emergencyStop.addActionListener(l); + cancelEmergencyStop.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + l.cancelEmergency(); + } + }); + add(cancelEmergencyStop); } } diff --git a/src/simulation/Elevator.java b/src/simulation/Elevator.java index 4071dc5..649bcfe 100644 --- a/src/simulation/Elevator.java +++ b/src/simulation/Elevator.java @@ -82,9 +82,6 @@ public class Elevator { break; case UP: height += step; - System.out.println("height: " + height - + ", prevFloor: " + prevFloor - + ", floor: " + Math.floor(height / floorHeight)); /* Top reached. */ if (height > 1-step) { diff --git a/src/simulation/Simulation.java b/src/simulation/Simulation.java index 026be65..79e0725 100644 --- a/src/simulation/Simulation.java +++ b/src/simulation/Simulation.java @@ -20,19 +20,19 @@ public class Simulation implements ElevatorListener { } public void elevatorCall(int floor) { - System.out.println("elevator call " + floor); + System.out.println("Call from elevator: " + floor); queue.computeEvent(new CallFromElevatorEvent(floor)); update(); } public void floorCall(int floor, Direction direction) { - System.out.println("floor call " + floor + " " + direction); + System.out.println("Call from floor: " + floor + " going " + direction); queue.computeEvent(new CallFromFloorEvent(floor, direction)); update(); } public void floorChange(Direction direction) { - System.out.println("floor change " + direction); + System.out.println("Floor reached: " + direction); switch (direction) { case UP: currentFloor++; @@ -45,19 +45,27 @@ public class Simulation implements ElevatorListener { update(); } + public void emergency() { + System.out.println("Emergency declared."); + } + + public void cancelEmergency() { + System.out.println("Emergency cancelled."); + } + private void update() { final int next = queue.getNextInstruction(); - System.out.println("next: " + next); + System.out.println("Next instruction: " + next); if (next == -1 || next == currentFloor) { - System.out.println("stopping"); + System.out.println("Stopping."); elevator.stop(); } else if (next > currentFloor) { - System.out.println("going up"); + System.out.println("Going up."); elevator.goUp(); } else if (next < currentFloor) { - System.out.println("going down"); + System.out.println("Going down."); elevator.goDown(); } }