Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KeyEvent.getKeyText() went wonky (won't display arrows)



On Jan 26, 2008, at 1:38 PM, Greg Guerin wrote:

Mac First wrote:

On my Intel/Leopard system, I get this:

[Session started at 2008-01-25 18:50:00 -0800.]
Pigs!
type  : 401             // (401 = keydown)
code: 32
text: ?               // <space>
type  : 400             // 400 = key-repeat?  Key-typed?  Whatever...
code: 0
text: Unknown keyCode: 0x0
type  : 402             // (402 = keyup)
code: 32
text: ?
type  : 401
code: 37              // left arrow
text: ?
type  : 402
code: 37
text: ?
type  : 401
code: 39              // right arrow

The ResourceBundle for "sun.awt.resources.awt" appears to be screwy under
Java 1.5, but fine under 1.4.2, both on Leopard. It's also fine under 1.5
or 1.4.2 on 10.4.9.


Test program:

- - - - -
// This code released into the public domain.
// AS-IS, WITHOUT WARRANTY.
import java.awt.event.*;
import java.util.*;

public class KeyTexts
{
 public static void main( String[] args )
 {
   show( 27 );
   show( 37 );
   show( 20 );
   show( 909 );  // illegal/unknown

   ResourceBundle bundle = null;
   try
   { bundle = ResourceBundle.getBundle( "sun.awt.resources.awt" ); }
   catch ( Exception ignored )
   { ; }

   System.out.println( "bundle = " + bundle );
 }

 private static void show( int code )
 {  System.out.println( "code: " + code
      + ", text: " + KeyEvent.getKeyText( code ) );  }
}
- - - - -

To understand what it's testing and the significance of that
ResourceBundle, look at the source of java.awt.Toolkit.getProperty(), and
Toolkit's static initializer for the 'resources' field. Also see source of
KeyEvent.getKeyText() for how Toolkit.getProperty() gets in.


I'm afraid I don't know of a fix. Maybe use reflection to set the
'resources' static field in Toolkit to null, but I'm not sure of all the
consequences. Alternatively, set the right property or config-value so the
ResourceBundle.getBundle() refers to something correct instead of screwy.


Definitely file a bug, because this ought to work.
 <http://developer.apple.com/bugreporter>

Feel free to use the above code to demonstrate the problem.

These were changed intentionally to provide the proper symbols for menu shortcuts in Swing for in-window menu bars. Instead of using the word "Meta" or "Command" we actually now return the unicode symbol that the system menu bar shows.


Unfortunately, there did not appear to be a reasonable injection point between the AWT toolkit properties and the Swing menu system...and the fallout is that it makes debugging modifier keys from Terminal more difficult. The tradeoff was basically between a user-visible bug, and a behavior only developers would see.

Any suggestions how to provide the key symbols in Swing, and maintain the existing semantics of KeyEvent.getKeyModifiersText() and KeyEvent.getKeyText() would be appreciated.

Thanks,
Mike Swingler
Java Frameworks Engineer
Apple Inc.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: KeyEvent.getKeyText() went wonky (won't display arrows) (From: Greg Guerin <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.