diff --git a/src/main/java/cz/kamma/kfmanager/config/AppConfig.java b/src/main/java/cz/kamma/kfmanager/config/AppConfig.java index 3bd2a26..dbc25e9 100644 --- a/src/main/java/cz/kamma/kfmanager/config/AppConfig.java +++ b/src/main/java/cz/kamma/kfmanager/config/AppConfig.java @@ -3,6 +3,7 @@ package cz.kamma.kfmanager.config; import java.awt.*; import java.io.*; import java.util.Properties; +import javax.swing.JTable; /** * Class for saving and loading the application configuration @@ -804,4 +805,151 @@ public class AppConfig { public void setMigrationPath(String path) { properties.setProperty("migration.path", path); } + + // --- SyncDirectoriesDialog persistence --- + public boolean getSyncIncludeSubdirs() { + return Boolean.parseBoolean(properties.getProperty("sync.includeSubdirs", "false")); + } + + public void setSyncIncludeSubdirs(boolean val) { + properties.setProperty("sync.includeSubdirs", String.valueOf(val)); + } + + public boolean getSyncByContent() { + return Boolean.parseBoolean(properties.getProperty("sync.byContent", "false")); + } + + public void setSyncByContent(boolean val) { + properties.setProperty("sync.byContent", String.valueOf(val)); + } + + public boolean getSyncIgnoreDate() { + return Boolean.parseBoolean(properties.getProperty("sync.ignoreDate", "false")); + } + + public void setSyncIgnoreDate(boolean val) { + properties.setProperty("sync.ignoreDate", String.valueOf(val)); + } + + public boolean getSyncShowLeftOnly() { + return Boolean.parseBoolean(properties.getProperty("sync.showLeftOnly", "true")); + } + + public void setSyncShowLeftOnly(boolean val) { + properties.setProperty("sync.showLeftOnly", String.valueOf(val)); + } + + public boolean getSyncShowEqual() { + return Boolean.parseBoolean(properties.getProperty("sync.showEqual", "true")); + } + + public void setSyncShowEqual(boolean val) { + properties.setProperty("sync.showEqual", String.valueOf(val)); + } + + public boolean getSyncShowDiff() { + return Boolean.parseBoolean(properties.getProperty("sync.showDiff", "true")); + } + + public void setSyncShowDiff(boolean val) { + properties.setProperty("sync.showDiff", String.valueOf(val)); + } + + public boolean getSyncShowRightOnly() { + return Boolean.parseBoolean(properties.getProperty("sync.showRightOnly", "true")); + } + + public void setSyncShowRightOnly(boolean val) { + properties.setProperty("sync.showRightOnly", String.valueOf(val)); + } + + public String getSyncLastLeftPath() { + return properties.getProperty("sync.lastLeftPath", ""); + } + + public void setSyncLastLeftPath(String path) { + properties.setProperty("sync.lastLeftPath", path); + } + + public String getSyncLastRightPath() { + return properties.getProperty("sync.lastRightPath", ""); + } + + public void setSyncLastRightPath(String path) { + properties.setProperty("sync.lastRightPath", path); + } + + // --- Sync dialog window state persistence --- + public int getSyncDialogX() { + return Integer.parseInt(properties.getProperty("syncDialog.x", "-1")); + } + + public void setSyncDialogX(int x) { + properties.setProperty("syncDialog.x", String.valueOf(x)); + } + + public int getSyncDialogY() { + return Integer.parseInt(properties.getProperty("syncDialog.y", "-1")); + } + + public void setSyncDialogY(int y) { + properties.setProperty("syncDialog.y", String.valueOf(y)); + } + + public int getSyncDialogWidth() { + return Integer.parseInt(properties.getProperty("syncDialog.width", "1000")); + } + + public void setSyncDialogWidth(int w) { + properties.setProperty("syncDialog.width", String.valueOf(w)); + } + + public int getSyncDialogHeight() { + return Integer.parseInt(properties.getProperty("syncDialog.height", "600")); + } + + public void setSyncDialogHeight(int h) { + properties.setProperty("syncDialog.height", String.valueOf(h)); + } + + public void saveSyncDialogState(Window win) { + if (win == null) return; + setSyncDialogX(win.getX()); + setSyncDialogY(win.getY()); + setSyncDialogWidth(win.getWidth()); + setSyncDialogHeight(win.getHeight()); + } + + public void restoreSyncDialogState(Window win) { + if (win == null) return; + int x = getSyncDialogX(); + int y = getSyncDialogY(); + if (x != -1 && y != -1) { + win.setLocation(x, y); + } + win.setSize(getSyncDialogWidth(), getSyncDialogHeight()); + } + + public void saveTableColumnWidths(String prefix, JTable table) { + if (table == null || prefix == null) return; + int count = table.getColumnCount(); + properties.setProperty(prefix + ".columnCount", String.valueOf(count)); + for (int i = 0; i < count; i++) { + properties.setProperty(prefix + ".column." + i + ".width", String.valueOf(table.getColumnModel().getColumn(i).getWidth())); + } + } + + public void restoreTableColumnWidths(String prefix, JTable table) { + if (table == null || prefix == null) return; + String countStr = properties.getProperty(prefix + ".columnCount"); + if (countStr == null) return; + int count = Integer.parseInt(countStr); + int actualCount = table.getColumnCount(); + for (int i = 0; i < Math.min(count, actualCount); i++) { + String w = properties.getProperty(prefix + ".column." + i + ".width"); + if (w != null) { + table.getColumnModel().getColumn(i).setPreferredWidth(Integer.parseInt(w)); + } + } + } } diff --git a/src/main/java/cz/kamma/kfmanager/ui/SyncDirectoriesDialog.java b/src/main/java/cz/kamma/kfmanager/ui/SyncDirectoriesDialog.java index 35f5f6e..9ac7c2c 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/SyncDirectoriesDialog.java +++ b/src/main/java/cz/kamma/kfmanager/ui/SyncDirectoriesDialog.java @@ -1,8 +1,6 @@ package cz.kamma.kfmanager.ui; import cz.kamma.kfmanager.config.AppConfig; -import cz.kamma.kfmanager.model.FileItem; -import cz.kamma.kfmanager.service.FileOperations; import javax.swing.*; import javax.swing.table.AbstractTableModel; @@ -14,9 +12,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.Collections; import java.util.Map; -import java.util.HashMap; import java.util.TreeMap; public class SyncDirectoriesDialog extends JDialog { @@ -40,8 +36,15 @@ public class SyncDirectoriesDialog extends JDialog { this.config = config; initComponents(leftDir, rightDir); - setSize(1000, 600); - setLocationRelativeTo(owner); + config.restoreSyncDialogState(this); + if (getBounds().x == -1) setLocationRelativeTo(owner); + + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + saveSettings(); + } + }); } private void initComponents(File leftDir, File rightDir) { @@ -80,8 +83,16 @@ public class SyncDirectoriesDialog extends JDialog { optionsPanel.add(compareBtn); subdirsCheckbox = new JCheckBox("Include subdirectories"); + subdirsCheckbox.setSelected(config.getSyncIncludeSubdirs()); + subdirsCheckbox.addActionListener(e -> config.setSyncIncludeSubdirs(subdirsCheckbox.isSelected())); + byContentCheckbox = new JCheckBox("By content"); + byContentCheckbox.setSelected(config.getSyncByContent()); + byContentCheckbox.addActionListener(e -> config.setSyncByContent(byContentCheckbox.isSelected())); + ignoreDateCheckbox = new JCheckBox("Ignore date"); + ignoreDateCheckbox.setSelected(config.getSyncIgnoreDate()); + ignoreDateCheckbox.addActionListener(e -> config.setSyncIgnoreDate(ignoreDateCheckbox.isSelected())); optionsPanel.add(subdirsCheckbox); optionsPanel.add(byContentCheckbox); @@ -95,12 +106,18 @@ public class SyncDirectoriesDialog extends JDialog { showDiffBtn = new JToggleButton("≠"); showRightOnlyBtn = new JToggleButton("⬅"); - showLeftOnlyBtn.setSelected(true); - showEqualBtn.setSelected(true); - showDiffBtn.setSelected(true); - showRightOnlyBtn.setSelected(true); + showLeftOnlyBtn.setSelected(config.getSyncShowLeftOnly()); + showEqualBtn.setSelected(config.getSyncShowEqual()); + showDiffBtn.setSelected(config.getSyncShowDiff()); + showRightOnlyBtn.setSelected(config.getSyncShowRightOnly()); - java.awt.event.ActionListener filterAl = e -> applyFilters(); + java.awt.event.ActionListener filterAl = e -> { + config.setSyncShowLeftOnly(showLeftOnlyBtn.isSelected()); + config.setSyncShowEqual(showEqualBtn.isSelected()); + config.setSyncShowDiff(showDiffBtn.isSelected()); + config.setSyncShowRightOnly(showRightOnlyBtn.isSelected()); + applyFilters(); + }; showLeftOnlyBtn.addActionListener(filterAl); showEqualBtn.addActionListener(filterAl); showDiffBtn.addActionListener(filterAl); @@ -118,6 +135,10 @@ public class SyncDirectoriesDialog extends JDialog { showDiffBtn.setSelected(true); showLeftOnlyBtn.setSelected(false); showRightOnlyBtn.setSelected(false); + config.setSyncShowLeftOnly(false); + config.setSyncShowEqual(true); + config.setSyncShowDiff(true); + config.setSyncShowRightOnly(false); applyFilters(); }); JButton singlesBtn = new JButton("singles"); @@ -126,6 +147,10 @@ public class SyncDirectoriesDialog extends JDialog { showDiffBtn.setSelected(false); showLeftOnlyBtn.setSelected(true); showRightOnlyBtn.setSelected(true); + config.setSyncShowLeftOnly(true); + config.setSyncShowEqual(false); + config.setSyncShowDiff(false); + config.setSyncShowRightOnly(true); applyFilters(); }); optionsPanel.add(duplicatesBtn); @@ -145,6 +170,8 @@ public class SyncDirectoriesDialog extends JDialog { resultsTable.getColumnModel().getColumn(3).setMaxWidth(40); // Icon column add(new JScrollPane(resultsTable), BorderLayout.CENTER); + + config.restoreTableColumnWidths("sync.table", resultsTable); // Bottom panel JPanel bottomPanel = new JPanel(new BorderLayout()); @@ -156,7 +183,10 @@ public class SyncDirectoriesDialog extends JDialog { JButton syncBtn = new JButton("Synchronize..."); syncBtn.addActionListener(e -> performSync()); JButton closeBtn = new JButton("Close"); - closeBtn.addActionListener(e -> dispose()); + closeBtn.addActionListener(e -> { + saveSettings(); + dispose(); + }); btnPanel.add(syncBtn); btnPanel.add(closeBtn); bottomPanel.add(btnPanel, BorderLayout.EAST); @@ -164,6 +194,16 @@ public class SyncDirectoriesDialog extends JDialog { add(bottomPanel, BorderLayout.SOUTH); } + private void saveSettings() { + if (config != null) { + config.saveSyncDialogState(this); + config.saveTableColumnWidths("sync.table", resultsTable); + config.setSyncLastLeftPath(leftPathField.getText()); + config.setSyncLastRightPath(rightPathField.getText()); + config.saveConfig(); + } + } + private void browsePath(JTextField field) { JFileChooser chooser = new JFileChooser(field.getText()); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);