1
2
3
4
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 DeleteViewAction extends AbstractAction{
19 ToolGraph graph;
20 ToolInternalFrame internalframe;
21 MainFrame frame;
22 static DeleteViewAction instance;
23
24
25 public static DeleteViewAction getinstance(final MainFrame frame,boolean flag){
26 if(flag)
27 instance=null;
28 if(instance==null){
29 instance=new DeleteViewAction(frame);
30 }
31 return instance;
32 }
33
34 /*** Creates a new instance of DeleteAction */
35 public DeleteViewAction(MainFrame frame) {
36 URL icon=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/DeleteView.gif");
37 putValue(Action.SMALL_ICON,new ImageIcon(icon));
38 putValue(Action.SHORT_DESCRIPTION,"Delete From Diagram");
39 this.frame=frame;
40 }
41
42 public void actionPerformed(ActionEvent e) {
43 internalframe=(ToolInternalFrame)frame.getDesktopPane().getSelectedFrame();
44 if(internalframe != null){
45
46 graph=internalframe.getGraph();
47 Object[] cells=graph.getSelectionCells();
48 if (cells==null)return;
49
50 cells = DefaultGraphModel.getDescendants(graph.getModel(), cells).toArray();
51
52
53
54 Object[] edges = DefaultGraphModel.getEdges(graph.getModel(),cells).toArray();
55
56 graph.getGraphLayoutCache().setVisible(cells,false);
57 graph.getGraphLayoutCache().setVisible(edges,false);
58
59
60
61
62
63 }
64 }
65 }
66
67