1 64 65 66 package swingwtx.swing; 67 68 import org.eclipse.swt.widgets.*; 69 import org.eclipse.swt.*; 70 71 import swingwt.awt.event.*; 72 73 import java.util.*; 74 75 public class JRadioButton extends swingwtx.swing.AbstractButton implements ButtonModel, SwingConstants { 76 77 78 private boolean bRetVal; 79 80 public JRadioButton() {this(""); } 81 public JRadioButton(String text) { this(text, false); } 82 public JRadioButton(String text, Icon icon) { this(text, false); } 83 public JRadioButton(String text, boolean selected) { pSelection = selected; pText = text; setModel(this); showMnemonic(); } 84 85 89 public void processMouseEvent(MouseEvent e) { 90 Iterator i = mouseListeners.iterator(); 91 while (i.hasNext()) { 92 MouseListener ml = (MouseListener) i.next(); 93 if (e.eventID == MouseEvent.CLICKED) { ml.mouseClicked(e); processItemEvent(); } 94 if (e.eventID == MouseEvent.ENTERED) ml.mouseEntered(e); 95 if (e.eventID == MouseEvent.EXITED) ml.mouseExited(e); 96 if (e.eventID == MouseEvent.PRESSED) ml.mousePressed(e); 97 if (e.eventID == MouseEvent.RELEASED) ml.mouseReleased(e); 98 } 99 } 100 101 105 public void processKeyEvent(KeyEvent e) { 106 Iterator i = keyListeners.iterator(); 107 while (i.hasNext()) { 108 KeyListener ml = (KeyListener) i.next(); 109 if (e.eventID == KeyEvent.PRESSED) { ml.keyTyped(e); processItemEvent(); } 110 if (e.eventID == KeyEvent.RELEASED) ml.keyReleased(e); 111 if (e.eventID == KeyEvent.PRESSED) ml.keyPressed(e); 112 } 113 } 114 115 118 protected swingwt.awt.Dimension calculatePreferredSize() { 119 swingwt.awt.Dimension size = new swingwt.awt.Dimension( 122 SwingWTUtils.getRenderStringWidth(pText) + 10, 123 SwingWTUtils.getRenderStringHeight(pText) + 6); 124 setSize(size); 125 return size; 126 } 127 128 129 134 public void setSwingWTParent(swingwt.awt.Container parent) throws Exception { 135 descendantHasPeer = true; 136 ppeer = new Button(parent.getComposite(), SWT.RADIO); 137 ppeer.setText(pText); 138 ppeer.setSelection(pSelection); 139 ppeer.setAlignment(SwingWTUtils.translateSwingAlignmentConstant(pVAlign) | 140 SwingWTUtils.translateSwingAlignmentConstant(pHAlign)); 141 peer = ppeer; 142 this.parent = parent; 143 } 144 145 public boolean isSelected() { 146 bRetVal = false; 147 SwingUtilities.invokeSync(new Runnable () { 148 public void run() { 149 if (!SwingWTUtils.isSWTControlAvailable(ppeer)) bRetVal = pSelection; else bRetVal = ppeer.getSelection(); 150 } 151 }); 152 return bRetVal; 153 } 154 155 public void setSelected(final boolean b) { 156 SwingUtilities.invokeSync(new Runnable () { 157 public void run() { 158 if (SwingWTUtils.isSWTControlAvailable(ppeer)) ppeer.setSelection(b); else pSelection = b; 159 } 160 }); 161 processItemEvent(); 162 } 163 164 public Object [] getSelectedObjects() { 165 return null; 166 } 167 168 public boolean isArmed() { 169 return false; 170 } 171 172 public boolean isPressed() { 173 return false; 174 } 175 176 public boolean isRollover() { 177 return false; 178 } 179 180 public void setArmed(boolean b) { 181 } 182 183 public void setPressed(boolean b) { 184 } 185 186 public void setRollover(boolean b) { 187 } 188 189 } 190 | Popular Tags |