/* * DeleteVertexMenuItem.java * * Created on March 21, 2007, 2:03 PM; Updated May 29, 2007 * * Copyright March 21, 2007 Grotto Networking * */ package Samples.MouseMenu; import edu.uci.ics.jung.visualization.VisualizationViewer; import edu.uci.ics.jung.visualization.picking.PickedState; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JMenuItem; /** * A class to implement the deletion of a vertex from within a * PopupVertexEdgeMenuMousePlugin. * @author Dr. Greg M. Bernstein */ public class DeleteVertexMenuItem<V> extends JMenuItem implements VertexMenuListener<V> { private V vertex; private VisualizationViewer visComp; /** Creates a new instance of DeleteVertexMenuItem */ public DeleteVertexMenuItem() { super("Delete Vertex"); this.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { visComp.getPickedVertexState().pick(vertex, false); visComp.getGraphLayout().getGraph().removeVertex(vertex); visComp.repaint(); } }); } /** * Implements the VertexMenuListener interface. * @param v * @param visComp */ public void setVertexAndView(V v, VisualizationViewer visComp) { this.vertex = v; this.visComp = visComp; this.setText("Delete Vertex " + v.toString()); } }