Skip to content
Snippets Groups Projects
Commit 35d6c396 authored by Mattéo Comti's avatar Mattéo Comti
Browse files

NO TIME

parent 57d84c14
No related branches found
No related tags found
No related merge requests found
Pipeline #19843 failed
...@@ -2,8 +2,9 @@ package elevator; ...@@ -2,8 +2,9 @@ package elevator;
import elevatorSimulator.IElevator; import elevatorSimulator.IElevator;
import java.util.Scanner; /**
* no time to finish, this is just an early draft probably completely wrong
*/
public class ControlCommand implements IControlCommand{ public class ControlCommand implements IControlCommand{
private final Scheduler scheduler; private final Scheduler scheduler;
private final IElevator elevator; private final IElevator elevator;
...@@ -17,6 +18,7 @@ public class ControlCommand implements IControlCommand{ ...@@ -17,6 +18,7 @@ public class ControlCommand implements IControlCommand{
stoppingNext = false; stoppingNext = false;
} }
// TODO SOME WAY TO TEST WITH TERMINAL // TODO SOME WAY TO TEST WITH TERMINAL
public void checkAndProcess() { public void checkAndProcess() {
......
package elevator;
import elevatorSimulator.ElevatorSimulator;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* I've never done this and i don't have time to finish
*/
public class GUI {
JTextArea states;
JTextArea currentStage;
ElevatorSimulator elevator;
int stages;
public GUI() {
this.stages = 10;
}
private JButton newButton(String name, ActionListener action) {
JButton button = new JButton(name);
button.addActionListener(action);
return button;
}
public void run() {
var frame = new JFrame();
states = new JTextArea();
currentStage = new JTextArea();
var panelElevator = new JPanel(new GridLayout(stages,1));
var panelStages = new JPanel(new GridLayout(stages,2));
panelElevator.setSize(10,25*stages);
var panel = new JPanel();
var textPanel = new JPanel();
textPanel.add(states,BorderLayout.EAST);
textPanel.add(currentStage,BorderLayout.WEST);
for (int i = 1; i <= stages; i++) {
panelElevator.add(newButton(i + "", this::actionBuild));
}
for (int i = 1; i <= stages; i++) {
panelStages.add(newButton(i + "", this::actionBuild));
panelStages.add(newButton(i + "", this::actionBuild));
}
panel.add(textPanel,BorderLayout.NORTH);
panel.add(panelElevator, BorderLayout.WEST);
panel.add(panelStages,BorderLayout.EAST);
frame.getContentPane().add(panel,BorderLayout.CENTER);
frame.setSize(500,500);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
private void actionBuild(ActionEvent event) {
if (states.getText().equals("Erreur")) {
states.setText("");
}
String str = event.getActionCommand();
states.setText(states.getText() + str);
}
public static void main(String[] args) {
var gui = new GUI();
gui.run();
}
}
...@@ -8,14 +8,36 @@ public class Scheduler { ...@@ -8,14 +8,36 @@ public class Scheduler {
private ElevatorSimulator elevatorSimulator; private ElevatorSimulator elevatorSimulator;
private boolean up = true; private boolean up = true;
/**
* list containing all the stages the elevator is going to stop at while going up,
*/
private static final ArrayList<Integer> currentUp = new ArrayList<>(); private static final ArrayList<Integer> currentUp = new ArrayList<>();
/**
* list containing all the stages the elevator is going to stop at while going up,
*/
private static final ArrayList<Integer> nextUp = new ArrayList<>(); private static final ArrayList<Integer> nextUp = new ArrayList<>();
/**
* list containing all the stages the elevator is going to stop at while going down,
*/
private static final ArrayList<Integer> currentDown = new ArrayList<>(); private static final ArrayList<Integer> currentDown = new ArrayList<>();
/**
* list containing all the stages the elevator is going to stop at while going down,
*/
private static final ArrayList<Integer> nextDown = new ArrayList<>(); private static final ArrayList<Integer> nextDown = new ArrayList<>();
/**
* reprensents one of the 4 lists (the one the elevator is currently using
*/
private static ArrayList<Integer> current = currentUp; private static ArrayList<Integer> current = currentUp;
/**
* adds the given level to the corresponding list
* @param level stage to add to one of the lists
* @param ups represents whether the person pressed up or down
*/
public void add(Integer level, boolean ups) { public void add(Integer level, boolean ups) {
ArrayList<Integer> list = getList(level, ups); ArrayList<Integer> list = getList(level, ups);
...@@ -52,7 +74,13 @@ public class Scheduler { ...@@ -52,7 +74,13 @@ public class Scheduler {
} }
} }
// TODO Change set level 5 to elevator.getLevel() and check for when currentLevel = level /**
* auxiliary method for add(), selects the right list
* // TODO currently level set to 5 for testing, change to elevator.getLevel() and check for when level = currentLevel
* @param level stage to add to one of the lists
* @param ups represents whether the person pressed up or down
* @return the right list to add the stage to
*/
private ArrayList<Integer> getList(Integer level, boolean ups) { private ArrayList<Integer> getList(Integer level, boolean ups) {
ArrayList<Integer> list; ArrayList<Integer> list;
...@@ -77,6 +105,10 @@ public class Scheduler { ...@@ -77,6 +105,10 @@ public class Scheduler {
return list; return list;
} }
/**
* called whem the elevator changes direction (from up to down and the other way around)
* changes the lists accordingly
*/
private void changeDirection() { private void changeDirection() {
if (up) { if (up) {
up = false; up = false;
...@@ -91,6 +123,10 @@ public class Scheduler { ...@@ -91,6 +123,10 @@ public class Scheduler {
} }
} }
/**
* gets the next level the elevator is going to go to
* @return
*/
public int getNextLevel() { public int getNextLevel() {
if (up && currentUp.isEmpty()) { if (up && currentUp.isEmpty()) {
changeDirection(); changeDirection();
...@@ -101,6 +137,9 @@ public class Scheduler { ...@@ -101,6 +137,9 @@ public class Scheduler {
return current.get(0); return current.get(0);
} }
/**
* remove the next level from its list
*/
public void removeNextLevel() { public void removeNextLevel() {
current.remove(0); current.remove(0);
} }
...@@ -116,6 +155,9 @@ public class Scheduler { ...@@ -116,6 +155,9 @@ public class Scheduler {
return currentUp.isEmpty() && currentDown.isEmpty(); return currentUp.isEmpty() && currentDown.isEmpty();
} }
/**
* prints the lists, mostly for testing
*/
public void printLists() { public void printLists() {
System.out.println("currentUP = "+currentUp); System.out.println("currentUP = "+currentUp);
System.out.println("nextUp = "+ nextUp); System.out.println("nextUp = "+ nextUp);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment