package chap6;

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

public class LineMover extends FigurePanel implements Mover {
    GraphicalPoint p0, p1;
    GraphicalLine line;

    public LineMover() {
	super(-3, -3, 3, 3);
	p0 = new GraphicalPoint(0, 0);
	p0.setColor(Color.red);
	p0.setSize(3);
	p1 = new GraphicalPoint(1, 1);
	p1.setColor(Color.red);
	p1.setSize(3);

	line = new GraphicalLine(p0.x, p0.y, p1.x, p1.y);
	line.setColor(Color.blue);

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

	add(grid);
	add(new Axes());
	add(line);
	add(p0);  add(p1);

	addMoveable(p0, this);  addMoveable(p1, this);
    }

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

    public static void main(String[] args) {
        JFrame frame = new JFrame("LineMover");
	frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	LineMover mover = new LineMover();
        mover.setPreferredSize(new Dimension(300, 300));
        frame.getContentPane().add(mover, BorderLayout.CENTER);

        frame.pack();
        frame.show();
    }
}
