diff --git a/src/main/java/ch/hepia/ui/MainWindowController.java b/src/main/java/ch/hepia/ui/MainWindowController.java index 20d2a8ac161fc5097216e9cb65bbadd5577bf33e..9e1a5ba0cae149f760af194a9332a42d02cc669e 100644 --- a/src/main/java/ch/hepia/ui/MainWindowController.java +++ b/src/main/java/ch/hepia/ui/MainWindowController.java @@ -16,8 +16,10 @@ import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.Node; import javafx.scene.canvas.Canvas; +import javafx.scene.canvas.GraphicsContext; import javafx.scene.control.*; import javafx.scene.image.Image; +import javafx.scene.image.ImageView; import javafx.scene.input.KeyCode; import javafx.scene.layout.Background; import javafx.scene.paint.Color; @@ -31,9 +33,7 @@ import java.text.ParseException; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; -import javafx.scene.image.Image; import javafx.scene.layout.Pane; -import javafx.scene.layout.StackPane; public class MainWindowController implements Initializable { @@ -111,32 +111,33 @@ public class MainWindowController implements Initializable { */ private void drawConnection(Connection connection, int x, int y){ List<Section> sections = connection.getSections(); - connectionCanvas.getGraphicsContext2D().setFill(Color.RED); - connectionCanvas.getGraphicsContext2D().fillText(sections.get(0).getDeparture().getLocation().getName(), x, y - 20); - connectionCanvas.getGraphicsContext2D().setFill(Color.BLACK); - connectionCanvas.getGraphicsContext2D().fillText(sections.get(0).getDeparture().getDepartureTime().toString(), x, y - 40); - connectionCanvas.getGraphicsContext2D().setFill(Color.RED); - connectionCanvas.getGraphicsContext2D().fillOval(x - 5, y - 5, 10, 10); - connectionCanvas.getGraphicsContext2D().strokeLine(x, y, x + 622 / (sections.size() + 1), y); + GraphicsContext gcx = connectionCanvas.getGraphicsContext2D(); + gcx.setFill(Color.RED); + gcx.fillText(sections.get(0).getDeparture().getLocation().getName(), x, y - 20); + gcx.setFill(Color.BLACK); + gcx.fillText(sections.get(0).getDeparture().getDepartureTime().toString(), x, y - 40); + gcx.setFill(Color.RED); + gcx.fillOval(x - 5, y - 5, 10, 10); + gcx.strokeLine(x, y, x + 622 / (sections.size() + 1), y); for (int i = 0; i < sections.size(); i++){ - connectionCanvas.getGraphicsContext2D().strokeLine( + gcx.strokeLine( x + (622 / (sections.size() + 1)) * (i + 1), y, 622 / (sections.size()), y); - connectionCanvas.getGraphicsContext2D().setFill(Color.RED); - connectionCanvas.getGraphicsContext2D().fillOval(x + (622 / (sections.size() + 1)) * (i + 1) - 5, y - 5, 10, 10); + gcx.setFill(Color.RED); + gcx.fillOval(x + (622 / (sections.size() + 1)) * (i + 1) - 5, y - 5, 10, 10); - connectionCanvas.getGraphicsContext2D().fillText(sections.get(i).getArrival().getLocation().getName(), + gcx.fillText(sections.get(i).getArrival().getLocation().getName(), x + (622 / (sections.size() + 1)) * (i + 1), y - 20); - connectionCanvas.getGraphicsContext2D().setFill(Color.BLACK); - connectionCanvas.getGraphicsContext2D().fillText(sections.get(i).getArrival().getArrivalTime().toString(), + gcx.setFill(Color.BLACK); + gcx.fillText(sections.get(i).getArrival().getArrivalTime().toString(), x + (622 / (sections.size() + 1)) * (i + 1), y - 40); Journey jrn = sections.get(i).getJourney(); String transportType = "MARCHE"; if (!(jrn instanceof Journey.EmptyJourney)) { transportType = jrn.getCategory() + ", " + jrn.getNumber(); } - connectionCanvas.getGraphicsContext2D().setFill(Color.BLUE); - connectionCanvas.getGraphicsContext2D().fillText(transportType, x + (622 / (sections.size() + 1)) * (i), y - 55); - connectionCanvas.getGraphicsContext2D().setFill(Color.RED); + gcx.setFill(Color.BLUE); + gcx.fillText(transportType, x + (622 / (sections.size() + 1)) * (i), y - 55); + gcx.setFill(Color.RED); } } @@ -147,13 +148,13 @@ public class MainWindowController implements Initializable { private void drawMessage(User user, String message){ Pane p = new Pane(); p.setMaxWidth(326); - + Image lblImg = new Image(Main.class.getResourceAsStream("/img/bubble.png")); Label msg = new Label(); msg.setWrapText(true); msg.setStyle("-fx-padding: 8px"); msg.setText(message); msg.setMaxWidth(310); - + msg.setGraphic(new ImageView(lblImg)); p.getChildren().add(msg); insertMessageIntoQueue(); chatContainer.getChildren().add(p); diff --git a/src/main/resources/img/bubble.png b/src/main/resources/img/bubble.png new file mode 100644 index 0000000000000000000000000000000000000000..98fcb6b83c43d21ba51d30df9f40b1b90c43769c Binary files /dev/null and b/src/main/resources/img/bubble.png differ