import edu.neu.ccs.*;
import edu.neu.ccs.gui.*;
import edu.neu.ccs.codec.*;
import edu.neu.ccs.console.*;
import edu.neu.ccs.filter.*;
import edu.neu.ccs.jpf.*;
import edu.neu.ccs.parser.*;
import edu.neu.ccs.pedagogy.*;
import edu.neu.ccs.quick.*;
import edu.neu.ccs.util.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.font.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
import java.util.*;
import java.math.*;
import java.beans.*;
import java.lang.reflect.*;
import java.net.URL;
import java.util.regex.*;
import java.text.ParseException;

public class Sketch extends DisplayPanel {
    public static final int WIDTH = 500;
    
    public static final int HEIGHT = 500;
    
    BufferedPanel window = new BufferedPanel(WIDTH, HEIGHT);
    
    String[] shapeOptions = { "Point", "Line", "Rect", "Oval" };
    
    public static final int POINT = 0;
    
    public static final int LINE = 1;
    
    public static final int RECT = 2;
    
    public static final int OVAL = 3;
    
    RadioPanel shapePanel = new RadioPanel(shapeOptions);
    
    Object[] LHS_Stuff = { shapePanel };
    
    VTable LHS_Panel = new VTable(LHS_Stuff, 10, 10, CENTER);
    
    Object[] Main_Stuff = { LHS_Panel, window };
    
    HTable Main_Panel = new HTable(Main_Stuff, 10, 10, NORTH);
    
    int x1, y1, x2, y2;
    
    Paintable p;
    
    XLine2D line;
    
    
    public Sketch() {
        addMouseActions();
        makeGUI();
    }
    
    
    void makeGUI() {
        window.lineBorder(5);
        Main_Panel.emptyBorder(10);
        
        add(Main_Panel);
    }
    
    
    void addMouseActions() {
        MouseActionAdapter adapter = window.getMouseActionAdapter();
        
        adapter.addMouseMovedAction
        (new MouseAction() {
            public void mouseActionPerformed(MouseEvent evt) {
                mouseMoved(evt);
            }
        });
        
        adapter.addMouseDraggedAction
        (new MouseAction() {
            public void mouseActionPerformed(MouseEvent evt) {
                mouseDragged(evt);
            }
        });
    
        adapter.addMousePressedAction
        (new MouseAction() {
            public void mouseActionPerformed(MouseEvent evt) {
                mousePressed(evt);
            }
        });
    
        adapter.addMouseClickedAction
        (new MouseAction() {
            public void mouseActionPerformed(MouseEvent evt) {
                mouseClicked(evt);
            }
        });
    
        adapter.addMouseReleasedAction
        (new MouseAction() {
            public void mouseActionPerformed(MouseEvent evt) {
                mouseReleased(evt);
            }
        });
    
        adapter.addMouseEnteredAction
        (new MouseAction() {
            public void mouseActionPerformed(MouseEvent evt) {
                mouseEntered(evt);
            }
        });
    
        adapter.addMouseExitedAction
        (new MouseAction() {
            public void mouseActionPerformed(MouseEvent evt) {
                mouseExited(evt);
            }
        });
    }
    
    
    void mouseMoved(MouseEvent evt) {
        switch (shapePanel.getSelectedIndex()) {
            case POINT:
                
                break;
                
            case LINE:
                
                break;
                
            case RECT:
                
                break;
                
            case OVAL:
                
                break;
                
            default:
                break;
        }
        
    }
    
    
    void mouseDragged(MouseEvent evt) {
        int x = evt.getX();
        int y = evt.getY();
        
        switch (shapePanel.getSelectedIndex()) {
            case POINT:
                p.moveCenterTo(x, y);
                break;
                
            case LINE:
                x2 = x;
                y2 = y;
                
                line.setLine(x1, y1, x2, y2);
                break;
                
            case RECT:
                
                break;
                
            case OVAL:
                
                break;
                
            default:
                break;
        }
        
        window.repaint();
    }
    
    
    void mousePressed(MouseEvent evt) {
        int x = evt.getX();
        int y = evt.getY();
        
        switch (shapePanel.getSelectedIndex()) {
            case POINT:
                p = new PointPaintable(x, y, null, null);
                window.addPaintable(p);
                break;
                
            case LINE:
                x1 = x;
                y1 = y;
                
                x2 = x;
                y2 = y;
                
                line = new XLine2D(x1, y1, x2, y2);
                
                p = new ShapePaintable(line);
                window.addPaintable(p);
                break;
                
            case RECT:
                
                break;
                
            case OVAL:
                
                break;
                
            default:
                break;
        }
        
        window.repaint();
    }
    
    
    void mouseClicked(MouseEvent evt) {
        switch (shapePanel.getSelectedIndex()) {
            case POINT:
                
                break;
                
            case LINE:
                
                break;
                
            case RECT:
                
                break;
                
            case OVAL:
                
                break;
                
            default:
                break;
        }
    }
    
    
    void mouseReleased(MouseEvent evt) {
        int x = evt.getX();
        int y = evt.getY();
        
        switch (shapePanel.getSelectedIndex()) {
            case POINT:
                
                break;
                
            case LINE:
                x2 = x;
                y2 = y;
                
                if ((x2 == x1) && (y2 == y1)) {
                    window.removePaintable(p);
                }
                else {
                    line.setLine(x1, y1, x2, y2);
                }
                break;
                
            case RECT:
                
                break;
                
            case OVAL:
                
                break;
                
            default:
                break;
        }
        
        window.repaint();
    }
    
    
    void mouseEntered(MouseEvent evt) {
        switch (shapePanel.getSelectedIndex()) {
            case POINT:
                
                break;
                
            case LINE:
                
                break;
                
            case RECT:
                
                break;
                
            case OVAL:
                
                break;
                
            default:
                break;
        }
        
    }
    
    
    void mouseExited(MouseEvent evt) {
        switch (shapePanel.getSelectedIndex()) {
            case POINT:
                
                break;
                
            case LINE:
                
                break;
                
            case RECT:
                
                break;
                
            case OVAL:
                
                break;
                
            default:
                break;
        }
        
    }
    
    
    public static void main(String[] args) {
        new Sketch().frame("Sketch");
    }
}

