Skip to content

Commit 368f622

Browse files
hansonrhansonr
authored andcommitted
menu mnemonics, MenuSelectionManager, KeyboardFocusManager, proper
FocusEvents. Still not accelerators (ALT-X, CTRL-Y, etc.)
1 parent 3790e0d commit 368f622

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2967
-2525
lines changed
1.32 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190110222432
1+
20190114011334
1.32 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190110222432
1+
20190114011334
1.32 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/awt/Component.java

Lines changed: 77 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.awt.event.HierarchyBoundsListener;
3838
import java.awt.event.HierarchyEvent;
3939
import java.awt.event.HierarchyListener;
40-
import java.awt.event.InputEvent;
4140
import java.awt.event.InputMethodEvent;
4241
import java.awt.event.InputMethodListener;
4342
import java.awt.event.ItemEvent;
@@ -1511,9 +1510,9 @@ boolean containsFocus() {
15111510
return isFocusOwner();
15121511
}
15131512

1514-
// void clearMostRecentFocusOwnerOnHide() {
1515-
// KeyboardFocusManager.clearMostRecentFocusOwner(this);
1516-
// }
1513+
void clearMostRecentFocusOwnerOnHide() {
1514+
KeyboardFocusManager.clearMostRecentFocusOwner(this);
1515+
}
15171516

