Waits until the image window becomes activated. This is necessary in macros or other programs if an ImagePlus is shown on the screen, because displaying the window is asynchronous (happens later) and will make the image the active one. Without waiting, in the meanwhile another window could be al
()
| 650 | * executing an IJ.run(...) call. |
| 651 | */ |
| 652 | public void waitTillActivated() { |
| 653 | if (win == null) return; |
| 654 | if (EventQueue.isDispatchThread()) { //'activated' is set in the EventQueue, we can't wait for it in the EventQueue |
| 655 | WindowManager.setTempCurrentImage(this); |
| 656 | return; |
| 657 | } |
| 658 | long start = System.currentTimeMillis(); |
| 659 | while (!activated) { |
| 660 | IJ.wait(5); |
| 661 | if (ij != null && ij.quitting()) return; |
| 662 | if ((System.currentTimeMillis()-start)>2000) { |
| 663 | WindowManager.setTempCurrentImage(this); |
| 664 | break; // 2 second timeout |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | /** Called by ImageWindow.windowActivated(); to end waiting in waitTillActivated. */ |
| 670 | public void setActivated() { |
no test coverage detected