package de.duehl.vocabulary.japanese.logic.symbol.kanji.strokes.test.ui;

import java.awt.BasicStroke;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Path2D;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class Path2DViewerForTesting extends JPanel {

    private static final long serialVersionUID = 1L;

    private final Path2D.Double path;

    public Path2DViewerForTesting(Path2D.Double path) {
        this.path = path;
        setPreferredSize(new Dimension(109, 109));
    }

    @Override
    protected void paintComponent(Graphics graphics) {
        super.paintComponent(graphics);

        Graphics2D g = (Graphics2D) graphics.create();
        try {
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

            g.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

            g.draw(path);
        }
        finally {
            g.dispose();
        }
    }

    public static void show(Path2D.Double path) {
        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame("Path2D");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setContentPane(new Path2DViewerForTesting(path));
            frame.pack();
            frame.setLocationByPlatform(true);
            frame.setVisible(true);
        });
    }

}