MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / selectWindow

Method selectWindow

ij/src/main/java/ij/IJ.java:1648–1700  ·  view source on GitHub ↗

For IDs less than zero, activates the image with the specified ID. For IDs greater than zero, activates the Nth image.

(int id)

Source from the content-addressed store, hash-verified

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) {

Callers 13

putBehindMethod · 0.95
selectWindowMethod · 0.95
selectImageMethod · 0.95
closeMethod · 0.95
setBatchModeMethod · 0.95
mergeStacksMethod · 0.95
doStackOperationMethod · 0.95
doOperationMethod · 0.95
addSliceMethod · 0.95
compositeToRGBMethod · 0.95
runMethod · 0.95

Calls 15

getNthImageIDMethod · 0.95
getImageMethod · 0.95
errorMethod · 0.95
isBatchModeMethod · 0.95
getTempCurrentImageMethod · 0.95
getCurrentImageMethod · 0.95
saveRoiMethod · 0.95
setTempCurrentImageMethod · 0.95
activateImageMethod · 0.95
setWindowMethod · 0.95
getWindowMethod · 0.95
isMacOSXMethod · 0.95

Tested by

no test coverage detected