1 41 42 43 package swingwtx.swing; 44 45 import swingwt.awt.Component; 46 47 import org.eclipse.swt.widgets.*; 48 import org.eclipse.swt.*; 49 50 import java.util.*; 51 52 public class JMenuBar extends JComponent { 53 54 55 protected Menu menu = null; 56 57 protected Vector components = new Vector(); 58 59 protected Shell shell = null; 60 private Object retval; 61 62 public JMenuBar() { 63 } 64 65 66 public JSWTMenuComponent add(final JSWTMenuComponent c) { 67 SwingUtilities.invokeSync(new Runnable () { 68 public void run() { 69 try { 70 if (menu == null) 71 components.add(c); 72 else { 73 c.setSwingWTParent(menu, shell); 74 c.setCachedProperties(); 75 c.registerEvents(); 76 } 77 } 78 catch (Exception e) { 79 e.printStackTrace(); 80 } 81 } 82 }); 83 return c; 84 } 85 86 public JMenu add(JMenu c) { 87 return (JMenu) add((JSWTMenuComponent) c); 88 } 89 90 public Component add(Component c) { 91 if (c instanceof JSWTMenuComponent) 92 return add(((JSWTMenuComponent) c)); 93 else 94 return c; 95 } 96 97 98 public void remove(JSWTMenuComponent c) { 99 c.dispose(); 100 } 101 102 public void setVisible(final boolean b) { 103 SwingUtilities.invokeSync(new Runnable () { 104 public void run() { 105 if (menu != null) 106 menu.setVisible(b); 107 } 108 }); 109 } 110 111 public boolean isVisible() { 112 SwingUtilities.invokeSync(new Runnable () { 113 public void run() { 114 if (menu != null) 115 retval = new Boolean (menu.isVisible()); 116 else 117 retval = new Boolean (false); 118 } 119 }); 120 return ((Boolean ) retval).booleanValue(); 121 } 122 123 public swingwt.awt.Dimension getPreferredSize() { 124 return new swingwt.awt.Dimension(0, 0); 125 } 126 127 public void addSeparator() { 128 add(new JSeparator()); 129 } 130 131 public Menu getSWTMenu() { 132 return menu; 133 } 134 135 public void setSwingWTParent(Shell parent) { 136 shell = parent; 137 menu = new Menu(parent, SWT.BAR); 138 parent.setMenuBar(menu); 139 140 if (components.size() > 0) { 142 Iterator i = components.iterator(); 143 while (i.hasNext()) { 144 add((JSWTMenuComponent) i.next()); 145 } 146 } 147 } 148 } 149 | Popular Tags |