View Javadoc

1   /*
2    * DeleteAction.java
3    *
4    * Created on 27. mai 2005, 21:25
5    */
6   
7   package com.vikash.firsttool.UI;
8   import com.vikash.firsttool.Diagram.ToolGraph;
9   import java.awt.event.*;
10  import java.net.URL;
11  import javax.swing.*;
12  
13  import org.jgraph.graph.DefaultGraphModel;
14  /***
15   *
16   * @author  studajb
17   */
18  public class DeleteAction extends AbstractAction{
19      ToolGraph graph;
20       ToolInternalFrame internalframe;
21       MainFrame frame;
22       static DeleteAction instance;
23      
24      
25      public static DeleteAction getinstance(final MainFrame frame,boolean flag){
26          if(flag)
27              instance=null;
28          if(instance==null){
29              instance=new DeleteAction(frame);
30          }
31              return instance;
32          }
33      
34      /*** Creates a new instance of DeleteAction */
35      public DeleteAction(MainFrame frame) {
36          URL icon=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/delete.gif");
37          putValue(Action.SMALL_ICON,new ImageIcon(icon));
38          putValue(Action.SHORT_DESCRIPTION,"Delete From Model");
39          putValue(Action.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0));
40          this.frame=frame;
41      }
42      
43      public void actionPerformed(ActionEvent e) {
44          internalframe=(ToolInternalFrame)frame.getDesktopPane().getSelectedFrame();
45          if(internalframe != null){ 
46              
47          graph=internalframe.getGraph();
48          Object[] cells=graph.getSelectionCells();
49          if (cells==null)return;
50          
51          cells = DefaultGraphModel.getDescendants(graph.getModel(), cells).toArray();
52          Object[] edges = DefaultGraphModel.getEdges(graph.getModel(),cells).toArray(); 
53          graph.getModel().remove(edges);
54  	graph.getModel().remove(cells);
55              
56          
57          }
58      }
59  }