Mike Swingler wrote:
>Any suggestions how to provide the key symbols in Swing, and maintain
>the existing semantics of KeyEvent.getKeyModifiersText() and
>KeyEvent.getKeyText() would be appreciated.
I don't see how there could be a universal solution. KeyEvent.getKeyText()
depends on a ResourceBundle, and that's dependent on locale, language, and
other externalities. Its semantics don't seem intended for println()
diagnostic use, either, or are at least debatable.
Adding code like below for the diagnostic use, as the OP was using it, will
at least clean up the println() output into something more useful than '?':
- - - - -
public static String diagnosticText( int vkCode )
{ return visible( KeyEvent.getKeyText( vkCode ) ); }
public static String
visible( String text )
{
StringBuffer build = new StringBuffer( text.length() );
for ( int i = 0; i < text.length(); ++i )
{
int each = text.charAt( i );
if ( each < 0x20 || each >= 0x7F )
build.append( "\\u" ).append( hex( each, 4 ) );
else
{
// Represented as-is, except...
build.append( (char) each );
// ...backslash (0x5C) is doubled in output text.
if ( each == 0x5C )
build.append( (char) each );
}
}
return ( build.toString() );
}
/** Return a zero-filled upper-case hex sequence of digits. */
public static char[]
hex( int value, int digits )
{
char[] chars = new char[ digits ];
for ( int i = chars.length; --i >= 0; value >>>= 4 )
{ chars[ i ] = HEX[ 0x0F & value ] ; }
return ( chars );
}
protected static final char[] HEX = "0123456789ABCDEF".toCharArray();
- - - - -
-- GG
_______________________________________________
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