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 181490 - JEditorPane gets focus after top component is closed
Summary: JEditorPane gets focus after top component is closed
Status: RESOLVED WONTFIX
Alias: None
Product: editor
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P2 normal (vote)
Assignee: Vitezslav Stejskal
URL:
Keywords: FOCUS
Depends on:
Blocks:
 
Reported: 2010-03-03 12:53 UTC by err
Modified: 2010-03-05 10:42 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description err 2010-03-03 12:53:38 UTC
For cleanup/simplification, jVi is now using focused gained on an JEP to set up stuff if needed, like the first time an editor is used, this works great for starting up an editor. However there is a problem with closing a top component in some circumstances. After getting notified that the top component is closed through TopComponent.Registry.PROP_TC_CLOSED jVi forgets about the JEP, but shortly thereafter the editor gets focus and jVi attempts to set up stuff for it again. While doing this some strange exceptions start happening, see below for one example.

The problems/exceptions seem to be related to using the JEP after NetBeans has closed it. And jVi uses it again because there is a focusGained event after NetBeans closes it.

There are a couple of ways to close an editor in jVi, one is a normal mode command and one is ":q". The normal mode command works fine, the other gets the exception. They use the same code paths to do the closing. However the ":q" command uses a dialog to determine the command. I am guessing that after the close command is processed and the dialog closes, the JVM attempts to pass focus back on the editor which NB has dismissed.

I'll look around for some hack to get around this for now. Any insight on what's going on and a clean way to either get rid of the problem focus gained event or reliably ignore it would be appreciated. (getting rid of the exception is not really a solution)

BTW, here is how jVi requests NetBeans to close an editor:

        // activate the previously active TC
        prevTC = avPrev.getTopComponent();

        // and close the one requested
        if(!avClose.getTopComponent().close())
            Msg.emsg(getBuffer().getDisplayFileName() + " not closed");


java.lang.ClassCastException: com.sun.java.swing.plaf.windows.WindowsEditorPaneUI cannot be cast to org.netbeans.editor.BaseTextUI
        at org.netbeans.editor.BaseCaret.update(BaseCaret.java:635)
        at org.netbeans.editor.BaseCaret$3.run(BaseCaret.java:613)
        at org.netbeans.editor.Utilities.runInEventDispatchThread(Utilities.java:1117)
        at org.netbeans.editor.BaseCaret.dispatchUpdate(BaseCaret.java:604)
        at org.netbeans.editor.BaseCaret.updateType(BaseCaret.java:333)
        at org.netbeans.editor.BaseCaret$2.run(BaseCaret.java:495)
        at org.netbeans.editor.Utilities.runInEventDispatchThread(Utilities.java:1117)
        at org.netbeans.editor.BaseCaret.modelChanged(BaseCaret.java:492)
        at org.netbeans.editor.BaseCaret.install(BaseCaret.java:381)
        at javax.swing.text.JTextComponent.setCaret(JTextComponent.java:582)
        at org.openide.text.QuietEditorPane.setCaret(QuietEditorPane.java:227)
        at org.netbeans.modules.jvi.NbFactory.installCaret(NbFactory.java:172)
        at org.netbeans.modules.jvi.NbFactory.setupCaret(NbFactory.java:152)
        at com.raelity.jvi.manager.Scheduler.switchTo(Scheduler.java:80)
        at com.raelity.jvi.manager.Scheduler$1.focusGained(Scheduler.java:124)
        at java.awt.AWTEventMulticaster.focusGained(AWTEventMulticaster.java:203)
        at java.awt.AWTEventMulticaster.focusGained(AWTEventMulticaster.java:202)
        at java.awt.Component.processFocusEvent(Component.java:6105)
        at java.awt.Component.processEvent(Component.java:5972)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4583)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4413)
        at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1848)
        at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:880)
        at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:511)
        at java.awt.Component.dispatchEventImpl(Component.java:4455)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Window.dispatchEventImpl(Window.java:2475)
        at java.awt.Component.dispatchEvent(Component.java:4413)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:125)
        at java.awt.SequencedEvent.dispatch(SequencedEvent.java:101)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:125)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
[catch] at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)



SEVERE [global]
java.lang.ClassCastException: com.sun.java.swing.plaf.windows.WindowsEditorPaneUI cannot be cast to org.netbeans.editor.BaseTextUI
        at org.netbeans.editor.BaseCaret.update(BaseCaret.java:635)
        at org.netbeans.editor.BaseCaret$3.run(BaseCaret.java:613)
        at org.netbeans.editor.Utilities.runInEventDispatchThread(Utilities.java:1117)
        at org.netbeans.editor.BaseCaret.dispatchUpdate(BaseCaret.java:604)
        at org.netbeans.editor.BaseCaret.changedUpdate(BaseCaret.java:1244)
        at org.netbeans.editor.HighlightingDrawLayer$5.run(HighlightingDrawLayer.java:530)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:125)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
[catch] at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Comment 1 Vitezslav Stejskal 2010-03-05 02:21:22 UTC
I don't really know what is going on with focus, etc, but my first idea was that Nb never reuses old JEPs for showing editors. So, once jVi decides that a JEP has been closed it can safely ignore any events coming from it. Would that be an acceptable solution on your side?
Comment 2 err 2010-03-05 10:38:53 UTC
I tried an extremely narrow solution for a few days. After a close if the next focus was to the just closed JEP then ignore it; this worked ok. Since the jVi close is advisory, I didn't want to permanently ignore it in case of a bug somewhere (could be a non NB app).

I just tried something else which should be reliable in any situation. If newly_focused_component.isDisplayable() is false then ignore the event. This seems to work and I'll try it for a few days. I looked and sure enough, the component does not have a peer, I'd say this is a JVM bug.

Closing this issue.