Use enter or esc to select station or cancel dialog
This commit is contained in:
parent
89181c0fa9
commit
e74ddc99ca
@ -111,7 +111,10 @@ public class MainController implements Initializable {
|
|||||||
selectStationStage.initModality(Modality.APPLICATION_MODAL);
|
selectStationStage.initModality(Modality.APPLICATION_MODAL);
|
||||||
selectStationStage.setUserData(null);
|
selectStationStage.setUserData(null);
|
||||||
selectStationStage.setTitle("Numbers Station Selection");
|
selectStationStage.setTitle("Numbers Station Selection");
|
||||||
selectStationStage.setScene(new Scene(root));
|
|
||||||
|
Scene scene = new Scene(root);
|
||||||
|
scene.addEventFilter(KeyEvent.KEY_PRESSED, (e) -> controller.handleKeyPressed(e));
|
||||||
|
selectStationStage.setScene(scene);
|
||||||
selectStationStage.show();
|
selectStationStage.show();
|
||||||
selectStationStage.setOnHiding(event -> {
|
selectStationStage.setOnHiding(event -> {
|
||||||
String newStationName = (String)selectStationStage.getUserData();
|
String newStationName = (String)selectStationStage.getUserData();
|
||||||
|
@ -13,6 +13,8 @@ import javafx.scene.control.ButtonType;
|
|||||||
import javafx.scene.control.ListCell;
|
import javafx.scene.control.ListCell;
|
||||||
import javafx.scene.control.ListView;
|
import javafx.scene.control.ListView;
|
||||||
import javafx.scene.control.TextInputDialog;
|
import javafx.scene.control.TextInputDialog;
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.event.Event;
|
import javafx.event.Event;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
@ -96,6 +98,17 @@ public class StationSelectionController {
|
|||||||
stage.close();
|
stage.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void handleKeyPressed(KeyEvent event) {
|
||||||
|
KeyCode code = event.getCode();
|
||||||
|
if (code == KeyCode.ENTER) {
|
||||||
|
selectHighlightedStation();
|
||||||
|
} else if (code == KeyCode.ESCAPE) {
|
||||||
|
Stage stage = (Stage) stationListView.getScene().getWindow();
|
||||||
|
stage.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void handleRemoveButtonPress(ActionEvent event) {
|
private void handleRemoveButtonPress(ActionEvent event) {
|
||||||
int selectedIndex = stationListView.getSelectionModel().getSelectedIndex();
|
int selectedIndex = stationListView.getSelectionModel().getSelectedIndex();
|
||||||
@ -115,15 +128,7 @@ public class StationSelectionController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void handleSelectButtonPress(Event e) {
|
private void handleSelectButtonPress(Event e) {
|
||||||
Node node = (Node) e.getSource();
|
selectHighlightedStation();
|
||||||
Stage stage = (Stage) node.getScene().getWindow();
|
|
||||||
StationSettings selectedStation = stationListView.getSelectionModel().getSelectedItem();
|
|
||||||
|
|
||||||
if (selectedStation != null) {
|
|
||||||
stage.setUserData(selectedStation.getName());
|
|
||||||
System.out.println("Selected Station: " + selectedStation.getName());
|
|
||||||
}
|
|
||||||
stage.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onStationListChanged(ListChangeListener.Change<? extends StationSettings> change) {
|
private void onStationListChanged(ListChangeListener.Change<? extends StationSettings> change) {
|
||||||
@ -155,4 +160,15 @@ public class StationSelectionController {
|
|||||||
settings.getStations().addAll(stationList);
|
settings.getStations().addAll(stationList);
|
||||||
settings.save();
|
settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void selectHighlightedStation() {
|
||||||
|
Stage stage = (Stage) stationListView.getScene().getWindow();
|
||||||
|
StationSettings selectedStation = stationListView.getSelectionModel().getSelectedItem();
|
||||||
|
|
||||||
|
if (selectedStation != null) {
|
||||||
|
stage.setUserData(selectedStation.getName());
|
||||||
|
System.out.println("Selected Station: " + selectedStation.getName());
|
||||||
|
}
|
||||||
|
stage.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user