From d1fe679bb9a8c14ef7ddce348116188a2e2ec8cf Mon Sep 17 00:00:00 2001 From: a2geek Date: Wed, 12 Aug 2026 14:17:38 -0500 Subject: [PATCH] Restructured and now showing where preferences are saved. --- .../applecommander/ui/UserPreferences.java | 11 +- .../applecommander/ui/swt/SettingsDialog.java | 196 ++++++++++-------- 2 files changed, 117 insertions(+), 90 deletions(-) diff --git a/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/UserPreferences.java b/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/UserPreferences.java index 097185b2..6c235abd 100644 --- a/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/UserPreferences.java +++ b/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/UserPreferences.java @@ -64,7 +64,7 @@ public class UserPreferences { private void load() { try { FileInputStream inputStream = - new FileInputStream(Host.getPrefDir() + FILENAME); + new FileInputStream(getPreferencesPath()); properties.load(inputStream); inputStream.close(); } catch (Exception ignored) { @@ -77,7 +77,7 @@ public class UserPreferences { public void save() { try { FileOutputStream outputStream = - new FileOutputStream(Host.getPrefDir() + FILENAME); + new FileOutputStream(getPreferencesPath()); properties.store(outputStream, UiBundle.getInstance(). get("UserPreferencesComment")); outputStream.close(); @@ -85,6 +85,13 @@ public class UserPreferences { // Ignored } } + + /** + * Returns the full pathname for the preferences file. + */ + public String getPreferencesPath() { + return Host.getPrefDir() + FILENAME; + } /** * Get the disk image directory (used for "open" command). */ diff --git a/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/SettingsDialog.java b/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/SettingsDialog.java index 8994f34f..61271d62 100644 --- a/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/SettingsDialog.java +++ b/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/SettingsDialog.java @@ -30,9 +30,15 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.*; +import java.util.Map; import java.util.Optional; +/** + * The settings dialog allows some management of AppleCommander behavior. + * It also shows some of the "hidden" things that people may be interested in. + */ public class SettingsDialog { + private final UserPreferences preference = UserPreferences.getInstance(); private final Shell parent; private Shell dialog; private Combo backupStrategyCombo; @@ -58,108 +64,24 @@ public class SettingsDialog { dialogLayout.verticalSpacing = 10; dialog.setLayout(dialogLayout); - UserPreferences preference = UserPreferences.getInstance(); - TabFolder tabFolder = new TabFolder(dialog, SWT.NONE); tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH)); - TabItem item = new TabItem(tabFolder, SWT.NONE); - item.setText("Backup"); - Composite control = new Composite(tabFolder, SWT.NONE); GridLayout tabItemLayout = new GridLayout(2, false); tabItemLayout.marginLeft = 5; tabItemLayout.marginRight = 5; tabItemLayout.verticalSpacing = 10; + tabItemLayout.horizontalSpacing = 10; tabItemLayout.marginTop = 5; tabItemLayout.marginBottom = 5; - control.setLayout(tabItemLayout); - item.setControl(control); - Label label = new Label(control, SWT.NONE); - label.setText("Strategy:"); - backupStrategyCombo = new Combo(control, SWT.READ_ONLY); - backupStrategyCombo.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL)); - backupStrategyCombo.setItems("Disabled", "Append '.bak'", "To directory"); - backupStrategyCombo.select(switch (preference.getBackupStrategy()) { - case "bak" -> 1; - case "" -> 0; - default -> 2; - }); - backupStrategyCombo.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - backupBrowseButton.setEnabled(backupStrategyCombo.getSelectionIndex() == 2); - if (backupStrategyCombo.getSelectionIndex() < 2) { - backupDirectoryText.setText(""); - } - } - }); - label = new Label(control, SWT.NONE); - label.setText("... To?"); - backupDirectoryText = new Text(control, SWT.WRAP | SWT.BORDER | SWT.V_SCROLL | SWT.MULTI); - float fontHeight = backupDirectoryText.getFont().getFontData()[0].height; - GridData textGridData = new GridData(GridData.FILL_BOTH); - textGridData.heightHint = (int)fontHeight * 4; - backupDirectoryText.setLayoutData(textGridData); - backupDirectoryText.setText(switch (preference.getBackupStrategy()) { - case "", "bak" -> ""; - default -> preference.getBackupStrategy(); - }); - label = new Label(control, SWT.NONE); // spacing - backupBrowseButton = new Button(control, SWT.PUSH); - backupBrowseButton.setText("Browse..."); - backupBrowseButton.setEnabled(backupStrategyCombo.getSelectionIndex() == 2); - backupBrowseButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - DirectoryDialog dialog = new DirectoryDialog(parent.getShell()); - dialog.setFilterPath(backupDirectoryText.getText()); - dialog.setText("Select backup directory"); - dialog.setMessage("Please select the backup directory."); - Optional result = dialog.openDialog(); - result.ifPresent(backupDirectoryText::setText); - } - }); - - item = new TabItem(tabFolder, SWT.NONE); - item.setText("Info"); - control = new Composite(tabFolder, SWT.NONE); - control.setLayout(tabItemLayout); - item.setControl(control); - - label = new Label(control, SWT.WRAP); - label.setText(""" - These are the current directories that AppleCommander is using. - They change as you select different folders for a related activity. - """); GridData rowSpanGridData = new GridData(GridData.FILL_HORIZONTAL); rowSpanGridData.horizontalSpan = 2; - label.setLayoutData(rowSpanGridData); - label = new Label(control, SWT.NONE); - label.setText("Images:"); - label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - label = new Label(control, SWT.NONE); - label.setText(preference.getDiskImageDirectory()); - - label = new Label(control, SWT.NONE); - label.setText("Export:"); - label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - label = new Label(control, SWT.NONE); - label.setText(preference.getExportDirectory()); - - label = new Label(control, SWT.NONE); - label.setText("Import:"); - label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - label = new Label(control, SWT.NONE); - label.setText(preference.getImportDirectory()); - - label = new Label(control, SWT.NONE); - label.setText("Save:"); - label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - label = new Label(control, SWT.NONE); - label.setText(preference.getSaveDirectory()); + createBackupTab(tabFolder, tabItemLayout, rowSpanGridData); + createInfoTab(tabFolder, tabItemLayout, rowSpanGridData); + // Bottom row of buttons Composite buttonRow = new Composite(dialog, SWT.NONE); GridData buttonRowGridData = new GridData(); buttonRowGridData.grabExcessHorizontalSpace = true; @@ -192,4 +114,102 @@ public class SettingsDialog { SwtUtil.center(parent, dialog); dialog.open(); } + + public void createBackupTab(TabFolder tabFolder, GridLayout tabItemLayout, GridData rowSpanGridData) { + TabItem item = new TabItem(tabFolder, SWT.NONE); + item.setText("Backup"); + Composite control = new Composite(tabFolder, SWT.NONE); + control.setLayout(tabItemLayout); + item.setControl(control); + + Label label = new Label(control, SWT.WRAP); + label.setText(""" + AppleCommander has the ability to backup an image on Save. + This does not impact Save As, since the image is under a new name. + """); + label.setLayoutData(rowSpanGridData); + + label = new Label(control, SWT.NONE); + label.setText("Strategy:"); + backupStrategyCombo = new Combo(control, SWT.READ_ONLY); + backupStrategyCombo.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL)); + backupStrategyCombo.setItems("Disabled", "Append '.bak'", "To directory"); + backupStrategyCombo.select(switch (preference.getBackupStrategy()) { + case "bak" -> 1; + case "" -> 0; + default -> 2; + }); + backupStrategyCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + backupBrowseButton.setEnabled(backupStrategyCombo.getSelectionIndex() == 2); + if (backupStrategyCombo.getSelectionIndex() < 2) { + backupDirectoryText.setText(""); + } + } + }); + + label = new Label(control, SWT.NONE); + label.setText("... To?"); + backupDirectoryText = new Text(control, SWT.WRAP | SWT.BORDER | SWT.V_SCROLL | SWT.MULTI); + float fontHeight = backupDirectoryText.getFont().getFontData()[0].height; + GridData textGridData = new GridData(GridData.FILL_BOTH); + textGridData.heightHint = (int)fontHeight * 4; + backupDirectoryText.setLayoutData(textGridData); + backupDirectoryText.setText(switch (preference.getBackupStrategy()) { + case "", "bak" -> ""; + default -> preference.getBackupStrategy(); + }); + label = new Label(control, SWT.NONE); // spacing + backupBrowseButton = new Button(control, SWT.PUSH); + backupBrowseButton.setText("Browse..."); + backupBrowseButton.setEnabled(backupStrategyCombo.getSelectionIndex() == 2); + backupBrowseButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + DirectoryDialog dialog = new DirectoryDialog(parent.getShell()); + dialog.setFilterPath(backupDirectoryText.getText()); + dialog.setText("Select backup directory"); + dialog.setMessage("Please select the backup directory."); + Optional result = dialog.openDialog(); + result.ifPresent(backupDirectoryText::setText); + } + }); + } + + public void createInfoTab(TabFolder tabFolder, GridLayout tabItemLayout, GridData rowSpanGridData) { + TabItem item = new TabItem(tabFolder, SWT.NONE); + item.setText("Info"); + Composite control = new Composite(tabFolder, SWT.NONE); + control.setLayout(tabItemLayout); + item.setControl(control); + + Label label = new Label(control, SWT.NONE); + label.setText("Location:"); + label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + label = new Label(control, SWT.WRAP); + label.setText(preference.getPreferencesPath()); + + label = new Label(control, SWT.WRAP); + label.setText(""" + These are the current directories that AppleCommander is using. + They change as you select different folders for a related activity. + """); + label.setLayoutData(rowSpanGridData); + + // Collapsing all the info into pairings as order doesn't matter too much: + final Map pairings = Map.of( + "Images:", preference.getDiskImageDirectory(), + "Export:", preference.getExportDirectory(), + "Import:", preference.getImportDirectory(), + "Save:", preference.getSaveDirectory() + ); + for (var entry : pairings.entrySet()) { + label = new Label(control, SWT.NONE); + label.setText(entry.getKey()); + label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + label = new Label(control, SWT.WRAP); + label.setText(entry.getValue()); + } + } }