/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info: http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2003, by :
* Corporate:
* Astrium SAS
* EADS CRC
* Individual:
* Nicolas Brodu
*
* $Id: NewShapePopup.java,v 1.5 2009/01/19 17:47:06 ogor Exp $
*
* Changes
* -------
* 25-Sep-2003 : Initial public release (NB);
*
*/
package jsynoptic.ui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import jsynoptic.base.ContextualActionProvider;
import simtools.diagram.Element;
import simtools.shapes.AbstractShape;
import simtools.ui.MenuResourceBundle;
import simtools.ui.ResourceFinder;
/**
*
* @author Nicolas Brodu
*
* @version 1.0 2001
*/
public class NewShapePopup extends ActionPopup implements ActionListener {
public static MenuResourceBundle resources = ResourceFinder.getMenu(NewShapePopup.class);
JMenuItem jmicreate;
ShapeCreator shapeCreator;
ShapesContainer invoker;
public NewShapePopup(ShapesContainer invoker, ShapeCreator s, double x, double y) {
super(invoker.getComponent(), x, y, s, ContextualActionProvider.SHAPELIST_CONTEXT);
this.invoker = invoker;
shapeCreator = s;
jmicreate = resources.getItem("create", this);
if ((super.getComponentCount()>0) && (!(super.getComponent(0) instanceof JPopupMenu.Separator)))
super.insert(new JPopupMenu.Separator(),0);
super.insert(jmicreate,0);
}
//
// ActionListener interface
//
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jmicreate) {
Element element = shapeCreator.create();
if (element instanceof AbstractShape){
((AbstractShape)element).setAnchor(0,0);
}
element.translate((int)actionX, (int)actionY);
invoker.addElement(element);
invoker.getComponent().repaint();
}
super.actionPerformed(e);
}
}