1 33 34 35 package swingwtx.swing; 36 37 import org.eclipse.swt.widgets.*; 38 import org.eclipse.swt.*; 39 40 import swingwt.awt.event.*; 41 42 import java.util.*; 43 44 public class JRadioButtonMenuItem extends JMenuItem implements ButtonModel { 45 46 private Shell shell = null; 47 protected boolean pState = false; 48 protected Vector itemListeners = new Vector(); 49 private Object retval; 50 51 public JRadioButtonMenuItem() {setModel(this);} 52 public JRadioButtonMenuItem(Action a) { setAction(a); setModel(this);} 53 public JRadioButtonMenuItem(Icon icon) { this("", icon); } 54 public JRadioButtonMenuItem(Icon icon, boolean b) { this("", icon, b); } 55 public JRadioButtonMenuItem(String text) { this(text, null, false); } 56 public JRadioButtonMenuItem(String text, boolean b) { this(text, null, b); } 57 public JRadioButtonMenuItem(String text, Icon icon) { this(text, null, false); } 58 public JRadioButtonMenuItem(String text, Icon icon, boolean b) { pText = text; pImage = icon; pState = b; setModel(this); } 59 public JRadioButtonMenuItem(String text, int mnemonic) { pText = text; setMnemonic(mnemonic); setModel(this);} 60 public JRadioButtonMenuItem(String text, int mnemonic, boolean b) { pText = text; setMnemonic(mnemonic); pState = b; setModel(this);} 61 62 public Object [] getSelectedObjects() { return new Object [] { getText() };} 63 public boolean getState() { 64 SwingUtilities.invokeSync(new Runnable () { 65 public void run() { 66 if (SwingWTUtils.isSWTMenuControlAvailable(peer)) 67 retval = new Boolean (ppeer.getSelection()); 68 else 69 retval = new Boolean (pState); 70 } 71 }); 72 return ((Boolean ) retval).booleanValue(); 73 } 74 75 public void setState(boolean b) { 76 pState = b; 77 SwingUtilities.invokeSync(new Runnable () { 78 public void run() { 79 if (SwingWTUtils.isSWTMenuControlAvailable(peer)) 80 ppeer.setSelection(pState); 81 } 82 }); 83 } 84 public boolean isSelected() { return getState(); } 85 public void setSelected(boolean b) { setState(b); } 86 87 public void addItemListener(ItemListener l) { 88 itemListeners.add(l); 89 } 90 91 public void removeItemListener(ItemListener l) { 92 itemListeners.remove(l); 93 } 94 95 99 public void processActionEvent(int id) { 100 super.processActionEvent(id); 101 processItemEvent(); 102 } 103 104 107 public void processItemEvent() { 108 if (itemListeners.size() == 0) return; 109 Iterator i = itemListeners.iterator(); 110 ItemEvent e = new ItemEvent(this, 0, this, (ppeer.getSelection() ? ItemEvent.SELECTED : ItemEvent.DESELECTED)); 111 while (i.hasNext()) { 112 ItemListener il = (ItemListener) i.next(); 113 il.itemStateChanged(e); 114 } 115 } 116 117 public void setSwingWTParent(Menu parent, Shell shell) throws Exception { 118 this.shell = shell; 119 peer = new MenuItem(parent, SWT.RADIO); 120 peer.setSelection(pState); 121 } 122 123 } 124 | Popular Tags |