package uebung10.logo;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Ellipse2D;
import java.util.ArrayList;
import java.util.List;

public class HanselGretelFrame extends JFrame implements DarkForest {
    private static final double RADIUS = 2;
    private static final Stroke THIN = new BasicStroke(0.2f);

    private final List<Shape> path = new ArrayList<>();
    private final List<Shape> dots = new ArrayList<>();

    private JPanel panel = new JPanel() {
        @Override
        protected void paintComponent(Graphics g) {
            final Graphics2D g2d = (Graphics2D) g;

            super.paintComponent(g2d);
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
            g2d.setColor(Color.BLACK);
            g2d.setStroke(THIN);
            for (Shape pe : new ArrayList<>(path))
                g2d.draw(pe);
            g2d.setColor(Color.RED);
            for (Shape pe : new ArrayList<>(dots))
                g2d.fill(pe);
        }
    };

    public HanselGretelFrame(String title) {
        super(title);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(500, 500);
        setLayout(new BorderLayout());
        add(panel, BorderLayout.CENTER);
        setVisible(true);
    }

    @Override
    public void breadCrumb(double x, double y) {
        dots.add(new Ellipse2D.Double(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS));
        repaint();
    }
}
