package figure;

import java.awt.*;
import javax.swing.*;

public class Figure1 extends FigurePanel implements Mover, Function {
    GraphicalPoint p1, p2;
    GraphicalLine line;
    public Figure1() {
	super(-2, -3, 2, 3);
	setBackground(Color.white);

	Grid grid =  new Grid();
	grid.setColor(Color.lightGray);
	add(grid);

	Axes axes = new Axes();
	add(axes);

	p1 = new GraphicalPoint(-1.5, 1);
	p1.setColor(Color.green);
	p1.setSize(5);
	p1.setStyle(GraphicalPoint.SQUARE);

	p2 = new GraphicalPoint(0.5, -1);
	p2.setSize(5);
	p2.setColor(Color.red);

	GraphicalFunction func = new GraphicalFunction(this, null);
	func.setStroke(new BasicStroke(2f));
	func.setColor(new Color(0.2f, 0.5f, 0.5f));
	add(func);
		

	line = new GraphicalLine(-1.5, 1, 0.5, -1);
	line.setColor(Color.blue);
	line.setStroke(new BasicStroke(2f));
	add(line);
	add(p1);
	add(p2);

	addMoveable(p1, this);
	addMoveable(p2, this);

    }

    public double valueAt(double x, double[] params) {
	return x*x-1;
    }

    public void move(Moveable m, double x, double y) {
	((GraphicalPoint) m).setPoint(x, y);
	line.setPoints(p1.x, p1.y, p2.x, p2.y);
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("Figure 1");
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Figure1 figure = new Figure1();
        frame.getContentPane().add(figure, BorderLayout.CENTER);
        figure.setPreferredSize(new Dimension(300, 300));

        frame.pack();
        frame.setVisible(true);
    }
}
	
