errael commented on issue #4437:
URL: https://github.com/apache/netbeans/issues/4437#issuecomment-1198315335
When a mouse click is used to activate the top component, the stack is
```
at
org.netbeans.core.windows.WindowManagerImpl.notifyRegistryTopComponentActivated(WindowManagerImpl.java:1199)
at org.netbeans.core.windows.Central.setActiveMode(Central.java:233)
at org.netbeans.core.windows.Central.userActivatedMode(Central.java:1876)
at
org.netbeans.core.windows.view.DefaultView.userActivatedModeView(DefaultView.java:643)
at
org.netbeans.core.windows.view.ui.TabbedHandler$ActivationManager.handleActivation(TabbedHandler.java:524)
at
org.netbeans.core.windows.view.ui.TabbedHandler$ActivationManager.eventDispatched(TabbedHandler.java:471)
at
java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Toolkit.java:2194)
```
I'm guessing a safe approach would be to use this same path when the
activation should be done due to a focus change. The following change to
`org.netbeans.core.windows.view.ui.TabbedHandler` seems to work in some
extremely limited testing. Invoking `handleActivation` through the
`KeyboardFocusManager` activates whatever TopComponenet gets keyboard focus; it
should only occur when needed. For example, note that in the regular case of a
mouse press that there is not a 2nd activation, the conditional test avoids
invocation.
The change adds a KeyboardFocusManager propertyChangeListener to
`ActivationManager`.
```
if (activationManager == null) {
activationManager = new ActivationManager();
Toolkit.getDefaultToolkit().addAWTEventListener(
activationManager, AWTEvent.MOUSE_EVENT_MASK);
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addPropertyChangeListener("focusOwner",
activationManager);
}
...
private static class ActivationManager implements AWTEventListener,
PropertyChangeListener {
@Override
public void eventDispatched(AWTEvent e) {
if(e.getID() == MouseEvent.MOUSE_PRESSED) {
System.err.println("ActivationManager: mouse: " +
(e.getSource() == null ? null : e.getSource().getClass().getSimpleName()));
handleActivation(e.getSource());
}
}
@Override
public void propertyChange(PropertyChangeEvent e) {
Frame mainWindowNB =
WindowManagerImpl.getInstance().getMainWindow();
Window activeWindowKB =
KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
TopComponent currentTC =
TopComponent.getRegistry().getActivated();
if(mainWindowNB == activeWindowKB
&& mainWindowNB != SwingUtilities.getRoot(currentTC)) {
System.err.println("ActivationManager: focus: " +
(e.getNewValue() == null ? null : e.getNewValue().getClass().getSimpleName()));
handleActivation(e.getNewValue());
}
}
...
private void handleActivation(Object evtObject) {
if (!(evtObject instanceof Component)) {
return;
}
Component comp = (Component) evtObject;
...
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists