Commit 9e6b5c78 authored by COQUERY EMMANUEL's avatar COQUERY EMMANUEL
Browse files

Checkstyle fixes

Kept the TODO comment and related error for students.
parent 1bf023c8
Pipeline #44681 failed with stage
in 7 seconds
......@@ -10,6 +10,8 @@ import javafx.stage.Stage;
public class App extends Application {
static final int WIDTH = 600;
static final int HEIGHT = 600;
private static final int NB_USERS = 4;
/**
* With javafx, start() is called when the application is launched.
......@@ -18,13 +20,14 @@ public class App extends Application {
public void start(final Stage stage) throws Exception {
//StopCovidUser model = new StopCovidUser(new File("."));
//Controller c = new Controller(model);
new JfxView(stage, 600, 600, 4);
new JfxView(stage, WIDTH, HEIGHT, NB_USERS);
}
/**
* A main method in case the user launches the application using
* App as the main class.
*
* @param args Command-line arguments
*/
// TODO: checkstyle will (rightfully) complain about this brace. Make sure it
......
......@@ -21,7 +21,14 @@ import javafx.stage.Stage;
public class JfxView extends HBox {
private List<StopCovidUserView> users = new ArrayList<>();
private StopCovidServerView server;
/** View for the whole application. */
/**
* View for the whole application.
* @param stage the window
* @param width width in px
* @param height height in px
* @param nbUsers number of users to manage
*/
public JfxView(final Stage stage, final int width,
final int height, final int nbUsers) {
server = new StopCovidServerView();
......
......@@ -16,7 +16,7 @@ public class StopCovidServerView {
*
* @param text Name of the user to declare risky.
*/
public void declareRisky(String text) {
public void declareRisky(final String text) {
for (Node c : gui.getChildren()) {
if (((Label) c).getText().equals(text)) {
return;
......
package fr.univ_lyon1.info.m1.stopcovid_simulator.view;
import java.util.Map.Entry;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
public class StopCovidUserView {
private final VBox gui = new VBox();
private final VBox contacts = new VBox();
final Label status = new Label("NO_DANGER");
private final Label status = new Label("NO_DANGER");
private final String name;
private final EventHandler<ActionEvent> declare = new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent event) {
setStatus("INFECTED");
final StopCovidServerView server = ((JfxView)(gui.getParent().getParent())).getServer();
final StopCovidServerView server =
((JfxView) (gui.getParent().getParent())).getServer();
for (final Node l : contacts.getChildren()) {
server.declareRisky(((Label) l).getText());
}
......@@ -35,7 +32,7 @@ public class StopCovidUserView {
this.name = name;
final Label l = new Label(name);
gui.setStyle("-fx-padding: 10; -fx-border-width: 1;"
+ " -fx-border-radius: 5; -fx-border-color: #505050;");
+ " -fx-border-radius: 5; -fx-border-color: #505050;");
final Button declareBtn = new Button("Declare Infected");
declareBtn.setOnAction(this.declare);
......@@ -43,15 +40,16 @@ public class StopCovidUserView {
}
@Override
public String toString() {
public String toString() {
return name;
}
/**
* Simulate the meeting of two users. Each user will keep the identifier of
* the other in memory, and will notify the other if infected.
*
* @param otherUser The other user being met.
*/
* Simulate the meeting of two users. Each user will keep the identifier of
* the other in memory, and will notify the other if infected.
*
* @param otherUser The other user being met.
*/
public void meet(final StopCovidUserView otherUser) {
for (final Node c : contacts.getChildren()) {
if (((Label) c).getText().equals(otherUser.toString())) {
......@@ -65,6 +63,10 @@ public class StopCovidUserView {
return name;
}
/**
* Changes the status in the view.
* @param status the new status.
*/
public void setStatus(final String status) {
this.status.setText(status);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment