/** @(#) ShapeSelectionPanel.java 1.1 99/11/18
 * Copyright (c) 1999 Lawrence Rodrigues
 */
package com.vistech.graphics;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.beans.*;
import com.vistech.shapes.*;

/** Creates a GUI panel for selecting shapes.
* @version 1.0  18 Nov 1999
* @author Lawrence Rodrigues
**/
public class ShapeSelectionPanel {
   protected DrawShapesController drawShapes;
   public ShapeSelectionPanel(DrawShapesController drawShapes){
       this.drawShapes = drawShapes;
   }
   public JMenu createShapeTypesMenu(){
      JMenu shapesMenu = new JMenu("Shapes");
      JMenuItem box = new JMenuItem("Box");
      JMenuItem el = new JMenuItem("Ellipse");
      JMenuItem ar = new JMenuItem("Arrow");
      JMenuItem line = new JMenuItem("Line");
      JMenuItem text = new JMenuItem("Text");
      JMenuItem curve = new JMenuItem("Curve");
      shapesMenu.add(box);
      shapesMenu.add(el);
      shapesMenu.add(ar);
      shapesMenu.add(line);
      shapesMenu.add(curve);
      shapesMenu.add(text);

      box.addActionListener(new ShapesAdapter(Drawable.BOX));
      el.addActionListener(new ShapesAdapter(Drawable.ELLIPSE));
      ar.addActionListener(new ShapesAdapter(Drawable.ARROW));
      line.addActionListener(new ShapesAdapter(Drawable.LINE));
      text.addActionListener(new ShapesAdapter(Drawable.ANNOTEXT));
      curve.addActionListener(new ShapesAdapter(Drawable.CURVE));
      return shapesMenu;
   }

   class ShapesAdapter implements ActionListener{
       int shapeType;
       public ShapesAdapter(int sh){
          shapeType = sh;
       }
       public void actionPerformed(ActionEvent e){
          drawShapes.setShapeType(shapeType);
          drawShapes.setCommand(DrawShapesController.DRAW);
       }
    }
}

