add emergency management callbacks and emergency cancel button
This commit is contained in:
parent
f58b035252
commit
7a1ca1ef65
@ -5,4 +5,6 @@ public interface ElevatorListener {
|
|||||||
public void elevatorCall(int floor);
|
public void elevatorCall(int floor);
|
||||||
public void floorCall(int floor, Direction direction);
|
public void floorCall(int floor, Direction direction);
|
||||||
public void floorChange(Direction direction);
|
public void floorChange(Direction direction);
|
||||||
|
public void emergency();
|
||||||
|
public void cancelEmergency();
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import commandSystem.ElevatorListener;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
class ElevatorPanel extends JPanel {
|
class ElevatorPanel extends JPanel {
|
||||||
private JButton emergencyStop = new JButton("Emergency stop.");
|
private JButton emergencyStop = new JButton("Emergency stop.");
|
||||||
|
private JButton cancelEmergencyStop = new JButton("Cancel emergency stop.");
|
||||||
private JButton[] buttons;
|
private JButton[] buttons;
|
||||||
|
|
||||||
public ElevatorPanel(int nbFloors, ElevatorListener l) {
|
public ElevatorPanel(int nbFloors, ElevatorListener l) {
|
||||||
@ -26,10 +27,17 @@ class ElevatorPanel extends JPanel {
|
|||||||
});
|
});
|
||||||
this.add(buttons[i]);
|
this.add(buttons[i]);
|
||||||
}
|
}
|
||||||
|
emergencyStop.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
l.emergency();
|
||||||
|
}
|
||||||
|
});
|
||||||
add(emergencyStop);
|
add(emergencyStop);
|
||||||
|
cancelEmergencyStop.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
l.cancelEmergency();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
public void addEmergencyStopListener(ActionListener l) {
|
add(cancelEmergencyStop);
|
||||||
emergencyStop.addActionListener(l);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,9 +82,6 @@ public class Elevator {
|
|||||||
break;
|
break;
|
||||||
case UP:
|
case UP:
|
||||||
height += step;
|
height += step;
|
||||||
System.out.println("height: " + height
|
|
||||||
+ ", prevFloor: " + prevFloor
|
|
||||||
+ ", floor: " + Math.floor(height / floorHeight));
|
|
||||||
|
|
||||||
/* Top reached. */
|
/* Top reached. */
|
||||||
if (height > 1-step) {
|
if (height > 1-step) {
|
||||||
|
@ -20,19 +20,19 @@ public class Simulation implements ElevatorListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void elevatorCall(int floor) {
|
public void elevatorCall(int floor) {
|
||||||
System.out.println("elevator call " + floor);
|
System.out.println("Call from elevator: " + floor);
|
||||||
queue.computeEvent(new CallFromElevatorEvent(floor));
|
queue.computeEvent(new CallFromElevatorEvent(floor));
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void floorCall(int floor, Direction direction) {
|
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));
|
queue.computeEvent(new CallFromFloorEvent(floor, direction));
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void floorChange(Direction direction) {
|
public void floorChange(Direction direction) {
|
||||||
System.out.println("floor change " + direction);
|
System.out.println("Floor reached: " + direction);
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case UP:
|
case UP:
|
||||||
currentFloor++;
|
currentFloor++;
|
||||||
@ -45,19 +45,27 @@ public class Simulation implements ElevatorListener {
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void emergency() {
|
||||||
|
System.out.println("Emergency declared.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancelEmergency() {
|
||||||
|
System.out.println("Emergency cancelled.");
|
||||||
|
}
|
||||||
|
|
||||||
private void update() {
|
private void update() {
|
||||||
final int next = queue.getNextInstruction();
|
final int next = queue.getNextInstruction();
|
||||||
System.out.println("next: " + next);
|
System.out.println("Next instruction: " + next);
|
||||||
if (next == -1 || next == currentFloor) {
|
if (next == -1 || next == currentFloor) {
|
||||||
System.out.println("stopping");
|
System.out.println("Stopping.");
|
||||||
elevator.stop();
|
elevator.stop();
|
||||||
}
|
}
|
||||||
else if (next > currentFloor) {
|
else if (next > currentFloor) {
|
||||||
System.out.println("going up");
|
System.out.println("Going up.");
|
||||||
elevator.goUp();
|
elevator.goUp();
|
||||||
}
|
}
|
||||||
else if (next < currentFloor) {
|
else if (next < currentFloor) {
|
||||||
System.out.println("going down");
|
System.out.println("Going down.");
|
||||||
elevator.goDown();
|
elevator.goDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user