/Users/lyon/j4p/src/gui/run/RunMenuItem.java

1    package gui.run; 
2     
3     
4    import gui.ClosableJFrame; 
5     
6    import javax.swing.*; 
7    import java.awt.*; 
8    import java.awt.event.ActionEvent; 
9    import java.awt.event.ActionListener; 
10    
11   public abstract class RunMenuItem extends 
12           JMenuItem 
13           implements 
14           ActionListener, Runnable { 
15    
16       public RunMenuItem(String label) { 
17           this(label, null); 
18       } 
19    
20       public RunMenuItem(String l, Icon i) { 
21           super(l, i); 
22           addActionListener(this); 
23           ShortcutUtils.addShortcut(this); 
24       } 
25    
26       public RunMenuItem(Icon i) { 
27           this(null, i); 
28       } 
29    
30       public RunMenuItem() { 
31           this(null, null); 
32       } 
33    
34       public void actionPerformed(ActionEvent e) { 
35           run(); 
36       } 
37    
38       public static void main(String args[]) { 
39           ClosableJFrame cf = new ClosableJFrame("RunMenuItem"); 
40           Container c = cf.getContentPane(); 
41           cf.setJMenuBar(getMenuBar()); 
42           c.setLayout(new java.awt.FlowLayout()); 
43           cf.setSize(200, 200); 
44           cf.setVisible(true); 
45       } 
46    
47       public static JMenuBar getMenuBar() { 
48           JMenuBar mb = new JMenuBar(); 
49           mb.add(getFileMenu()); 
50           mb.add(getEditMenu()); 
51           return mb; 
52       } 
53    
54       public static RunMenu getDrawMenu() { 
55           RunMenu drawMenu = new RunMenu("[draw"); 
56           drawMenu.add(new RunMenuItem("[rect{alt shift R}") { 
57               public void run() { 
58                   System.out.println(getText()); 
59               } 
60           }); 
61           drawMenu.add(new RunMenuItem("[square{shift F12}") { 
62               public void run() { 
63                   System.out.println(getText()); 
64               } 
65           }); 
66           drawMenu.add(new RunMenuItem("[quad{alt 1}") { 
67               public void run() { 
68                   System.out.println(getText()); 
69               } 
70           }); 
71           drawMenu.add(new RunMenuItem("[right arrow{alt RIGHT}") { 
72               public void run() { 
73                   System.out.println(getText()); 
74               } 
75           }); 
76           drawMenu.add(new RunMenuItem("[fat line{ctrl alt shift L}") { 
77               public void run() { 
78                   System.out.println(getText()); 
79               } 
80           }); 
81           drawMenu.add(new RunMenuItem("[circle{ctrl C}") { 
82               public void run() { 
83                   System.out.println(getText()); 
84               } 
85           }); 
86           return drawMenu; 
87       } 
88    
89       public static RunMenu getEditMenu() { 
90           RunMenu editMenu = new RunMenu("[Edit"); 
91           editMenu.add(new RunMenuItem("[Undo{control DELETE}") { 
92               public void run() { 
93                   System.out.println(getText()); 
94               } 
95           }); 
96           editMenu.add(new RunMenuItem("[cut{ctrl shift C}") { 
97               public void run() { 
98                   System.out.println(getText()); 
99               } 
100          }); 
101          editMenu.add(getDrawMenu()); 
102          return editMenu; 
103      } 
104   
105      public static RunMenu getFileMenu() { 
106          RunMenu fileMenu = new RunMenu("[File"); 
107          fileMenu.add(new RunMenuItem("[open{alt shift X}") { 
108              public void run() { 
109                  System.out.println(getText()); 
110              } 
111          }); 
112          fileMenu.add(new RunMenuItem("[save{alt control DELETE}") { 
113              public void run() { 
114                  System.out.println(getText()); 
115              } 
116          }); 
117          return fileMenu; 
118      } 
119   
120  }