Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/preferences/ValidIntListener.java |
diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/preferences/ValidIntListener.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/preferences/ValidIntListener.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..913a2ce1289b398fbbacdcafc7b6a520e32fdef5 |
--- /dev/null |
+++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/preferences/ValidIntListener.java |
@@ -0,0 +1,30 @@ |
+package com.google.dart.tools.ui.internal.preferences; |
+ |
+import org.eclipse.swt.widgets.Event; |
+import org.eclipse.swt.widgets.Listener; |
+ |
+/** |
+ * Listener that only allows digits to be entered into a text field |
+ */ |
+class ValidIntListener implements Listener { |
+ @Override |
+ public void handleEvent(Event e) { |
+ String txt = e.text; |
+ // Allow for delete |
+ if (txt.isEmpty()) { |
+ return; |
+ } |
+ try { |
+ // Only allow digits |
+ int num = Integer.parseInt(txt); |
+ if (num >= 0) { |
+ return; |
+ } |
+ } catch (NumberFormatException nfe) { |
+ // Error |
+ } |
+ |
+ e.doit = false; |
+ return; |
+ } |
+} |