syncdir design improved

This commit is contained in:
rdavidek 2026-01-21 19:33:27 +01:00
parent db8ae16f01
commit 3471f7ad68

View File

@ -38,6 +38,7 @@ public class SyncDirectoriesDialog extends JDialog {
initComponents(leftDir, rightDir);
config.restoreSyncDialogState(this);
if (getBounds().x == -1) setLocationRelativeTo(owner);
applyAppearance();
addWindowListener(new WindowAdapter() {
@Override
@ -204,6 +205,49 @@ public class SyncDirectoriesDialog extends JDialog {
}
}
private void applyAppearance() {
if (config == null) return;
Color bg = config.getBackgroundColor();
if (bg == null) return;
updateComponentBackground(getContentPane(), bg);
}
private void updateComponentBackground(Container container, Color bg) {
if (container == null) return;
container.setBackground(bg);
boolean dark = isDark(bg);
Color selColor = config != null ? config.getSelectionColor() : null;
for (Component c : container.getComponents()) {
if (c instanceof JPanel || c instanceof JScrollPane || c instanceof JViewport || c instanceof JTabbedPane || c instanceof JButton || c instanceof JComboBox || c instanceof JTable) {
if (!(c instanceof JToggleButton)) {
c.setBackground(bg);
}
}
if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || c instanceof JButton) {
c.setForeground(dark ? Color.WHITE : Color.BLACK);
}
if (c instanceof javax.swing.text.JTextComponent) {
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c;
tc.setBackground(bg);
tc.setForeground(dark ? Color.WHITE : Color.BLACK);
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
if (selColor != null) {
tc.setSelectionColor(selColor);
}
}
if (c instanceof Container) {
updateComponentBackground((Container) c, bg);
}
}
}
private boolean isDark(Color c) {
if (c == null) return false;
double darkness = 1 - (0.299 * c.getRed() + 0.587 * c.getGreen() + 0.114 * c.getBlue()) / 255;
return darkness >= 0.5;
}
private void browsePath(JTextField field) {
JFileChooser chooser = new JFileChooser(field.getText());
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
@ -421,21 +465,30 @@ public class SyncDirectoriesDialog extends JDialog {
}
private static class SyncTableCellRenderer extends DefaultTableCellRenderer {
private boolean isDark(Color c) {
if (c == null) return false;
double darkness = 1 - (0.299 * c.getRed() + 0.587 * c.getGreen() + 0.114 * c.getBlue()) / 255;
return darkness >= 0.5;
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSel, boolean hasFocus, int row, int col) {
Component c = super.getTableCellRendererComponent(table, value, isSel, hasFocus, row, col);
SyncTableModel model = (SyncTableModel) table.getModel();
SyncEntry entry = model.entries.get(row);
boolean dark = isDark(table.getBackground());
if (!isSel) {
if ("=".equals(entry.relation)) {
c.setForeground(Color.BLACK);
c.setForeground(dark ? Color.WHITE : Color.BLACK);
} else if ("!=".equals(entry.relation)) {
c.setForeground(Color.RED);
c.setForeground(dark ? new Color(255, 120, 120) : Color.RED);
} else if ("->".equals(entry.relation)) {
c.setForeground(new Color(0, 100, 0)); // Dark green
// Left only / newer
c.setForeground(dark ? new Color(120, 255, 120) : new Color(0, 130, 0));
} else if ("<-".equals(entry.relation)) {
c.setForeground(Color.BLUE);
// Right only / newer
c.setForeground(dark ? new Color(130, 180, 255) : Color.BLUE);
}
}
@ -448,6 +501,10 @@ public class SyncDirectoriesDialog extends JDialog {
setHorizontalAlignment(LEFT);
}
if (c instanceof JComponent) {
((JComponent) c).setBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, dark ? new Color(60, 60, 60) : new Color(220, 220, 220)));
}
return c;
}
}