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.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings dialog with categories on the left and parameters on the right.
|
* 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(appearanceFontBtn);
|
||||||
|
|
||||||
grid.add(new JLabel("Background color:"));
|
grid.add(new JLabel("Background color:"));
|
||||||
appearanceBgBtn = new JButton();
|
appearanceBgBtn = createColorButton(config.getBackgroundColor(), "Choose background color", c -> {
|
||||||
appearanceBgBtn.setOpaque(true);
|
config.setBackgroundColor(c);
|
||||||
appearanceBgBtn.setContentAreaFilled(false);
|
if (onChange != null) onChange.run();
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
grid.add(appearanceBgBtn);
|
grid.add(appearanceBgBtn);
|
||||||
|
|
||||||
grid.add(new JLabel("Selection color:"));
|
grid.add(new JLabel("Selection color:"));
|
||||||
appearanceSelBtn = new JButton();
|
appearanceSelBtn = createColorButton(config.getSelectionColor() != null ? config.getSelectionColor() : new Color(184, 207, 229),
|
||||||
appearanceSelBtn.setOpaque(true);
|
"Choose selection color", c -> {
|
||||||
appearanceSelBtn.setContentAreaFilled(false);
|
config.setSelectionColor(c);
|
||||||
appearanceSelBtn.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
if (onChange != null) onChange.run();
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
grid.add(appearanceSelBtn);
|
grid.add(appearanceSelBtn);
|
||||||
|
|
||||||
grid.add(new JLabel("Marked item color:"));
|
grid.add(new JLabel("Marked item color:"));
|
||||||
appearanceMarkBtn = new JButton();
|
appearanceMarkBtn = createColorButton(config.getMarkedColor() != null ? config.getMarkedColor() : new Color(204, 153, 0),
|
||||||
appearanceMarkBtn.setOpaque(true);
|
"Choose marked item color", c -> {
|
||||||
appearanceMarkBtn.setContentAreaFilled(false);
|
config.setMarkedColor(c);
|
||||||
appearanceMarkBtn.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
if (onChange != null) onChange.run();
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
grid.add(appearanceMarkBtn);
|
grid.add(appearanceMarkBtn);
|
||||||
|
|
||||||
@ -244,6 +217,38 @@ public class SettingsDialog extends JDialog {
|
|||||||
return p;
|
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() {
|
private JPanel buildEditorPanel() {
|
||||||
JPanel p = new JPanel(new BorderLayout(8, 8));
|
JPanel p = new JPanel(new BorderLayout(8, 8));
|
||||||
JPanel grid = new JPanel(new GridLayout(2, 2, 8, 8));
|
JPanel grid = new JPanel(new GridLayout(2, 2, 8, 8));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user