15181517
void clearCurrentFocusCycleRootOnHide() {
15191518
/* do nothing */
@@ -1527,14 +1526,13 @@ public void hide() {
15271526
isPacked = false;
15281527
if (visible) {
15291528
clearCurrentFocusCycleRootOnHide();
1530-
// clearMostRecentFocusOwnerOnHide();
1529+
clearMostRecentFocusOwnerOnHide();
15311530
// synchronized (getTreeLock()) {
15321531
visible = false;
15331532
mixOnHiding(isLightweight());
1534-
// if (containsFocus() &&
1535-
// KeyboardFocusManager.isAutoFocusTransferEnabled()) {
1536-
// transferFocus(true);
1537-
// }
1533+
if (containsFocus() && KeyboardFocusManager.isAutoFocusTransferEnabled()) {
1534+
transferFocus(true);
1535+
}
15381536

15391537
updatePeerVisibility(false);
15401538

@@ -3706,17 +3704,16 @@ protected void dispatchEventImplComp(AWTEvent e) {
37063704
/*
37073705
* 0. Set timestamp and modifiers of current event.
37083706
*/
3709-
EventQueue.setCurrentEventAndMostRecentTime(e);
3707+
if (!(e instanceof KeyEvent)) {
3708+
// Timestamp of a key event is set later in DKFM.preDispatchKeyEvent(KeyEvent).
3709+
EventQueue.setCurrentEventAndMostRecentTime(e);
3710+
}
37103711

37113712
/*
37123713
* 1. Pre-dispatchers. Do any necessary retargeting/reordering here before we
37133714
* notify AWTEventListeners.
37143715
*/
37153716

3716-
// if (e instanceof JSDnD.JSDropTargetEvent) {
3717-
// ((JSDnD.JSDropFileMouseEvent) e).dispatch();
3718-
// return;
3719-
// }
37203717
// if (e instanceof SunDropTargetEvent) {
37213718
// ((SunDropTargetEvent)e).dispatch();
37223719
// return;
@@ -3726,18 +3723,16 @@ protected void dispatchEventImplComp(AWTEvent e) {
37263723
// Invoke the private focus retargeting method which provides
37273724
// lightweight Component support
37283725
if (e.isPosted) {
3729-
// e = KeyboardFocusManager.retargetFocusEvent(e);
3726+
e = KeyboardFocusManager.retargetFocusEvent(e);
37303727
e.isPosted = true;
37313728
}
37323729

37333730
// Now, with the event properly targeted to a lightweight
37343731
// descendant if necessary, invoke the public focus retargeting
37353732
// and dispatching function
3736-
// if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
3737-
// dispatchEvent(e))
3738-
// {
3739-
// return;
3740-
// }
3733+
if (KeyboardFocusManager.getCurrentKeyboardFocusManager().dispatchEvent(e)) {
3734+
return;
3735+
}
37413736
}
37423737
// if ((e instanceof FocusEvent) && focusLog.isLoggable(Level.FINEST)) {
37433738
// focusLog.log(Level.FINEST, "" + e);
@@ -3771,60 +3766,58 @@ protected void dispatchEventImplComp(AWTEvent e) {
37713766
if (!e.isConsumed()) {
37723767
if (e instanceof KeyEvent) {
37733768
// check for tab navigation:
3774-
// KeyboardFocusManager.getCurrentKeyboardFocusManager().
3775-
// processKeyEvent(this, (KeyEvent)e);
3776-
// if (e.isConsumed()) {
3777-
// return;
3778-
// }
3769+
KeyboardFocusManager.getCurrentKeyboardFocusManager().processKeyEvent(this, (KeyEvent) e);
3770+
if (e.isConsumed()) {
3771+
return;
3772+
}
37793773
}
37803774
}
37813775

37823776
/*
37833777
* 4. Allow input methods to process the event
37843778
*/
3785-
if (areInputMethodsEnabled()) {
3786-
// We need to pass on InputMethodEvents since some host
3787-
// input method adapters send them through the Java
3788-
// event queue instead of directly to the component,
3789-
// and the input context also handles the Java composition window
3790-
if (
3791-
// ((e instanceof InputMethodEvent) && !(this instanceof
3792-
// CompositionArea))
3793-
// ||
3794-
// Otherwise, we only pass on input and focus events, because
3795-
// a) input methods shouldn't know about semantic or component-level
3796-
// events
3797-
// b) passing on the events takes time
3798-
// c) isConsumed() is always true for semantic events.
3799-
(e instanceof InputEvent) || (e instanceof FocusEvent)) {
3800-
// InputContext inputContext = getInputContext();
3801-
//
3802-
//
3803-
// if (inputContext != null) {
3804-
// inputContext.dispatchEvent(e);
3805-
// if (e.isConsumed()) {
3806-
// // if ((e instanceof FocusEvent) &&
3807-
// focusLog.isLoggable(Level.FINEST)) {
3808-
// // focusLog.log(Level.FINEST, "3579: Skipping " + e);
3809-
// // }
3810-
// return;
3811-
// }
3812-
// }
3813-
}
3814-
} else {
3815-
// When non-clients get focus, we need to explicitly disable the
3816-
// native
3817-
// input method. The native input method is actually not disabled
3818-
// when
3819-
// the active/passive/peered clients loose focus.
3820-
if (id == FocusEvent.FOCUS_GAINED) {
3821-
// InputContext inputContext = getInputContext();
3822-
// if (inputContext != null && inputContext instanceof
3823-
// sun.awt.im.InputContext) {
3824-
// ((sun.awt.im.InputContext)inputContext).disableNativeIM();
3825-
// }
3826-
}
3827-
}
3779+
// if (areInputMethodsEnabled()) {
3780+
// // We need to pass on InputMethodEvents since some host
3781+
// // input method adapters send them through the Java
3782+
// // event queue instead of directly to the component,
3783+
// // and the input context also handles the Java composition window
3784+
// if (
3785+
// // ((e instanceof InputMethodEvent) && !(this instanceof
3786+
// // CompositionArea))
3787+
// // ||
3788+
// // Otherwise, we only pass on input and focus events, because
3789+
// // a) input methods shouldn't know about semantic or component-level
3790+
// // events
3791+
// // b) passing on the events takes time
3792+
// // c) isConsumed() is always true for semantic events.
3793+
// (e instanceof InputEvent) || (e instanceof FocusEvent)) {
3794+
// InputContext inputContext = getInputContext();
3795+
//
3796+
// if (inputContext != null) {
3797+
// inputContext.dispatchEvent(e);
3798+
// if (e.isConsumed()) {
3799+
// // if ((e instanceof FocusEvent) &&
3800+
// // focusLog.isLoggable(Level.FINEST)) {
3801+
// // focusLog.log(Level.FINEST, "3579: Skipping " + e);
3802+
// // }
3803+
// return;
3804+
// }
3805+
// }
3806+
// }
3807+
// } else {
3808+
// // When non-clients get focus, we need to explicitly disable the
3809+
// // native
3810+
// // input method. The native input method is actually not disabled
3811+
// // when
3812+
// // the active/passive/peered clients loose focus.
3813+
// if (id == FocusEvent.FOCUS_GAINED) {
3814+
// // InputContext inputContext = getInputContext();
3815+
// // if (inputContext != null && inputContext instanceof
3816+
// // sun.awt.im.InputContext) {
3817+
// // ((sun.awt.im.InputContext)inputContext).disableNativeIM();
3818+
// // }
3819+
// }
3820+
// }
38283821

38293822
/*
38303823
* 5. Pre-process any special events before delivery
@@ -5909,19 +5902,15 @@ public void removeNotify() {
59095902
}
59105903

59115904
protected void removeNotifyComp() {
5912-
// KeyboardFocusManager.clearMostRecentFocusOwner(this);
5913-
// if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
5914-
// getPermanentFocusOwner() == this)
5915-
// {
5916-
// KeyboardFocusManager.getCurrentKeyboardFocusManager().
5917-
// setGlobalPermanentFocusOwner(null);
5918-
// }
5905+
KeyboardFocusManager.clearMostRecentFocusOwner(this);
5906+
if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner() == this) {
5907+
KeyboardFocusManager.getCurrentKeyboardFocusManager().setGlobalPermanentFocusOwner(null);
5908+
}
59195909

5920-
synchronized (getTreeLock()) {
5921-
// if (isFocusOwner() &&
5922-
// KeyboardFocusManager.isAutoFocusTransferEnabledFor(this)) {
5923-
// transferFocus(true);
5924-
// }
5910+
// synchronized (getTreeLock()) {
5911+
if (isFocusOwner() && KeyboardFocusManager.isAutoFocusTransferEnabledFor(this)) {
5912+
transferFocus(true);
5913+
}
59255914

59265915
// if (getContainer() != null && isAddNotifyComplete) {
59275916
// getContainer().decreaseComponentCount(this);
@@ -5963,8 +5952,7 @@ protected void removeNotifyComp() {
59635952
// peerFont = null;
59645953

59655954
Toolkit.getEventQueue().removeSourceEvents(this, false);
5966-
// KeyboardFocusManager.getCurrentKeyboardFocusManager().
5967-
// discardKeyEvents(this);
5955+
KeyboardFocusManager.getCurrentKeyboardFocusManager().discardKeyEvents(this);
59685956

59695957
p.dispose();
59705958

@@ -5984,7 +5972,7 @@ protected void removeNotifyComp() {
59845972
| ((isRecursivelyVisible()) ? HierarchyEvent.SHOWING_CHANGED : 0));
59855973
dispatchEvent(e);
59865974
}
5987-
}
5975+
// }
59885976
}
59895977

59905978
/**
@@ -6050,13 +6038,12 @@ public void setFocusable(boolean focusable) {
60506038
isFocusTraversableOverridden = FOCUS_TRAVERSABLE_SET;
60516039

60526040
firePropertyChange("focusable", Boolean.valueOf(oldFocusable), Boolean.valueOf(focusable));
6053-
// if (oldFocusable && !focusable) {
6054-
// if (isFocusOwner() &&
6055-
// KeyboardFocusManager.isAutoFocusTransferEnabled()) {
6056-
// transferFocus(true);
6057-
// }
6058-
// KeyboardFocusManager.clearMostRecentFocusOwner(this);
6059-
// }
6041+
if (oldFocusable && !focusable) {
6042+
if (isFocusOwner() && KeyboardFocusManager.isAutoFocusTransferEnabled()) {
6043+
transferFocus(true);
6044+
}
6045+
KeyboardFocusManager.clearMostRecentFocusOwner(this);
6046+
}
60606047
}
60616048

60626049
final boolean isFocusTraversableOverridden() {

sources/net.sf.j2s.java.core/src/java/awt/Container.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,10 +2216,11 @@ void dispatchEventImpl(AWTEvent e) {
22162216
// gets forwarded. If the native host has been removed
22172217
// as a result of the sending the lightweight event,
22182218
// the peer reference will be null.
2219-
e.consume();
2220-
if (peer != null) {
2221-
peer.handleEvent(e);
2222-
}
2219+
// SwingJS why this? true return indicates consumed e.consume();
2220+
// SwingJS next is unnecessary for JavaScript
2221+
// if (peer != null) {
2222+
// peer.handleEvent(e);
2223+
// }
22232224
return;
22242225
}
22252226

0 commit comments

Comments
 (0)