This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 26678 - I18N - Problems with localized mnemonics
Summary: I18N - Problems with localized mnemonics
Status: CLOSED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Actions (show other bugs)
Version: 3.x
Hardware: PC Linux
: P2 blocker (vote)
Assignee: David Simonek
URL:
Keywords: A11Y, I18N
: 24521 (view as bug list)
Depends on:
Blocks: 26640
  Show dependency tree
 
Reported: 2002-08-21 11:05 UTC by Jaroslav Tulach
Modified: 2008-12-23 00:05 UTC (History)
6 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Suggested patch (1.63 KB, patch)
2002-08-21 11:08 UTC, Jaroslav Tulach
Details | Diff
Another (changed patch) (1.88 KB, patch)
2002-08-21 20:52 UTC, _ mihmax
Details | Diff
Handy solution for JLabel's (unverified) (1.31 KB, text/plain)
2002-08-21 21:07 UTC, _ mihmax
Details
Picture of Russian File menu (Alt+A must work) (3.87 KB, image/jpeg)
2002-08-22 09:23 UTC, _ mihmax
Details
Patch that works on jdk1.3 (does not underline RU characters) and also on jdk1.4 (does underline) (4.50 KB, patch)
2002-08-22 11:01 UTC, Jaroslav Tulach
Details | Diff
Patch that works on jdk1.3 & jdk1.4 !!! (4.56 KB, patch)
2002-08-22 12:39 UTC, _ mihmax
Details | Diff
Patch that works on jdk1.3 & jdk1.4 !!! (4.56 KB, patch)
2002-08-22 12:39 UTC, _ mihmax
Details | Diff
Under jdk1.3 (2.70 KB, image/jpeg)
2002-08-22 13:31 UTC, _ mihmax
Details
Under jdk1.4 (2.44 KB, image/jpeg)
2002-08-22 13:34 UTC, _ mihmax
Details
VERIFIED Patch that works both for jdk1.3 & jdk1.4 (4.64 KB, patch)
2002-08-22 13:56 UTC, _ mihmax
Details | Diff
FINAL patch, working both for JDK1.3 & JDK1.4 (4.45 KB, patch)
2002-08-23 20:39 UTC, _ mihmax
Details | Diff
FINAL file Actions.java - Provided by Jaroslav Tulach (1.19 KB, text/plain)
2002-08-23 20:42 UTC, _ mihmax
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jaroslav Tulach 2002-08-21 11:05:48 UTC
Maxym described problem in 
http://www.netbeans.org/servlets/BrowseList?listName=nbdev&by=subject&from=168984
that he cannot specify a cyrilic letter as one for
mnemonic in menu.
Comment 1 Jaroslav Tulach 2002-08-21 11:08:41 UTC
Created attachment 7157 [details]
Suggested patch
Comment 2 Jaroslav Tulach 2002-08-21 11:14:35 UTC
Here are comments how to use the above given patch:

In Bundle_ru.properties one has to specify line:

MNEMONIC_\u5224=C

which would mean that the when a unicode letter 5224 is to be a
mnemonic 'C' should be used instead of it. I have tested that on

MNEMONIC_F=L 

which succeffully changed the mnemonic of &File to be L. 

One could also specify

MNEMONIC_F=5345

where 5345 is value of a constant from java.awt.event.KeyEvent.VK_***
so one could specify that a mnemonic is key 1, 2, 3 or even Home, etc.


Of course the patch works only for menu items that use services of
org.openide.awt.Actions, but I am not aware of anyone not using this
method.


Comment 3 _ mihmax 2002-08-21 11:57:59 UTC
Jaroslav, Great Work!
And wind-fast!

But as I've already written in nbdev, 
> SWING is not very smart about underlining:
> It will not underline the Russian symbol.

