Select Git revision
decisiontree-iris.py
MainWindowController.java 1.97 KiB
package ch.hepia.ui;
import ch.hepia.api.transport.LinkAPI;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import org.json.JSONArray;
import java.net.URL;
import java.util.ResourceBundle;
public class MainWindowController implements Initializable {
@FXML
private Label currentJourneyLabel;
@FXML
private Label startStopLabel;
@FXML
private ComboBox<String> originComboBox;
@FXML
private ComboBox<String> destinationComboBox;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
currentJourneyLabel.setText("Vous n'avez prévu aucun voyage pour le moment.");
startStopLabel.setText(""); // No text should be visible when no journey has been selected.
LinkAPI transportApi = new LinkAPI();
originComboBox.valueProperty().addListener(
(observable, oldValue, newValue) -> {
if (!newValue.isEmpty() && newValue.length() > 3){
originComboBox.getItems().clear();
try {
JSONArray a = transportApi.getStations(newValue);
for (int i = 0; i < a.length(); i++){
originComboBox.getItems().add(a.getJSONObject(i).getString("name"));
}
} catch (Exception e) {
AlertUtils.dialog(
Alert.AlertType.ERROR, "Erreur",
"Une erreur est survenue.",
"Impossible de contacter les services de transport Suisses.");
}
}
});
destinationComboBox.valueProperty().addListener(
(observable, oldValue, newValue) -> {
if (!newValue.isEmpty() && !originComboBox.getValue().isEmpty()){
}
}
);
}
}