1 34 35 36 package swingwtx.swing; 37 38 import org.eclipse.swt.widgets.*; 39 import org.eclipse.swt.*; 40 41 import swingwt.awt.event.*; 42 43 import java.util.*; 44 45 public class JToggleButton extends swingwtx.swing.AbstractButton implements ButtonModel, SwingConstants { 46 47 protected Icon pImage = null; 48 49 50 private boolean bRetVal; 51 52 public JToggleButton() {this(""); } 53 public JToggleButton(String text) { pText = text; setModel(this); showMnemonic(); } 54 public JToggleButton(String text, Icon icon) { pText = text; pImage = icon; setModel(this); showMnemonic(); } 55 56 public void setIcon(Icon icon) { 57 pImage = icon; 58 final JToggleButton pthis = this; 59 SwingUtilities.invokeSync(new Runnable () { 60 public void run() { 61 if (SwingWTUtils.isSWTControlAvailable(ppeer)) 62 ppeer.setImage(SwingWTUtils.getSWTImageFromSwingIcon(pthis, pImage)); 63 } 64 }); 65 } 66 67 71 public void processMouseEvent(MouseEvent e) { 72 Iterator i = mouseListeners.iterator(); 73 while (i.hasNext()) { 74 MouseListener ml = (MouseListener) i.next(); 75 if (e.eventID == MouseEvent.CLICKED) { ml.mouseClicked(e); processItemEvent(); } 76 if (e.eventID == MouseEvent.ENTERED) ml.mouseEntered(e); 77 if (e.eventID == MouseEvent.EXITED) ml.mouseExited(e); 78 if (e.eventID == MouseEvent.PRESSED) ml.mousePressed(e); 79 if (e.eventID == MouseEvent.RELEASED) ml.mouseReleased(e); 80 } 81 } 82 83 87 public void processKeyEvent(KeyEvent e) { 88 Iterator i = keyListeners.iterator(); 89 while (i.hasNext()) { 90 KeyListener ml = (KeyListener) i.next(); 91 if (e.eventID == KeyEvent.PRESSED) { ml.keyTyped(e); processItemEvent(); } 92 if (e.eventID == KeyEvent.RELEASED) ml.keyReleased(e); 93 if (e.eventID == KeyEvent.PRESSED) ml.keyPressed(e); 94 } 95 } 96 97 102 public void setSwingWTParent(swingwt.awt.Container parent) throws Exception { 103 descendantHasPeer = true; 104 ppeer = new Button(parent.getComposite(), SWT.TOGGLE); 105 if (pText != null) ppeer.setText(pText); 106 ppeer.setSelection(pSelection); 107 ppeer.setAlignment(pVAlign | pHAlign); 108 peer = ppeer; 109 this.parent = parent; 110 } 111 112 public boolean isSelected() { 113 bRetVal = false; 114 SwingUtilities.invokeSync(new Runnable () { 115 public void run() { 116 if (!SwingWTUtils.isSWTControlAvailable(ppeer)) bRetVal = false; else bRetVal = ppeer.getSelection(); 117 } 118 }); 119 return bRetVal; 120 } 121 122 public void setSelected(final boolean b) { 123 SwingUtilities.invokeSync(new Runnable () { 124 public void run() { 125 if (SwingWTUtils.isSWTControlAvailable(ppeer)) ppeer.setSelection(b); else pSelection = b; 126 } 127 }); 128 } 129 130 public Object [] getSelectedObjects() { 131 return null; 132 } 133 134 public boolean isArmed() { 135 return false; 136 } 137 138 public boolean isPressed() { 139 return false; 140 } 141 142 public boolean isRollover() { 143 return false; 144 } 145 146 public void setArmed(boolean b) { 147 } 148 149 public void setPressed(boolean b) { 150 } 151 152 public void setRollover(boolean b) { 153 } 154 155 } 156 | Popular Tags |