For IDs less than zero, activates the image with the specified ID. For IDs greater than zero, activates the Nth image.
(int id)
| 1646 | /** For IDs less than zero, activates the image with the specified ID. |
| 1647 | For IDs greater than zero, activates the Nth image. */ |
| 1648 | @AstroImageJ(reason = "make sure infinite loop will bail out", modified = true) |
| 1649 | public static void selectWindow(int id) { |
| 1650 | if (id>0) |
| 1651 | id = WindowManager.getNthImageID(id); |
| 1652 | ImagePlus imp = WindowManager.getImage(id); |
| 1653 | if (imp==null) |
| 1654 | error("Macro Error", "Image "+id+" not found or no images are open."); |
| 1655 | if (Interpreter.isBatchMode()) { |
| 1656 | ImagePlus impT = WindowManager.getTempCurrentImage(); |
| 1657 | ImagePlus impC = WindowManager.getCurrentImage(); |
| 1658 | if (impC!=null && impC!=imp && impT!=null) |
| 1659 | impC.saveRoi(); |
| 1660 | WindowManager.setTempCurrentImage(imp); |
| 1661 | Interpreter.activateImage(imp); |
| 1662 | WindowManager.setWindow(null); |
| 1663 | } else { |
| 1664 | if (imp==null) |
| 1665 | return; |
| 1666 | ImageWindow win = imp.getWindow(); |
| 1667 | if (win!=null) { |
| 1668 | win.toFront(); |
| 1669 | win.setState(Frame.NORMAL); |
| 1670 | WindowManager.setWindow(win); |
| 1671 | } |
| 1672 | long start = System.currentTimeMillis(); |
| 1673 | // timeout after 1 second unless current thread is event dispatch thread |
| 1674 | String thread = Thread.currentThread().getName(); |
| 1675 | int timeout = thread!=null&&thread.indexOf("EventQueue")!=-1?0:1000; |
| 1676 | if (IJ.isMacOSX() && IJ.isJava18() && timeout>0) |
| 1677 | timeout = 250; //work around OS X/Java 8 window activation bug |
| 1678 | while (true) { |
| 1679 | wait(10); |
| 1680 | imp = WindowManager.getCurrentImage(); |
| 1681 | if (imp!=null && imp.getID()==id) |
| 1682 | return; // specified image is now active |
| 1683 | if ((System.currentTimeMillis()-start)>timeout && win!=null) { |
| 1684 | WindowManager.setCurrentWindow(win); |
| 1685 | return; |
| 1686 | } |
| 1687 | if (win == null && imp != null) { |
| 1688 | win = imp.getWindow(); |
| 1689 | if (win!=null) { |
| 1690 | win.toFront(); |
| 1691 | win.setState(Frame.NORMAL); |
| 1692 | WindowManager.setWindow(win); |
| 1693 | } |
| 1694 | } |
| 1695 | if ((System.currentTimeMillis()-start)>timeout) { |
| 1696 | error("Macro Error", "Image "+id+" could not find open window."); |
| 1697 | } |
| 1698 | } |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | /** Activates the window with the specified title. */ |
| 1703 | public static void selectWindow(String title) { |
no test coverage detected