From b820f041ae470de7a40a842cd6ad53512a1bf214 Mon Sep 17 00:00:00 2001 From: COLIN Cyril Date: Mon, 14 Oct 2019 13:38:17 +0200 Subject: [PATCH 1/4] fix makefile --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3901323..2ae09e9 100644 --- a/Makefile +++ b/Makefile @@ -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/* From 771d76da3f73513cd0fd9c5019d00d022f48ae44 Mon Sep 17 00:00:00 2001 From: COLIN Cyril Date: Mon, 14 Oct 2019 13:43:04 +0200 Subject: [PATCH 2/4] fix stage ordering --- src/gui/ElevatorPanel.java | 2 +- src/gui/FloorPanels.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/ElevatorPanel.java b/src/gui/ElevatorPanel.java index b9f1fb4..2d8e6f7 100644 --- a/src/gui/ElevatorPanel.java +++ b/src/gui/ElevatorPanel.java @@ -13,7 +13,7 @@ class ElevatorPanel extends JPanel { 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--) { buttons[i] = new JButton("" + i); this.add(buttons[i]); } diff --git a/src/gui/FloorPanels.java b/src/gui/FloorPanels.java index fb0c0be..529a4a0 100644 --- a/src/gui/FloorPanels.java +++ b/src/gui/FloorPanels.java @@ -17,15 +17,15 @@ 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) { JButton upButton = new JButton("↑"); floors[i].add(upButton); } - if (i > 1) { + if (i > 0) { JButton downButton = new JButton("↓"); floors[i].add(downButton); } From 9a9c128f31463ce4b36e1d33e2d85bce1b94e4f5 Mon Sep 17 00:00:00 2001 From: MathieuPietri Date: Mon, 14 Oct 2019 13:59:12 +0200 Subject: [PATCH 3/4] =?UTF-8?q?ajout=20de=20requ=C3=AAtes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .~lock.Cahier_des_charges.odt# | 1 - src/Requests/CallFromElevatorRequest.java | 3 +-- src/Requests/CallFromFloorRequest.java | 3 +-- src/Requests/CancelEmergencyStopRequest.java | 9 ++++++++ src/Requests/EmergencyStopRequest.java | 3 +-- src/Requests/ReachedFloorSignal.java | 10 ++++++++ src/Requests/Request.java | 24 ++++++++++++++++---- src/Requests/RequestType.java | 2 +- 8 files changed, 42 insertions(+), 13 deletions(-) delete mode 100644 .~lock.Cahier_des_charges.odt# create mode 100644 src/Requests/CancelEmergencyStopRequest.java create mode 100644 src/Requests/ReachedFloorSignal.java diff --git a/.~lock.Cahier_des_charges.odt# b/.~lock.Cahier_des_charges.odt# deleted file mode 100644 index 5733deb..0000000 --- a/.~lock.Cahier_des_charges.odt# +++ /dev/null @@ -1 +0,0 @@ -,p16003795,L-662722FORM-16.salsa.univ-amu.fr,14.10.2019 13:17,file:///amuhome/p16003795/.config/libreoffice/4; \ No newline at end of file diff --git a/src/Requests/CallFromElevatorRequest.java b/src/Requests/CallFromElevatorRequest.java index ab3acad..677c543 100644 --- a/src/Requests/CallFromElevatorRequest.java +++ b/src/Requests/CallFromElevatorRequest.java @@ -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; } } diff --git a/src/Requests/CallFromFloorRequest.java b/src/Requests/CallFromFloorRequest.java index 317662d..a6c3a93 100644 --- a/src/Requests/CallFromFloorRequest.java +++ b/src/Requests/CallFromFloorRequest.java @@ -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; } } diff --git a/src/Requests/CancelEmergencyStopRequest.java b/src/Requests/CancelEmergencyStopRequest.java new file mode 100644 index 0000000..02020a1 --- /dev/null +++ b/src/Requests/CancelEmergencyStopRequest.java @@ -0,0 +1,9 @@ +package Requests; + +public class CancelEmergencyStopRequest extends Request{ + + public CancelEmergencyStopRequest() { + super(RequestType.CANCELEMERGENCYSTOP); + } + +} diff --git a/src/Requests/EmergencyStopRequest.java b/src/Requests/EmergencyStopRequest.java index e0552dd..40d4fe8 100644 --- a/src/Requests/EmergencyStopRequest.java +++ b/src/Requests/EmergencyStopRequest.java @@ -3,7 +3,6 @@ package Requests; public class EmergencyStopRequest extends Request { public EmergencyStopRequest() { - super(); - this.type = RequestType.EMERGENCYSTOP; + super(RequestType.EMERGENCYSTOP); } } diff --git a/src/Requests/ReachedFloorSignal.java b/src/Requests/ReachedFloorSignal.java new file mode 100644 index 0000000..e6446d1 --- /dev/null +++ b/src/Requests/ReachedFloorSignal.java @@ -0,0 +1,10 @@ +package Requests; + +public class ReachedFloorSignal extends Request{ + public ReachedFloorSignal(int reachedFLoor) { + super(RequestType.REACHEDFLOORSIGNAL); + this.reachedFloor = reachedFLoor; + } + + +} diff --git a/src/Requests/Request.java b/src/Requests/Request.java index 4624e61..ca7499c 100644 --- a/src/Requests/Request.java +++ b/src/Requests/Request.java @@ -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; + } } diff --git a/src/Requests/RequestType.java b/src/Requests/RequestType.java index 6d4dc8d..f8daaea 100644 --- a/src/Requests/RequestType.java +++ b/src/Requests/RequestType.java @@ -1,5 +1,5 @@ package Requests; public enum RequestType { - CALLFROMFLOOR, CALLFROMELEVATOR, EMERGENCYSTOP, CANCELEMERGENCYSTOP + CALLFROMFLOOR, CALLFROMELEVATOR, EMERGENCYSTOP, CANCELEMERGENCYSTOP, REACHEDFLOORSIGNAL } From 0d56ac1e3c91231419e8f3807960d1f4446926c1 Mon Sep 17 00:00:00 2001 From: COLIN Cyril Date: Mon, 14 Oct 2019 14:02:08 +0200 Subject: [PATCH 4/4] implement event callbacks --- src/gui/ElevatorApplication.java | 2 +- src/gui/ElevatorPanel.java | 11 ++++++++++- src/gui/FloorPanels.java | 13 +++++++++++++ src/simulation/Simulation.java | 2 ++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/gui/ElevatorApplication.java b/src/gui/ElevatorApplication.java index 8d5dbed..fbf325a 100644 --- a/src/gui/ElevatorApplication.java +++ b/src/gui/ElevatorApplication.java @@ -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); diff --git a/src/gui/ElevatorPanel.java b/src/gui/ElevatorPanel.java index 2d8e6f7..99b78af 100644 --- a/src/gui/ElevatorPanel.java +++ b/src/gui/ElevatorPanel.java @@ -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 = 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); diff --git a/src/gui/FloorPanels.java b/src/gui/FloorPanels.java index 529a4a0..6f3e983 100644 --- a/src/gui/FloorPanels.java +++ b/src/gui/FloorPanels.java @@ -5,6 +5,7 @@ import java.awt.*; import java.awt.event.*; import commandSystem.ElevatorListener; +import commandSystem.Direction; @SuppressWarnings("serial") @@ -22,11 +23,23 @@ class FloorPanels extends JPanel { floors[i].setLayout(new BoxLayout(floors[i], BoxLayout.LINE_AXIS)); 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 > 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]); diff --git a/src/simulation/Simulation.java b/src/simulation/Simulation.java index f8884bc..cbbec24 100644 --- a/src/simulation/Simulation.java +++ b/src/simulation/Simulation.java @@ -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) {