1 /*******************************************************************************
\r
2 * Copyright (c) 2011 Laurent CARON
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * Laurent CARON (laurent.caron at gmail dot com) - Implementation
\r
10 *******************************************************************************/
\r
11 package org.mihalis.opal.horizontalSpinner;
\r
13 import java.text.DecimalFormatSymbols;
\r
14 import java.util.ArrayList;
\r
15 import java.util.List;
\r
17 import org.eclipse.swt.SWT;
\r
18 import org.eclipse.swt.SWTException;
\r
19 import org.eclipse.swt.events.KeyAdapter;
\r
20 import org.eclipse.swt.events.KeyEvent;
\r
21 import org.eclipse.swt.events.ModifyEvent;
\r
22 import org.eclipse.swt.events.ModifyListener;
\r
23 import org.eclipse.swt.events.SelectionAdapter;
\r
24 import org.eclipse.swt.events.SelectionEvent;
\r
25 import org.eclipse.swt.events.SelectionListener;
\r
26 import org.eclipse.swt.events.VerifyEvent;
\r
27 import org.eclipse.swt.events.VerifyListener;
\r
28 import org.eclipse.swt.graphics.Color;
\r
29 import org.eclipse.swt.graphics.Cursor;
\r
30 import org.eclipse.swt.graphics.Font;
\r
31 import org.eclipse.swt.graphics.Image;
\r
32 import org.eclipse.swt.layout.GridData;
\r
33 import org.eclipse.swt.layout.GridLayout;
\r
34 import org.eclipse.swt.widgets.Button;
\r
35 import org.eclipse.swt.widgets.Composite;
\r
36 import org.eclipse.swt.widgets.Menu;
\r
37 import org.eclipse.swt.widgets.Text;
\r
38 import org.mihalis.opal.utils.StringUtil;
\r
41 * Instances of this class are selectable user interface objects that allow the user to enter and modify numeric values.
\r
44 * <dt><b>Styles:</b></dt>
\r
45 * <dd>READ_ONLY, FLAP</dd>
\r
46 * <dt><b>Events:</b></dt>
\r
47 * <dd>Selection, Modify</dd>
\r
51 public class HorizontalSpinner extends Composite {
\r
52 private final List<ModifyListener> modifyListeners = new ArrayList<ModifyListener>();
\r
53 private final List<SelectionListener> selectionListeners = new ArrayList<SelectionListener>();
\r
55 private Button leftButton;
\r
56 private Button rightButton;
\r
58 private int digits = 0;
\r
59 private int increment = 1;
\r
60 private int maximum = 0;
\r
61 private int minimum = 255;
\r
62 private int pageIncrement = 10;
\r
63 private int storedValue = 0;
\r
65 private final char decimalFormatSeparator;
\r
68 * Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
\r
70 * The style value is either one of the style constants defined in class <code>SWT</code> which is applicable to instances of this class, or must be built by <em>bitwise OR</em>'ing together (that is, using the <code>int</code> "|" operator) two or more of those <code>SWT</code> style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.
\r
73 * @param parent a composite control which will be the parent of the new instance (cannot be null)
\r
74 * @param style the style of control to construct
\r
76 * @exception IllegalArgumentException <ul>
\r
77 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
\r
79 * @exception SWTException <ul>
\r
80 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
\r
81 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
\r
84 * @see SWT#READ_ONLY
\r
87 public HorizontalSpinner(final Composite parent, final int style) {
\r
88 super(parent, style);
\r
90 final GridLayout gd = new GridLayout(3, false);
\r
91 gd.horizontalSpacing = gd.verticalSpacing = 0;
\r
92 gd.marginWidth = gd.marginHeight = 0;
\r
95 this.createContent(style);
\r
96 this.addTextListeners();
\r
97 this.addButtonsListener();
\r
98 this.addModifyListeners();
\r
100 this.decimalFormatSeparator = new DecimalFormatSymbols().getDecimalSeparator();
\r
104 * Create the content of the widget
\r
106 * @param style style of the widget
\r
108 private void createContent(final int style) {
\r
109 final boolean readOnly = (style & SWT.READ_ONLY) == SWT.READ_ONLY;
\r
110 final boolean flat = (style & SWT.FLAT) == SWT.FLAT;
\r
112 final int buttonStyle = SWT.ARROW | (flat ? SWT.FLAT : SWT.NONE);
\r
113 this.leftButton = new Button(this, buttonStyle | SWT.LEFT);
\r
114 this.leftButton.setFont(this.getFont());
\r
115 this.leftButton.setBackground(this.getBackground());
\r
116 this.leftButton.setCursor(this.getCursor());
\r
117 this.leftButton.setEnabled(this.getEnabled());
\r
118 this.leftButton.setFont(this.getFont());
\r
119 this.leftButton.setForeground(this.getForeground());
\r
120 this.leftButton.setLayoutData(new GridData(GridData.FILL, GridData.FILL, false, false));
\r
122 this.text = new Text(this, readOnly ? SWT.READ_ONLY : SWT.NONE);
\r
123 final GridData gd = new GridData(GridData.FILL, GridData.CENTER, true, false);
\r
124 gd.minimumWidth = 40;
\r
125 this.text.setLayoutData(gd);
\r
127 this.rightButton = new Button(this, buttonStyle | SWT.RIGHT);
\r
128 this.rightButton.setFont(this.getFont());
\r
129 this.rightButton.setBackground(this.getBackground());
\r
130 this.rightButton.setCursor(this.getCursor());
\r
131 this.rightButton.setEnabled(this.getEnabled());
\r
132 this.rightButton.setFont(this.getFont());
\r
133 this.rightButton.setForeground(this.getForeground());
\r
134 this.rightButton.setLayoutData(new GridData(GridData.FILL, GridData.FILL, false, false));
\r
139 * Add the text listeners
\r
141 private void addTextListeners() {
\r
142 this.text.addVerifyListener(new VerifyListener() {
\r
145 public void verifyText(final VerifyEvent e) {
\r
146 if (e.character != 0 && !Character.isDigit(e.character) && e.keyCode != SWT.BS && e.keyCode != SWT.DEL) {
\r
151 e.doit = HorizontalSpinner.this.verifyEntryAndStoreValue(e.text, e.keyCode);
\r
156 this.text.addKeyListener(new KeyAdapter() {
\r
159 * @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent)
\r
162 public void keyReleased(final KeyEvent e) {
\r
163 if (e.keyCode == SWT.ARROW_UP) {
\r
164 HorizontalSpinner.this.increaseValue(HorizontalSpinner.this.increment);
\r
166 if (e.keyCode == SWT.ARROW_DOWN) {
\r
167 HorizontalSpinner.this.decreaseValue(HorizontalSpinner.this.increment);
\r
169 if (e.keyCode == SWT.PAGE_UP) {
\r
170 HorizontalSpinner.this.increaseValue(HorizontalSpinner.this.pageIncrement);
\r
172 if (e.keyCode == SWT.PAGE_DOWN) {
\r
173 HorizontalSpinner.this.decreaseValue(HorizontalSpinner.this.pageIncrement);
\r
179 this.text.addFocusListener(new org.eclipse.swt.events.FocusAdapter() {
\r
182 * @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent)
\r
185 public void focusLost(final org.eclipse.swt.events.FocusEvent e) {
\r
186 if (HorizontalSpinner.this.text.getText().trim().equals("")) {
\r
187 HorizontalSpinner.this.setSelection(HorizontalSpinner.this.storedValue);
\r
196 * Verify the entry and store the value in the field storedValue
\r
198 * @param entry entry to check
\r
199 * @param keyCode code of the typed key
\r
200 * @return <code>true</code> if the entry if correct, <code>false</code> otherwise
\r
202 private boolean verifyEntryAndStoreValue(final String entry, final int keyCode) {
\r
204 if (keyCode == SWT.DEL) {
\r
205 work = StringUtil.removeCharAt(this.text.getText(), this.text.getCaretPosition());
\r
206 } else if (keyCode == SWT.BS && this.text.getCaretPosition() == 0) {
\r
207 work = StringUtil.removeCharAt(this.text.getText(), this.text.getCaretPosition() - 1);
\r
208 } else if (keyCode == 0) {
\r
211 work = StringUtil.insertString(this.text.getText(), entry, this.text.getCaretPosition());
\r
215 final double d = Double.parseDouble(work.replace(this.decimalFormatSeparator, '.'));
\r
216 this.storedValue = (int) (d * Math.pow(10, this.getDigits()));
\r
217 } catch (final NumberFormatException nfe) {
\r
221 for (final SelectionListener s : HorizontalSpinner.this.selectionListeners) {
\r
222 s.widgetSelected(null);
\r
229 * Add the listener to the buttons
\r
231 private void addButtonsListener() {
\r
232 this.leftButton.addSelectionListener(new SelectionAdapter() {
\r
235 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
\r
238 public void widgetSelected(final SelectionEvent e) {
\r
239 HorizontalSpinner.this.decreaseValue(HorizontalSpinner.this.increment);
\r
243 this.rightButton.addSelectionListener(new SelectionAdapter() {
\r
246 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
\r
249 public void widgetSelected(final SelectionEvent e) {
\r
250 HorizontalSpinner.this.increaseValue(HorizontalSpinner.this.increment);
\r
257 * Increase the value stored in this snippet
\r
259 * @param value value to increase
\r
261 private void increaseValue(final int value) {
\r
262 this.setSelection(this.getSelection() + value);
\r
267 * Decrease the value stored in this snippet
\r
269 * @param value value to decrease
\r
271 private void decreaseValue(final int value) {
\r
272 this.setSelection(this.getSelection() - value);
\r
276 * Add the modify listeners
\r
278 private void addModifyListeners() {
\r
279 this.text.addModifyListener(new ModifyListener() {
\r
282 public void modifyText(final ModifyEvent e) {
\r
283 for (final ModifyListener m : HorizontalSpinner.this.modifyListeners) {
\r
293 * Adds the listener to the collection of listeners who will be notified when the receiver's text is modified, by sending it one of the messages defined in the <code>ModifyListener</code> interface.
\r
295 * @param listener the listener which should be notified
\r
297 * @exception IllegalArgumentException <ul>
\r
298 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
\r
300 * @exception SWTException <ul>
\r
301 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
302 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
305 * @see ModifyListener
\r
306 * @see #removeModifyListener
\r
307 * @see org.eclipse.swt.widgets.Spinner#addModifyListener(org.eclipse.swt.events.ModifyListener)
\r
310 public void addModifyListener(final ModifyListener listener) {
\r
311 this.checkWidget();
\r
312 this.modifyListeners.add(listener);
\r
316 * Adds the listener to the collection of listeners who will be notified when the control is selected by the user, by sending it one of the messages defined in the <code>SelectionListener</code> interface.
\r
318 * <code>widgetSelected</code> is not called for texts. <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text.
\r
321 * @param listener the listener which should be notified when the control is selected by the user
\r
323 * @exception IllegalArgumentException <ul>
\r
324 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
\r
326 * @exception SWTException <ul>
\r
327 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
328 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
331 * @see SelectionListener
\r
332 * @see #removeSelectionListener
\r
333 * @see SelectionEvent
\r
335 public void addSelectionListener(final SelectionListener listener) {
\r
336 this.checkWidget();
\r
337 this.selectionListeners.add(listener);
\r
341 * Copies the selected text.
\r
343 * The current selection is copied to the clipboard.
\r
346 * @exception SWTException <ul>
\r
347 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
348 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
351 public void copy() {
\r
352 this.checkWidget();
\r
357 * Cuts the selected text.
\r
359 * The current selection is first copied to the clipboard and then deleted from the widget.
\r
362 * @exception SWTException <ul>
\r
363 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
364 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
367 public void cut() {
\r
368 this.checkWidget();
\r
373 * Returns the number of decimal places used by the receiver.
\r
375 * @return the digits
\r
377 * @exception SWTException <ul>
\r
378 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
379 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
382 public int getDigits() {
\r
383 this.checkWidget();
\r
384 return this.digits;
\r
388 * Returns the amount that the receiver's value will be modified by when the up/down arrows are pressed.
\r
390 * @return the increment
\r
392 * @exception SWTException <ul>
\r
393 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
394 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
397 public int getIncrement() {
\r
398 this.checkWidget();
\r
399 return this.increment;
\r
403 * Returns the maximum value which the receiver will allow.
\r
405 * @return the maximum
\r
407 * @exception SWTException <ul>
\r
408 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
409 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
412 public int getMaximum() {
\r
413 this.checkWidget();
\r
414 return this.maximum;
\r
418 * Returns the minimum value which the receiver will allow.
\r
420 * @return the minimum
\r
422 * @exception SWTException <ul>
\r
423 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
424 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
427 public int getMinimum() {
\r
428 this.checkWidget();
\r
429 return this.minimum;
\r
433 * Returns the amount that the receiver's position will be modified by when the page up/down keys are pressed.
\r
435 * @return the page increment
\r
437 * @exception SWTException <ul>
\r
438 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
439 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
442 public int getPageIncrement() {
\r
443 this.checkWidget();
\r
444 return this.pageIncrement;
\r
448 * Returns the <em>selection</em>, which is the receiver's position.
\r
450 * @return the selection
\r
452 * @exception SWTException <ul>
\r
453 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
454 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
457 public int getSelection() {
\r
458 this.checkWidget();
\r
459 return this.storedValue;
\r
464 * Returns a string containing a copy of the contents of the receiver's text field, or an empty string if there are no contents.
\r
466 * @return the receiver's text
\r
468 * @exception SWTException <ul>
\r
469 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
470 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
474 public String getText() {
\r
475 this.checkWidget();
\r
476 return this.text.getText();
\r
480 * Returns the maximum number of characters that the receiver's text field is capable of holding. If this has not been changed by <code>setTextLimit()</code>, it will be the constant <code>Spinner.LIMIT</code>.
\r
482 * @return the text limit
\r
484 * @exception SWTException <ul>
\r
485 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
486 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
491 public int getTextLimit() {
\r
492 this.checkWidget();
\r
493 return this.text.getTextLimit();
\r
497 * Pastes text from clipboard.
\r
499 * The selected text is deleted from the widget and new text inserted from the clipboard.
\r
502 * @exception SWTException <ul>
\r
503 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
504 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
507 public void paste() {
\r
508 this.checkWidget();
\r
513 * Removes the listener from the collection of listeners who will be notified when the receiver's text is modified.
\r
515 * @param listener the listener which should no longer be notified
\r
517 * @exception IllegalArgumentException <ul>
\r
518 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
\r
520 * @exception SWTException <ul>
\r
521 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
522 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
525 * @see ModifyListener
\r
526 * @see #addModifyListener
\r
528 public void removeModifyListener(final ModifyListener listener) {
\r
529 this.checkWidget();
\r
530 this.modifyListeners.remove(listener);
\r
534 * Removes the listener from the collection of listeners who will be notified when the control is selected by the user.
\r
536 * @param listener the listener which should no longer be notified
\r
538 * @exception IllegalArgumentException <ul>
\r
539 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
\r
541 * @exception SWTException <ul>
\r
542 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
543 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
546 * @see SelectionListener
\r
547 * @see #addSelectionListener
\r
549 public void removeSelectionListener(final SelectionListener listener) {
\r
550 this.checkWidget();
\r
551 this.selectionListeners.remove(listener);
\r
555 * Sets the number of decimal places used by the receiver.
\r
557 * The digit setting is used to allow for floating point values in the receiver. For example, to set the selection to a floating point value of 1.37 call setDigits() with a value of 2 and setSelection() with a value of 137. Similarly, if getDigits() has a value of 2 and getSelection() returns 137 this should be interpreted as 1.37. This applies to all numeric APIs.
\r
560 * @param value the new digits (must be greater than or equal to zero)
\r
562 * @exception IllegalArgumentException <ul>
\r
563 * <li>ERROR_INVALID_ARGUMENT - if the value is less than zero</li>
\r
565 * @exception SWTException <ul>
\r
566 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
567 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
570 public void setDigits(final int value) {
\r
571 this.checkWidget();
\r
572 this.digits = value;
\r
573 this.convertSelection();
\r
577 * Sets the amount that the receiver's value will be modified by when the up/down arrows are pressed to the argument, which must be at least one.
\r
579 * @param value the new increment (must be greater than zero)
\r
581 * @exception SWTException <ul>
\r
582 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
583 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
586 public void setIncrement(final int value) {
\r
587 this.checkWidget();
\r
588 this.increment = value;
\r
592 * Sets the maximum value that the receiver will allow. This new value will be ignored if it is less than the receiver's current minimum value. If the new maximum is applied then the receiver's selection value will be adjusted if necessary to fall within its new range.
\r
594 * @param value the new maximum, which must be greater than or equal to the current minimum
\r
596 * @exception SWTException <ul>
\r
597 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
598 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
601 public void setMaximum(final int value) {
\r
602 this.checkWidget();
\r
603 this.maximum = value;
\r
607 * Sets the minimum value that the receiver will allow. This new value will be ignored if it is greater than the receiver's current maximum value. If the new minimum is applied then the receiver's selection value will be adjusted if necessary to fall within its new range.
\r
609 * @param value the new minimum, which must be less than or equal to the current maximum
\r
611 * @exception SWTException <ul>
\r
612 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
613 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
616 public void setMinimum(final int value) {
\r
617 this.checkWidget();
\r
618 this.minimum = value;
\r
622 * Sets the amount that the receiver's position will be modified by when the page up/down keys are pressed to the argument, which must be at least one.
\r
624 * @param value the page increment (must be greater than zero)
\r
626 * @exception SWTException <ul>
\r
627 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
628 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
631 public void setPageIncrement(final int value) {
\r
632 this.checkWidget();
\r
633 this.pageIncrement = value;
\r
637 * Sets the <em>selection</em>, which is the receiver's position, to the argument. If the argument is not within the range specified by minimum and maximum, it will be adjusted to fall within this range.
\r
639 * @param value the new selection (must be zero or greater)
\r
641 * @exception SWTException <ul>
\r
642 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
643 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
646 public void setSelection(int selection) {
\r
647 this.checkWidget();
\r
648 if (selection < this.minimum) {
\r
649 selection = this.minimum;
\r
650 } else if (selection > this.maximum) {
\r
651 selection = this.maximum;
\r
654 this.storedValue = selection;
\r
655 this.text.setText(this.convertSelection());
\r
656 this.text.selectAll();
\r
657 this.text.setFocus();
\r
659 for (final SelectionListener s : HorizontalSpinner.this.selectionListeners) {
\r
660 s.widgetSelected(null);
\r
666 * Convert the selection into a string
\r
668 * @return the string representation of the selection
\r
670 private String convertSelection() {
\r
671 if (this.getDigits() == 0) {
\r
672 return String.valueOf(this.storedValue);
\r
674 final String temp = String.valueOf(this.storedValue * Math.pow(10, -1 * this.getDigits()));
\r
675 return temp.replace('.', this.decimalFormatSeparator);
\r
679 * Sets the maximum number of characters that the receiver's text field is capable of holding to be the argument.
\r
681 * To reset this value to the default, use <code>setTextLimit(Spinner.LIMIT)</code>. Specifying a limit value larger than <code>Spinner.LIMIT</code> sets the receiver's limit to <code>Spinner.LIMIT</code>.
\r
684 * @param limit new text limit
\r
686 * @exception IllegalArgumentException <ul>
\r
687 * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
\r
689 * @exception SWTException <ul>
\r
690 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
691 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
696 public void setTextLimit(final int limit) {
\r
697 this.checkWidget();
\r
698 this.text.setTextLimit(limit);
\r
702 * Sets the receiver's selection, minimum value, maximum value, digits, increment and page increment all at once.
\r
704 * Note: This is similar to setting the values individually using the appropriate methods, but may be implemented in a more efficient fashion on some platforms.
\r
707 * @param selection the new selection value
\r
708 * @param minimum the new minimum value
\r
709 * @param maximum the new maximum value
\r
710 * @param digits the new digits value
\r
711 * @param increment the new increment value
\r
712 * @param pageIncrement the new pageIncrement value
\r
714 * @exception SWTException <ul>
\r
715 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
716 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
719 public void setValues(final int selection, final int minimum, final int maximum, final int digits, final int increment, final int pageIncrement) {
\r
720 this.setMinimum(minimum);
\r
721 this.setMaximum(maximum);
\r
722 this.setDigits(digits);
\r
723 this.setIncrement(increment);
\r
724 this.setPageIncrement(pageIncrement);
\r
725 this.setSelection(selection);
\r
729 * Sets the receiver's drag detect state. If the argument is <code>true</code>, the receiver will detect drag gestures, otherwise these gestures will be ignored.
\r
731 * @param dragDetect the new drag detect state
\r
733 * @exception SWTException <ul>
\r
734 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
735 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
739 public boolean setFocus() {
\r
740 this.checkWidget();
\r
741 return this.text.setFocus();
\r
745 * Forces the receiver to have the <em>keyboard focus</em>, causing all keyboard events to be delivered to it.
\r
747 * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
\r
749 * @exception SWTException <ul>
\r
750 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
751 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
757 public boolean forceFocus() {
\r
758 this.checkWidget();
\r
759 return this.text.forceFocus();
\r
763 * Sets the receiver's background color to the color specified by the argument, or to the default system color for the control if the argument is null.
\r
765 * Note: This operation is a hint and may be overridden by the platform. For example, on Windows the background of a Button cannot be changed.
\r
768 * @param color the new color (or null)
\r
770 * @exception IllegalArgumentException <ul>
\r
771 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
\r
773 * @exception SWTException <ul>
\r
774 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
775 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
779 public void setBackground(final Color color) {
\r
780 super.setBackground(color);
\r
781 this.leftButton.setBackground(color);
\r
782 this.rightButton.setBackground(color);
\r
783 this.text.setBackground(color);
\r
787 * Sets the receiver's background image to the image specified by the argument, or to the default system color for the control if the argument is null. The background image is tiled to fill the available space.
\r
789 * Note: This operation is a hint and may be overridden by the platform. For example, on Windows the background of a Button cannot be changed.
\r
792 * @param image the new image (or null)
\r
794 * @exception IllegalArgumentException <ul>
\r
795 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
\r
796 * <li>ERROR_INVALID_ARGUMENT - if the argument is not a bitmap</li>
\r
798 * @exception SWTException <ul>
\r
799 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
800 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
804 public void setBackgroundImage(final Image image) {
\r
805 super.setBackgroundImage(image);
\r
806 this.leftButton.setBackgroundImage(image);
\r
807 this.rightButton.setBackgroundImage(image);
\r
808 this.text.setBackgroundImage(image);
\r
813 * Sets the receiver's cursor to the cursor specified by the argument, or to the default cursor for that kind of control if the argument is null.
\r
815 * When the mouse pointer passes over a control its appearance is changed to match the control's cursor.
\r
818 * @param cursor the new cursor (or null)
\r
820 * @exception IllegalArgumentException <ul>
\r
821 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
\r
823 * @exception SWTException <ul>
\r
824 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
825 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
829 public void setCursor(final Cursor cursor) {
\r
830 super.setCursor(cursor);
\r
831 this.leftButton.setCursor(cursor);
\r
832 this.rightButton.setCursor(cursor);
\r
833 this.text.setCursor(cursor);
\r
838 * Enables the receiver if the argument is <code>true</code>, and disables it otherwise. A disabled control is typically not selectable from the user interface and draws with an inactive or "grayed" look.
\r
840 * @param enabled the new enabled state
\r
842 * @exception SWTException <ul>
\r
843 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
844 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
848 public void setEnabled(final boolean enabled) {
\r
849 super.setEnabled(enabled);
\r
850 this.leftButton.setEnabled(enabled);
\r
851 this.rightButton.setEnabled(enabled);
\r
852 this.text.setEnabled(enabled);
\r
857 * Sets the font that the receiver will use to paint textual information to the font specified by the argument, or to the default font for that kind of control if the argument is null.
\r
859 * @param font the new font (or null)
\r
861 * @exception IllegalArgumentException <ul>
\r
862 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
\r
864 * @exception SWTException <ul>
\r
865 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
866 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
870 public void setFont(final Font font) {
\r
871 super.setFont(font);
\r
872 this.text.setFont(font);
\r
876 * Sets the receiver's foreground color to the color specified by the argument, or to the default system color for the control if the argument is null.
\r
878 * Note: This operation is a hint and may be overridden by the platform.
\r
881 * @param color the new color (or null)
\r
883 * @exception IllegalArgumentException <ul>
\r
884 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
\r
886 * @exception SWTException <ul>
\r
887 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
888 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
892 public void setForeground(final Color color) {
\r
893 super.setForeground(color);
\r
894 this.leftButton.setForeground(color);
\r
895 this.rightButton.setForeground(color);
\r
896 this.text.setForeground(color);
\r
901 * Sets the receiver's pop up menu to the argument. All controls may optionally have a pop up menu that is displayed when the user requests one for the control. The sequence of key strokes, button presses and/or button releases that are used to request a pop up menu is platform specific.
\r
903 * Note: Disposing of a control that has a pop up menu will dispose of the menu. To avoid this behavior, set the menu to null before the control is disposed.
\r
906 * @param menu the new pop up menu
\r
908 * @exception IllegalArgumentException <ul>
\r
909 * <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li>
\r
910 * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
\r
911 * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
\r
913 * @exception SWTException <ul>
\r
914 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
915 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
919 public void setMenu(final Menu menu) {
\r
920 super.setMenu(menu);
\r
921 this.leftButton.setMenu(menu);
\r
922 this.rightButton.setMenu(menu);
\r
923 this.text.setMenu(menu);
\r
927 * Sets the receiver's tool tip text to the argument, which may be null indicating that the default tool tip for the control will be shown. For a control that has a default tool tip, such as the Tree control on Windows, setting the tool tip text to an empty string replaces the default, causing no tool tip text to be shown.
\r
929 * The mnemonic indicator (character '&') is not displayed in a tool tip. To display a single '&' in the tool tip, the character '&' can be escaped by doubling it in the string.
\r
932 * @param string the new tool tip text (or null)
\r
934 * @exception SWTException <ul>
\r
935 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
\r
936 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
\r
940 public void setToolTipText(final String tooltipText) {
\r
941 super.setToolTipText(tooltipText);
\r
942 this.leftButton.setToolTipText(tooltipText);
\r
943 this.rightButton.setToolTipText(tooltipText);
\r
944 this.text.setToolTipText(tooltipText);
\r