From e3ae1523cb08f04817dac0f6ad1d42463d322b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A1udio=20Gomes?= Date: Mon, 11 Mar 2024 18:26:17 -0300 Subject: [PATCH] wip ColorChooserComponent --- .../gui/component/ColorChooserComponent.java | 27 +++++++++++++++++-- .../pirilampo/gui/form/MainForm.java | 10 +++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/gui/src/main/java/com/github/clagomess/pirilampo/gui/component/ColorChooserComponent.java b/gui/src/main/java/com/github/clagomess/pirilampo/gui/component/ColorChooserComponent.java index 7b5e60e..77ad710 100644 --- a/gui/src/main/java/com/github/clagomess/pirilampo/gui/component/ColorChooserComponent.java +++ b/gui/src/main/java/com/github/clagomess/pirilampo/gui/component/ColorChooserComponent.java @@ -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); } diff --git a/gui/src/main/java/com/github/clagomess/pirilampo/gui/form/MainForm.java b/gui/src/main/java/com/github/clagomess/pirilampo/gui/form/MainForm.java index 67f2b88..2f4fa05 100644 --- a/gui/src/main/java/com/github/clagomess/pirilampo/gui/form/MainForm.java +++ b/gui/src/main/java/com/github/clagomess/pirilampo/gui/form/MainForm.java @@ -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 rbLayoutPdfEnum = new RadioButtonGroupComponent<>(Arrays.asList(