linux UI dark theme fixes
This commit is contained in:
parent
8370e1cf76
commit
eec2973b0a
@ -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 {
|
||||
// On Linux and macOS, use FlatLaf as a better-looking alternative
|
||||
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 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) {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user