cursor visibility
This commit is contained in:
parent
3645fdc78b
commit
38aa55c463
@ -58,6 +58,26 @@ public class MainApp {
|
|||||||
}, AWTEvent.KEY_EVENT_MASK);
|
}, AWTEvent.KEY_EVENT_MASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to set reflective caret color for all text components in a container
|
||||||
|
*/
|
||||||
|
public static void applyReflectiveCaretColor(Container container) {
|
||||||
|
if (container == null) return;
|
||||||
|
for (Component c : container.getComponents()) {
|
||||||
|
if (c instanceof javax.swing.text.JTextComponent) {
|
||||||
|
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c;
|
||||||
|
Color bg = tc.getBackground();
|
||||||
|
if (bg != null) {
|
||||||
|
double darkness = 1 - (0.299 * bg.getRed() + 0.587 * bg.getGreen() + 0.114 * bg.getBlue()) / 255;
|
||||||
|
tc.setCaretColor(darkness >= 0.5 ? Color.WHITE : Color.BLACK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (c instanceof Container) {
|
||||||
|
applyReflectiveCaretColor((Container) c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isInsideJOptionPane(Component c) {
|
private static boolean isInsideJOptionPane(Component c) {
|
||||||
Component parent = c;
|
Component parent = c;
|
||||||
while (parent != null) {
|
while (parent != null) {
|
||||||
|
|||||||
@ -382,12 +382,18 @@ public class FileEditor extends JDialog {
|
|||||||
if (container == null) return;
|
if (container == null) return;
|
||||||
container.setBackground(bg);
|
container.setBackground(bg);
|
||||||
for (Component c : container.getComponents()) {
|
for (Component c : container.getComponents()) {
|
||||||
if (c instanceof JPanel || c instanceof JScrollPane || c instanceof JViewport) {
|
if (c instanceof JPanel || c instanceof JScrollPane || c instanceof JViewport || c instanceof JToolBar) {
|
||||||
c.setBackground(bg);
|
c.setBackground(bg);
|
||||||
}
|
}
|
||||||
if (c instanceof JLabel) {
|
if (c instanceof JLabel) {
|
||||||
c.setForeground(dark ? Color.WHITE : Color.BLACK);
|
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) {
|
if (c instanceof Container) {
|
||||||
applyRecursiveColors((Container) c, bg, dark);
|
applyRecursiveColors((Container) c, bg, dark);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,6 +83,14 @@ public class FilePanelTab extends JPanel {
|
|||||||
Component ed = fileTable.getEditorComponent();
|
Component ed = fileTable.getEditorComponent();
|
||||||
if (ed instanceof JTextField) {
|
if (ed instanceof JTextField) {
|
||||||
JTextField tf = (JTextField) ed;
|
JTextField tf = (JTextField) ed;
|
||||||
|
|
||||||
|
// Ensure caret is visible
|
||||||
|
Color bg = tf.getBackground();
|
||||||
|
if (bg != null) {
|
||||||
|
double darkness = 1 - (0.299 * bg.getRed() + 0.587 * bg.getGreen() + 0.114 * bg.getBlue()) / 255;
|
||||||
|
tf.setCaretColor(darkness >= 0.5 ? Color.WHITE : Color.BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
String text = tf.getText();
|
String text = tf.getText();
|
||||||
int lastDot = text.lastIndexOf('.');
|
int lastDot = text.lastIndexOf('.');
|
||||||
if (lastDot > 0) { // Found a dot, and it's not the first character
|
if (lastDot > 0) { // Found a dot, and it's not the first character
|
||||||
@ -123,6 +131,14 @@ public class FilePanelTab extends JPanel {
|
|||||||
Component ed = fileTable.getEditorComponent();
|
Component ed = fileTable.getEditorComponent();
|
||||||
if (ed instanceof JTextField) {
|
if (ed instanceof JTextField) {
|
||||||
JTextField tf = (JTextField) ed;
|
JTextField tf = (JTextField) ed;
|
||||||
|
|
||||||
|
// Ensure caret is visible
|
||||||
|
Color bg = tf.getBackground();
|
||||||
|
if (bg != null) {
|
||||||
|
double darkness = 1 - (0.299 * bg.getRed() + 0.587 * bg.getGreen() + 0.114 * bg.getBlue()) / 255;
|
||||||
|
tf.setCaretColor(darkness >= 0.5 ? Color.WHITE : Color.BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
tf.requestFocusInWindow();
|
tf.requestFocusInWindow();
|
||||||
tf.selectAll();
|
tf.selectAll();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package cz.kamma.kfmanager.ui;
|
package cz.kamma.kfmanager.ui;
|
||||||
|
|
||||||
|
import cz.kamma.kfmanager.MainApp;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ public class FontChooserDialog extends JDialog {
|
|||||||
selectFont(initialFont);
|
selectFont(initialFont);
|
||||||
|
|
||||||
setSize(600, 400);
|
setSize(600, 400);
|
||||||
|
MainApp.applyReflectiveCaretColor(getContentPane());
|
||||||
setLocationRelativeTo(parent);
|
setLocationRelativeTo(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -638,6 +638,7 @@ public class MainWindow extends JFrame {
|
|||||||
panel.add(iconPanel);
|
panel.add(iconPanel);
|
||||||
|
|
||||||
String title = (existing != null) ? "Edit Toolbar Shortcut" : "Add Toolbar Shortcut";
|
String title = (existing != null) ? "Edit Toolbar Shortcut" : "Add Toolbar Shortcut";
|
||||||
|
cz.kamma.kfmanager.MainApp.applyReflectiveCaretColor(panel);
|
||||||
int result = JOptionPane.showConfirmDialog(this, panel, title, JOptionPane.OK_CANCEL_OPTION);
|
int result = JOptionPane.showConfirmDialog(this, panel, title, JOptionPane.OK_CANCEL_OPTION);
|
||||||
if (result == JOptionPane.OK_OPTION) {
|
if (result == JOptionPane.OK_OPTION) {
|
||||||
String label = labelField.getText().trim();
|
String label = labelField.getText().trim();
|
||||||
@ -861,10 +862,8 @@ public class MainWindow extends JFrame {
|
|||||||
Color selColor = config.getSelectionColor();
|
Color selColor = config.getSelectionColor();
|
||||||
if (selColor != null) {
|
if (selColor != null) {
|
||||||
tf.setSelectionColor(selColor);
|
tf.setSelectionColor(selColor);
|
||||||
tf.setCaretColor(selColor);
|
|
||||||
} else {
|
|
||||||
tf.setCaretColor(dark ? Color.WHITE : Color.BLACK);
|
|
||||||
}
|
}
|
||||||
|
tf.setCaretColor(dark ? Color.WHITE : Color.BLACK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -875,13 +874,15 @@ public class MainWindow extends JFrame {
|
|||||||
if (leftPanel != null) leftPanel.applySelectionColor(sel);
|
if (leftPanel != null) leftPanel.applySelectionColor(sel);
|
||||||
if (rightPanel != null) rightPanel.applySelectionColor(sel);
|
if (rightPanel != null) rightPanel.applySelectionColor(sel);
|
||||||
|
|
||||||
// Apply selection color to command line editor for cursor and selection
|
// Apply selection color to command line editor for selection
|
||||||
if (commandLine != null) {
|
if (commandLine != null) {
|
||||||
Component ed = commandLine.getEditor().getEditorComponent();
|
Component ed = commandLine.getEditor().getEditorComponent();
|
||||||
if (ed instanceof JTextField) {
|
if (ed instanceof JTextField) {
|
||||||
JTextField tf = (JTextField) ed;
|
JTextField tf = (JTextField) ed;
|
||||||
tf.setSelectionColor(sel);
|
tf.setSelectionColor(sel);
|
||||||
tf.setCaretColor(sel);
|
Color fieldBg = tf.getBackground();
|
||||||
|
boolean darkField = isDark(fieldBg);
|
||||||
|
tf.setCaretColor(darkField ? Color.WHITE : Color.BLACK);
|
||||||
tf.setSelectedTextColor(Color.WHITE); // Ensure selected text is readable on selection bg
|
tf.setSelectedTextColor(Color.WHITE); // Ensure selected text is readable on selection bg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -927,11 +928,9 @@ public class MainWindow extends JFrame {
|
|||||||
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c;
|
javax.swing.text.JTextComponent tc = (javax.swing.text.JTextComponent) c;
|
||||||
tc.setBackground(bg);
|
tc.setBackground(bg);
|
||||||
tc.setForeground(dark ? Color.WHITE : Color.BLACK);
|
tc.setForeground(dark ? Color.WHITE : Color.BLACK);
|
||||||
|
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
|
||||||
if (selColor != null) {
|
if (selColor != null) {
|
||||||
tc.setSelectionColor(selColor);
|
tc.setSelectionColor(selColor);
|
||||||
tc.setCaretColor(selColor);
|
|
||||||
} else {
|
|
||||||
tc.setCaretColor(dark ? Color.WHITE : Color.BLACK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c instanceof Container) {
|
if (c instanceof Container) {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package cz.kamma.kfmanager.ui;
|
package cz.kamma.kfmanager.ui;
|
||||||
|
|
||||||
|
import cz.kamma.kfmanager.MainApp;
|
||||||
import cz.kamma.kfmanager.model.FileItem;
|
import cz.kamma.kfmanager.model.FileItem;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@ -33,6 +34,8 @@ public class PropertiesDialog extends JDialog {
|
|||||||
|
|
||||||
initComponents();
|
initComponents();
|
||||||
|
|
||||||
|
MainApp.applyReflectiveCaretColor(getContentPane());
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
setMinimumSize(new Dimension(500, 550));
|
setMinimumSize(new Dimension(500, 550));
|
||||||
setLocationRelativeTo(owner);
|
setLocationRelativeTo(owner);
|
||||||
|
|||||||
@ -58,8 +58,60 @@ public class SearchDialog extends JDialog {
|
|||||||
setSize(700, 500);
|
setSize(700, 500);
|
||||||
setLocationRelativeTo(parent);
|
setLocationRelativeTo(parent);
|
||||||
}
|
}
|
||||||
|
applyAppearance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.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 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;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 initComponents() {
|
private void initComponents() {
|
||||||
setLayout(new BorderLayout(10, 10));
|
setLayout(new BorderLayout(10, 10));
|
||||||
((JComponent) getContentPane()).setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
((JComponent) getContentPane()).setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||||
|
|||||||
@ -105,6 +105,8 @@ public class SettingsDialog extends JDialog {
|
|||||||
|
|
||||||
add(split, BorderLayout.CENTER);
|
add(split, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
applyAppearance();
|
||||||
|
|
||||||
JPanel btns = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
JPanel btns = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||||
JButton ok = new JButton("OK");
|
JButton ok = new JButton("OK");
|
||||||
ok.addActionListener(e -> {
|
ok.addActionListener(e -> {
|
||||||
@ -249,6 +251,47 @@ public class SettingsDialog 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 JSplitPane || c instanceof JList) {
|
||||||
|
c.setBackground(bg);
|
||||||
|
}
|
||||||
|
if (c instanceof JLabel || c instanceof JCheckBox || c instanceof JRadioButton || c instanceof JButton || 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 (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 JPanel buildAppearancePanel() {
|
private JPanel buildAppearancePanel() {
|
||||||
JPanel p = new JPanel(new BorderLayout(8, 8));
|
JPanel p = new JPanel(new BorderLayout(8, 8));
|
||||||
JPanel grid = new JPanel(new GridBagLayout());
|
JPanel grid = new JPanel(new GridBagLayout());
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package cz.kamma.kfmanager.ui;
|
package cz.kamma.kfmanager.ui;
|
||||||
|
|
||||||
|
import cz.kamma.kfmanager.MainApp;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
@ -15,6 +16,9 @@ public class WildcardSelectDialog extends JDialog {
|
|||||||
public WildcardSelectDialog(Frame parent) {
|
public WildcardSelectDialog(Frame parent) {
|
||||||
super(parent, "Vybrat podle masky", true);
|
super(parent, "Vybrat podle masky", true);
|
||||||
initComponents();
|
initComponents();
|
||||||
|
|
||||||
|
MainApp.applyReflectiveCaretColor(getContentPane());
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
setLocationRelativeTo(parent);
|
setLocationRelativeTo(parent);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user