diff --git a/src/main/java/cz/kamma/kfmanager/MainApp.java b/src/main/java/cz/kamma/kfmanager/MainApp.java index 611f5a3..961bca3 100644 --- a/src/main/java/cz/kamma/kfmanager/MainApp.java +++ b/src/main/java/cz/kamma/kfmanager/MainApp.java @@ -49,8 +49,22 @@ public class MainApp { } else { FlatLightLaf.setup(); } + } else if (CURRENT_OS == OS.LINUX) { + // On Linux, use FlatLaf and detect system theme (light/dark) + if (isLinuxDarkMode()) { + FlatDarkLaf.setup(); + } else { + FlatLightLaf.setup(); + } + } else if (CURRENT_OS == OS.MACOS) { + // On macOS, use FlatLaf and detect system theme (light/dark) + if (isMacDarkMode()) { + FlatDarkLaf.setup(); + } else { + FlatLightLaf.setup(); + } } else { - // On Linux and macOS, use FlatLaf as a better-looking alternative + // On other OS, use FlatLaf as a better-looking alternative // to the default system L&F FlatLightLaf.setup(); } @@ -88,6 +102,40 @@ public class MainApp { return false; } + private static boolean isLinuxDarkMode() { + try { + // Check for GNOME/Cinnamon/MATE dark mode preference via gsettings + Process process = Runtime.getRuntime().exec(new String[]{"gsettings", "get", "org.gnome.desktop.interface", "color-scheme"}); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { + String line = reader.readLine(); + if (line != null && line.contains("dark")) return true; + } + + // Fallback: Check GTK theme name + process = Runtime.getRuntime().exec(new String[]{"gsettings", "get", "org.gnome.desktop.interface", "gtk-theme"}); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { + String line = reader.readLine(); + if (line != null && line.toLowerCase().contains("dark")) return true; + } + } catch (Exception e) { + // ignore + } + return false; + } + + private static boolean isMacDarkMode() { + try { + Process process = Runtime.getRuntime().exec(new String[]{"defaults", "read", "-g", "AppleInterfaceStyle"}); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { + String line = reader.readLine(); + return line != null && line.contains("Dark"); + } + } catch (Exception e) { + // ignore + } + return false; + } + private static void setupGlobalKeyNavigation() { Toolkit.getDefaultToolkit().addAWTEventListener(event -> { if (event instanceof KeyEvent) { diff --git a/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java b/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java index 7852000..5290896 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java +++ b/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java @@ -216,11 +216,28 @@ public class FilePanelTab extends JPanel { container.setBackground(bg); boolean dark = isDark(bg); for (Component c : container.getComponents()) { - if (c instanceof JPanel || c instanceof JToolBar || c instanceof JScrollPane || c instanceof JViewport || c instanceof JTabbedPane) { + if (c instanceof JPanel || c instanceof JToolBar || c instanceof JScrollPane || c instanceof JViewport || + c instanceof JTabbedPane || c instanceof JSplitPane || c instanceof JList || + c instanceof JComboBox || c instanceof JTable || c instanceof JButton) { c.setBackground(bg); - } else if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton) { + if (c instanceof JTable) { + JTable t = (JTable) c; + if (t.getTableHeader() != null) { + t.getTableHeader().setBackground(bg); + t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK); + } + } + } + if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || + c instanceof JButton || c instanceof JComboBox || c instanceof JList) { 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 (c instanceof Container) { updateComponentBackground((Container) c, bg); } diff --git a/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java b/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java index acbef7c..2de29c4 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java +++ b/src/main/java/cz/kamma/kfmanager/ui/MainWindow.java @@ -1016,10 +1016,20 @@ public class MainWindow extends JFrame { Color selColor = config != null ? config.getSelectionColor() : null; for (Component c : container.getComponents()) { - if (c instanceof JPanel || c instanceof JToolBar || c instanceof JScrollPane || c instanceof JViewport || c instanceof JTabbedPane || c instanceof JButton) { + if (c instanceof JPanel || c instanceof JToolBar || c instanceof JScrollPane || c instanceof JViewport || + c instanceof JTabbedPane || c instanceof JButton || c instanceof JSplitPane || + c instanceof JList || c instanceof JComboBox || c instanceof JTable) { c.setBackground(bg); + if (c instanceof JTable) { + JTable t = (JTable) c; + if (t.getTableHeader() != null) { + t.getTableHeader().setBackground(bg); + t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK); + } + } } - if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || c instanceof JButton) { + if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || + c instanceof JButton || c instanceof JComboBox || c instanceof JList) { c.setForeground(dark ? Color.WHITE : Color.BLACK); } if (c instanceof javax.swing.text.JTextComponent) { @@ -1031,6 +1041,19 @@ public class MainWindow extends JFrame { tc.setSelectionColor(selColor); } } + if (c instanceof JComboBox) { + JComboBox cb = (JComboBox) c; + Component ed = cb.getEditor().getEditorComponent(); + if (ed instanceof javax.swing.text.JTextComponent) { + javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) ed; + 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); } diff --git a/src/main/java/cz/kamma/kfmanager/ui/SearchDialog.java b/src/main/java/cz/kamma/kfmanager/ui/SearchDialog.java index 55edd0c..ef853bf 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/SearchDialog.java +++ b/src/main/java/cz/kamma/kfmanager/ui/SearchDialog.java @@ -75,10 +75,20 @@ public class SearchDialog extends JDialog { 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) { + if (c instanceof JPanel || c instanceof JToolBar || c instanceof JScrollPane || c instanceof JViewport || + c instanceof JTabbedPane || c instanceof JButton || c instanceof JSplitPane || + c instanceof JList || c instanceof JComboBox || c instanceof JTable) { c.setBackground(bg); + if (c instanceof JTable) { + JTable t = (JTable) c; + if (t.getTableHeader() != null) { + t.getTableHeader().setBackground(bg); + t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK); + } + } } - if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || c instanceof JButton) { + if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || + c instanceof JButton || c instanceof JComboBox || c instanceof JList) { c.setForeground(dark ? Color.WHITE : Color.BLACK); } if (c instanceof javax.swing.text.JTextComponent) { @@ -92,12 +102,15 @@ public class SearchDialog extends JDialog { } if (c instanceof JComboBox) { JComboBox cb = (JComboBox) c; - Component editor = cb.getEditor().getEditorComponent(); - if (editor instanceof javax.swing.text.JTextComponent) { - javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) editor; + Component ed = cb.getEditor().getEditorComponent(); + if (ed instanceof javax.swing.text.JTextComponent) { + javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) ed; 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) { diff --git a/src/main/java/cz/kamma/kfmanager/ui/SettingsDialog.java b/src/main/java/cz/kamma/kfmanager/ui/SettingsDialog.java index 4d2ac71..c90e1d5 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/SettingsDialog.java +++ b/src/main/java/cz/kamma/kfmanager/ui/SettingsDialog.java @@ -275,10 +275,20 @@ public class SettingsDialog extends JDialog { continue; } - if (c instanceof JPanel || c instanceof JScrollPane || c instanceof JViewport || c instanceof JTabbedPane || c instanceof JButton || c instanceof JSplitPane || c instanceof JList) { + if (c instanceof JPanel || c instanceof JToolBar || c instanceof JScrollPane || c instanceof JViewport || + c instanceof JTabbedPane || c instanceof JButton || c instanceof JSplitPane || + c instanceof JList || c instanceof JComboBox || c instanceof JTable) { c.setBackground(bg); + if (c instanceof JTable) { + JTable t = (JTable) c; + if (t.getTableHeader() != null) { + t.getTableHeader().setBackground(bg); + t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK); + } + } } - if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || c instanceof JButton || c instanceof JList) { + if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || + c instanceof JButton || c instanceof JComboBox || c instanceof JList) { c.setForeground(dark ? Color.WHITE : Color.BLACK); } if (c instanceof javax.swing.text.JTextComponent) { @@ -290,6 +300,19 @@ public class SettingsDialog extends JDialog { tc.setSelectionColor(selColor); } } + if (c instanceof JComboBox) { + JComboBox cb = (JComboBox) c; + Component ed = cb.getEditor().getEditorComponent(); + if (ed instanceof javax.swing.text.JTextComponent) { + javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) ed; + 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); } diff --git a/src/main/java/cz/kamma/kfmanager/ui/SyncDirectoriesDialog.java b/src/main/java/cz/kamma/kfmanager/ui/SyncDirectoriesDialog.java index a1c8acb..fcbab12 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/SyncDirectoriesDialog.java +++ b/src/main/java/cz/kamma/kfmanager/ui/SyncDirectoriesDialog.java @@ -279,12 +279,22 @@ public class SyncDirectoriesDialog extends JDialog { 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 AbstractButton || c instanceof JComboBox || c instanceof JTable) { + if (c instanceof JPanel || c instanceof JToolBar || c instanceof JScrollPane || c instanceof JViewport || + c instanceof JTabbedPane || c instanceof AbstractButton || c instanceof JSplitPane || + c instanceof JList || c instanceof JComboBox || c instanceof JTable) { if (!(c instanceof JToggleButton)) { c.setBackground(bg); } + if (c instanceof JTable) { + JTable t = (JTable) c; + if (t.getTableHeader() != null) { + t.getTableHeader().setBackground(bg); + t.getTableHeader().setForeground(dark ? Color.WHITE : Color.BLACK); + } + } } - if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || c instanceof AbstractButton) { + if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || + c instanceof AbstractButton || c instanceof JComboBox || c instanceof JList) { if (!(c instanceof JToggleButton)) { c.setForeground(dark ? Color.WHITE : Color.BLACK); } @@ -298,6 +308,19 @@ public class SyncDirectoriesDialog extends JDialog { tc.setSelectionColor(selColor); } } + if (c instanceof JComboBox) { + JComboBox cb = (JComboBox) c; + Component ed = cb.getEditor().getEditorComponent(); + if (ed instanceof javax.swing.text.JTextComponent) { + javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) ed; + 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); }