Quit using a separate thread, hopefully avoiding thread deadlocks.
()
| 941 | |
| 942 | /** Quit using a separate thread, hopefully avoiding thread deadlocks. */ |
| 943 | @AstroImageJ(reason = "Add event calls for closing when DP, AstroConvert, multiplot, or astro stack windows are " + |
| 944 | "open; Wait for event queue to finish", modified = true) |
| 945 | public void run() { |
| 946 | quitting = true; |
| 947 | boolean changes = false; |
| 948 | int[] wList = WindowManager.getIDList(); |
| 949 | if (wList!=null) { |
| 950 | for (int i=0; i<wList.length; i++) { |
| 951 | ImagePlus imp = WindowManager.getImage(wList[i]); |
| 952 | if (imp!=null && imp.changes==true) { |
| 953 | changes = true; |
| 954 | break; |
| 955 | } |
| 956 | } |
| 957 | } |
| 958 | Frame[] frames = WindowManager.getNonImageWindows(); |
| 959 | if (frames!=null) { |
| 960 | for (int i=0; i<frames.length; i++) { |
| 961 | if (frames[i]!=null && (frames[i] instanceof Editor)) { |
| 962 | if (((Editor)frames[i]).fileChanged()) { |
| 963 | changes = true; |
| 964 | break; |
| 965 | } |
| 966 | } |
| 967 | } |
| 968 | } |
| 969 | if (windowClosed && !changes && Menus.window.getItemCount()>Menus.WINDOW_MENU_ITEMS && !(IJ.macroRunning()&&WindowManager.getImageCount()==0)) { |
| 970 | GenericDialog gd = new GenericDialog("ImageJ", this); |
| 971 | gd.addMessage("Are you sure you want to quit ImageJ?"); |
| 972 | gd.showDialog(); |
| 973 | quitting = !gd.wasCanceled(); |
| 974 | windowClosed = false; |
| 975 | } |
| 976 | if (!quitting) |
| 977 | return; |
| 978 | if (!WindowManager.closeAllWindows()) { |
| 979 | quitting = false; |
| 980 | return; |
| 981 | } |
| 982 | if (applet==null) { |
| 983 | saveWindowLocations(); |
| 984 | Prefs.set(ImageWindow.LOC_KEY,null); // don't save image window location |
| 985 | Frame[] dp = Frame.getFrames(); |
| 986 | for (int i=0; i<dp.length;i++) { |
| 987 | if (dp[i].getTitle().equals("CCD Data Processor") || |
| 988 | dp[i].getTitle().equals("Multi-plot Main") || |
| 989 | dp[i].getTitle().equals("Coordinate Converter") || |
| 990 | dp[i].getClass().getName().contains("AstroStackWindow")) { |
| 991 | WindowEvent wev = new WindowEvent(dp[i], WindowEvent.WINDOW_CLOSING); |
| 992 | Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev); |
| 993 | try { |
| 994 | SwingUtilities.invokeAndWait(() -> {}); |
| 995 | } catch (InterruptedException | InvocationTargetException e) { |
| 996 | e.printStackTrace(); |
| 997 | } |
| 998 | } |
| 999 | } |
| 1000 | Prefs.savePreferences(); |
nothing calls this directly
no test coverage detected