Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet363.java')
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet363.java130
1 files changed, 65 insertions, 65 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet363.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet363.java
index ed14dc4436..23431a48cf 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet363.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet363.java
@@ -28,86 +28,86 @@ import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class Snippet363 {
- static final String errorMessage = "Error: Number expected.";
- static Label icon;
- static Image errorIcon;
- static Text liveLabel;
+ static final String errorMessage = "Error: Number expected.";
+ static Label icon;
+ static Image errorIcon;
+ static Text liveLabel;
public static void main(String [] args) {
- Display display = new Display();
- errorIcon = display.getSystemImage(SWT.ICON_ERROR);
- Shell shell = new Shell(display);
+ Display display = new Display();
+ errorIcon = display.getSystemImage(SWT.ICON_ERROR);
+ Shell shell = new Shell(display);
shell.setText("Snippet 363");
- shell.setLayout(new GridLayout(2, false));
- shell.setText("LiveRegion Test");
+ shell.setLayout(new GridLayout(2, false));
+ shell.setText("LiveRegion Test");
- icon = new Label(shell, SWT.NONE);
- icon.setLayoutData(new GridData(32, 32));
+ icon = new Label(shell, SWT.NONE);
+ icon.setLayoutData(new GridData(32, 32));
- liveLabel = new Text(shell, SWT.READ_ONLY);
- GC gc = new GC(liveLabel);
- Point pt = gc.textExtent(errorMessage);
- GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
- data.minimumWidth = (int) (pt.x + gc.getFontMetrics().getAverageCharacterWidth() * 2);
- gc.dispose();
- liveLabel.setLayoutData(data);
- liveLabel.setText("");
- liveLabel.getAccessible().addAccessibleAttributeListener(new AccessibleAttributeAdapter() {
- @Override
+ liveLabel = new Text(shell, SWT.READ_ONLY);
+ GC gc = new GC(liveLabel);
+ Point pt = gc.textExtent(errorMessage);
+ GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ data.minimumWidth = (int) (pt.x + gc.getFontMetrics().getAverageCharacterWidth() * 2);
+ gc.dispose();
+ liveLabel.setLayoutData(data);
+ liveLabel.setText("");
+ liveLabel.getAccessible().addAccessibleAttributeListener(new AccessibleAttributeAdapter() {
+ @Override
public void getAttributes(AccessibleAttributeEvent e) {
- e.attributes = new String[] {
- "container-live", "polite",
- "live", "polite",
- "container-live-role", "status",
- };
- }
- });
+ e.attributes = new String[] {
+ "container-live", "polite",
+ "live", "polite",
+ "container-live-role", "status",
+ };
+ }
+ });
- final Label textFieldLabel = new Label(shell, SWT.NONE);
- textFieldLabel.setText("Type a number:");
- textFieldLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+ final Label textFieldLabel = new Label(shell, SWT.NONE);
+ textFieldLabel.setText("Type a number:");
+ textFieldLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- final Text textField = new Text(shell, SWT.SINGLE | SWT.BORDER);
- textField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+ final Text textField = new Text(shell, SWT.SINGLE | SWT.BORDER);
+ textField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- final Button okButton = new Button(shell, SWT.PUSH);
- okButton.setText("OK");
- okButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false, 2, 1));
- okButton.setEnabled(false);
+ final Button okButton = new Button(shell, SWT.PUSH);
+ okButton.setText("OK");
+ okButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false, 2, 1));
+ okButton.setEnabled(false);
- textField.addModifyListener(e -> {
- boolean isNumber = false;
- String textValue = textField.getText();
- try {
- Integer.parseInt(textValue);
- isNumber = true;
- setMessageText(false, "Thank-you");
- } catch (NumberFormatException ex) {
- if (textValue.isEmpty()) {
- setMessageText(false, "");
- } else {
- setMessageText(true, "Error: Number expected.");
- }
- }
- okButton.setEnabled(isNumber);
+ textField.addModifyListener(e -> {
+ boolean isNumber = false;
+ String textValue = textField.getText();
+ try {
+ Integer.parseInt(textValue);
+ isNumber = true;
+ setMessageText(false, "Thank-you");
+ } catch (NumberFormatException ex) {
+ if (textValue.isEmpty()) {
+ setMessageText(false, "");
+ } else {
+ setMessageText(true, "Error: Number expected.");
+ }
+ }
+ okButton.setEnabled(isNumber);
});
- textField.setFocus();
- shell.pack();
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) display.sleep();
- }
- display.dispose();
+ textField.setFocus();
+ shell.pack();
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) display.sleep();
+ }
+ display.dispose();
}
static void setMessageText(boolean error, String newMessage) {
- String oldMessage = liveLabel.getText();
- icon.setImage(error ? errorIcon : null);
- liveLabel.setText(newMessage);
- liveLabel.getAccessible().sendEvent(ACC.EVENT_ATTRIBUTE_CHANGED, null);
- liveLabel.getAccessible().sendEvent(ACC.EVENT_TEXT_CHANGED, new Object[] {ACC.TEXT_DELETE, 0, oldMessage.length(), oldMessage});
- liveLabel.getAccessible().sendEvent(ACC.EVENT_TEXT_CHANGED, new Object[] {ACC.TEXT_INSERT, 0, newMessage.length(), newMessage});
+ String oldMessage = liveLabel.getText();
+ icon.setImage(error ? errorIcon : null);
+ liveLabel.setText(newMessage);
+ liveLabel.getAccessible().sendEvent(ACC.EVENT_ATTRIBUTE_CHANGED, null);
+ liveLabel.getAccessible().sendEvent(ACC.EVENT_TEXT_CHANGED, new Object[] {ACC.TEXT_DELETE, 0, oldMessage.length(), oldMessage});
+ liveLabel.getAccessible().sendEvent(ACC.EVENT_TEXT_CHANGED, new Object[] {ACC.TEXT_INSERT, 0, newMessage.length(), newMessage});
}
}

Back to the top