This fixes the filtering in DefaultEditorKit.DefaultKeyTypedAction.

2006-08-24  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/text/DefaultEditorKit.java:
        (DefaultKeyTypedAction.actionPerform): Also filter
        ALT and CTRL modifiers.

/Roman
Index: javax/swing/text/DefaultEditorKit.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultEditorKit.java,v
retrieving revision 1.33
diff -u -1 -2 -r1.33 DefaultEditorKit.java
--- javax/swing/text/DefaultEditorKit.java	13 May 2006 12:23:37 -0000	1.33
+++ javax/swing/text/DefaultEditorKit.java	24 Aug 2006 16:07:00 -0000
@@ -29,25 +29,24 @@
 modules, and to copy and distribute the resulting executable under
 terms of your choice, provided that you also meet, for each linked
 independent module, the terms and conditions of the license of that
 module.  An independent module is a module which is not derived from
 or based on this library.  If you modify this library, you may extend
 this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
 
 package javax.swing.text;
 
-import java.awt.Point;
 import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.Writer;
 
@@ -948,32 +947,44 @@
       super(defaultKeyTypedAction);
     }
 
     /**
      * Performs the <code>Action</code>.
      *
      * @param event the action event describing the user action
      */
     public void actionPerformed(ActionEvent event)
     {
       // first we filter the following events:
       // - control characters
-      // - key events with the ALT modifier (FIXME: filter that too!)
-      int cp = event.getActionCommand().codePointAt(0);
-      if (Character.isISOControl(cp))
-        return;
-
-      JTextComponent t = getTextComponent(event);
-      if (t != null && t.isEnabled() && t.isEditable())
-        t.replaceSelection(event.getActionCommand());
+      // - key events with the ALT modifier
+      JTextComponent target = getTextComponent(event);
+      if ((target != null) && (event != null))
+        {
+          if ((target.isEditable()) && (target.isEnabled()))
+            {
+              String content = event.getActionCommand();
+              int mod = event.getModifiers();
+              if ((content != null) && (content.length() > 0)
+                  && (mod & ActionEvent.ALT_MASK) == 0
+                  && (mod & ActionEvent.CTRL_MASK) == 0)
+                {
+                  char c = content.charAt(0);
+                  if ((c >= 0x20) && (c != 0x7F))
+                    {
+                      target.replaceSelection(content);
+                    }
+                }
+            }
+        }
     }    
   }
 
   /**
    * This action inserts a newline character into the document
    * of the text component. This is typically triggered by hitting
    * ENTER on the keyboard.
    */
   public static class InsertBreakAction extends TextAction
   {
 
     /**

Reply via email to