fixed settings color buttons
This commit is contained in:
parent
0fc9a543d5
commit
aac1531fae
@ -7,6 +7,7 @@ import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Settings dialog with categories on the left and parameters on the right.
|
||||
@ -189,53 +190,25 @@ public class SettingsDialog extends JDialog {
|
||||
grid.add(appearanceFontBtn);
|
||||
|
||||
grid.add(new JLabel("Background color:"));
|
||||
appearanceBgBtn = new JButton();
|
||||
appearanceBgBtn.setOpaque(true);
|
||||
appearanceBgBtn.setContentAreaFilled(false);
|
||||
appearanceBgBtn.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
||||
Color bg = config.getBackgroundColor();
|
||||
appearanceBgBtn.setBackground(bg != null ? bg : UIManager.getColor("Panel.background"));
|
||||
appearanceBgBtn.addActionListener(e -> {
|
||||
Color chosen = JColorChooser.showDialog(this, "Choose background color", appearanceBgBtn.getBackground());
|
||||
if (chosen != null) {
|
||||
config.setBackgroundColor(chosen);
|
||||
appearanceBgBtn.setBackground(chosen);
|
||||
if (onChange != null) onChange.run();
|
||||
}
|
||||
appearanceBgBtn = createColorButton(config.getBackgroundColor(), "Choose background color", c -> {
|
||||
config.setBackgroundColor(c);
|
||||
if (onChange != null) onChange.run();
|
||||
});
|
||||
grid.add(appearanceBgBtn);
|
||||
|
||||
grid.add(new JLabel("Selection color:"));
|
||||
appearanceSelBtn = new JButton();
|
||||
appearanceSelBtn.setOpaque(true);
|
||||
appearanceSelBtn.setContentAreaFilled(false);
|
||||
appearanceSelBtn.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
||||
Color sel = config.getSelectionColor();
|
||||
appearanceSelBtn.setBackground(sel != null ? sel : new Color(184, 207, 229));
|
||||
appearanceSelBtn.addActionListener(e -> {
|
||||
Color chosen = JColorChooser.showDialog(this, "Choose selection color", appearanceSelBtn.getBackground());
|
||||
if (chosen != null) {
|
||||
config.setSelectionColor(chosen);
|
||||
appearanceSelBtn.setBackground(chosen);
|
||||
if (onChange != null) onChange.run();
|
||||
}
|
||||
appearanceSelBtn = createColorButton(config.getSelectionColor() != null ? config.getSelectionColor() : new Color(184, 207, 229),
|
||||
"Choose selection color", c -> {
|
||||
config.setSelectionColor(c);
|
||||
if (onChange != null) onChange.run();
|
||||
});
|
||||
grid.add(appearanceSelBtn);
|
||||
|
||||
grid.add(new JLabel("Marked item color:"));
|
||||
appearanceMarkBtn = new JButton();
|
||||
appearanceMarkBtn.setOpaque(true);
|
||||
appearanceMarkBtn.setContentAreaFilled(false);
|
||||
appearanceMarkBtn.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
||||
Color mark = config.getMarkedColor();
|
||||
appearanceMarkBtn.setBackground(mark != null ? mark : new Color(204, 153, 0));
|
||||
appearanceMarkBtn.addActionListener(e -> {
|
||||
Color chosen = JColorChooser.showDialog(this, "Choose marked item color", appearanceMarkBtn.getBackground());
|
||||
if (chosen != null) {
|
||||
config.setMarkedColor(chosen);
|
||||
appearanceMarkBtn.setBackground(chosen);
|
||||
if (onChange != null) onChange.run();
|
||||
}
|
||||
appearanceMarkBtn = createColorButton(config.getMarkedColor() != null ? config.getMarkedColor() : new Color(204, 153, 0),
|
||||
"Choose marked item color", c -> {
|
||||
config.setMarkedColor(c);
|
||||
if (onChange != null) onChange.run();
|
||||
});
|
||||
grid.add(appearanceMarkBtn);
|
||||
|
||||
@ -244,6 +217,38 @@ public class SettingsDialog extends JDialog {
|
||||
return p;
|
||||
}
|
||||
|
||||
private JButton createColorButton(Color initialColor, String title, Consumer<Color> onColorChosen) {
|
||||
JButton btn = new JButton(" ") {
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
if (getModel().isRollover()) {
|
||||
g.setColor(new Color(255, 255, 255, 60));
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
}
|
||||
if (getModel().isPressed()) {
|
||||
g.setColor(new Color(0, 0, 0, 60));
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
}
|
||||
}
|
||||
};
|
||||
btn.setOpaque(true);
|
||||
btn.setContentAreaFilled(false);
|
||||
btn.setFocusPainted(false);
|
||||
btn.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
||||
btn.setPreferredSize(new Dimension(80, 25));
|
||||
btn.setBackground(initialColor != null ? initialColor : UIManager.getColor("Panel.background"));
|
||||
btn.addActionListener(e -> {
|
||||
Color chosen = JColorChooser.showDialog(this, title, btn.getBackground());
|
||||
if (chosen != null) {
|
||||
btn.setBackground(chosen);
|
||||
onColorChosen.accept(chosen);
|
||||
}
|
||||
});
|
||||
return btn;
|
||||
}
|
||||
|
||||
private JPanel buildEditorPanel() {
|
||||
JPanel p = new JPanel(new BorderLayout(8, 8));
|
||||
JPanel grid = new JPanel(new GridLayout(2, 2, 8, 8));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user