changeset 5201:9fb41ec54d94

7124210: [macosx] Replacing text in a TextField does generate an extra TextEvent Reviewed-by: serb
author alexp
date Fri, 27 Apr 2012 18:39:37 +0400
parents 61906002d2a2
children f7e9f377bb5e
files src/macosx/classes/sun/lwawt/LWTextAreaPeer.java src/macosx/classes/sun/lwawt/LWTextComponentPeer.java src/macosx/classes/sun/lwawt/LWTextFieldPeer.java
diffstat 3 files changed, 23 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/LWTextAreaPeer.java	Fri Apr 27 18:27:49 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/LWTextAreaPeer.java	Fri Apr 27 18:39:37 2012 +0400
@@ -201,6 +201,15 @@
             }
 
             @Override
+            public void replaceSelection(String content) {
+                getDocument().removeDocumentListener(LWTextAreaPeer.this);
+                super.replaceSelection(content);
+                // post only one text event in this case
+                postTextEvent();
+                getDocument().addDocumentListener(LWTextAreaPeer.this);
+            }
+
+            @Override
             public boolean hasFocus() {
                 return getTarget().hasFocus();
             }
--- a/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java	Fri Apr 27 18:27:49 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java	Fri Apr 27 18:39:37 2012 +0400
@@ -187,7 +187,7 @@
         }
     }
 
-    private void sendTextEvent(final DocumentEvent e) {
+    protected final void postTextEvent() {
         postEvent(new TextEvent(getTarget(), TextEvent.TEXT_VALUE_CHANGED));
         synchronized (getDelegateLock()) {
             revalidate();
@@ -196,17 +196,17 @@
 
     @Override
     public final void changedUpdate(final DocumentEvent e) {
-        sendTextEvent(e);
+        postTextEvent();
     }
 
     @Override
     public final void insertUpdate(final DocumentEvent e) {
-        sendTextEvent(e);
+        postTextEvent();
     }
 
     @Override
     public final void removeUpdate(final DocumentEvent e) {
-        sendTextEvent(e);
+        postTextEvent();
     }
 
     @Override
--- a/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java	Fri Apr 27 18:27:49 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java	Fri Apr 27 18:39:37 2012 +0400
@@ -104,7 +104,7 @@
     @Override
     public void actionPerformed(final ActionEvent e) {
         postEvent(new ActionEvent(getTarget(), ActionEvent.ACTION_PERFORMED,
-                                  getText(), e.getWhen(), e.getModifiers()));
+                getText(), e.getWhen(), e.getModifiers()));
     }
 
     /**
@@ -131,6 +131,15 @@
         }
 
         @Override
+        public void replaceSelection(String content) {
+            getDocument().removeDocumentListener(LWTextFieldPeer.this);
+            super.replaceSelection(content);
+            // post only one text event in this case
+            postTextEvent();
+            getDocument().addDocumentListener(LWTextFieldPeer.this);
+        }
+
+        @Override
         public boolean hasFocus() {
             return getTarget().hasFocus();
         }