1022 lines
37 KiB
Java
1022 lines
37 KiB
Java
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
|
|
*/
|
|
public class AppConfig {
|
|
|
|
private static final String CONFIG_FILE = System.getProperty("user.home") +
|
|
File.separator + ".kfmanager" + File.separator + "config.properties";
|
|
|
|
private Properties properties;
|
|
|
|
public AppConfig() {
|
|
properties = new Properties();
|
|
loadConfig();
|
|
}
|
|
|
|
/**
|
|
* Load configuration from file
|
|
*/
|
|
private void loadConfig() {
|
|
File configFile = new File(CONFIG_FILE);
|
|
if (configFile.exists()) {
|
|
try (FileInputStream fis = new FileInputStream(configFile)) {
|
|
properties.load(fis);
|
|
} catch (IOException e) {
|
|
System.err.println("Could not load configuration: " + e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Save configuration to file
|
|
*/
|
|
public void saveConfig() {
|
|
File configFile = new File(CONFIG_FILE);
|
|
File configDir = configFile.getParentFile();
|
|
|
|
// Create configuration directory if it does not exist
|
|
if (!configDir.exists()) {
|
|
configDir.mkdirs();
|
|
}
|
|
|
|
try (FileOutputStream fos = new FileOutputStream(configFile)) {
|
|
properties.store(fos, "KF File Manager Configuration");
|
|
} catch (IOException e) {
|
|
System.err.println("Could not save configuration: " + e.getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Export current configuration to a specified file
|
|
*/
|
|
public void exportConfig(File targetFile) throws IOException {
|
|
try (FileOutputStream fos = new FileOutputStream(targetFile)) {
|
|
properties.store(fos, "KF File Manager Exported Configuration");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Import configuration from a specified file
|
|
*/
|
|
public void importConfig(File sourceFile) throws IOException {
|
|
try (FileInputStream fis = new FileInputStream(sourceFile)) {
|
|
properties.load(fis);
|
|
}
|
|
saveConfig(); // Persist imported settings
|
|
}
|
|
|
|
// Getters and setters for individual configuration values
|
|
|
|
public int getWindowX() {
|
|
return Integer.parseInt(properties.getProperty("window.x", "100"));
|
|
}
|
|
|
|
public void setWindowX(int x) {
|
|
properties.setProperty("window.x", String.valueOf(x));
|
|
}
|
|
|
|
public int getWindowY() {
|
|
return Integer.parseInt(properties.getProperty("window.y", "100"));
|
|
}
|
|
|
|
public void setWindowY(int y) {
|
|
properties.setProperty("window.y", String.valueOf(y));
|
|
}
|
|
|
|
public int getWindowWidth() {
|
|
return Integer.parseInt(properties.getProperty("window.width", "1200"));
|
|
}
|
|
|
|
public void setWindowWidth(int width) {
|
|
properties.setProperty("window.width", String.valueOf(width));
|
|
}
|
|
|
|
public int getWindowHeight() {
|
|
return Integer.parseInt(properties.getProperty("window.height", "700"));
|
|
}
|
|
|
|
public void setWindowHeight(int height) {
|
|
properties.setProperty("window.height", String.valueOf(height));
|
|
}
|
|
|
|
public boolean isWindowMaximized() {
|
|
return Boolean.parseBoolean(properties.getProperty("window.maximized", "false"));
|
|
}
|
|
|
|
public void setWindowMaximized(boolean maximized) {
|
|
properties.setProperty("window.maximized", String.valueOf(maximized));
|
|
}
|
|
|
|
public int getFileEditorX() {
|
|
return Integer.parseInt(properties.getProperty("fileeditor.x", "150"));
|
|
}
|
|
|
|
public void setFileEditorX(int x) {
|
|
properties.setProperty("fileeditor.x", String.valueOf(x));
|
|
}
|
|
|
|
public int getFileEditorY() {
|
|
return Integer.parseInt(properties.getProperty("fileeditor.y", "150"));
|
|
}
|
|
|
|
public void setFileEditorY(int y) {
|
|
properties.setProperty("fileeditor.y", String.valueOf(y));
|
|
}
|
|
|
|
public int getFileEditorWidth() {
|
|
return Integer.parseInt(properties.getProperty("fileeditor.width", "800"));
|
|
}
|
|
|
|
public void setFileEditorWidth(int width) {
|
|
properties.setProperty("fileeditor.width", String.valueOf(width));
|
|
}
|
|
|
|
public int getFileEditorHeight() {
|
|
return Integer.parseInt(properties.getProperty("fileeditor.height", "600"));
|
|
}
|
|
|
|
public void setFileEditorHeight(int height) {
|
|
properties.setProperty("fileeditor.height", String.valueOf(height));
|
|
}
|
|
|
|
public String getLastFileChooserDirectory() {
|
|
return properties.getProperty("filechooser.last.dir", System.getProperty("user.home"));
|
|
}
|
|
|
|
public void setLastFileChooserDirectory(String path) {
|
|
if (path != null) {
|
|
properties.setProperty("filechooser.last.dir", path);
|
|
}
|
|
}
|
|
|
|
public int getFileChooserX() {
|
|
return Integer.parseInt(properties.getProperty("filechooser.x", "-1"));
|
|
}
|
|
|
|
public int getFileChooserY() {
|
|
return Integer.parseInt(properties.getProperty("filechooser.y", "-1"));
|
|
}
|
|
|
|
public int getFileChooserWidth() {
|
|
return Integer.parseInt(properties.getProperty("filechooser.width", "600"));
|
|
}
|
|
|
|
public int getFileChooserHeight() {
|
|
return Integer.parseInt(properties.getProperty("filechooser.height", "450"));
|
|
}
|
|
|
|
public void setFileChooserBounds(int x, int y, int width, int height) {
|
|
properties.setProperty("filechooser.x", String.valueOf(x));
|
|
properties.setProperty("filechooser.y", String.valueOf(y));
|
|
properties.setProperty("filechooser.width", String.valueOf(width));
|
|
properties.setProperty("filechooser.height", String.valueOf(height));
|
|
}
|
|
|
|
public String getActivePanel() {
|
|
return properties.getProperty("active.panel", "left");
|
|
}
|
|
|
|
public void setActivePanel(String panel) {
|
|
properties.setProperty("active.panel", panel);
|
|
}
|
|
|
|
public String getLeftPanelPath() {
|
|
return properties.getProperty("leftPanel.path", System.getProperty("user.home"));
|
|
}
|
|
|
|
public void setLeftPanelPath(String path) {
|
|
properties.setProperty("leftPanel.path", path);
|
|
}
|
|
|
|
public String getRightPanelPath() {
|
|
return properties.getProperty("rightPanel.path", System.getProperty("user.home"));
|
|
}
|
|
|
|
public void setRightPanelPath(String path) {
|
|
properties.setProperty("rightPanel.path", path);
|
|
}
|
|
|
|
// ViewMode configuration
|
|
public String getLeftPanelViewMode() {
|
|
return properties.getProperty("leftPanel.viewMode", "FULL");
|
|
}
|
|
|
|
public void setLeftPanelViewMode(String viewMode) {
|
|
properties.setProperty("leftPanel.viewMode", viewMode);
|
|
}
|
|
|
|
public String getRightPanelViewMode() {
|
|
return properties.getProperty("rightPanel.viewMode", "FULL");
|
|
}
|
|
|
|
public void setRightPanelViewMode(String viewMode) {
|
|
properties.setProperty("rightPanel.viewMode", viewMode);
|
|
}
|
|
|
|
// --- Tab/session persistence ---
|
|
public int getLeftPanelTabCount() {
|
|
return Integer.parseInt(properties.getProperty("leftPanel.tabs.count", "0"));
|
|
}
|
|
|
|
public String getLeftPanelTabPath(int index) {
|
|
return properties.getProperty("leftPanel.tab." + index + ".path", null);
|
|
}
|
|
|
|
public String getLeftPanelTabFocusedItem(int index) {
|
|
return properties.getProperty("leftPanel.tab." + index + ".focusedItem", null);
|
|
}
|
|
|
|
public String getLeftPanelTabViewMode(int index) {
|
|
return properties.getProperty("leftPanel.tab." + index + ".viewMode", "FULL");
|
|
}
|
|
|
|
public int getLeftPanelSelectedIndex() {
|
|
return Integer.parseInt(properties.getProperty("leftPanel.selectedIndex", "0"));
|
|
}
|
|
|
|
public void saveLeftPanelTabs(java.util.List<String> paths, java.util.List<String> viewModes, java.util.List<String> focusedItems, int selectedIndex) {
|
|
int old = getLeftPanelTabCount();
|
|
properties.setProperty("leftPanel.tabs.count", String.valueOf(paths.size()));
|
|
for (int i = 0; i < paths.size(); i++) {
|
|
properties.setProperty("leftPanel.tab." + i + ".path", paths.get(i));
|
|
properties.setProperty("leftPanel.tab." + i + ".viewMode", viewModes.get(i));
|
|
if (focusedItems != null && i < focusedItems.size() && focusedItems.get(i) != null) {
|
|
properties.setProperty("leftPanel.tab." + i + ".focusedItem", focusedItems.get(i));
|
|
} else {
|
|
properties.remove("leftPanel.tab." + i + ".focusedItem");
|
|
}
|
|
}
|
|
for (int i = paths.size(); i < old; i++) {
|
|
properties.remove("leftPanel.tab." + i + ".path");
|
|
properties.remove("leftPanel.tab." + i + ".viewMode");
|
|
properties.remove("leftPanel.tab." + i + ".focusedItem");
|
|
}
|
|
properties.setProperty("leftPanel.selectedIndex", String.valueOf(selectedIndex));
|
|
}
|
|
|
|
public int getRightPanelTabCount() {
|
|
return Integer.parseInt(properties.getProperty("rightPanel.tabs.count", "0"));
|
|
}
|
|
|
|
public String getRightPanelTabFocusedItem(int index) {
|
|
return properties.getProperty("rightPanel.tab." + index + ".focusedItem", null);
|
|
}
|
|
|
|
public String getRightPanelTabPath(int index) {
|
|
return properties.getProperty("rightPanel.tab." + index + ".path", null);
|
|
}
|
|
|
|
public String getRightPanelTabViewMode(int index) {
|
|
return properties.getProperty("rightPanel.tab." + index + ".viewMode", "FULL");
|
|
}
|
|
|
|
public int getRightPanelSelectedIndex() {
|
|
return Integer.parseInt(properties.getProperty("rightPanel.selectedIndex", "0"));
|
|
}
|
|
|
|
public void saveRightPanelTabs(java.util.List<String> paths, java.util.List<String> viewModes, java.util.List<String> focusedItems, int selectedIndex) {
|
|
int oldCount = getRightPanelTabCount();
|
|
properties.setProperty("rightPanel.tabs.count", String.valueOf(paths.size()));
|
|
for (int i = 0; i < paths.size(); i++) {
|
|
properties.setProperty("rightPanel.tab." + i + ".path", paths.get(i));
|
|
properties.setProperty("rightPanel.tab." + i + ".viewMode", viewModes.get(i));
|
|
if (focusedItems != null && i < focusedItems.size() && focusedItems.get(i) != null) {
|
|
properties.setProperty("rightPanel.tab." + i + ".focusedItem", focusedItems.get(i));
|
|
} else {
|
|
properties.remove("rightPanel.tab." + i + ".focusedItem");
|
|
}
|
|
}
|
|
for (int i = paths.size(); i < oldCount; i++) {
|
|
properties.remove("rightPanel.tab." + i + ".path");
|
|
properties.remove("rightPanel.tab." + i + ".viewMode");
|
|
properties.remove("rightPanel.tab." + i + ".focusedItem");
|
|
}
|
|
properties.setProperty("rightPanel.selectedIndex", String.valueOf(selectedIndex));
|
|
}
|
|
|
|
// Font configuration
|
|
public String getEditorFontName() {
|
|
return properties.getProperty("editor.font.name", "Monospaced");
|
|
}
|
|
|
|
public void setEditorFontName(String fontName) {
|
|
properties.setProperty("editor.font.name", fontName);
|
|
}
|
|
|
|
public int getEditorFontSize() {
|
|
return Integer.parseInt(properties.getProperty("editor.font.size", "12"));
|
|
}
|
|
|
|
public void setEditorFontSize(int fontSize) {
|
|
properties.setProperty("editor.font.size", String.valueOf(fontSize));
|
|
}
|
|
|
|
public int getEditorFontStyle() {
|
|
return Integer.parseInt(properties.getProperty("editor.font.style", String.valueOf(Font.PLAIN)));
|
|
}
|
|
|
|
public void setEditorFontStyle(int style) {
|
|
properties.setProperty("editor.font.style", String.valueOf(style));
|
|
}
|
|
|
|
public Font getEditorFont() {
|
|
return new Font(getEditorFontName(), getEditorFontStyle(), getEditorFontSize());
|
|
}
|
|
|
|
public void setEditorFont(Font font) {
|
|
setEditorFontName(font.getName());
|
|
setEditorFontSize(font.getSize());
|
|
setEditorFontStyle(font.getStyle());
|
|
}
|
|
|
|
// Toolbar configuration
|
|
public int getToolbarButtonSize() {
|
|
return Integer.parseInt(properties.getProperty("toolbar.button.size", "30"));
|
|
}
|
|
|
|
public void setToolbarButtonSize(int size) {
|
|
properties.setProperty("toolbar.button.size", String.valueOf(size));
|
|
}
|
|
|
|
public int getToolbarIconSize() {
|
|
return Integer.parseInt(properties.getProperty("toolbar.icon.size", "24"));
|
|
}
|
|
|
|
public void setToolbarIconSize(int size) {
|
|
properties.setProperty("toolbar.icon.size", String.valueOf(size));
|
|
}
|
|
|
|
// --- External editor configuration ---
|
|
/** Path to external editor binary (empty = use internal editor) */
|
|
public String getExternalEditorPath() {
|
|
return properties.getProperty("editor.external.path", "");
|
|
}
|
|
|
|
public void setExternalEditorPath(String path) {
|
|
if (path == null || path.isEmpty()) {
|
|
properties.remove("editor.external.path");
|
|
} else {
|
|
properties.setProperty("editor.external.path", path);
|
|
}
|
|
}
|
|
|
|
// --- Open With Configuration ---
|
|
public static class OpenWithEntry {
|
|
public String label;
|
|
public String type; // "directory" or extension
|
|
public String command;
|
|
|
|
public OpenWithEntry() {}
|
|
public OpenWithEntry(String label, String type, String command) {
|
|
this.label = label;
|
|
this.type = type;
|
|
this.command = command;
|
|
}
|
|
}
|
|
|
|
public java.util.List<OpenWithEntry> getOpenWithEntries() {
|
|
java.util.List<OpenWithEntry> list = new java.util.ArrayList<>();
|
|
String countStr = properties.getProperty("openwith.count", "0");
|
|
int count = Integer.parseInt(countStr);
|
|
for (int i = 0; i < count; i++) {
|
|
String label = properties.getProperty("openwith." + i + ".label");
|
|
String type = properties.getProperty("openwith." + i + ".type");
|
|
String command = properties.getProperty("openwith." + i + ".command");
|
|
if (label != null && type != null && command != null) {
|
|
list.add(new OpenWithEntry(label, type, command));
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public void setOpenWithEntries(java.util.List<OpenWithEntry> entries) {
|
|
// Remove old entries
|
|
String countStr = properties.getProperty("openwith.count", "0");
|
|
int count = Integer.parseInt(countStr);
|
|
for (int i = 0; i < count; i++) {
|
|
properties.remove("openwith." + i + ".label");
|
|
properties.remove("openwith." + i + ".type");
|
|
properties.remove("openwith." + i + ".command");
|
|
}
|
|
|
|
if (entries == null) {
|
|
properties.setProperty("openwith.count", "0");
|
|
return;
|
|
}
|
|
|
|
properties.setProperty("openwith.count", String.valueOf(entries.size()));
|
|
for (int i = 0; i < entries.size(); i++) {
|
|
OpenWithEntry e = entries.get(i);
|
|
properties.setProperty("openwith." + i + ".label", e.label != null ? e.label : "");
|
|
properties.setProperty("openwith." + i + ".type", e.type != null ? e.type : "");
|
|
properties.setProperty("openwith." + i + ".command", e.command != null ? e.command : "");
|
|
}
|
|
}
|
|
|
|
// --- Appearance (global) settings ---
|
|
public String getGlobalFontName() {
|
|
return properties.getProperty("global.font.name", "Monospaced");
|
|
}
|
|
|
|
public void setGlobalFontName(String name) {
|
|
properties.setProperty("global.font.name", name);
|
|
}
|
|
|
|
public int getGlobalFontSize() {
|
|
return Integer.parseInt(properties.getProperty("global.font.size", "12"));
|
|
}
|
|
|
|
public void setGlobalFontSize(int size) {
|
|
properties.setProperty("global.font.size", String.valueOf(size));
|
|
}
|
|
|
|
public Font getGlobalFont() {
|
|
return new Font(getGlobalFontName(), getGlobalFontStyle(), getGlobalFontSize());
|
|
}
|
|
|
|
public void setGlobalFont(Font font) {
|
|
setGlobalFontName(font.getName());
|
|
setGlobalFontSize(font.getSize());
|
|
setGlobalFontStyle(font.getStyle());
|
|
}
|
|
|
|
public int getGlobalFontStyle() {
|
|
return Integer.parseInt(properties.getProperty("global.font.style", String.valueOf(Font.PLAIN)));
|
|
}
|
|
|
|
public void setGlobalFontStyle(int style) {
|
|
properties.setProperty("global.font.style", String.valueOf(style));
|
|
}
|
|
|
|
// Colors stored as hex strings (e.g. #RRGGBB)
|
|
public Color getBackgroundColor() {
|
|
String v = properties.getProperty("appearance.bg", null);
|
|
if (v == null) return null;
|
|
try { return Color.decode(v); } catch (Exception ex) { return null; }
|
|
}
|
|
|
|
public void setBackgroundColor(Color c) {
|
|
if (c == null) {
|
|
properties.remove("appearance.bg");
|
|
} else {
|
|
properties.setProperty("appearance.bg", "#%02x%02x%02x".formatted(c.getRed(), c.getGreen(), c.getBlue()));
|
|
}
|
|
}
|
|
|
|
public Color getSelectionColor() {
|
|
String v = properties.getProperty("appearance.selection", null);
|
|
if (v == null) return null;
|
|
try { return Color.decode(v); } catch (Exception ex) { return null; }
|
|
}
|
|
|
|
public void setSelectionColor(Color c) {
|
|
if (c == null) {
|
|
properties.remove("appearance.selection");
|
|
} else {
|
|
properties.setProperty("appearance.selection", "#%02x%02x%02x".formatted(c.getRed(), c.getGreen(), c.getBlue()));
|
|
}
|
|
}
|
|
|
|
public Color getMarkedColor() {
|
|
String v = properties.getProperty("appearance.marked", null);
|
|
if (v == null) return null;
|
|
try { return Color.decode(v); } catch (Exception ex) { return null; }
|
|
}
|
|
|
|
public void setMarkedColor(Color c) {
|
|
if (c == null) {
|
|
properties.remove("appearance.marked");
|
|
} else {
|
|
properties.setProperty("appearance.marked", "#%02x%02x%02x".formatted(c.getRed(), c.getGreen(), c.getBlue()));
|
|
}
|
|
}
|
|
|
|
public Color getFolderColor() {
|
|
String v = properties.getProperty("appearance.folder", null);
|
|
if (v == null) return new Color(255, 200, 0); // Default yellow/gold
|
|
try { return Color.decode(v); } catch (Exception ex) { return new Color(255, 200, 0); }
|
|
}
|
|
|
|
public void setFolderColor(Color c) {
|
|
if (c == null) {
|
|
properties.remove("appearance.folder");
|
|
} else {
|
|
properties.setProperty("appearance.folder", "#%02x%02x%02x".formatted(c.getRed(), c.getGreen(), c.getBlue()));
|
|
}
|
|
}
|
|
|
|
public int getBriefModeMaxNameLength() {
|
|
return Integer.parseInt(properties.getProperty("appearance.brief.max.len", "30"));
|
|
}
|
|
|
|
public void setBriefModeMaxNameLength(int len) {
|
|
properties.setProperty("appearance.brief.max.len", String.valueOf(len));
|
|
}
|
|
|
|
public int getBriefModeStartLength() {
|
|
return Integer.parseInt(properties.getProperty("appearance.brief.start.len", "20"));
|
|
}
|
|
|
|
public void setBriefModeStartLength(int len) {
|
|
properties.setProperty("appearance.brief.start.len", String.valueOf(len));
|
|
}
|
|
|
|
public int getBriefModeEndLength() {
|
|
return Integer.parseInt(properties.getProperty("appearance.brief.end.len", "10"));
|
|
}
|
|
|
|
public void setBriefModeEndLength(int len) {
|
|
properties.setProperty("appearance.brief.end.len", String.valueOf(len));
|
|
}
|
|
|
|
public String getBriefModeSeparator() {
|
|
return properties.getProperty("appearance.brief.separator", "...");
|
|
}
|
|
|
|
public void setBriefModeSeparator(String sep) {
|
|
if (sep != null) {
|
|
properties.setProperty("appearance.brief.separator", sep);
|
|
}
|
|
}
|
|
|
|
// -- Sorting persistence (global default)
|
|
public int getDefaultSortColumn() {
|
|
return Integer.parseInt(properties.getProperty("global.sort.column", "-1"));
|
|
}
|
|
|
|
public void setDefaultSortColumn(int col) {
|
|
properties.setProperty("global.sort.column", String.valueOf(col));
|
|
}
|
|
|
|
public boolean getDefaultSortAscending() {
|
|
return Boolean.parseBoolean(properties.getProperty("global.sort.ascending", "true"));
|
|
}
|
|
|
|
public void setDefaultSortAscending(boolean asc) {
|
|
properties.setProperty("global.sort.ascending", String.valueOf(asc));
|
|
}
|
|
|
|
// Hidden files ordering: true = hidden after visible (default true)
|
|
public boolean getHiddenFilesLast() {
|
|
return Boolean.parseBoolean(properties.getProperty("global.sort.hidden.last", "true"));
|
|
}
|
|
|
|
public void setHiddenFilesLast(boolean last) {
|
|
properties.setProperty("global.sort.hidden.last", String.valueOf(last));
|
|
}
|
|
|
|
// Uppercase preference: when names equal ignoring case, prefer uppercase first
|
|
public boolean getUppercasePriority() {
|
|
return Boolean.parseBoolean(properties.getProperty("global.sort.uppercase.priority", "true"));
|
|
}
|
|
|
|
public void setUppercasePriority(boolean priority) {
|
|
properties.setProperty("global.sort.uppercase.priority", String.valueOf(priority));
|
|
}
|
|
|
|
// Numeric-aware name sorting (natural sort): default true
|
|
public boolean getNumericSortEnabled() {
|
|
return Boolean.parseBoolean(properties.getProperty("global.sort.numeric.enabled", "true"));
|
|
}
|
|
|
|
public void setNumericSortEnabled(boolean enabled) {
|
|
properties.setProperty("global.sort.numeric.enabled", String.valueOf(enabled));
|
|
}
|
|
|
|
// Ignore leading dot in names when sorting (treat ".name" as "name")
|
|
public boolean getIgnoreLeadingDot() {
|
|
return Boolean.parseBoolean(properties.getProperty("global.sort.ignore.leadingdot", "false"));
|
|
}
|
|
|
|
public void setIgnoreLeadingDot(boolean enabled) {
|
|
properties.setProperty("global.sort.ignore.leadingdot", String.valueOf(enabled));
|
|
}
|
|
|
|
public int getAutoRefreshInterval() {
|
|
return Integer.parseInt(properties.getProperty("panel.autoRefreshInterval", "2000"));
|
|
}
|
|
|
|
public void setAutoRefreshInterval(int interval) {
|
|
properties.setProperty("panel.autoRefreshInterval", String.valueOf(interval));
|
|
}
|
|
|
|
// -- Multiple sort criteria persistence
|
|
public java.util.List<String> getMultipleSortCriteria() {
|
|
java.util.List<String> list = new java.util.ArrayList<>();
|
|
int count = Integer.parseInt(properties.getProperty("global.sort.criteria.count", "0"));
|
|
for (int i = 0; i < count; i++) {
|
|
String v = properties.getProperty("global.sort.criteria." + i, null);
|
|
if (v != null && !v.isEmpty()) list.add(v);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public void setMultipleSortCriteria(java.util.List<String> criteria) {
|
|
if (criteria == null || criteria.isEmpty()) {
|
|
properties.setProperty("global.sort.criteria.count", "0");
|
|
return;
|
|
}
|
|
|
|
int limit = Math.min(criteria.size(), 5); // cap stored entries
|
|
properties.setProperty("global.sort.criteria.count", String.valueOf(limit));
|
|
for (int i = 0; i < limit; i++) {
|
|
properties.setProperty("global.sort.criteria." + i, criteria.get(i));
|
|
}
|
|
|
|
// remove any old entries beyond limit
|
|
int old = Integer.parseInt(properties.getProperty("global.sort.criteria.count", "0"));
|
|
for (int i = limit; i < old; i++) {
|
|
properties.remove("global.sort.criteria." + i);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Save window state
|
|
*/
|
|
public void saveWindowState(Frame frame) {
|
|
if (frame.getExtendedState() == Frame.MAXIMIZED_BOTH) {
|
|
setWindowMaximized(true);
|
|
} else {
|
|
setWindowMaximized(false);
|
|
setWindowX(frame.getX());
|
|
setWindowY(frame.getY());
|
|
setWindowWidth(frame.getWidth());
|
|
setWindowHeight(frame.getHeight());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Restore window state
|
|
*/
|
|
public void restoreWindowState(Frame frame) {
|
|
frame.setLocation(getWindowX(), getWindowY());
|
|
frame.setSize(getWindowWidth(), getWindowHeight());
|
|
|
|
if (isWindowMaximized()) {
|
|
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
|
|
}
|
|
}
|
|
|
|
// --- Search dialog persistence ---
|
|
public int getSearchDialogX() {
|
|
return Integer.parseInt(properties.getProperty("searchDialog.x", "100"));
|
|
}
|
|
|
|
public void setSearchDialogX(int x) {
|
|
properties.setProperty("searchDialog.x", String.valueOf(x));
|
|
}
|
|
|
|
public int getSearchDialogY() {
|
|
return Integer.parseInt(properties.getProperty("searchDialog.y", "100"));
|
|
}
|
|
|
|
public void setSearchDialogY(int y) {
|
|
properties.setProperty("searchDialog.y", String.valueOf(y));
|
|
}
|
|
|
|
public int getSearchDialogWidth() {
|
|
return Integer.parseInt(properties.getProperty("searchDialog.width", "700"));
|
|
}
|
|
|
|
public void setSearchDialogWidth(int w) {
|
|
properties.setProperty("searchDialog.width", String.valueOf(w));
|
|
}
|
|
|
|
public int getSearchDialogHeight() {
|
|
return Integer.parseInt(properties.getProperty("searchDialog.height", "500"));
|
|
}
|
|
|
|
public void setSearchDialogHeight(int h) {
|
|
properties.setProperty("searchDialog.height", String.valueOf(h));
|
|
}
|
|
|
|
/** Save search dialog bounds */
|
|
public void saveSearchDialogState(Window win) {
|
|
if (win == null) return;
|
|
setSearchDialogX(win.getX());
|
|
setSearchDialogY(win.getY());
|
|
setSearchDialogWidth(win.getWidth());
|
|
setSearchDialogHeight(win.getHeight());
|
|
}
|
|
|
|
/** Restore search dialog bounds */
|
|
public void restoreSearchDialogState(Window win) {
|
|
if (win == null) return;
|
|
win.setLocation(getSearchDialogX(), getSearchDialogY());
|
|
win.setSize(getSearchDialogWidth(), getSearchDialogHeight());
|
|
}
|
|
|
|
// --- Search history persistence ---
|
|
public java.util.List<String> getSearchHistory() {
|
|
java.util.List<String> list = new java.util.ArrayList<>();
|
|
int count = Integer.parseInt(properties.getProperty("search.history.count", "0"));
|
|
for (int i = 0; i < count; i++) {
|
|
String v = properties.getProperty("search.history." + i, null);
|
|
if (v != null && !v.isEmpty()) list.add(v);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public void saveSearchHistory(java.util.List<String> history) {
|
|
if (history == null) {
|
|
properties.setProperty("search.history.count", "0");
|
|
return;
|
|
}
|
|
int limit = Math.min(history.size(), 50); // cap stored entries
|
|
properties.setProperty("search.history.count", String.valueOf(limit));
|
|
for (int i = 0; i < limit; i++) {
|
|
properties.setProperty("search.history." + i, history.get(i));
|
|
}
|
|
// remove any old entries beyond limit
|
|
int old = Integer.parseInt(properties.getProperty("search.history.count", "0"));
|
|
for (int i = limit; i < old; i++) {
|
|
properties.remove("search.history." + i);
|
|
}
|
|
}
|
|
|
|
// --- Content search history persistence ---
|
|
public java.util.List<String> getContentSearchHistory() {
|
|
java.util.List<String> list = new java.util.ArrayList<>();
|
|
int count = Integer.parseInt(properties.getProperty("search.content.history.count", "0"));
|
|
for (int i = 0; i < count; i++) {
|
|
String v = properties.getProperty("search.content.history." + i, null);
|
|
if (v != null && !v.isEmpty()) list.add(v);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public void saveContentSearchHistory(java.util.List<String> history) {
|
|
if (history == null) {
|
|
properties.setProperty("search.content.history.count", "0");
|
|
return;
|
|
}
|
|
int limit = Math.min(history.size(), 50);
|
|
properties.setProperty("search.content.history.count", String.valueOf(limit));
|
|
for (int i = 0; i < limit; i++) {
|
|
properties.setProperty("search.content.history." + i, history.get(i));
|
|
}
|
|
// remove old entries beyond limit
|
|
int old = Integer.parseInt(properties.getProperty("search.content.history.count", "0"));
|
|
for (int i = limit; i < old; i++) {
|
|
properties.remove("search.content.history." + i);
|
|
}
|
|
}
|
|
|
|
// --- Command line history persistence ---
|
|
public java.util.List<String> getCommandLineHistory() {
|
|
java.util.List<String> list = new java.util.ArrayList<>();
|
|
int count = Integer.parseInt(properties.getProperty("cmd.history.count", "0"));
|
|
for (int i = 0; i < count; i++) {
|
|
String v = properties.getProperty("cmd.history." + i, null);
|
|
if (v != null && !v.isEmpty()) list.add(v);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public void saveCommandLineHistory(java.util.List<String> history) {
|
|
if (history == null) {
|
|
properties.setProperty("cmd.history.count", "0");
|
|
return;
|
|
}
|
|
int limit = Math.min(history.size(), 50);
|
|
properties.setProperty("cmd.history.count", String.valueOf(limit));
|
|
for (int i = 0; i < limit; i++) {
|
|
properties.setProperty("cmd.history." + i, history.get(i));
|
|
}
|
|
// remove old entries beyond limit
|
|
int old = Integer.parseInt(properties.getProperty("cmd.history.count", "0"));
|
|
for (int i = limit; i < old; i++) {
|
|
properties.remove("cmd.history." + i);
|
|
}
|
|
}
|
|
|
|
// --- Toolbar shortcuts persistence ---
|
|
public static class ToolbarShortcut implements Serializable {
|
|
public String command;
|
|
public String label;
|
|
public String iconPath;
|
|
public String workingDir;
|
|
|
|
public ToolbarShortcut(String command, String label, String iconPath, String workingDir) {
|
|
this.command = command;
|
|
this.label = label;
|
|
this.iconPath = iconPath;
|
|
this.workingDir = workingDir;
|
|
}
|
|
}
|
|
|
|
public java.util.List<ToolbarShortcut> getToolbarShortcuts() {
|
|
java.util.List<ToolbarShortcut> list = new java.util.ArrayList<>();
|
|
int count = Integer.parseInt(properties.getProperty("toolbar.shortcuts.count", "0"));
|
|
for (int i = 0; i < count; i++) {
|
|
String cmd = properties.getProperty("toolbar.shortcut." + i + ".command");
|
|
String label = properties.getProperty("toolbar.shortcut." + i + ".label");
|
|
String icon = properties.getProperty("toolbar.shortcut." + i + ".iconPath");
|
|
String workDir = properties.getProperty("toolbar.shortcut." + i + ".workingDir");
|
|
if (cmd != null) {
|
|
list.add(new ToolbarShortcut(cmd, label, icon, workDir));
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public void saveToolbarShortcuts(java.util.List<ToolbarShortcut> shortcuts) {
|
|
// remove old entries first
|
|
int old = Integer.parseInt(properties.getProperty("toolbar.shortcuts.count", "0"));
|
|
for (int i = 0; i < old; i++) {
|
|
properties.remove("toolbar.shortcut." + i + ".command");
|
|
properties.remove("toolbar.shortcut." + i + ".label");
|
|
properties.remove("toolbar.shortcut." + i + ".iconPath");
|
|
properties.remove("toolbar.shortcut." + i + ".workingDir");
|
|
}
|
|
|
|
properties.setProperty("toolbar.shortcuts.count", String.valueOf(shortcuts.size()));
|
|
for (int i = 0; i < shortcuts.size(); i++) {
|
|
ToolbarShortcut s = shortcuts.get(i);
|
|
properties.setProperty("toolbar.shortcut." + i + ".command", s.command != null ? s.command : "");
|
|
properties.setProperty("toolbar.shortcut." + i + ".label", s.label != null ? s.label : "");
|
|
properties.setProperty("toolbar.shortcut." + i + ".iconPath", s.iconPath != null ? s.iconPath : "");
|
|
properties.setProperty("toolbar.shortcut." + i + ".workingDir", s.workingDir != null ? s.workingDir : "");
|
|
}
|
|
}
|
|
|
|
public String getMigrationPath() {
|
|
return properties.getProperty("migration.path", "");
|
|
}
|
|
|
|
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));
|
|
}
|
|
}
|
|
}
|
|
|
|
// --- Divider position persistence (split pane) ---
|
|
public double getDividerPosition() {
|
|
return Double.parseDouble(properties.getProperty("mainPanel.dividerPosition", "0.5"));
|
|
}
|
|
|
|
public void setDividerPosition(double position) {
|
|
properties.setProperty("mainPanel.dividerPosition", String.valueOf(position));
|
|
}
|
|
|
|
public int getMaxCompareLines() {
|
|
return Integer.parseInt(properties.getProperty("compare.maxLines", "10000"));
|
|
}
|
|
|
|
public void setMaxCompareLines(int lines) {
|
|
properties.setProperty("compare.maxLines", String.valueOf(lines));
|
|
}
|
|
}
|