This commit is contained in:
Oriane 2019-10-15 11:26:51 +02:00
commit 3463e4c8a7
12 changed files with 75 additions and 19 deletions

View File

@ -1,12 +1,14 @@
all: build assemble
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
.PHONY: build
build:
mkdir -p build
javac -Xlint $(shell find src -type f -name '*.java') -d build
assemble:
cd build/; jar cvmf ../MANIFEST.MF ../Elevator.jar $(shell cd build/; find -type f -name '*.class')
cd build/; jar cvmf ../MANIFEST.MF ../Elevator.jar $(patsubst %,'%',$(shell cd build; find -name '*.class'))
clean:
-rm -r build/*

View File

@ -3,8 +3,7 @@ package Requests;
public class CallFromElevatorRequest extends Request {
public CallFromElevatorRequest(int wantedFloor) {
super();
super(RequestType.CALLFROMELEVATOR);
this.wantedFloor = wantedFloor;
this.type = RequestType.CALLFROMELEVATOR;
}
}

View File

@ -6,10 +6,9 @@ public class CallFromFloorRequest extends Request {
public CallFromFloorRequest(int sourceFloor, Direction direction) {
super();
super(RequestType.CALLFROMFLOOR);
this.sourceFloor = sourceFloor;
this.direction = direction;
this.type = RequestType.CALLFROMFLOOR;
}
}

View File

@ -0,0 +1,9 @@
package Requests;
public class CancelEmergencyStopRequest extends Request{
public CancelEmergencyStopRequest() {
super(RequestType.CANCELEMERGENCYSTOP);
}
}

View File

@ -3,7 +3,6 @@ package Requests;
public class EmergencyStopRequest extends Request {
public EmergencyStopRequest() {
super();
this.type = RequestType.EMERGENCYSTOP;
super(RequestType.EMERGENCYSTOP);
}
}

View File

@ -0,0 +1,10 @@
package Requests;
public class ReachedFloorSignal extends Request{
public ReachedFloorSignal(int reachedFLoor) {
super(RequestType.REACHEDFLOORSIGNAL);
this.reachedFloor = reachedFLoor;
}
}

View File

@ -8,8 +8,11 @@ public abstract class Request {
protected int wantedFloor;
protected int sourceFloor;
protected Direction direction;
protected int reachedFloor;
public Request() {
public Request(RequestType type) {
this.type = type;
this.reachedFloor = -1;
this.wantedFloor = -1;
this.sourceFloor = -1;
this.direction = Direction.NONE;
@ -17,7 +20,7 @@ public abstract class Request {
/**
*
* @return the direction of the request, unconcerned extending classes return NONE
* @return the direction of the request, unconcerned extending classes return NONE.
*/
public Direction getDirection() {
return direction;
@ -25,7 +28,7 @@ public abstract class Request {
/**
*
* @return the wished floor, unconcerned extending classes return -1
* @return the wished floor, unconcerned extending classes return -1.
*/
public int getWantedFloor() {
return wantedFloor;
@ -33,14 +36,25 @@ public abstract class Request {
/**
*
* @return the floor it was called from, unconcerned extending classes return -1
* @return the floor it was called from, unconcerned extending classes return -1.
*/
public int getIncomingCallFloor() {
return sourceFloor;
}
/**
*
* @return the RequestType of the request.
*/
public RequestType getType() {
return type;
}
/**
*
* @return the floor the elevator just reached, unconcerned extending classes return -1.
*/
public int getReachedFloor() {
return reachedFloor;
}
}

View File

@ -1,5 +1,5 @@
package Requests;
public enum RequestType {
CALLFROMFLOOR, CALLFROMELEVATOR, EMERGENCYSTOP, CANCELEMERGENCYSTOP
CALLFROMFLOOR, CALLFROMELEVATOR, EMERGENCYSTOP, CANCELEMERGENCYSTOP, REACHEDFLOORSIGNAL
}

View File

@ -48,7 +48,7 @@ public class ElevatorApplication implements ActionListener {
pane.add(Box.createRigidArea(new Dimension(20, 0)));
ElevatorPanel elevatorPanel = new ElevatorPanel(5);
ElevatorPanel elevatorPanel = new ElevatorPanel(5, simulation);
elevatorPanel.setAlignmentY(Component.TOP_ALIGNMENT);
pane.add(elevatorPanel);

View File

@ -1,20 +1,29 @@
package gui;
import javax.swing.*;
import java.awt.event.*;
import commandSystem.ElevatorListener;
@SuppressWarnings("serial")
class ElevatorPanel extends JPanel {
private JButton emergencyStop = new JButton("Emergency stop.");
private JButton[] buttons;
public ElevatorPanel(int nbFloors) {
public ElevatorPanel(int nbFloors, ElevatorListener l) {
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
this.add(new JLabel("Elevator panel."));
buttons = new JButton[nbFloors];
for (int i = 0; i < nbFloors; i++) {
for (int i = nbFloors-1; i >= 0; i--) {
final int j = i;
buttons[i] = new JButton("" + i);
buttons[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
l.elevatorCall(j);
}
});
this.add(buttons[i]);
}
add(emergencyStop);

View File

@ -5,6 +5,7 @@ import java.awt.*;
import java.awt.event.*;
import commandSystem.ElevatorListener;
import commandSystem.Direction;
@SuppressWarnings("serial")
@ -17,16 +18,28 @@ class FloorPanels extends JPanel {
floors = new JPanel[nbFloors];
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
this.add(new JLabel("Call."));
for (int i = 0; i < nbFloors; i++) {
for (int i = nbFloors-1; i >= 0; i--) {
floors[i] = new JPanel();
floors[i].setLayout(new BoxLayout(floors[i], BoxLayout.LINE_AXIS));
floors[i].add(new JLabel("" + (i + 1)));
floors[i].add(new JLabel("" + i));
if (i < nbFloors - 1) {
final int j = i;
JButton upButton = new JButton("");
upButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
l.floorCall(j, Direction.UP);
}
});
floors[i].add(upButton);
}
if (i > 1) {
if (i > 0) {
final int j = i;
JButton downButton = new JButton("");
downButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
l.floorCall(j, Direction.DOWN);
}
});
floors[i].add(downButton);
}
this.add(floors[i]);

View File

@ -20,9 +20,11 @@ public class Simulation implements ElevatorListener {
}
public void elevatorCall(int floor) {
System.out.println("elevator call " + floor);
}
public void floorCall(int floor, Direction direction) {
System.out.println("floor call " + floor + " " + direction);
}
public void floorChange(Direction d) {