persist syncdir settings
This commit is contained in:
parent
413487f25c
commit
db8ae16f01
@ -3,6 +3,7 @@ package cz.kamma.kfmanager.config;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for saving and loading the application configuration
|
* Class for saving and loading the application configuration
|
||||||
@ -804,4 +805,151 @@ public class AppConfig {
|
|||||||
public void setMigrationPath(String path) {
|
public void setMigrationPath(String path) {
|
||||||
properties.setProperty("migration.path", 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
package cz.kamma.kfmanager.ui;
|
package cz.kamma.kfmanager.ui;
|
||||||
|
|
||||||
import cz.kamma.kfmanager.config.AppConfig;
|
import cz.kamma.kfmanager.config.AppConfig;
|
||||||
import cz.kamma.kfmanager.model.FileItem;
|
|
||||||
import cz.kamma.kfmanager.service.FileOperations;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
@ -14,9 +12,7 @@ import java.io.File;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class SyncDirectoriesDialog extends JDialog {
|
public class SyncDirectoriesDialog extends JDialog {
|
||||||
@ -40,8 +36,15 @@ public class SyncDirectoriesDialog extends JDialog {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
initComponents(leftDir, rightDir);
|
initComponents(leftDir, rightDir);
|
||||||
setSize(1000, 600);
|
config.restoreSyncDialogState(this);
|
||||||
setLocationRelativeTo(owner);
|
if (getBounds().x == -1) setLocationRelativeTo(owner);
|
||||||
|
|
||||||
|
addWindowListener(new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
saveSettings();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initComponents(File leftDir, File rightDir) {
|
private void initComponents(File leftDir, File rightDir) {
|
||||||
@ -80,8 +83,16 @@ public class SyncDirectoriesDialog extends JDialog {
|
|||||||
optionsPanel.add(compareBtn);
|
optionsPanel.add(compareBtn);
|
||||||
|
|
||||||
subdirsCheckbox = new JCheckBox("Include subdirectories");
|
subdirsCheckbox = new JCheckBox("Include subdirectories");
|
||||||
|
subdirsCheckbox.setSelected(config.getSyncIncludeSubdirs());
|
||||||
|
subdirsCheckbox.addActionListener(e -> config.setSyncIncludeSubdirs(subdirsCheckbox.isSelected()));
|
||||||
|
|
||||||
byContentCheckbox = new JCheckBox("By content");
|
byContentCheckbox = new JCheckBox("By content");
|
||||||
|
byContentCheckbox.setSelected(config.getSyncByContent());
|
||||||
|
byContentCheckbox.addActionListener(e -> config.setSyncByContent(byContentCheckbox.isSelected()));
|
||||||
|
|
||||||
ignoreDateCheckbox = new JCheckBox("Ignore date");
|
ignoreDateCheckbox = new JCheckBox("Ignore date");
|
||||||
|
ignoreDateCheckbox.setSelected(config.getSyncIgnoreDate());
|
||||||
|
ignoreDateCheckbox.addActionListener(e -> config.setSyncIgnoreDate(ignoreDateCheckbox.isSelected()));
|
||||||
|
|
||||||
optionsPanel.add(subdirsCheckbox);
|
optionsPanel.add(subdirsCheckbox);
|
||||||
optionsPanel.add(byContentCheckbox);
|
optionsPanel.add(byContentCheckbox);
|
||||||
@ -95,12 +106,18 @@ public class SyncDirectoriesDialog extends JDialog {
|
|||||||
showDiffBtn = new JToggleButton("≠");
|
showDiffBtn = new JToggleButton("≠");
|
||||||
showRightOnlyBtn = new JToggleButton("⬅");
|
showRightOnlyBtn = new JToggleButton("⬅");
|
||||||
|
|
||||||
showLeftOnlyBtn.setSelected(true);
|
showLeftOnlyBtn.setSelected(config.getSyncShowLeftOnly());
|
||||||
showEqualBtn.setSelected(true);
|
showEqualBtn.setSelected(config.getSyncShowEqual());
|
||||||
showDiffBtn.setSelected(true);
|
showDiffBtn.setSelected(config.getSyncShowDiff());
|
||||||
showRightOnlyBtn.setSelected(true);
|
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);
|
showLeftOnlyBtn.addActionListener(filterAl);
|
||||||
showEqualBtn.addActionListener(filterAl);
|
showEqualBtn.addActionListener(filterAl);
|
||||||
showDiffBtn.addActionListener(filterAl);
|
showDiffBtn.addActionListener(filterAl);
|
||||||
@ -118,6 +135,10 @@ public class SyncDirectoriesDialog extends JDialog {
|
|||||||
showDiffBtn.setSelected(true);
|
showDiffBtn.setSelected(true);
|
||||||
showLeftOnlyBtn.setSelected(false);
|
showLeftOnlyBtn.setSelected(false);
|
||||||
showRightOnlyBtn.setSelected(false);
|
showRightOnlyBtn.setSelected(false);
|
||||||
|
config.setSyncShowLeftOnly(false);
|
||||||
|
config.setSyncShowEqual(true);
|
||||||
|
config.setSyncShowDiff(true);
|
||||||
|
config.setSyncShowRightOnly(false);
|
||||||
applyFilters();
|
applyFilters();
|
||||||
});
|
});
|
||||||
JButton singlesBtn = new JButton("singles");
|
JButton singlesBtn = new JButton("singles");
|
||||||
@ -126,6 +147,10 @@ public class SyncDirectoriesDialog extends JDialog {
|
|||||||
showDiffBtn.setSelected(false);
|
showDiffBtn.setSelected(false);
|
||||||
showLeftOnlyBtn.setSelected(true);
|
showLeftOnlyBtn.setSelected(true);
|
||||||
showRightOnlyBtn.setSelected(true);
|
showRightOnlyBtn.setSelected(true);
|
||||||
|
config.setSyncShowLeftOnly(true);
|
||||||
|
config.setSyncShowEqual(false);
|
||||||
|
config.setSyncShowDiff(false);
|
||||||
|
config.setSyncShowRightOnly(true);
|
||||||
applyFilters();
|
applyFilters();
|
||||||
});
|
});
|
||||||
optionsPanel.add(duplicatesBtn);
|
optionsPanel.add(duplicatesBtn);
|
||||||
@ -146,6 +171,8 @@ public class SyncDirectoriesDialog extends JDialog {
|
|||||||
|
|
||||||
add(new JScrollPane(resultsTable), BorderLayout.CENTER);
|
add(new JScrollPane(resultsTable), BorderLayout.CENTER);
|
||||||
|
|
||||||
|
config.restoreTableColumnWidths("sync.table", resultsTable);
|
||||||
|
|
||||||
// Bottom panel
|
// Bottom panel
|
||||||
JPanel bottomPanel = new JPanel(new BorderLayout());
|
JPanel bottomPanel = new JPanel(new BorderLayout());
|
||||||
statusLabel = new JLabel("Waiting for comparison...");
|
statusLabel = new JLabel("Waiting for comparison...");
|
||||||
@ -156,7 +183,10 @@ public class SyncDirectoriesDialog extends JDialog {
|
|||||||
JButton syncBtn = new JButton("Synchronize...");
|
JButton syncBtn = new JButton("Synchronize...");
|
||||||
syncBtn.addActionListener(e -> performSync());
|
syncBtn.addActionListener(e -> performSync());
|
||||||
JButton closeBtn = new JButton("Close");
|
JButton closeBtn = new JButton("Close");
|
||||||
closeBtn.addActionListener(e -> dispose());
|
closeBtn.addActionListener(e -> {
|
||||||
|
saveSettings();
|
||||||
|
dispose();
|
||||||
|
});
|
||||||
btnPanel.add(syncBtn);
|
btnPanel.add(syncBtn);
|
||||||
btnPanel.add(closeBtn);
|
btnPanel.add(closeBtn);
|
||||||
bottomPanel.add(btnPanel, BorderLayout.EAST);
|
bottomPanel.add(btnPanel, BorderLayout.EAST);
|
||||||
@ -164,6 +194,16 @@ public class SyncDirectoriesDialog extends JDialog {
|
|||||||
add(bottomPanel, BorderLayout.SOUTH);
|
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) {
|
private void browsePath(JTextField field) {
|
||||||
JFileChooser chooser = new JFileChooser(field.getText());
|
JFileChooser chooser = new JFileChooser(field.getText());
|
||||||
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user