/** Called by ImageJ when the user selects Quit. */ public void quit() { quitMacro = IJ.macroRunning(); Thread thread = new Thread(this, "Quit"); thread.setPriority(Thread.NORM_PRIORITY); thread.start(); IJ.wait(10); }
/** Quit using a separate thread, hopefully avoiding thread deadlocks. */ public void run() { quitting = true; boolean changes = false; int[] wList = WindowManager.getIDList(); if (wList != null) { for (int i = 0; i < wList.length; i++) { ImagePlus imp = WindowManager.getImage(wList[i]); if (imp != null && imp.changes == true) { changes = true; break; } } } Frame[] frames = WindowManager.getNonImageWindows(); if (frames != null) { for (int i = 0; i < frames.length; i++) { if (frames[i] != null && (frames[i] instanceof Editor)) { if (((Editor) frames[i]).fileChanged()) { changes = true; break; } } } } if (windowClosed && !changes && Menus.window.getItemCount() > Menus.WINDOW_MENU_ITEMS && !(IJ.macroRunning() && WindowManager.getImageCount() == 0)) { GenericDialog gd = new GenericDialog("ImageJ", this); gd.addMessage("Are you sure you want to quit ImageJ?"); gd.showDialog(); quitting = !gd.wasCanceled(); windowClosed = false; } if (!quitting) return; if (!WindowManager.closeAllWindows()) { quitting = false; return; } // IJ.log("savePreferences"); if (applet == null) { saveWindowLocations(); Prefs.savePreferences(); } IJ.cleanup(); // setVisible(false); // IJ.log("dispose"); dispose(); if (exitWhenQuitting) System.exit(0); }