FILE COMPARISON
Produced: 2/18/2011 1:28:07 AM
   
Mode:  All Lines  
Left base folder: C:\Documents and Settings\krollins\My Documents\Admin\OpenSource\eRCP\eSWT\eSWT-1.2.orig  
Right base folder: C:\Documents and Settings\krollins\My Documents\Admin\OpenSource\eRCP\eSWT\eSWT-1.2.today  
   
File: org.eclipse.ercp.swt.core.win\src-platform\org\eclipse\swt\widgets\Button.java  
1 /******************************************************************************* = 1 /*******************************************************************************
2 * Copyright (c) 2000, 2005 IBM Corporation and others.   2 * Copyright (c) 2000, 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials   3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0   4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at   5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html   6 * http://www.eclipse.org/legal/epl-v10.html
7 *   7 *
8 * Contributors:   8 * Contributors:
9 *     IBM Corporation - initial API and implementation   9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/   10 *******************************************************************************/
    <> 11  
      12 /*******************************************************************************
      13 * Additions/modifications to this source file by Oracle America, Inc. 2011
      14 *******************************************************************************/
      15  
11 package org.eclipse.swt.widgets; = 16 package org.eclipse.swt.widgets;
12     17  
13     18  
14 import org.eclipse.swt.*;   19 import org.eclipse.swt.*;
15 import org.eclipse.swt.graphics.*;   20 import org.eclipse.swt.graphics.*;
16 import org.eclipse.swt.events.*;   21 import org.eclipse.swt.events.*;
17     22  
18 import com.ibm.ugl.eswt.OS;   23 import com.ibm.ugl.eswt.OS;
19     24  
20 /**   25 /**
21 * Instances of this class represent a selectable user interface object that   26 * Instances of this class represent a selectable user interface object that
22 * issues notification when pressed and released.   27 * issues notification when pressed and released.
23 * <dl>   28 * <dl>
24 * <dt><b>Styles:</b></dt>   29 * <dt><b>Styles:</b></dt>
25 * <dd>CHECK, PUSH, RADIO, TOGGLE, FLAT</dd>   30 * <dd>CHECK, PUSH, RADIO, TOGGLE, FLAT</dd>
26 * <dd>LEFT, RIGHT, CENTER</dd>   31 * <dd>LEFT, RIGHT, CENTER</dd>
27 * <dt><b>Events:</b></dt>   32 * <dt><b>Events:</b></dt>
28 * <dd>Selection</dd>   33 * <dd>Selection</dd>
29 * </dl>   34 * </dl>
30 * <p>   35 * <p>
31 * Note: Only one of the styles CHECK, PUSH, RADIO, and TOGGLE   36 * Note: Only one of the styles CHECK, PUSH, RADIO, and TOGGLE
32 * may be specified.   37 * may be specified.
33 * </p><p>   38 * </p><p>
34 * Note: Only one of the styles LEFT, RIGHT, and CENTER may be specified.   39 * Note: Only one of the styles LEFT, RIGHT, and CENTER may be specified.
35 * </p><p>   40 * </p><p>
36 * IMPORTANT: This class is intended to be subclassed <em>only</em>   41 * IMPORTANT: This class is intended to be subclassed <em>only</em>
37 * within the SWT implementation.   42 * within the SWT implementation.
38 * </p>   43 * </p>
39 */   44 */
40     45  
41 public class Button extends Control {   46 public class Button extends Control {
42         Image image;   47         Image image;
43         int alignment = -1;   48         int alignment = -1;
44         boolean selection = false;   49         boolean selection = false;
45         String text;   50         String text;
46         boolean isDefault = false;   51         boolean isDefault = false;
47           52        
48 /**   53 /**
49 * Constructs a new instance of this class given its parent   54 * Constructs a new instance of this class given its parent
50 * and a style value describing its behavior and appearance.   55 * and a style value describing its behavior and appearance.
51 * <p>   56 * <p>
52 * The style value is either one of the style constants defined in   57 * The style value is either one of the style constants defined in
53 * class <code>SWT</code> which is applicable to instances of this   58 * class <code>SWT</code> which is applicable to instances of this
54 * class, or must be built by <em>bitwise OR</em>'ing together   59 * class, or must be built by <em>bitwise OR</em>'ing together
55 * (that is, using the <code>int</code> "|" operator) two or more   60 * (that is, using the <code>int</code> "|" operator) two or more
56 * of those <code>SWT</code> style constants. The class description   61 * of those <code>SWT</code> style constants. The class description
57 * lists the style constants that are applicable to the class.   62 * lists the style constants that are applicable to the class.
58 * Style bits are also inherited from superclasses.   63 * Style bits are also inherited from superclasses.
59 * </p>   64 * </p>
60 *   65 *
61 * @param parent a composite control which will be the parent of the new instance (cannot be null)   66 * @param parent a composite control which will be the parent of the new instance (cannot be null)
62 * @param style the style of control to construct   67 * @param style the style of control to construct
63 *   68 *
64 * @exception IllegalArgumentException <ul>   69 * @exception IllegalArgumentException <ul>
65 *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>   70 *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
66 * </ul>   71 * </ul>
67 * @exception SWTException <ul>   72 * @exception SWTException <ul>
68 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>   73 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
69 *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>   74 *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
70 * </ul>   75 * </ul>
71 *   76 *
72 * @see SWT#CHECK   77 * @see SWT#CHECK
73 * @see SWT#PUSH   78 * @see SWT#PUSH
74 * @see SWT#RADIO   79 * @see SWT#RADIO
75 * @see SWT#TOGGLE   80 * @see SWT#TOGGLE
76 * @see SWT#FLAT   81 * @see SWT#FLAT
77 * @see SWT#LEFT   82 * @see SWT#LEFT
78 * @see SWT#RIGHT   83 * @see SWT#RIGHT
79 * @see SWT#CENTER   84 * @see SWT#CENTER
80 * @see Widget#checkSubclass   85 * @see Widget#checkSubclass
81 * @see Widget#getStyle   86 * @see Widget#getStyle
82 */   87 */
83 public Button(Composite parent, int style) {   88 public Button(Composite parent, int style) {
84         super(parent, checkStyle(style));   89         super(parent, checkStyle(style));
85         OS.Button_SetAlignment(internal_handle, getAlignmentStyle(internal_style));   90         OS.Button_SetAlignment(internal_handle, getAlignmentStyle(internal_style));
86 }   91 }
87 /**   92 /**
88 * Adds the listener to the collection of listeners who will   93 * Adds the listener to the collection of listeners who will
89 * be notified when the control is selected, by sending   94 * be notified when the control is selected, by sending
90 * it one of the messages defined in the <code>SelectionListener</code>   95 * it one of the messages defined in the <code>SelectionListener</code>
91 * interface.   96 * interface.
92 * <p>   97 * <p>
93 * <code>widgetSelected</code> is called when the control is selected.   98 * <code>widgetSelected</code> is called when the control is selected.
94 * <code>widgetDefaultSelected</code> is not called.   99 * <code>widgetDefaultSelected</code> is not called.
95 * </p>   100 * </p>
96 *   101 *
97 * @param listener the listener which should be notified   102 * @param listener the listener which should be notified
98 *   103 *
99 * @exception IllegalArgumentException <ul>   104 * @exception IllegalArgumentException <ul>
100 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>   105 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
101 * </ul>   106 * </ul>
102 * @exception SWTException <ul>   107 * @exception SWTException <ul>
103 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   108 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
104 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   109 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
105 * </ul>   110 * </ul>
106 *   111 *
107 * @see SelectionListener   112 * @see SelectionListener
108 * @see #removeSelectionListener   113 * @see #removeSelectionListener
109 * @see SelectionEvent   114 * @see SelectionEvent
110 */   115 */
111 public void addSelectionListener(SelectionListener listener) {   116 public void addSelectionListener(SelectionListener listener) {
112         checkWidget();   117         checkWidget();
113         if (listener == null) error(SWT.ERROR_NULL_ARGUMENT);   118         if (listener == null) error(SWT.ERROR_NULL_ARGUMENT);
114         TypedListener typedListener = new TypedListener(listener);   119         TypedListener typedListener = new TypedListener(listener);
115         addListener(SWT.Selection, typedListener);   120         addListener(SWT.Selection, typedListener);
116         addListener(SWT.DefaultSelection, typedListener);   121         addListener(SWT.DefaultSelection, typedListener);
117 }   122 }
118 static int checkStyle(int style) {   123 static int checkStyle(int style) {
119         style = checkBits(style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, 0, 0);   124         style = checkBits(style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, 0, 0);
120         if ((style & SWT.PUSH) != 0) {   125         if ((style & SWT.PUSH) != 0) {
121                 return checkBits(style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);   126                 return checkBits(style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
122         }   127         }
123         if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) {   128         if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) {
124                 return checkBits(style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);   129                 return checkBits(style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
125         }   130         }
126         return style;   131         return style;
127 }   132 }
128 private int getAlignmentStyle(int style) {   133 private int getAlignmentStyle(int style) {
129         int nativeStyle = 0;   134         int nativeStyle = 0;
130           135        
131         if ((style & SWT.LEAD) == SWT.LEAD) {   136         if ((style & SWT.LEAD) == SWT.LEAD) {
132                 nativeStyle = OS.STYLE_LEAD;   137                 nativeStyle = OS.STYLE_LEAD;
133         } else if ((style & SWT.CENTER) == SWT.CENTER) {   138         } else if ((style & SWT.CENTER) == SWT.CENTER) {
134                 nativeStyle = OS.STYLE_CENTER;   139                 nativeStyle = OS.STYLE_CENTER;
135         } else if ((style & SWT.TRAIL) == SWT.TRAIL) {   140         } else if ((style & SWT.TRAIL) == SWT.TRAIL) {
136                 nativeStyle = OS.STYLE_TRAIL;   141                 nativeStyle = OS.STYLE_TRAIL;
137         }   142         }
138         return nativeStyle;   143         return nativeStyle;
139 }   144 }
140 private void buttonCallback() {   145 private void buttonCallback() {
141     if ((internal_style & SWT.PUSH) == 0) {   146     if ((internal_style & SWT.PUSH) == 0) {
142                 if ((internal_style & SWT.RADIO) != 0 && (internal_parent.getStyle() & SWT.NO_RADIO_GROUP) == 0) {   147                 if ((internal_style & SWT.RADIO) != 0 && (internal_parent.getStyle() & SWT.NO_RADIO_GROUP) == 0) {
143                     selectRadio();   148                     selectRadio();
144                 }   149                 }
145                 else {   150                 else {
146                     this.selection = !this.selection;   151                     this.selection = !this.selection;
147                 }   152                 }
148     }   153     }
149     postEvent(SWT.Selection);   154     postEvent(SWT.Selection);
150 }   155 }
151     156  
152 void click() {   157 void click() {
153         internal_sendEvent(SWT.Selection);                158         internal_sendEvent(SWT.Selection);             
154 }   159 }
155     160  
156 protected void internal_createHandle(int index) {   161 protected void internal_createHandle(int index) {
157         /*   162         /*
158          * Feature in QT. Buttons don't support alignment, so   163          * Feature in QT. Buttons don't support alignment, so
159          * we only need to check the flags for button type.   164          * we only need to check the flags for button type.
160          */                       165          */                    
161         /*   166         /*
162          * Another feature in QT - widgets are initially set to   167          * Another feature in QT - widgets are initially set to
163          * be their preferred sizes.Fix is to explictily set the   168          * be their preferred sizes.Fix is to explictily set the
164          * initial widget size to (0, 0).   169          * initial widget size to (0, 0).
165          */   170          */
166            171         
167         /* CHECK button */   172         /* CHECK button */
168         if ((internal_style & SWT.CHECK) != 0) {   173         if ((internal_style & SWT.CHECK) != 0) {
169                 internal_handle = OS.Checkbox_New(internal_parent.internal_handle, internal_getNativeStyle());   174                 internal_handle = OS.Checkbox_New(internal_parent.internal_handle, internal_getNativeStyle());
170                 if (internal_handle == 0) error(SWT.ERROR_NO_HANDLES);   175                 if (internal_handle == 0) error(SWT.ERROR_NO_HANDLES);
171                 return;   176                 return;
172         }   177         }
173     178  
174         /* RADIO button */   179         /* RADIO button */
175         if ((internal_style & SWT.RADIO) != 0) {   180         if ((internal_style & SWT.RADIO) != 0) {
176                 internal_handle = OS.RadioButton_New(internal_parent.internal_handle, internal_getNativeStyle());   181                 internal_handle = OS.RadioButton_New(internal_parent.internal_handle, internal_getNativeStyle());
177                 if (internal_handle == 0) error(SWT.ERROR_NO_HANDLES);   182                 if (internal_handle == 0) error(SWT.ERROR_NO_HANDLES);
178                 return;   183                 return;
179         }   184         }
180     185  
181         /* PUSH button */   186         /* PUSH button */
182         if ((internal_style & SWT.PUSH) != 0) {   187         if ((internal_style & SWT.PUSH) != 0) {
183                 internal_handle = OS.PushButton_New(internal_parent.internal_handle, internal_getNativeStyle());   188                 internal_handle = OS.PushButton_New(internal_parent.internal_handle, internal_getNativeStyle());
184                 if (internal_handle == 0) error(SWT.ERROR_NO_HANDLES);   189                 if (internal_handle == 0) error(SWT.ERROR_NO_HANDLES);
185                 return;   190                 return;
186         }   191         }
187     192  
188         /* TOGGLE button */   193         /* TOGGLE button */
189         if ((internal_style & SWT.TOGGLE) != 0) {   194         if ((internal_style & SWT.TOGGLE) != 0) {
190                 internal_handle = OS.ToggleButton_New(internal_parent.internal_handle, internal_getNativeStyle());   195                 internal_handle = OS.ToggleButton_New(internal_parent.internal_handle, internal_getNativeStyle());
191                 if (internal_handle == 0) error(SWT.ERROR_NO_HANDLES);   196                 if (internal_handle == 0) error(SWT.ERROR_NO_HANDLES);
192                 return;   197                 return;
193         }   198         }
194         OS.Button_SetAlignment(internal_handle, getAlignmentStyle(internal_style));   199         OS.Button_SetAlignment(internal_handle, getAlignmentStyle(internal_style));
195 }   200 }
196 protected int internal_getNativeStyle() {   201 protected int internal_getNativeStyle() {
197         int nativeStyle = super.internal_getNativeStyle();   202         int nativeStyle = super.internal_getNativeStyle();
198         if ((internal_style & SWT.FLAT) == SWT.FLAT) {   203         if ((internal_style & SWT.FLAT) == SWT.FLAT) {
199                 nativeStyle |= OS.STYLE_FLAT;   204                 nativeStyle |= OS.STYLE_FLAT;
200         }   205         }
201         return nativeStyle;   206         return nativeStyle;
202 }   207 }
203 /**   208 /**
204 * Returns a value which describes the position of the   209 * Returns a value which describes the position of the
205 * text or image in the receiver. The value will be one of   210 * text or image in the receiver. The value will be one of
206 * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.   211 * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.
207 *   212 *
208 * @return the alignment   213 * @return the alignment
209 *   214 *
210 * @exception SWTException <ul>   215 * @exception SWTException <ul>
211 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   216 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
212 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   217 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
213 * </ul>   218 * </ul>
214 */   219 */
215 public int getAlignment() {   220 public int getAlignment() {
216         checkWidget();   221         checkWidget();
217         if (alignment != -1) return alignment;   222         if (alignment != -1) return alignment;
218         if ((internal_style & SWT.LEFT) != 0) return SWT.LEFT;   223         if ((internal_style & SWT.LEFT) != 0) return SWT.LEFT;
219         if ((internal_style & SWT.CENTER) != 0) return SWT.CENTER;   224         if ((internal_style & SWT.CENTER) != 0) return SWT.CENTER;
220         return SWT.RIGHT;   225         return SWT.RIGHT;
221 }   226 }
222     227  
223 /**   228 /**
224 * Returns the receiver's image if it has one, or null   229 * Returns the receiver's image if it has one, or null
225 * if it does not.   230 * if it does not.
226 *   231 *
227 * @return the receiver's image   232 * @return the receiver's image
228 *   233 *
229 * @exception SWTException <ul>   234 * @exception SWTException <ul>
230 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   235 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
231 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   236 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
232 * </ul>   237 * </ul>
233 */   238 */
234 public Image getImage() {   239 public Image getImage() {
235         checkWidget();   240         checkWidget();
236         return image;   241         return image;
237 }   242 }
238     243  
239 /**   244 /**
240 * Returns <code>true</code> if the receiver is selected,   245 * Returns <code>true</code> if the receiver is selected,
241 * and false otherwise.   246 * and false otherwise.
242 * <p>   247 * <p>
243 * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,   248 * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
244 * it is selected when it is checked. When it is of type <code>TOGGLE</code>,   249 * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
245 * it is selected when it is pushed in. If the receiver is of any other type,   250 * it is selected when it is pushed in. If the receiver is of any other type,
246 * this method returns false.   251 * this method returns false.
247 *   252 *
248 * @return the selection state   253 * @return the selection state
249 *   254 *
250 * @exception SWTException <ul>   255 * @exception SWTException <ul>
251 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   256 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
252 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   257 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
253 * </ul>   258 * </ul>
254 */   259 */
255 public boolean getSelection() {   260 public boolean getSelection() {
256         checkWidget();   261         checkWidget();
    <> 262         if ((internal_style & SWT.CHECK) != 0 || (internal_style & SWT.RADIO) != 0 || (internal_style & SWT.TOGGLE) != 0) {
257         return selection;                 263             return selection;
      264     } else {
      265                 return OS.Button_GetSelection(internal_handle);
      266     }
258 } = 267 }
259 /**   268 /**
260 * Returns the receiver's text, which will be an empty   269 * Returns the receiver's text, which will be an empty
261 * string if it has never been set.   270 * string if it has never been set.
262 *   271 *
263 * @return the receiver's text   272 * @return the receiver's text
264 *   273 *
265 * @exception SWTException <ul>   274 * @exception SWTException <ul>
266 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   275 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
267 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   276 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
268 * </ul>   277 * </ul>
269 */   278 */
270 public String getText() {   279 public String getText() {
271         checkWidget();   280         checkWidget();
272         return text;   281         return text;
273 }   282 }
274     283  
275 void releaseWidget() {   284 void releaseWidget() {
276         // Unset the default button before the widget is   285         // Unset the default button before the widget is
277         // disposed   286         // disposed
278         if (isDefault) {   287         if (isDefault) {
279                 getShell().setDefaultButton(null);   288                 getShell().setDefaultButton(null);
280         }         289         }      
281           290        
282         super.releaseWidget();   291         super.releaseWidget();
283         image = null;   292         image = null;
284 }   293 }
285     294  
286 /**   295 /**
287 * Removes the listener from the collection of listeners who will   296 * Removes the listener from the collection of listeners who will
288 * be notified when the control is selected.   297 * be notified when the control is selected.
289 *   298 *
290 * @param listener the listener which should no longer be notified   299 * @param listener the listener which should no longer be notified
291 *   300 *
292 * @exception IllegalArgumentException <ul>   301 * @exception IllegalArgumentException <ul>
293 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>   302 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
294 * </ul>   303 * </ul>
295 * @exception SWTException <ul>   304 * @exception SWTException <ul>
296 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   305 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
297 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   306 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
298 * </ul>   307 * </ul>
299 *   308 *
300 * @see SelectionListener   309 * @see SelectionListener
301 * @see #addSelectionListener   310 * @see #addSelectionListener
302 */   311 */
303 public void removeSelectionListener(SelectionListener listener) {   312 public void removeSelectionListener(SelectionListener listener) {
304         checkWidget();   313         checkWidget();
305         if (listener == null) error(SWT.ERROR_NULL_ARGUMENT);   314         if (listener == null) error(SWT.ERROR_NULL_ARGUMENT);
306         if (eventTable == null) return;   315         if (eventTable == null) return;
307         eventTable.unhook(SWT.Selection, listener);   316         eventTable.unhook(SWT.Selection, listener);
308         eventTable.unhook(SWT.DefaultSelection, listener);   317         eventTable.unhook(SWT.DefaultSelection, listener);
309 }   318 }
310 void selectRadio() {   319 void selectRadio() {
311         /*   320         /*
312         * This code is intentionally commented.  When two groups   321         * This code is intentionally commented.  When two groups
313         * of radio buttons with the same parent are separated by   322         * of radio buttons with the same parent are separated by
314         * another control, the correct behavior should be that   323         * another control, the correct behavior should be that
315         * the two groups act independently.  This is consistent   324         * the two groups act independently.  This is consistent
316         * with radio tool and menu items.  The commented code   325         * with radio tool and menu items.  The commented code
317         * implements this behavior.   326         * implements this behavior.
318         */   327         */
319 //      int index = 0;   328 //      int index = 0;
320 //      Control [] children = parent.getChildren ();   329 //      Control [] children = parent.getChildren ();
321 //      while (index < children.length && children [index] != this) index++;   330 //      while (index < children.length && children [index] != this) index++;
322 //      int i = index - 1;   331 //      int i = index - 1;
323 //      while (i >= 0 && children [i].setRadioSelection (false)) --i;   332 //      while (i >= 0 && children [i].setRadioSelection (false)) --i;
324 //      int j = index + 1;   333 //      int j = index + 1;
325 //      while (j < children.length && children [j].setRadioSelection (false)) j++;   334 //      while (j < children.length && children [j].setRadioSelection (false)) j++;
326 //      setSelection (true);   335 //      setSelection (true);
327       336    
328         Control[] children = internal_parent.getChildren();   337         Control[] children = internal_parent.getChildren();
329         for (int i = 0; i < children.length; i++) {   338         for (int i = 0; i < children.length; i++) {
330                 Control child = children[i];   339                 Control child = children[i];
331                 if (this != child) child.setRadioSelection(false);   340                 if (this != child) child.setRadioSelection(false);
332         }   341         }
333         setSelection(true);   342         setSelection(true);
334 }   343 }
335 boolean setRadioSelection(boolean value) {   344 boolean setRadioSelection(boolean value) {
336         if ((internal_style & SWT.RADIO) == 0) return false;   345         if ((internal_style & SWT.RADIO) == 0) return false;
337         if (getSelection() != value) {   346         if (getSelection() != value) {
338                 setSelection(value);   347                 setSelection(value);
339                 postEvent(SWT.Selection);   348                 postEvent(SWT.Selection);
340         }   349         }
341         return true;   350         return true;
342 }   351 }
343 /**   352 /**
344 * Controls how text and images will be displayed   353 * Controls how text and images will be displayed
345 * in the receiver. The argument should be one of   354 * in the receiver. The argument should be one of
346 * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.   355 * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.
347 *   356 *
348 * @param alignment the new alignment   357 * @param alignment the new alignment
349 *   358 *
350 * @exception SWTException <ul>   359 * @exception SWTException <ul>
351 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   360 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
352 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   361 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
353 * </ul>   362 * </ul>
354 */   363 */
355 public void setAlignment(int alignment) {   364 public void setAlignment(int alignment) {
356         checkWidget();   365         checkWidget();
357         if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;   366         if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
358         if (this.alignment == alignment) return;   367         if (this.alignment == alignment) return;
359         this.alignment = alignment;   368         this.alignment = alignment;
360         OS.Button_SetAlignment(internal_handle, getAlignmentStyle(alignment));   369         OS.Button_SetAlignment(internal_handle, getAlignmentStyle(alignment));
361 }   370 }
362 void setDefault(boolean value) {   371 void setDefault(boolean value) {
363         isDefault = value;   372         isDefault = value;
364 }   373 }
365     374  
366 /**   375 /**
367 * Sets the receiver's image to the argument, which may be   376 * Sets the receiver's image to the argument, which may be
368 * <code>null</code> indicating that no image should be displayed.   377 * <code>null</code> indicating that no image should be displayed.
369 *   378 *
370 * @param image the image to display on the receiver (may be <code>null</code>)   379 * @param image the image to display on the receiver (may be <code>null</code>)
371 *   380 *
372 * @exception IllegalArgumentException <ul>   381 * @exception IllegalArgumentException <ul>
373 *    <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>   382 *    <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
374 * </ul>   383 * </ul>
375 * @exception SWTException <ul>   384 * @exception SWTException <ul>
376 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   385 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
377 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   386 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
378 * </ul>   387 * </ul>
379 */   388 */
380 public void setImage(Image image) {   389 public void setImage(Image image) {
381         checkWidget();   390         checkWidget();
382         this.image = image;   391         this.image = image;
383           392        
384         if (image == null) {   393         if (image == null) {
385                 OS.Button_SetImage(internal_handle, 0);   394                 OS.Button_SetImage(internal_handle, 0);
386         } else {   395         } else {
387                 if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);   396                 if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
388                 OS.Button_SetImage(internal_handle, image.internal_handle);   397                 OS.Button_SetImage(internal_handle, image.internal_handle);
389         }   398         }
390 }   399 }
391 /**   400 /**
392 * Sets the selection state of the receiver, if it is of type <code>CHECK</code>,   401 * Sets the selection state of the receiver, if it is of type <code>CHECK</code>,
393 * <code>RADIO</code>, or <code>TOGGLE</code>.   402 * <code>RADIO</code>, or <code>TOGGLE</code>.
394 *   403 *
395 * <p>   404 * <p>
396 * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,   405 * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
397 * it is selected when it is checked. When it is of type <code>TOGGLE</code>,   406 * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
398 * it is selected when it is pushed in.   407 * it is selected when it is pushed in.
399 *   408 *
400 * @param selected the new selection state   409 * @param selected the new selection state
401 *   410 *
402 * @exception SWTException <ul>   411 * @exception SWTException <ul>
403 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   412 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
404 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   413 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
405 * </ul>   414 * </ul>
406 */   415 */
407 public void setSelection(boolean selected) {   416 public void setSelection(boolean selected) {
408         checkWidget();   417         checkWidget();
409         if ((internal_style & SWT.CHECK) != 0 || (internal_style & SWT.RADIO) != 0 || (internal_style & SWT.TOGGLE) != 0) {   418         if ((internal_style & SWT.CHECK) != 0 || (internal_style & SWT.RADIO) != 0 || (internal_style & SWT.TOGGLE) != 0) {
410                 selection = selected;   419                 selection = selected;
411                 OS.Button_SetSelection(internal_handle, selected);   420                 OS.Button_SetSelection(internal_handle, selected);
412         }   421         }
413 }   422 }
414 /**   423 /**
415 * Sets the receiver's text.   424 * Sets the receiver's text.
416 * <p>   425 * <p>
417 * This method sets the button label.  The label may include   426 * This method sets the button label.  The label may include
418 * the mnemonic character but must not contain line delimiters.   427 * the mnemonic character but must not contain line delimiters.
419 * </p>   428 * </p>
420 * <p>   429 * <p>
421 * Mnemonics are indicated by an '&amp' that causes the next   430 * Mnemonics are indicated by an '&amp' that causes the next
422 * character to be the mnemonic.  When the user presses a   431 * character to be the mnemonic.  When the user presses a
423 * key sequence that matches the mnemonic, a selection   432 * key sequence that matches the mnemonic, a selection
424 * event occurs. On most platforms, the mnemonic appears   433 * event occurs. On most platforms, the mnemonic appears
425 * underlined but may be emphasised in a platform specific   434 * underlined but may be emphasised in a platform specific
426 * manner.  The mnemonic indicator character '&amp' can be   435 * manner.  The mnemonic indicator character '&amp' can be
427 * escaped by doubling it in the string, causing a single   436 * escaped by doubling it in the string, causing a single
428 *'&amp' to be displayed.   437 *'&amp' to be displayed.
429 * </p>   438 * </p>
430 *   439 *
431 * @param string the new text   440 * @param string the new text
432 *   441 *
433 * @exception IllegalArgumentException <ul>   442 * @exception IllegalArgumentException <ul>
434 *    <li>ERROR_NULL_ARGUMENT - if the text is null</li>   443 *    <li>ERROR_NULL_ARGUMENT - if the text is null</li>
435 * </ul>   444 * </ul>
436 * @exception SWTException <ul>   445 * @exception SWTException <ul>
437 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>   446 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
438 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>   447 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
439 * </ul>   448 * </ul>
440 */   449 */
441 public void setText(String string) {   450 public void setText(String string) {
442         checkWidget();   451         checkWidget();
443         if (string == null) error (SWT.ERROR_NULL_ARGUMENT);   452         if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
444         text = string;   453         text = string;
445         OS.Button_SetLabel(internal_handle, string);   454         OS.Button_SetLabel(internal_handle, string);
446         OS.Button_SetImage(internal_handle,0);   455         OS.Button_SetImage(internal_handle,0);
447 }   456 }
448     457  
449 public boolean allowTraverseByArrowKey(Event event) {   458 public boolean allowTraverseByArrowKey(Event event) {
450         switch (event.keyCode) {   459         switch (event.keyCode) {
451                 case SWT.ARROW_UP :   460                 case SWT.ARROW_UP :
452                 case SWT.ARROW_LEFT :   461                 case SWT.ARROW_LEFT :
453                 case SWT.ARROW_DOWN :   462                 case SWT.ARROW_DOWN :
454                 case SWT.ARROW_RIGHT :   463                 case SWT.ARROW_RIGHT :
455                 return true;   464                 return true;
456         }   465         }
457         return false;   466         return false;
458 }   467 }
459     468  
460 protected boolean traverse(Event event) {   469 protected boolean traverse(Event event) {
461         if (isDisposed()) return false;   470         if (isDisposed()) return false;
462         if(allowTraverseByArrowKey(event)) {   471         if(allowTraverseByArrowKey(event)) {
463                 return traverseByArrowKey(event);   472                 return traverseByArrowKey(event);
464         }   473         }
465         return super.traverse(event);   474         return super.traverse(event);
466 }   475 }
467     476  
468 }   477 }