/*
 * Copyright (c) 2024. Elex. All Rights Reesrved.
 * https://www.elex-project.com/
 */

package com.elex_project.examples.components.chooser;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ColorChooser2Example extends JPanel {
	public ColorChooser2Example() {
		super(new BorderLayout());

		final JLabel label = new JLabel("Welcome", JLabel.CENTER);
		label.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
		final JButton button = new JButton("Open Color Chooser...");

		// 버튼을 클릭하면 대화상자를 띄운다.
		button.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent actionEvent) {
				Color color = JColorChooser
						.showDialog(ColorChooser2Example.this,
								"Color Dialog", label.getForeground());
				if (null != color) {
					label.setForeground(color);
				} else {
					System.out.println("color is null.");
				}
			}
		});

		// 레이아웃에 추가
		add(label, BorderLayout.NORTH);
		add(button, BorderLayout.SOUTH);


	}

	public static void main(String... args) {

		final JFrame jFrame = new JFrame();
		jFrame.setTitle("Example");
		jFrame.setSize(800, 600);
		jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jFrame.setContentPane(new ColorChooser2Example());

		SwingUtilities.invokeLater(() -> {
			jFrame.setVisible(true);
		});


	}

	class DummyIcon implements Icon {

		@Override
		public void paintIcon(Component component, Graphics graphics, int x, int y) {
			graphics.setColor(Color.DARK_GRAY);
			graphics.fillRect(x, y, x + getIconWidth(), y + getIconHeight());
		}

		@Override
		public int getIconWidth() {
			return 16;
		}

		@Override
		public int getIconHeight() {
			return 16;
		}
	}
}
