diff options
author | Lars Vogel | 2018-02-06 07:59:05 +0000 |
---|---|---|
committer | Lars Vogel | 2018-02-06 10:10:24 +0000 |
commit | bc72eb49ce870f19dae15562cfb525a2e46e9586 (patch) | |
tree | f402cea0cc8d37ccb5924142e96669c342827920 | |
parent | 0eaa2637451a6b7217156c899b55f795b52f3463 (diff) | |
download | eclipse.platform.swt-bc72eb49ce870f19dae15562cfb525a2e46e9586.tar.gz eclipse.platform.swt-bc72eb49ce870f19dae15562cfb525a2e46e9586.tar.xz eclipse.platform.swt-bc72eb49ce870f19dae15562cfb525a2e46e9586.zip |
Bug 530764 - Improve readability of Snippet19
Change-Id: Ided3343821270cb4ea760c423756886dce1c8713
Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
-rw-r--r-- | examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet19.java | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet19.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet19.java index 77d7b3b8c1..1ab24efe93 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet19.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet19.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Lars Vogel <Lars.Vogel@vogella.com> - Bug 530764 *******************************************************************************/ package org.eclipse.swt.snippets; @@ -17,32 +18,30 @@ package org.eclipse.swt.snippets; * http://www.eclipse.org/swt/snippets/ */ import org.eclipse.swt.*; +import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; public class Snippet19 { -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Text text = new Text (shell, SWT.BORDER | SWT.V_SCROLL); - Rectangle clientArea = shell.getClientArea (); - text.setBounds ( clientArea.x + 10, clientArea.y + 10, 200, 200); - text.addListener (SWT.Verify, e -> { - String string = e.text; - char [] chars = new char [string.length ()]; - string.getChars (0, chars.length, chars, 0); - for (int i=0; i<chars.length; i++) { - if (!('0' <= chars [i] && chars [i] <= '9')) { - e.doit = false; - return; - } + public static void main(String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + Text text = new Text(shell, SWT.BORDER | SWT.V_SCROLL); + Rectangle clientArea = shell.getClientArea(); + text.setBounds(clientArea.x + 10, clientArea.y + 10, 200, 200); + text.addVerifyListener(Snippet19::ensureTextContainsOnlyDigits); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); } - }); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); + display.dispose(); + } + + private static void ensureTextContainsOnlyDigits(VerifyEvent e) { + String string = e.text; + e.doit = string.matches("\\d*"); + return; } - display.dispose (); -} } |