// File: ActionCreateVertex.java
// Classes: ActionCreateVertex
// Author: Kedar Patankar

package edu.neu.ccs.demeter.tools.apstudio.graphedit;

import java.awt.Point;
import edu.neu.ccs.demeter.Ident;

/**
 * Editor Action to create a new Perspective on a new Construction class.
 */

public class ActionCreateVertex extends Action
{
	private Point _click;
	private int _vertexType;

	public ActionCreateVertex(Editor editor,Document d,Point p,int type) 
	{
		super(editor,d);
		_click=p;
		_vertexType=type;
	}

    public String name() { return "Create Vertex"; }

    public void doIt() 
	{
		UVertex newNode=null;
		String name=null;
		switch(_vertexType)
		{
		case UVertex.CONSTVERT	:	name = _document.getNextConstvertName();
									newNode = new UConstVertex();
									newNode.set_vertexname(new UVertexName(new Ident(name)));
									break;
		case UVertex.ALTVERT	:	name = _document.getNextAltvertName();
									newNode = new UAltVertex();
									newNode.set_vertexname(new UVertexName(new Ident(name)));
									break;
		case UVertex.INTERFACE	:	name = _document.getNextInterfacevertName();
									newNode = new UInterface();
									newNode.set_vertexname(new UVertexName(new Ident(name)));
									break;
		default : return;
		}
		newNode.initialize(newNode,name,_document,_click);
		_document.add(newNode.get_Perspective());
		showDefaultMessage();
		_editor.showVertexPropertySheet(newNode.get_Perspective());
		_document.selectItem(newNode.get_Perspective());
		_editor.menuForsingleSelection();
	}

	public void undoIt() { }
	
	public void showDefaultMessage(){_editor.setDefaultMessage();}

} /* end class ActionCreateVertex */

