Skip to content

Commit 40794c1

Browse files
committed
Refactor settings window fetching.
1 parent 9e5ff51 commit 40794c1

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/main/java/com/github/mfl28/boundingboxeditor/controller/Controller.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public void onRegisterSettingsApplyAction(ActionEvent event, ButtonType buttonTy
229229
if(!inferenceSettingsView.validateSettings()) {
230230
MainView.displayErrorAlert(SETTINGS_APPLICATION_ERROR_DIALOG_TITLE,
231231
SETTINGS_APPLICATION_INVALID_FIELDS_ERROR_DIALOG_CONTENT,
232-
view.getSettingsWindow());
232+
view.getSettingsWindow().orElse(stage));
233233
event.consume();
234234
return;
235235
}
@@ -238,7 +238,7 @@ public void onRegisterSettingsApplyAction(ActionEvent event, ButtonType buttonTy
238238
inferenceSettingsView.getSelectedModelLabel().getText().equals("None")) {
239239
MainView.displayErrorAlert(SETTINGS_APPLICATION_ERROR_DIALOG_TITLE,
240240
SETTINGS_APPLICATION_NO_MODEL_SELECTED_ERROR_DIALOG_CONTENT,
241-
view.getSettingsWindow());
241+
view.getSettingsWindow().orElse(stage));
242242
event.consume();
243243
return;
244244
}
@@ -363,7 +363,7 @@ public void onRegisterModelNameFetchingAction() {
363363
makeClientAvailable();
364364
modelNameFetchService.setClient(BoundingBoxPredictorClient.create(client, clientConfig));
365365
modelNameFetchService.getProgressViewer()
366-
.setParentWindow(view.getInferenceSettingsView().getScene().getWindow());
366+
.setParentWindow(view.getSettingsWindow().orElse(stage));
367367
modelNameFetchService.restart();
368368
}
369369

@@ -858,22 +858,21 @@ private void onModelNameFetchingSucceeded(WorkerStateEvent event) {
858858
if(modelNames.isEmpty()) {
859859
MainView.displayErrorAlert(MODEL_FETCHING_ERROR_DIALOG_TITLE,
860860
MODEL_FETCHING_NO_MODELS_ERROR_DIALOG_CONTENT,
861-
view.getInferenceSettingsView().getScene().getWindow());
861+
view.getSettingsWindow().orElse(stage));
862862
} else {
863863
final Optional<String> modelChoice = MainView.displayChoiceDialogAndGetResult(modelNames.get(0),
864864
modelNames,
865865
MODEL_CHOICE_DIALOG_TITLE,
866866
MODEL_CHOICE_DIALOG_HEADER,
867867
MODEL_CHOICE_DIALOG_CONTENT,
868-
view.getInferenceSettingsView()
869-
.getScene()
870-
.getWindow());
868+
view.getSettingsWindow()
869+
.orElse(stage));
871870
modelChoice
872871
.ifPresent(s -> view.getInferenceSettingsView().getSelectedModelLabel()
873872
.setText(s));
874873
}
875874
} else {
876-
MainView.displayIOResultErrorInfoAlert(result, view.getInferenceSettingsView().getScene().getWindow());
875+
MainView.displayIOResultErrorInfoAlert(result, view.getSettingsWindow().orElse(stage));
877876
}
878877
}
879878

src/main/java/com/github/mfl28/boundingboxeditor/ui/MainView.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,12 @@ public void displaySettingsDialog(Controller controller, Window owner) {
529529
settingsDialog.showAndWait();
530530
}
531531

532-
public Window getSettingsWindow() {
533-
return List.of(inferenceSettingsView, uiSettingsView)
534-
.stream()
535-
.filter(item -> item.getScene() != null && item.getScene().getWindow() != null)
536-
.map(item -> item.getScene().getWindow())
537-
.findFirst().orElse(null);
532+
public Optional<Window> getSettingsWindow() {
533+
return Window.getWindows()
534+
.stream()
535+
.filter(window -> window instanceof Stage
536+
&& ((Stage) window).getTitle().equals(SettingsDialogView.SETTINGS_TITLE))
537+
.findFirst();
538538
}
539539

540540
private static void displayImageMetadataLoadingInfoAlert(IOResult ioResult, TableView<IOErrorInfoEntry> errorTable,

src/main/java/com/github/mfl28/boundingboxeditor/ui/settings/SettingsDialogView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
import java.util.Map;
3333

3434
public class SettingsDialogView extends Dialog<ButtonType> implements View {
35+
public static final String SETTINGS_TITLE = "Settings";
3536
private static final String SETTINGS_DIALOG_PANE_ID = "settings-dialog-pane";
36-
private static final String SETTINGS_TITLE = "Settings";
3737
private static final double SPLITPANE_DIVIDER_POSITION = 0.35;
3838
private final ObservableList<String> settingCategories = FXCollections.observableArrayList();
3939
private final Map<String, Node> categoryToContentMap = new HashMap<>();

0 commit comments

Comments
 (0)