1 73 74 75 package swingwtx.swing; 76 77 import org.eclipse.swt.widgets.*; 78 import org.eclipse.swt.*; 79 80 import swingwt.awt.event.*; 81 82 import java.util.*; 83 84 public class JCheckBox extends swingwtx.swing.AbstractButton implements ButtonModel, SwingConstants { 85 86 87 private boolean bRetVal; 88 89 90 private boolean isAWTRadio = false; 91 92 public JCheckBox() {this(""); } 93 public JCheckBox(String text) { this(text, false); } 94 public JCheckBox(String text, Icon icon) { this(text, false); } 95 public JCheckBox(String text, boolean selected) { pText = text; pSelection = selected; setModel(this); showMnemonic();} 96 97 public JCheckBox(String text, boolean selected, ButtonGroup bg) { pText = text; pSelection = selected; isAWTRadio = true; setModel(this); showMnemonic();} 98 99 100 104 public void processMouseEvent(MouseEvent e) { 105 Iterator i = mouseListeners.iterator(); 106 while (i.hasNext()) { 107 MouseListener ml = (MouseListener) i.next(); 108 if (e.eventID == MouseEvent.CLICKED) { ml.mouseClicked(e); processItemEvent(); } 109 if (e.eventID == MouseEvent.ENTERED) ml.mouseEntered(e); 110 if (e.eventID == MouseEvent.EXITED) ml.mouseExited(e); 111 if (e.eventID == MouseEvent.PRESSED) ml.mousePressed(e); 112 if (e.eventID == MouseEvent.RELEASED) ml.mouseReleased(e); 113 } 114 } 115 116 120 public void processKeyEvent(KeyEvent e) { 121 Iterator i = keyListeners.iterator(); 122 while (i.hasNext()) { 123 KeyListener ml = (KeyListener) i.next(); 124 if (e.eventID == KeyEvent.PRESSED) { ml.keyTyped(e); processItemEvent(); } 125 if (e.eventID == KeyEvent.RELEASED) ml.keyReleased(e); 126 if (e.eventID == KeyEvent.PRESSED) ml.keyPressed(e); 127 } 128 } 129 130 133 protected swingwt.awt.Dimension calculatePreferredSize() { 134 swingwt.awt.Dimension size = new swingwt.awt.Dimension( 137 SwingWTUtils.getRenderStringWidth(pText) + 6, 138 SwingWTUtils.getRenderStringHeight(pText) + 6); 139 setSize(size); 140 return size; 141 } 142 143 148 public void setSwingWTParent(swingwt.awt.Container parent) throws Exception { 149 descendantHasPeer = true; 150 if (isAWTRadio) { 151 ppeer = new Button(parent.getComposite(), SWT.RADIO); 152 } else { 153 ppeer = new Button(parent.getComposite(), SWT.CHECK); 154 } 155 ppeer.setText(pText); 156 ppeer.setSelection(pSelection); 157 ppeer.setAlignment( SwingWTUtils.translateSwingAlignmentConstant(pVAlign) | 158 SwingWTUtils.translateSwingAlignmentConstant(pHAlign) ); 159 peer = ppeer; 160 this.parent = parent; 161 } 162 163 public boolean isSelected() { 164 bRetVal = false; 165 SwingUtilities.invokeSync(new Runnable () { 166 public void run() { 167 if (!SwingWTUtils.isSWTControlAvailable(ppeer)) bRetVal = pSelection; else bRetVal = ppeer.getSelection(); 168 } 169 }); 170 return bRetVal; 171 } 172 173 public void setSelected(final boolean b) { 174 SwingUtilities.invokeSync(new Runnable () { 175 public void run() { 176 if (SwingWTUtils.isSWTControlAvailable(ppeer)) ppeer.setSelection(b); else pSelection = b; 177 } 178 }); 179 } 180 181 public Object [] getSelectedObjects() { 182 return null; 183 } 184 185 public int getMnemonic() { 186 return 0; 187 } 188 189 public boolean isArmed() { 190 return false; 191 } 192 193 public boolean isPressed() { 194 return false; 195 } 196 197 public boolean isRollover() { 198 return false; 199 } 200 201 public void setArmed(boolean b) { 202 } 203 204 public void setPressed(boolean b) { 205 } 206 207 public void setRollover(boolean b) { 208 } 209 210 } 211 | Popular Tags |