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 /***
14 *
15 * @author studajb
16 */
17 public class AddDiagramAction extends AbstractAction{
18 Class diagramclass;
19 MainEditor editor;
20 MainFrame frame;
21
22 /*** Creates a new instance of AddDiagramAction */
23 public AddDiagramAction(MainFrame frame,Class diagramclass,String type) {
24
25 URL icon=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/"+type+".gif");
26 putValue(Action.SMALL_ICON,new ImageIcon(icon));
27 putValue(Action.SHORT_DESCRIPTION,"New "+type+" Diagram");
28 this.diagramclass=diagramclass;
29 this.frame=frame;
30
31 }
32 public void actionPerformed(ActionEvent e){
33
34 editor=frame.getEditor();
35 try{
36 editor.adddiagram((ToolGraph)diagramclass.newInstance(),null,true);
37 }catch(Exception exp){
38 exp.printStackTrace();
39
40 }
41
42 }
43
44 }