Moved settings into AppleCommanderFX class. Preserving both. Theme gives a preview.

This commit is contained in:
a2geek committed 2026-10-03 15:36:13 -05:00
1 parent 07560aca17
commit e55e7a0bfe
2 files changed
+52 -24

No files matched your search

@@ -35,6 +35,7 @@ import java.util.prefs.Preferences;
public class AppleCommanderFX extends Application {
private static final String IMAGE_DIRECTORY_KEY = "image_directory";
private static final String THEME_SELECTION = "theme_selection";
private static final String EXPORT_OPTION = "export_option";
@Override
public void start(Stage stage) throws Exception {
@@ -97,6 +98,19 @@ public class AppleCommanderFX extends Application {
prefs.put(THEME_SELECTION, themeSelection.name());
}
public static Optional<ExportOption> getExportOption() {
Preferences prefs = Preferences.userNodeForPackage(AppleCommanderFX.class);
String exportName = prefs.get(EXPORT_OPTION, null);
if (exportName == null || exportName.isBlank()) {
return Optional.of(ExportOption.RAW_BINARY);
}
return Optional.of(ExportOption.valueOf(exportName));
}
public static void setExportOption(ExportOption exportOption) {
Preferences prefs = Preferences.userNodeForPackage(AppleCommanderFX.class);
prefs.put(EXPORT_OPTION, exportOption.name());
}
public enum ThemeSelection {
MODENA("Modena (JavaFX default)", Application.STYLESHEET_MODENA),
CASPIAN("Caspian (JavaFX legacy)", Application.STYLESHEET_CASPIAN),
@@ -128,4 +142,20 @@ public class AppleCommanderFX extends Application {
return this != DRACULA;
}
}
public enum ExportOption {
RAW_BINARY("Raw Binary (filename)"),
APPLE_SINGLE("AppleSingle (filename.as)"),
ATTRIBUTE_PRESERVATION("ProDOS Attribute Preservation (filename#TTAAAA)");
private final String description;
ExportOption(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}
}
@@ -14,10 +14,11 @@ import javafx.stage.Window;
import java.util.Objects;
import java.util.Optional;
import static org.applecommander.javafx.AppleCommanderFX.*;
import static org.applecommander.javafx.FxUtils.createGenericSelectionPage;
public class SettingsDialog {
private final ObjectProperty<AppleCommanderFX.ThemeSelection> themeSelection = new SimpleObjectProperty<>();
private final ObjectProperty<ThemeSelection> themeSelection = new SimpleObjectProperty<>();
private final ObjectProperty<ExportOption> exportOption = new SimpleObjectProperty<>();
private final Dialog<ButtonType> dialog;
@@ -25,8 +26,8 @@ public class SettingsDialog {
public SettingsDialog() {
Tab themeTab = new Tab("Theme");
themeTab.setClosable(false);
themeTab.setContent(createGenericSelectionPage("Please choose a theme:", AppleCommanderFX.ThemeSelection.values(),
AppleCommanderFX.ThemeSelection::getDescription, themeSelection));
themeTab.setContent(createGenericSelectionPage("Please choose a theme:", ThemeSelection.values(),
ThemeSelection::getDescription, themeSelection));
Tab exportTab = new Tab("Export");
exportTab.setClosable(false);
@@ -39,15 +40,23 @@ public class SettingsDialog {
dialog = new Dialog<>();
dialog.setTitle("Settings");
dialog.setHeaderText("AppleCommanderFX Settings");
dialog.setHeaderText("Settings");
dialog.getDialogPane().setContent(tabPane);
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CLOSE, ButtonType.APPLY);
themeSelection.addListener((_, _, newValue) -> {
// This gives users a preview when clicking the radio buttons
if (newValue != null) {
newValue.apply();
}
});
}
public void showAndWait(Stage parent) {
Objects.requireNonNull(parent);
AppleCommanderFX.getThemeSelection().ifPresent(themeSelection::set);
getThemeSelection().ifPresent(themeSelection::set);
getExportOption().ifPresent(exportOption::set);
Window window = dialog.getDialogPane().getScene().getWindow();
@@ -70,26 +79,15 @@ public class SettingsDialog {
Optional<ButtonType> button = dialog.showAndWait();
button.ifPresent(result -> {
if (result == ButtonType.APPLY) {
AppleCommanderFX.ThemeSelection theme = themeSelection.get();
AppleCommanderFX.setThemeSelection(theme);
theme.apply();
if (themeSelection.isNotNull().get()) {
setThemeSelection(themeSelection.get());
}
if (exportOption.isNotNull().get()) {
setExportOption(exportOption.get());
}
}
});
}
enum ExportOption {
RAW_BINARY("Raw Binary (filename)"),
APPLE_SINGLE("AppleSingle (filename.as)"),
ATTRIBUTE_PRESERVATION("ProDOS Attribute Preservation (filename#TTAAAA)");
private final String description;
ExportOption(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
// Always go back to what we've set
getThemeSelection().ifPresent(ThemeSelection::apply);
}
}