Skip to content

Commit

Permalink
wip ColorChooserComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
clagomess committed Mar 11, 2024
1 parent d7c4df8 commit e3ae152
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
package com.github.clagomess.pirilampo.gui.component;

import lombok.Getter;
import net.miginfocom.swing.MigLayout;
import org.apache.commons.lang.StringUtils;

import javax.swing.*;
import javax.swing.colorchooser.AbstractColorChooserPanel;
import java.awt.*;

public class ColorChooserComponent extends JPanel {
private final JPanel color = new JPanel();
private final JTextField text = new JTextField();
private final JButton button = new JButton("Select");

public ColorChooserComponent(){
@Getter
private String value;

public ColorChooserComponent(String label, String defaultColor){
setLayout(new MigLayout("insets 0 0 0 0", "[grow,fill]"));

value = StringUtils.isNotBlank(text.getText()) ? text.getText() : defaultColor;
text.setText(value);
color.setBackground(Color.decode(value));

button.addActionListener(l -> {
JColorChooser.showDialog(null, "aa", Color.WHITE);
JColorChooser pane = new JColorChooser(Color.decode(value));

AbstractColorChooserPanel[] defaultPanels = pane.getChooserPanels();
pane.removeChooserPanel(defaultPanels[4]);
pane.removeChooserPanel(defaultPanels[2]);
pane.removeChooserPanel(defaultPanels[1]);

JColorChooser.createDialog(null, label, true, pane, a -> {
value = "#" + String.format("%06X", 0xFFFFFF & pane.getColor().getRGB());
text.setText(value);
color.setBackground(pane.getColor());
},null).setVisible(true);
});

add(color);
add(text, "width 100%");
add(button);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ public class MainForm {
));

public final JCheckBox chkEmbedImages = new JCheckBox();
public final ColorChooserComponent ccMenuColor = new ColorChooserComponent();
public final ColorChooserComponent ccMenuTextColor = new ColorChooserComponent();
public final ColorChooserComponent ccMenuColor = new ColorChooserComponent(
"Menu Color",
defaultDto.getMenuColor()
);
public final ColorChooserComponent ccMenuTextColor = new ColorChooserComponent(
"Menu Text Coloer",
defaultDto.getMenuTextColor()
);

// PDF
public final RadioButtonGroupComponent<LayoutPdfEnum> rbLayoutPdfEnum = new RadioButtonGroupComponent<>(Arrays.asList(
Expand Down

0 comments on commit e3ae152

Please sign in to comment.