1 package gnu.jemacs.swing; 2 import java.awt.event.*; 3 import javax.swing.*; 4 import gnu.lists.*; 5 import gnu.mapping.Procedure; 6 import gnu.jemacs.buffer.Command; 7 import gnu.jemacs.buffer.EMenu; 8 import gnu.jemacs.lang.*; 9 import java.util.*; 10 11 15 16 public class SwingMenu extends JMenu implements EMenu 17 { 18 public SwingMenu () 19 { 20 super(); 21 } 22 23 public SwingMenu (LList menu) 24 { 25 super(); 26 setMenu (menu); 27 } 28 29 public void setMenu (LList menu) 30 { 31 java.util.Enumeration e = menu.elements(); 32 for (int i = 0; e.hasMoreElements(); i++) 33 { 34 Object item = e.nextElement(); 35 if (item == null) 36 { 37 this.add(Box.createHorizontalGlue()); 38 } 39 else if (item instanceof FString) 40 { 41 if (i == 0) 42 this.setText(item.toString()); 43 else 44 this.addSeparator(); 46 } 47 else if (item instanceof FVector) 48 { 49 FVector menuEntry = (FVector) item; 50 51 if (menuEntry.get(0) instanceof FString) 52 { 53 FString txt = (FString) menuEntry.get(0); 54 Object proc = menuEntry.get(1); 55 56 58 JMenuItem menuItem = new MenuItem (txt.toString(), proc); 59 this.add(menuItem); 60 } 61 } 62 else if (item instanceof JComponent) 63 this.add((JComponent) item); 64 else if (item instanceof LList) 65 { 66 SwingMenu tmp = new SwingMenu((LList) item); 68 this.add(tmp); 69 } 70 } 71 } 72 73 } 74 75 class MenuItem extends JMenuItem implements java.awt.event.ActionListener 76 { 77 Object command; 78 79 public MenuItem(String text, Object command) 80 { 81 super(text); 82 this.command = command; 83 this.addActionListener(this); 84 } 85 86 public void actionPerformed(java.awt.event.ActionEvent event) 87 { 88 JMenuItem source = (JMenuItem) event.getSource(); 89 Command.perform(command); 90 } 91 } 92 | Popular Tags |