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

package com.elex_project.examples.components.label;

import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.awt.*;
import java.util.Objects;

public class LabelExample extends JPanel {
	public LabelExample() {
		super(new FlowLayout());

		final ImageIcon icon = new ImageIcon(Objects.requireNonNull(LabelExample.class.getResource("/icon.png")));

		final JLabel label = new JLabel("I'm a label.", icon, SwingConstants.CENTER);
		label.setHorizontalAlignment(JLabel.CENTER);
		label.setVerticalAlignment(JLabel.BOTTOM);
		label.setOpaque(true);// 배경색을 지정하려면 불투명으로 변경해야 한다.
		label.setBackground(Color.PINK);

		final JTextField textField = new JTextField();
		label.setLabelFor(textField);

		this.add(label);
		this.add(textField);

	}

	private static class DummyIcon implements Icon {
		private int width = 16;
		private int height = 16;
		@Override
		public void paintIcon(Component component, Graphics graphics, int x, int y) {
			Graphics2D g2d = (Graphics2D) graphics.create();

			g2d.setColor(Color.WHITE);
			g2d.fillRect(x +1 ,y + 1,width -2 ,height -2);

			g2d.setColor(Color.BLACK);
			g2d.drawRect(x +1 ,y + 1,width -2 ,height -2);

			g2d.setColor(Color.RED);

			g2d.setStroke(new BasicStroke(4));
			g2d.drawLine(x +10, y + 10, x + width -10, y + height -10);
			g2d.drawLine(x +10, y + height -10, x + width -10, y + 10);

			g2d.dispose();
		}

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

		@Override
		public int getIconHeight() {
			return height;
		}
	}
	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 LabelExample());

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


	}
}
