-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using swing UI causes command dialogs to show some invisible items #18
Comments
I think the problem can be pinpointed to the DefaultDisplayService. When I set a breakpoint at the 114 line, the problem does not appear; but if I set a breakpoint at the 117 line, the problem appears, and the conditional breakpoint shows that the Therefore, it seems that the display-activation event is published too slowly for the swing UI when a command is called programmatically, so that the display input is not resolved at that moment. @ctrueden any reason this would happen? |
After playing around with the Eclipse debugger for a while, I think I figure out how most of this process works and where the problem lies. DefaultUIService#onEvent is invoked due to a DisplayCreatedEvent, which consequently schedule a runnable that will invoke the view(w, d) method of a corresponding DisplayViewer. In the case of opening an image, the legacy mode uses LegacyImageDisplayViewer, which sets the active display immediately in the view(w, d) call; in contrast, the corresponding DisplayViewer does not set the active display until a display window is constructed, and then the DefaultDisplayService#onEvent finally sets the active display. In the meanwhile, the main thread is running to preprocess the command, which looks for a suitable active display to inject into the command. I found that the call stack of constructing a swing window is quite large, so that the main thread always asks for active display before the WinActivatedEvent can invoke the setActiveDisplay method. Since the legacy mode sets the active display before constructing the window, there is no such problem in legacy mode. If this is actually the problem, then adding a line of code that sets the active display in the view(w, d) will be a hacky solution, but should we also suppose that a display should not be not ready until its window is ready? Then we might need to let other threads wait until the display is active. @ctrueden What do you think? |
For now, this could be a workaround:
But the call to |
Using
|
Thanks for the thorough followup, Leon. I'm definitely not a fan of any sleep-based workarounds. IJ1 is full of those and it causes nothing but trouble in the long run. We can make things concurrency safe, I'm sure. |
Racing condition occurs when a command is programmatically invoked immediately after a display is created, using swing ui. The racing condition is resovled in a similar way to the LegacyImageDisplayViewer. See scijava/scijava-ui-swing#18
When ImageJ is launched with the swing as the default UI:
Any following calls to commands that have a ImageDisplay parameter with
type = ItemIO.BOTH
ortype = ItemIO.INPUT
will cause the command dialog to show an item "display" with a long string of its ImageDisplay.toString().For example,
ij.command().run(SubtractFromDataValues.class, true);
pops up such dialog with unexpected behavior. Using the legacy UI (e.g. removing the "setDefaultUI" line of code above) does not produce such problem, so I suspect that it is the swing UI causes the problem.Is this a bug, or is there any correct way to programmatically run a command so that the display item will be invisible? Thanks!
The text was updated successfully, but these errors were encountered: