7124210: [macosx] Replacing text in a TextField does generate an extra TextEvent
authoralexp
Thu, 26 Apr 2012 21:16:12 +0400
changeset 12531 42a9335fd8b3
parent 12530 07f0154e90ea
child 12532 dbf5d9a4b7bb
7124210: [macosx] Replacing text in a TextField does generate an extra TextEvent Reviewed-by: serb
jdk/src/macosx/classes/sun/lwawt/LWTextAreaPeer.java
jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java
jdk/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java
--- a/jdk/src/macosx/classes/sun/lwawt/LWTextAreaPeer.java	Thu Apr 26 12:39:11 2012 +0800
+++ b/jdk/src/macosx/classes/sun/lwawt/LWTextAreaPeer.java	Thu Apr 26 21:16:12 2012 +0400
@@ -211,6 +211,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/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java	Thu Apr 26 12:39:11 2012 +0800
+++ b/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java	Thu Apr 26 21:16:12 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/jdk/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java	Thu Apr 26 12:39:11 2012 +0800
+++ b/jdk/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java	Thu Apr 26 21:16:12 2012 +0400
@@ -95,7 +95,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()));
     }
 
     /**
@@ -122,6 +122,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();
         }