<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi Sean,<br>
<br>
We still doesn't have consensus about native LAF behavior. As
noticed Mario "I believe that native look and feel should mandate
the different keybindings". I agree with him and I'd like to not
extend the new behavior on all LAFs.<br>
<br>
I also glanced at the fix and have one comment: you should use
getModifiersEx method instead of getModifiers (see javadoc for the
InputEvent#ALT_MASK field for details)<br>
<br>
Regards, Pavel<br>
<blockquote
cite="mid:CAOo=rxXASaRnoPrgFgQ8daW9jLKdec=Cu_LJOt94ENUgNuNiRg@mail.gmail.com"
type="cite">Hi all,
<div><br>
</div>
<div> I modified the patch and added the testcase, please see
attachment.</div>
<div><br>
</div>
<div> However, the testcase works on windows, but does not work
right on linux. That's</div>
<div>
the reason for the Manualbug7108342.java file. When I test it
manually, it works. And</div>
<div>because of this problem, I haven't tested it with jtreg.</div>
<div><br>
</div>
<div> Following is the scenario of testcase:</div>
<div> The test has three buttons with Mnemonic key "b", at
start up, focus is on button1,</div>
<div>when alt+b is pressed, focus goes to button3, and if pressed
again, it goes to button2,</div>
<div>and then button1, etc.</div>
<div><br>
</div>
<div> When the testcase runs on linux, only button3 and button1
get focused, and there </div>
<div>are 18 focus events recorded instead of 9. I'm not sure
what's the problem with it. </div>
<div>When I press alt+b manually(using Manualbug7108342.java), it
works well. </div>
<div><br>
</div>
<div> Does anyone have some comments about the patch or the
testcase ? </div>
<div><br>
<div class="gmail_quote">On Sat, Oct 8, 2011 at 7:35 PM, Pavel
Porvatov <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:pavel.porvatov@oracle.com">pavel.porvatov@oracle.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div text="#000000" bgcolor="#ffffff"> Hi Sean,
<div class="im">
<blockquote type="cite">Hi Pavel,
<div><br>
</div>
<div> Your observation is right, but I can't agree
with the conclusion. Windows and</div>
<div>GTK behave differently about how to close an
opened menu. Under GTK, press</div>
<div>"alt" can not close an opened menu, so, the "esc"
is used to close it; while </div>
<div>windows performs more friendly, when mnemonic key
is pressed again, the first</div>
<div>opened menu is closed automatically. This is
totally about how to close an </div>
<div>opened menu, and it doesn't change the fact that
menus with same mnemonic</div>
<div>key are iterated.</div>
<div><br>
</div>
<div> On the other side, swing implementation
doesn't follow GTK's behavior about</div>
<div>how to close the menu at all. Open the swingset2
and you can find its behavior</div>
<div>is the same with windows. Press "alt+f" and then
press "alt+l" will open the</div>
<div>"look and feel" menu instead of GTK's "alt+f",
"esc", and "alt+l".</div>
<div><br>
</div>
<div> So, I think GTK's behavior about "use esc to
close an opened menu" is not</div>
<div>user friendly and we can ignore it, while GTK's
"iterate over menus with same </div>
<div>mnemonic key" is better than current java
implementation and we can add </div>
<div>this feature. And if a user wants to use GTK's
key sequence "alt+f", "esc", </div>
<div>"alt+l", it is also functional. </div>
<div><br>
</div>
<div> So I think this enhancement will help keep the
behavior same with both these</div>
<div>platforms, how do you think?<br>
</div>
</blockquote>
</div>
Sounds reasonable and I don't object now to the decision.
Does anybody have ideas (e.g. objections) about the new
functionality?<br>
<br>
I glanced at your patch and have the following comments:<br>
1. Could you please file CR about the problem<br>
2. A test is needed (I think it's possible to write an
automatic one)<br>
3. Could you please correct the new code to obey our code
standards (aligning, spacing, mandatory braces in if/else
conditions and others)<br>
<br>
If possible send patch as a webrev, please.<br>
<br>
Thanks, Pavel
<div>
<div class="h5"><br>
<br>
<blockquote type="cite">
<div><br>
<div class="gmail_quote">2011/9/21 Pavel Porvatov
<span dir="ltr"><<a moz-do-not-send="true"
href="mailto:pavel.porvatov@oracle.com"
target="_blank">pavel.porvatov@oracle.com</a>></span><br>
<blockquote class="gmail_quote"
style="margin:0pt 0pt 0pt
0.8ex;border-left:1px solid rgb(204, 204,
204);padding-left:1ex">
<div bgcolor="#ffffff" text="#000000"> Hi
Sean,<br>
<br>
I found out that Windows and GTK works in
different ways (I used your apps):<br>
<br>
1. When Alt+i is pressed several times:<br>
In Windows focus moves between items<br>
In Ubuntu focus stays at the initially
selected item<br>
<br>
2. When sequence Alt+i and Escape pressed
several times<br>
In Windows the first menu item is selected<br>
In Ubuntu after every sequence the next item
is selected<br>
<br>
In such case we should use different
strategies for different platforms...
<div>
<div><br>
<br>
Regards, Pavel<br>
<br>
<blockquote type="cite"> Hi Pavel,
<div><br>
</div>
<div> I just tested linux gtk
platform. With gtk2+, ubuntu linux
with kernel 2.6.38, xfce, x86_32.</div>
<div>I set four menus with mnemonic
"i". Press "alt+i" will travel
through four menus. The difference</div>
<div>is that each menu must be closed
with "esc" before "alt+i" opens the
next one.</div>
<div><br>
</div>
<div> So press "alt+i" opens
"File", and press "esc" to close it;</div>
<div> then press "alt+i" opens
"Edit", and press "esc" to close it;</div>
<div> ... for next menu with
mnemonic "i"</div>
<div><br>
</div>
<div>I attached the test application
and its ui file. If it is blocked,
please use</div>
<div>this link: <a
moz-do-not-send="true"
href="https://docs.google.com/leaf?id=0B8kRxsymP7imOGU1NjhiM2ItMGQ5Ni00NWNhLWJmMDQtZjZiZmQzN2U4ZGUw&hl=en_US"
target="_blank">https://docs.google.com/leaf?id=0B8kRxsymP7imOGU1NjhiM2ItMGQ5Ni00NWNhLWJmMDQtZjZiZmQzN2U4ZGUw&hl=en_US</a></div>
<div><br>
</div>
<div>Ubuntu x86_32 should work.</div>
<div><br>
</div>
<div><br>
</div>
<div>So, I think both windows and
linux gtk have supported traversal
of same mnemonic keyed</div>
<div>items already. </div>
<div><br>
</div>
<div> <br>
<div>2011/9/14 Pavel Porvatov <span><<a
moz-do-not-send="true"
href="mailto:pavel.porvatov@oracle.com"
target="_blank">pavel.porvatov@oracle.com</a>></span><br>
<blockquote>
<div> Hi Sean,
<div>
<blockquote type="cite">
<div>Hi Pavel,</div>
<div><br>
</div>
<div> Let's see if this
time works. The
attachement just
contains the exe file
written by C#, the
application is very
simple, I just drag a
menu to the default
WinForm in VS2003. </div>
<div> Please change
the extension from exe1
to exe after unzip as
gmail doesn't allow exe
file to be sent.</div>
</blockquote>
</div>
Yes, I see. And what about
other platforms/lafs? Your
patch affects behavior of all
lafs. So we must be sure, that
such behavior is correct for
every supported platform...<br>
<br>
Regards, Pavel
<div>
<div><br>
<blockquote type="cite"><br>
<div>2011/9/13 Pavel
Porvatov <span><<a
moz-do-not-send="true" href="mailto:pavel.porvatov@oracle.com"
target="_blank">pavel.porvatov@oracle.com</a>></span><br>
<blockquote>
<div> Hi Sean,<br>
<br>
I think the
attached sample
was removed
because I didn't
get any
attachments...<br>
<br>
Regards, Pavel
<div>
<div><br>
<blockquote
type="cite">
<div>Hi Pavel,</div>
<div><br>
</div>
<div> I
found C# Form
application
treats
Mnemonics in
menu in this
way. I
attached the
sample</div>
<div>application.
Press alt+i
will iterate
over three
menu.</div>
<br>
<div>
2011/9/13
Pavel Porvatov
<span><<a
moz-do-not-send="true"
href="mailto:pavel.porvatov@oracle.com" target="_blank">pavel.porvatov@oracle.com</a>></span><br>
<blockquote>
<div> Hi Sean,
<div>
<blockquote
type="cite">
Hi,
<div><br>
</div>
<div>
Thanks. </div>
<div><br>
</div>
<div> So is
there any one
can give me a
suggestion
about what
shall I</div>
<div>do if we
want these
feature ?
Thanks again.<br>
</div>
</blockquote>
</div>
First of all
you should
file a bug
(RFE
actually).
BTW: before
reviewing the
fix I'd like
to ask about
OS behavior
when there are
several
components
with the same
mnemonic. How
Windows
XP/Vista/7 and
Linux
(Gnome/KDE)
manage the
described
situation?<br>
<br>
Regards, Pavel
<div>
<div><br>
<br>
<blockquote
type="cite">
<div><br>
<div>2011/7/6
Jean-Remi
Desjardins <span><<a
moz-do-not-send="true" href="mailto:jeanremi.desjardins@gmail.com"
target="_blank">jeanremi.desjardins@gmail.com</a>></span><br>
<blockquote>
<div>
<div>I think
that sounds
like a great
idea!</div>
<div><br>
</div>
<div>Regards,</div>
<div>Jean-Rémi
Desjardins<br>
<br>
Sent from my
iPhone (so
don't expect
me to be too
verbose)</div>
<div>
<div>
<div><br>
On 2011-07-06,
at 5:42 AM,
Sean Chou <<a
moz-do-not-send="true" href="mailto:zhouyx@linux.vnet.ibm.com"
target="_blank">zhouyx@linux.vnet.ibm.com</a>>
wrote:<br>
<br>
</div>
<blockquote
type="cite">
<div>Hi,
<div><br>
</div>
<div> Is
there anybody
interested in
this feature?
Or any other
comments? <br>
<br>
<div>2011/4/21
Sean Chou <span><<a
moz-do-not-send="true" href="mailto:zhouyx@linux.vnet.ibm.com"
target="_blank">zhouyx@linux.vnet.ibm.com</a>></span><br>
<blockquote>
<div>Hi,</div>
<div><br>
</div>
<div> I have
a simple patch
to demo the
new behavior.
With the
patch, the
focus will go
through the
radiobuttons
with mnemonic
key Y when
alt+y is
pressed
instead of
select the
last.</div>
<div> <br>
</div>
<div><br>
</div>
<div>The patch
is as follows:</div>
<div>
<pre>diff -r 554adcfb615e src/share/classes/javax/swing/KeyboardManager.java
--- a/src/share/classes/javax/swing/KeyboardManager.java Wed Mar 16 15:01:07 2011 -0700
+++ b/src/share/classes/javax/swing/KeyboardManager.java Thu Mar 17 14:57:14 2011 +0800
@@ -251,6 +251,93 @@
}
} else if ( tmp instanceof Vector) { //more than one comp registered for this
Vector v = (Vector)tmp;
+
+ /* The below code is added to make sure the focus is not always
+ transferred to the last component in the vector when
+ more than one component have the same mnemonic
+ */
+ if ((e.getModifiers() & Event.ALT_MASK) == Event.ALT_MASK) {
+ /* Mnemonic key should transfer the focus only, do not select.
+ * The following code works in this way:
+ * 1. If only one component in the vector is visible, fireBinding on it.
+ * 2. If multi-components in the vector are visible, move the focus to next component.
+ * 2.1 If the next component is not a JAbstractButton, fireBinding on it.
+ * 2.2 If the next component is a JMenu, which is a JAbstractButton, fireBinding
+ * on it to open the menu.
+ * 2.3 If the next component is another JAbstractButton like JRadioButton. Request
+ * focus on it instead of fireBinding. To AVOID SELECTION & CLICK of the button.
+ * 3. If the code is triggered by release event, fireBinding on current focus component
+ * instead of move focus.
+ * 4. Further consideration: there may be more swing control like JMenu, or customized
+ * controls, which may break this behavior.
+ */
+ // This has alt as it's modifier so this could be a mnemonic
+ Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
+ {
+ // If only one visible component, invoke it.
+ int visibleComponentCounter = 0;
+ int nextFocus = 0;
+ for (int i = 0; i < v.size(); i++){
+ JComponent c = (JComponent) v.elementAt(i);
+ if (c.isShowing() && c.isEnabled()){
+ visibleComponentCounter++ ;
+ nextFocus = i;
+ }
+ }
+ if (visibleComponentCounter == 1){
+ JComponent tmpc = (JComponent) v.elementAt(nextFocus);
+ fireBinding(tmpc, ks, e, pressed);
+ if (e.isConsumed())
+ return true;
+ }
+ // If multi-components are visible, do not select the button, just move the focus.
+ for (int counter = v.size() - 1; counter >= 0; counter--) {
+ JComponent c = (JComponent) v.elementAt(counter);
+ if (c.isShowing() && c.isEnabled()) {
+ if ((c == focusOwner)
+ || (c instanceof JLabel && ((JLabel) c).getLabelFor() == focusOwner)) {
+ if (e.getID() == KeyEvent.KEY_RELEASED){
+ nextFocus = counter;
+ break;
+ }
+ nextFocus = (counter - 1 + v.size()) % v.size();
+ break;
+ }
+ }
+ }
+ for (; nextFocus >= 0; nextFocus--) {
+ JComponent c = (JComponent) v.elementAt(nextFocus);
+ if (c.isShowing() && c.isEnabled()) {
+ break;
+ }
+ }
+ if (nextFocus >= 0) {
+ JComponent tmpc = (JComponent) v.elementAt(nextFocus);
+ // Next is the hack for this accessibility:
+ // For general Buttons, do not press them, but request focus only.
+ // For special buttons like JMenu, needs press.
+ // If it is not a button, let the component handles by itself.
+ if (!(tmpc instanceof javax.swing.AbstractButton)){
+ fireBinding(tmpc, ks, e, pressed);
+ if (e.isConsumed())
+ return true;
+ }
+ if (tmpc instanceof JMenu ) {
+ fireBinding(tmpc, ks, e, pressed);
+ tmpc.requestFocusInWindow();
+ if (e.isConsumed())
+ return true;
+ } else {
+ boolean result = tmpc.requestFocusInWindow();
+ e.consume();
+ return result;
+ }
+ }
+ // If it is not handled here, default behavior is selecting the last.
+ }
+ }
+
+
// There is no well defined order for WHEN_IN_FOCUSED_WINDOW
// bindings, but we give precedence to those bindings just
// added. This is done so that JMenus WHEN_IN_FOCUSED_WINDOW
</pre>
</div>
<div>
<div>
<div><br>
</div>
<br>
<br>
<div>2011/4/1
Sean Chou <span><<a
moz-do-not-send="true" href="mailto:zhouyx@linux.vnet.ibm.com"
target="_blank">zhouyx@linux.vnet.ibm.com</a>></span><br>
<blockquote>
<div>Hi all,</div>
<div><br>
</div>
<div> In
daily use, we
may encounter
a problem of
mnemonic key:
there may be
several</div>
<div>controls
want the same
key to be set
as mnemonic
key. It is not
common but it
does exist.</div>
<div><br>
</div>
<div>
Current
openjdk
implementation
allows users
to set a same
mnemonic key
for </div>
<div>different
controls; but
during the
execution,
when the
mnemonic key
is pressed,</div>
<div>the last
control always
gets the
action. Users
are not able
to touch other
controls with</div>
<div>that
mnemonic key.
This may
confuse them.</div>
<div><br>
</div>
<div> If all
the controls
with the same
mnemonic key
can be
accessed
through, for</div>
<div>example,
when the
mnemonic key
is pressed,
the focus is
moved to the
last control, </div>
<div>and when
the mnemonic
key is pressed
again, the
focus is moved
to the second
control</div>
<div>with that
mnemonic, it
will give user
the choice to
select other
controls.</div>
<div><br>
</div>
<div> Here
is an example
for the case:</div>
<div><br>
</div>
<div>package
test;</div>
<div><br>
</div>
<div>import
java.awt.BorderLayout;</div>
<div>import
java.awt.Container;</div>
<div>import
javax.swing.ButtonGroup;</div>
<div>import
javax.swing.JFrame;</div>
<div>import
javax.swing.JRadioButton;</div>
<div><br>
</div>
<div>public
class
TestFocus
extends JFrame
{<span> </span></div>
<div><span> </span>public
TestFocus() {</div>
<div> <span>
</span>Container
pane =
getContentPane();</div>
<div><span> </span>pane.setLayout(new
BorderLayout());</div>
<div><span> </span>JRadioButton
btn1,btn2,btn3;</div>
<div><span> </span>btn1
= new
JRadioButton("Yes");</div>
<div><span> </span>btn1.setMnemonic('Y');</div>
<div> <span>
</span>btn2 =
new
JRadioButton("Yup");</div>
<div><span> </span>btn2.setMnemonic('Y');</div>
<div><span> </span>btn3
= new
JRadioButton("No");</div>
<div><span> </span>btn3.setMnemonic('N');</div>
<div><span> </span>btn3.setSelected(true);</div>
<div><span> </span>ButtonGroup
group = new
ButtonGroup();</div>
<div><span> </span>group.add(btn1);</div>
<div><span> </span>group.add(btn2);</div>
<div><span> </span>group.add(btn3);</div>
<div><span> </span>pane.add(btn1,BorderLayout.NORTH);</div>
<div><span> </span>pane.add(btn2,BorderLayout.CENTER);</div>
<div><span> </span>pane.add(btn3,BorderLayout.SOUTH);</div>
<div><span> </span>setSize(200,200);</div>
<div><span> </span>setVisible(true);</div>
<div><span> </span>setDefaultCloseOperation(EXIT_ON_CLOSE);<span>
</span></div>
<div><span> </span>}</div>
<div><span> </span></div>
<div><span> </span>public
static void
main(String[]
args) {</div>
<div><span> </span>new
TestFocus();</div>
<div><span> </span>}</div>
<div>}</div>
<div><br>
</div>
<br>
<div><br>
</div>
<div><br>
-- <br>
Best Regards,<br>
Sean Chou<br>
<br>
</div>
</blockquote>
</div>
<br>
<br>
<br>
</div>
</div>
-- <br>
Best Regards,<br>
Sean Chou<br>
<br>
</blockquote>
</div>
<br>
<br>
<br>
-- <br>
Best Regards,<br>
Sean Chou<br>
<br>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
<br>
<br>
<div><br>
</div>
-- <br>
Best Regards,<br>
Sean Chou<br>
<br>
</div>
</blockquote>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
<br>
<div><br>
</div>
-- <br>
Best Regards,<br>
Sean Chou<br>
<br>
</blockquote>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
<br>
<div><br>
</div>
-- <br>
Best Regards,<br>
Sean Chou<br>
<br>
</blockquote>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
<br>
<div><br>
</div>
-- <br>
Best Regards,<br>
Sean Chou<br>
<br>
</div>
</blockquote>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
Best Regards,<br>
Sean Chou<br>
<br>
</div>
</blockquote>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
Best Regards,<br>
Sean Chou<br>
<br>
</div>
</blockquote>
<br>
</body>
</html>