Do you know any way to solve this?
Comment 4 _ mihmax 2002-08-21 12:04:03 UTC
in javadoc for AbstractButton:
> If the corresponding character is not contained within 
> the button's label, then it will be displayed near the 
> label in a look and feel dependent manner (commonly to 
> the right, surrounded by parenthesis). 

But it's UGLY and still there's no (&<latin>) near The 
file menu,
so no symbol is underlined, but Alt+A (the mnemonic) works.

JDK/Swing bug?
Comment 5 _ ttran 2002-08-21 16:15:22 UTC
and if the letter is not underlined how the user finds out what the
mnemonic he's looking for is?

Not a bug but I would like to see it fixed for 4.0
Comment 6 Jaroslav Tulach 2002-08-21 17:39:12 UTC
"It will not underline the Russian symbol" - really? I am not sure
why. I have checked the sources of jdk1.4 and there does not seem to
be such restriction. MetalButtonUI seems to work with any character.
I was able to set 'i' with carka above it to be mnemonic for my JButton.


Moreover I have found that since JDK1.4 there is a method
AbstractButton.setMnemonicIndex. So the actual mnemonic and the
underlined character can be different. This can be used to assign
mnemonic 'X' and select a russian letter.


Maxim, if you want to experiment with it, try to modify the patch to
use setMnemonicIndex, maybe it will work.
Comment 7 _ mihmax 2002-08-21 20:28:25 UTC
AbstractButton.setDisplayedMnemonicIndex to be exact ;)

> "It will not underline the Russian symbol" - really?
Yes, it DOESN'T (I work with localized IDE for more than 
half a year).
It either: (when I specify &<RU>, without the patch) - 
underlines, but Alt-combinations do not work,
Or (with the patch) - Alt-combination perfectly works, but 
the Symbol doesn't get underlined.
Comment 8 _ mihmax 2002-08-21 20:52:22 UTC
Created attachment 7171 [details]
Another (changed patch)
Comment 9 _ mihmax 2002-08-21 20:55:21 UTC
> Maxim, if you want to experiment with it, try to modify
> the patch to use setMnemonicIndex, maybe it will work.

It Works!!!
Please integrate the proposed change in trunk,
and maybe it's not too late for release34?
Comment 10 _ mihmax 2002-08-21 21:03:13 UTC
"Tor Norbye" <Torbjorn.Norbye@Sun.COM> wrote in the news: 
> Maxym Mykhalchuk wrote:
> MM > There're actually so many setMnemonic's around ALL 
Netbeans
> MM > code
<skipped>
> 
> You've noticed 
>   org.openide.awt.Actions's
> setMenuText(AbstractButton item, String text, boolean 
useMnemonic)
> method. This is used for a lot of actions, but as you can
> see, it only applies to buttons.
> 
> In NetBeans we have to set mnemonics on lots of labels 
too
> (for accessibility reasons; e.g. when a label is 
associated
> with a focusable component, you use the mnemonic on the 
label
> to jump to the focusable component.)
> 
> Unfortunately there's no corresponding method which 
works on
> labels - which is why you see all those setMnemonic calls
> (and lots of mnemonic entries in the bundle files.)
> 
> My opinion is that we should add a corresponding method 
to
> org.openide.awt.Actions which works for labels, and 
convert
> code elsewhere to use it. Then these two methods can 
share
> some common code, and you can hack on it to make it work
> better for the Russian locale.    This will mean smaller
> bundle files too.

code attached
Comment 11 _ mihmax 2002-08-21 21:07:38 UTC
Created attachment 7172 [details]
Handy solution for JLabel's (unverified)
Comment 12 Jesse Glick 2002-08-21 21:17:19 UTC
We are very close to 3.4 release, this patch was just developed, and
it does not sound like it solves a critical bug relative to other bugs
we have been fixing - rather a situation of poor usability and/or
ugliness, and only affecting a small percentage of users. I  would
suggest we try to push it into 3.4.1 if there is such a release (mark
with keyword: 3.4.1_CANDIDATE).

Possible counterargument: the patch is small and in an
English-language build, the behavior will be the same, except for an
additionally thrown MissingResourceException (hopefully not a
performance problem), so it would probably be harmless. Would need to
be tested some to confirm it is safe and works as documented, in
various locales (English, Russian, Japanese).

Of course the patch can be applied to the trunk right away if it
breaks nothing.
Comment 13 Ken Frank 2002-08-21 22:10:08 UTC
Is this related to 24521 and/or does it not change
the 2 ways of specifying mnemonics:

using the character after the &
(and being sure to put the & there and not relying on
default of letter after it since localization center needs that)

or

having 2 keys per mnemonic - one for mnemonic letter itself
and one for the label of the mnemonic

ken.frank@sun.com
08-20-2002
Comment 14 _ mihmax 2002-08-21 22:32:31 UTC
to Ken.Frank: no it does not, it still uses "&".

The problem that patch2 solves is mostly for the Languages 
like Russian & Greek, which have different from Latin, but 
still a small number of symbols, so it's possible to fit 
them all into the keyboard.
Hence, user should be able to use Alt+<These keys>,
but Swing doesn't directly allow this, so Netbeans 
needs "to reinvent the bicycle", hacking around the Swing.

This is a patch, and not the Action system redesign ;(
Comment 15 _ mihmax 2002-08-21 22:51:43 UTC
2 Jesse:
> We are very close to 3.4 release, this patch was just 
> developed, and
> it does not sound like it solves a critical bug 

For Russian distribution - it's a very critical bug,
not for English distribution, of course.

> I  would suggest we try to push it into 
> 3.4.1 if there is such a release 

Agreed. Is there any way to make it come into Russian 
distribution of Netbeans 3.4, while not coming into 
English distrib?
Comment 16 Jesse Glick 2002-08-22 04:57:02 UTC
"Is there any way to make it come into Russian distribution of
Netbeans 3.4, while not coming into English distrib?" - not really.

If you're serious about trying to test this and get it into 3.4,
please double-check

http://www.netbeans.org/devhome/docs/releases/34/high-resistance.html

and specifically post to nbreviewers@netbeans.org ASAP. Since we are
so close to the release date, I think it would be wise to have at
least one code review (besides Yarda), some basic check for possible
performance impact from the MREs, some confirmation that it really
works as stated in Russian builds, and some assurance from a QA person
that no harmful effects are visible. All of this ought to be attached
to the bug report here.

BTW I am talking about Maxym's 8/21 revised patch, not the additional
JLabel-related patch which will need more work and should be for 4.0 IMHO.
Comment 17 _ mihmax 2002-08-22 07:53:59 UTC
Mailed to reviewers@netbeans.org
Comment 18 _ mihmax 2002-08-22 08:03:28 UTC
> some confirmation that it really
> works as stated in Russian builds

I can confirm, maybe someone else may help?

To confirm, one must:
1. Checkout the fresh translatedfiles_nowww, 
2. apply the patch#2:
http://www.netbeans.org/issues/showattachment.cgi?
attach_id=7171&file=D:\Actions.diff
3. Build Netbeans with translatedfiles in it,
4. Start Netbeans with "-locale ru" passed to runide

He sees:
File menu starts from "underlined Greek F (Phi)",
on the Russian keyboard it corresponds to Latin A,
so Alt+A should work to open File menu.
(See attach#4 - the picture).
Comment 19 _ mihmax 2002-08-22 09:23:21 UTC
Created attachment 7178 [details]
Picture of Russian File menu (Alt+A must work)
Comment 20 Petr Nejedly 2002-08-22 09:49:39 UTC
OK from performance.
It adds about 10-15 MREs which will fit well under 1ms.
I may be better to add a mnemonic cahhing map to the Actions though.
Comment 21 Jaroslav Tulach 2002-08-22 09:54:31 UTC
My review:

The performance of the patch is not problem. The method is invoked
just ten (or so) times during startup and ten times when opening a
menu. Throwing such low number of exceptions should not be problem. 

We cannot integrate
http://www.netbeans.org/issues/showattachment.cgi?attach_id=7171&file=D:\Actions.diff
patch without modification. It uses method from JDK1.4 and NetBeans
are supposed to run on JDK1.3. We need to use reflection or something
like that.

To Maxim: If you think this is a bug and not enhancement than change
it to bug.

Ad. 3.4.1: Russian version is distributed as NBM on autoupdate. I
believe we might  as well distribute update of openide there too. Thus
we will not prevent release 3.4 from finishing and we allow russian
localization to work (even by increasing the download size).
Comment 22 Jan Chalupa 2002-08-22 10:23:58 UTC
I'm sorry, but I don't think this fix should go into 3.4 at this
point. Hacking around Swing at this level is risky and may cause
undesirable side-effects. I'm afraid there's not enough time to test
it thoroughly unless we want to postpone the release for another week
or two.

IMO, fixing it in trunk and marking it a candidate for 3.4.1 would be
more appropriate.
Comment 23 _ mihmax 2002-08-22 10:44:09 UTC
OK, it's siply too late ;(

Please do not commit into main trunk, it will not compile 
under 1.3.
I will prepare a better patch: cached & JDK1.3 compatible.
Comment 24 Jaroslav Tulach 2002-08-22 11:01:59 UTC
Created attachment 7180 [details]
Patch that works on jdk1.3 (does not underline RU characters) and also on jdk1.4 (does underline)
Comment 25 _ mihmax 2002-08-22 12:39:32 UTC
Created attachment 7182 [details]
Patch that works on jdk1.3 & jdk1.4 !!!
Comment 26 _ mihmax 2002-08-22 12:39:44 UTC
Created attachment 7183 [details]
Patch that works on jdk1.3 & jdk1.4 !!!
Comment 27 _ mihmax 2002-08-22 12:47:08 UTC
The last proposed patch (sorry for double-posting)
works BOTH on jdk1.3 & jdk1.4

It's achieved by:
jdk1.3: adding " (<latin char>)" to the text of 
AbstractButton (JMenuItem), and setting this <latin char> 
to be the mnemonics.
jdk1.4: setting <latin char> as mnemonics, and calling 
setDisplayedMnemonicIndex to underline <locale character>.

Please verify and commit into the main trunk.
Comment 28 _ mihmax 2002-08-22 13:05:18 UTC
Do not commit, please,
On JDK1.4 it doesn't work as expected, sorry for 
inconveniece, please
Comment 29 _ mihmax 2002-08-22 13:31:20 UTC
Created attachment 7184 [details]
Under jdk1.3
Comment 30 _ mihmax 2002-08-22 13:34:58 UTC
Created attachment 7185 [details]
Under jdk1.4
Comment 31 _ mihmax 2002-08-22 13:56:35 UTC
Created attachment 7187 [details]
VERIFIED Patch that works both for jdk1.3 & jdk1.4
Comment 32 _ mihmax 2002-08-22 14:04:53 UTC
The latest three attachments:
1. http://www.netbeans.org/issues/showattachment.cgi?
attach_id=7184&file=E:\picture_jdk13.jpg
2. http://www.netbeans.org/issues/showattachment.cgi?
attach_id=7185&file=E:\picture_jdk14.jpg

3. http://www.netbeans.org/issues/showattachment.cgi?
attach_id=7187&file=E:\Actions.verified.diff

Are about the VERIFIED on jdk1.3.1, jdk1.4.0 and 
jdk1.4.1beta patch.
The 3rd is a patch itself.

If you are not bothered with me for today ;), please 
review, check and integrate into the main trunk.

The patch is optimized for speed for English locales:
 it doesn't even try to lookup the bundle if the letter is 
a latin symbol, so no Exceptions and bundle loading are 
needed.

Comment 33 Ken Frank 2002-08-22 15:13:23 UTC
following up on comment below
"Is there any way to make it come into Russian distribution of
     Netbeans 3.4, while not coming into English distrib?" - not
really.

Yes, please make sure that this or any other localized files
do not come into the English builds of Netbeans.

This could also have effects on the Netbeans that is used
by FFJ also - the assumption is that no localized files
are part of a basic build.

Thanks - Ken
Comment 34 Petr Nejedly 2002-08-22 15:14:09 UTC
I'd add a little optimalization for russian version as well:
use static instance of the method or null, you'll get only
one NSME on 1.3 and will have to lookup the method only once
on 1.4.
Comment 35 _ mihmax 2002-08-22 16:23:52 UTC
To Ken:
> Yes, please make sure that this or any other 
> localized files
> do not come into the English builds of Netbeans.

Localized files (except for Japanese) reside in 
translatedfiles module.

> This could also have effects on the Netbeans that is 
> used by FFJ also - the assumption is that no localized
> files are part of a basic build.

I'm willing to have the Programmatic support integrated 
into Netbeans, not the _ru bundles.
Comment 36 _ mihmax 2002-08-22 16:26:32 UTC
To Petr:

> use static instance of the method or null, you'll get
> only one NSME on 1.3 and will have to lookup the method
> only once on 1.4.

Not sure it's good solution. If a subclass of 
AbstractButton overrides this method, will the reflect 
call the correct method of a subclass?


Comment 37 _ mihmax 2002-08-22 17:01:29 UTC
To All: 
Who will integrate this patch into the trunk? 
I do not have access to openide's CVS.

To Petr:

> If the underlying method is an instance method, it is
> invoked using dynamic method lookup as documented in 
> The Java Language Specification, Second Edition, section
> 15.12.4.4; in particular, overriding based on the
> runtime type of the target object will occur. 

Sorry for not carefully reading JavaDoc on Method.invoke,
but I had to read the above paragraph 3 or 4 times to 
understand, that static Method will be OK.
Thanks for the proposal. 

There're some other perfomance issues on Russian version, 
but this method is called rarely, only when menus are 
created, so throwing such low number of exceptions should 
not be a problem.
Comment 38 Jesse Glick 2002-08-22 19:55:46 UTC
Misc. comments:

Rather than using reflection this way, it is now customary to put the
1.4-specific code into a separate class named *14.java, which may use
1.4 APIs. From the main class, try to load and use this class,
catching ClassNotFoundException and LinkageError which should revert
to the 1.3 impl.

Re. integrator: it is assigned to Dafe, so he is responsible unless
someone else accepts it.

BTW Maxym don't use JPEGs for screenshots - use GIF or PNG, which are
non-lossy.

The 1.4 screenshot looks nice!

Has anyone checked whether the non-ASCII mnemonics (Alt-<<keycode>>)
actually work on non-Windows systems? Linux? Solaris? Seems like a
potential trouble area for users of different kinds of keyboards, so
it would be good to check this as soon as possible.
Comment 39 _ mihmax 2002-08-22 21:29:20 UTC
I don't have Linux/Solaris,
but the patch seems to be OS/independent (I think so).

The layout of Russian keyboards is standardized, and 
there's a strong correspondence between Ciryllic & Latin 
letters.

About *14.java : should I change the patch? I didn't know 
about this Netbeans code convention.
Comment 40 Jesse Glick 2002-08-22 22:16:32 UTC
It would be nice to use the *14.java style, but it's definitely not
very important. Mainly a style convention, so we don't have to read
dozens of lines of java.lang.reflect.* code every time someone wants
to use a 1.4 API.
Comment 41 _ mihmax 2002-08-23 13:07:55 UTC
To Integrator:
I'll create a new patch which uses *14-style

To Jaroslav Tulach:
I cannot apply the patch you suggested:
Exception: Missing comma.

Any ideas?
Comment 42 _ mihmax 2002-08-23 16:46:13 UTC
BTW:
in Actions.java on line 195:

//Ampersand is last characted, use first character as 
shortcut
...
    item.setMnemonic (0);
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

and not
    item.setMnemonic (text.charAt(0));

It's a bug, or comment is outdated?
Comment 43 _ mihmax 2002-08-23 20:39:48 UTC
Created attachment 7199 [details]
FINAL patch, working both for JDK1.3 & JDK1.4
Comment 44 _ mihmax 2002-08-23 20:42:05 UTC
Created attachment 7200 [details]
FINAL file Actions.java - Provided by Jaroslav Tulach
Comment 45 _ mihmax 2002-08-23 20:44:13 UTC
Latest two marked FINAL are really final.

Sorry for providing two files (not one), but I cannot create a single
patch using Netbeans CVS / GUI Style
Comment 46 _ mihmax 2002-08-23 20:47:52 UTC
To integrator:
Please verify that CVS client you use integrates the patch correctly,
because internal Netbeans Patcher produces bad results ;(
I'll file an issue.
Comment 47 Jesse Glick 2002-08-23 21:24:33 UTC
This use of reflection is unsafe. The VM could throw a
NoSuchMethodError when the method is *called*, rather than when the
class is *loaded*. This is because of lazy bytecode compilation by
HotSpot when verification is disabled (as it is in release builds).

Use e.g.:

if (actions14 instanceof Map.Entry) {
    actions14.setValue(...);
}
if (actions14 == null) {
    try {
        Class c = Class.forName(...);
        Map.Entry e = (Map.Entry)c.newInstance();
        e.setValue(...);
        actions14 = e;
    } catch (Exception e) {
        actions14 = new Object();
    } catch (LinkageError e) {
        actions14 = new Object();
    }
}
if (!(actions14 instanceof Map.Entry)) {
    // JDK 1.3 style...
}

or similar.
Comment 48 Jaroslav Tulach 2002-08-28 09:32:49 UTC
*** Issue 24521 has been marked as a duplicate of this issue. ***
Comment 49 _ mihmax 2002-08-28 10:15:33 UTC
I've started discussion on nbdiscuss on how to properly do 
all this stuff:
Localize mnemonics of Buttons, Labels, etc.
Comment 50 Jesse Glick 2002-08-28 13:59:34 UTC
Sure, just nbui (for how it should appear to the user) or nbdev (for
how to implement it) please, rather than nbdiscuss.
Comment 51 David Simonek 2002-09-04 13:58:34 UTC
Patch integrated into main trunk.
To Maxym: I used console based patch command to apply your patch and
everything should be ok, test build was also ok.
Comment 52 _ mihmax 2002-09-04 14:26:50 UTC
Thanks,

I will reopen 
http://www.netbeans.org/issues/show_bug.cgi?id=26640

and send there a new patch for setLabelText method with similiar way
of setting text,mnemonic & displayedMnemonicIndex
Comment 53 _ mihmax 2002-10-05 15:11:32 UTC
works, thanks, I do work using this fix since 23.08.2002
Comment 54 _ mihmax 2002-12-01 23:37:05 UTC
Checking in openide/src/org/openide/awt/Actions.java;
new revision: 1.64.14.1; previous revision: 1.64

Commited to release341 branch,

Also added a tag release341_base & branched to release341 the file
Actions14.java
Comment 55 _ mihmax 2002-12-02 18:21:30 UTC
Adding a tag is bad, thanks to Jesse for pointing that out, I followed
his recommendations:

Checking in openide/src/org/openide/awt/Actions14.java;
new revision: 1.1.38.1; previous revision: 1.1
Comment 56 Quality Engineering 2003-07-01 16:31:46 UTC
Resolved for 3.4.x or earlier, no new info since then -> closing.