Skip to content
Snippets Groups Projects
Commit 9edce9fc authored by Alexis Durgnat's avatar Alexis Durgnat :milky_way:
Browse files

Clickable connections

parent b8a41bbe
No related branches found
No related tags found
1 merge request!21*poof* final version
...@@ -9,6 +9,7 @@ import ch.hepia.api.transport.Section; ...@@ -9,6 +9,7 @@ import ch.hepia.api.transport.Section;
import ch.hepia.config.AppConfig; import ch.hepia.config.AppConfig;
import ch.hepia.config.AppContext; import ch.hepia.config.AppContext;
import ch.hepia.events.ChatMessage; import ch.hepia.events.ChatMessage;
import ch.hepia.events.JoinedJourney;
import ch.hepia.models.User; import ch.hepia.models.User;
import javafx.animation.TranslateTransition; import javafx.animation.TranslateTransition;
import javafx.application.Platform; import javafx.application.Platform;
...@@ -69,6 +70,11 @@ public class MainWindowController implements Initializable { ...@@ -69,6 +70,11 @@ public class MainWindowController implements Initializable {
@FXML @FXML
private Pane chatContainer; private Pane chatContainer;
@FXML
private Pane connectionContainer;
private List<Connection> currentConnections;
/** /**
* Shows a sad message when the API crashes. * Shows a sad message when the API crashes.
*/ */
...@@ -192,6 +198,28 @@ public class MainWindowController implements Initializable { ...@@ -192,6 +198,28 @@ public class MainWindowController implements Initializable {
p.setMaxWidth(320); 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 * Wrapper for local chat message
* @param message Message to print * @param message Message to print
...@@ -284,13 +312,26 @@ public class MainWindowController implements Initializable { ...@@ -284,13 +312,26 @@ public class MainWindowController implements Initializable {
try { try {
connectionCanvas.getGraphicsContext2D() connectionCanvas.getGraphicsContext2D()
.clearRect(0, 0, connectionCanvas.getWidth(), connectionCanvas.getHeight()); .clearRect(0, 0, connectionCanvas.getWidth(), connectionCanvas.getHeight());
connectionContainer.getChildren().removeIf(c -> c instanceof Pane);
List<Connection> connections = transportApi.getConnections( currentConnections = transportApi.getConnections(
originComboBox.getValue(), destinationComboBox.getValue()); originComboBox.getValue(), destinationComboBox.getValue());
startStopLabel.setText(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 // 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) { } catch (IOException e) {
showSadMessage(AppConfig.ERROR_API_UNREACHABLE); showSadMessage(AppConfig.ERROR_API_UNREACHABLE);
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
</children></Pane> </children></Pane>
</right> </right>
<center> <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> <children>
<Label id="startStopLabel" fx:id="startStopLabel" layoutX="14.0" layoutY="14.0" text="Arrêt : CHANGEZ-MOI" textFill="#4c7ba8"> <Label id="startStopLabel" fx:id="startStopLabel" layoutX="14.0" layoutY="14.0" text="Arrêt : CHANGEZ-MOI" textFill="#4c7ba8">
<font> <font>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment