diff --git a/src/main/java/ch/hepia/ui/MainWindowController.java b/src/main/java/ch/hepia/ui/MainWindowController.java index 8dfdd6080d77fddb55d36639968d53e161ef9ed0..ae2bcbceafe1b91cf47410f20afe4dd693208ef9 100644 --- a/src/main/java/ch/hepia/ui/MainWindowController.java +++ b/src/main/java/ch/hepia/ui/MainWindowController.java @@ -9,6 +9,7 @@ import ch.hepia.api.transport.Section; import ch.hepia.config.AppConfig; import ch.hepia.config.AppContext; import ch.hepia.events.ChatMessage; +import ch.hepia.events.JoinedJourney; import ch.hepia.models.User; import javafx.animation.TranslateTransition; import javafx.application.Platform; @@ -69,6 +70,11 @@ public class MainWindowController implements Initializable { @FXML private Pane chatContainer; + @FXML + private Pane connectionContainer; + + private List<Connection> currentConnections; + /** * Shows a sad message when the API crashes. */ @@ -192,6 +198,28 @@ public class MainWindowController implements Initializable { p.setMaxWidth(320); } + /** + * Style a connection panel + * @param p Panel to style + * @param color Background color of the gradient + */ + private void setConnectionPanelStyle(Pane p) { + p.setBackground( + new Background( + new BackgroundFill( + new LinearGradient(0, 0, 0, 1, true, + CycleMethod.NO_CYCLE, + new Stop(1, AppConfig.COLOR_BLUE_10_OPACITY), + new Stop(0, Color.TRANSPARENT) + ), + new CornerRadii(5), + Insets.EMPTY))); + p.setBorder(new Border(new BorderStroke(Color.color(0.6, 0.6, 0.6), BorderStrokeStyle.SOLID, new CornerRadii(5), + BorderWidths.DEFAULT))); + p.setPrefWidth(AppConfig.APP_MAIN_VIEW_WIDTH + 10); + p.setPrefHeight(90); + } + /** * Wrapper for local chat message * @param message Message to print @@ -283,14 +311,27 @@ public class MainWindowController implements Initializable { launchItinaryButton.setOnAction(event -> { try { connectionCanvas.getGraphicsContext2D() - .clearRect(0, 0, connectionCanvas.getWidth(), connectionCanvas.getHeight()); - - List<Connection> connections = transportApi.getConnections( + .clearRect(0, 0, connectionCanvas.getWidth(), connectionCanvas.getHeight()); + connectionContainer.getChildren().removeIf(c -> c instanceof Pane); + currentConnections = transportApi.getConnections( originComboBox.getValue(), destinationComboBox.getValue()); startStopLabel.setText(originComboBox.getValue() + " - " + destinationComboBox.getValue()); - for (int i = 0; i < connections.size(); i++){ + for (int i = 0; i < currentConnections.size(); i++){ // Now iterating over connections - drawConnection(connections.get(i), 30, 100 + 100 * i); + drawConnection(currentConnections.get(i), 30, 100 + 100 * i); + Pane pane = new Pane(); + setConnectionPanelStyle(pane); + pane.setTranslateX(20); + pane.setTranslateY(85 + 100 * i); + pane.setId(Integer.toString(i)); + Platform.runLater(() -> { + connectionContainer.getChildren().add(pane); + pane.setOnMouseClicked(e -> { + Pane pnl = (Pane) e.getSource(); + Integer pos = Integer.parseInt(pnl.getId()); + app.getMessageManager().sendJoinedJourney(new JoinedJourney(app.getUser().get(), currentConnections.get(pos))); + }); + }); } } catch (IOException e) { showSadMessage(AppConfig.ERROR_API_UNREACHABLE); diff --git a/src/main/resources/fxml/MainWindow.fxml b/src/main/resources/fxml/MainWindow.fxml index 35e9be27c159b0fe217872191b50afd54745e551..bb483de30b6746b53187be5d4855c290c815550a 100644 --- a/src/main/resources/fxml/MainWindow.fxml +++ b/src/main/resources/fxml/MainWindow.fxml @@ -51,7 +51,7 @@ </children></Pane> </right> <center> - <Pane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER"> + <Pane id="connectionContainer" fx:id="connectionContainer" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER"> <children> <Label id="startStopLabel" fx:id="startStopLabel" layoutX="14.0" layoutY="14.0" text="ArrĂȘt : CHANGEZ-MOI" textFill="#4c7ba8"> <font>