/* @(#) CommandSelectionPanel.java 1.1 99/21/11
 * Copyright (c) 1999 Lawrence Rodrigues
 */
package com.vistech.graphics;
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.beans.*;
/** Creates a GUI panel for selecting operations.
  * @version 1.0  24  July 1998
  * @author Larry Rodrigues
  * **/
public class CommandSelectionPanel extends MouseAdapter{
    protected DrawShapesController drawShapes;
    public CommandSelectionPanel(DrawShapesController drawShapes){
       this.drawShapes = drawShapes;
    }

    public void mousePressed(MouseEvent e) {
       if(SwingUtilities.isRightMouseButton(e)){
          popupMenu((JComponent)e.getSource(), e.getX(), e.getY());
       }
    }
    protected void popupMenu(JComponent comp,int x, int y){
       JPopupMenu jp = new JPopupMenu("");
       jp.setLightWeightPopupEnabled(true);
       comp.add(jp);
       JMenuItem draw = new JMenuItem("Draw");
       draw.addActionListener(
         new ActionListener(){
           public void actionPerformed(ActionEvent e){
              drawShapes.setCommand(DrawShapesController.DRAW);
           }
         });

       JMenuItem fill = new JMenuItem("Fill");
       fill.addActionListener(
         new ActionListener(){
           public void actionPerformed(ActionEvent e){
              drawShapes.setCommand(DrawShapesController.FILL);
           }
         });

       JMenuItem move = new JMenuItem("Move");
       move.addActionListener(
         new ActionListener(){
           public void actionPerformed(ActionEvent e){
              drawShapes.setCommand(DrawShapesController.MOVE);
           }
         });

       JMenuItem erase = new JMenuItem("Erase");
       erase.addActionListener(
         new ActionListener(){
           public void actionPerformed(ActionEvent e){
              drawShapes.setCommand(DrawShapesController.ERASE);
           }
         });

       JMenuItem copy = new JMenuItem("Copy");
       copy.addActionListener(
         new ActionListener(){
           public void actionPerformed(ActionEvent e){
              drawShapes.setCommand(DrawShapesController.COPY);
           }
         });
       JMenuItem paste = new JMenuItem("Paste");
       paste.addActionListener(
         new ActionListener(){
           public void actionPerformed(ActionEvent e){
              drawShapes.setCommand(DrawShapesController.PASTE);
           }
         });

       JMenuItem eraseall = new JMenuItem("Erase All");
        eraseall.addActionListener(
         new ActionListener(){
           public void actionPerformed(ActionEvent e){
              drawShapes.setCommand(DrawShapesController.ERASE_ALL);
              drawShapes.setCommand(DrawShapesController.DRAW);
           }
         });

       JMenuItem save = new JMenuItem("Save Shapes");
       save.addActionListener(
         new ActionListener(){
           public void actionPerformed(ActionEvent e){
              drawShapes.setCommand(DrawShapesController.SAVE);
              drawShapes.setCommand(DrawShapesController.DRAW);
           }
         });

       JMenuItem load = new JMenuItem("Load Shapes");
       load.addActionListener(
         new ActionListener(){
           public void actionPerformed(ActionEvent e){
             drawShapes.setCommand(DrawShapesController.LOAD);
             drawShapes.setCommand(DrawShapesController.DRAW);
            }
         });
       jp.add(draw);
       jp.add(fill);
       jp.add(move);
       jp.add(erase);
       jp.add(copy);
       jp.add(paste);
       jp.addSeparator();
       jp.add(save);
       jp.add(load);
       jp.add(eraseall);
       jp.show(comp,x,y);
   }
}