Removes this window from the window list and disposes of it. Returns false if the user cancels the "save changes" dialog.
()
| 466 | /** Removes this window from the window list and disposes of it. |
| 467 | Returns false if the user cancels the "save changes" dialog. */ |
| 468 | @AstroImageJ(reason = "Save AIJ plot window location", modified = true) |
| 469 | public boolean close() { |
| 470 | if (this instanceof PlotWindow) { |
| 471 | Prefs.set("plot2.plotFrameLocationX",getX()); |
| 472 | Prefs.set("plot2.plotFrameLocationY",getY()); |
| 473 | } |
| 474 | boolean isRunning = running || running2; |
| 475 | running = running2 = false; |
| 476 | if (imp==null) return true; |
| 477 | boolean virtual = imp.getStackSize()>1 && imp.getStack().isVirtual(); |
| 478 | if (isRunning) IJ.wait(500); |
| 479 | if (imp==null) return true; |
| 480 | boolean changes = imp.changes; |
| 481 | Roi roi = imp.getRoi(); |
| 482 | if (roi!=null && (roi instanceof PointRoi) && ((PointRoi)roi).promptBeforeDeleting()) |
| 483 | changes = true; |
| 484 | if (ij==null || ij.quittingViaMacro() || IJ.getApplet()!=null || Interpreter.isBatchMode() || IJ.macroRunning() || virtual) |
| 485 | changes = false; |
| 486 | if (changes) { |
| 487 | String msg; |
| 488 | String name = imp.getTitle(); |
| 489 | if (name.length()>22) |
| 490 | msg = "Save changes to\n" + "\"" + name + "\"?"; |
| 491 | else |
| 492 | msg = "Save changes to \"" + name + "\"?"; |
| 493 | if (imp.isLocked()) |
| 494 | msg += "\nWARNING: This image is locked.\nProbably, processing is unfinished (slow or still previewing)."; |
| 495 | toFront(); |
| 496 | YesNoCancelDialog d = new YesNoCancelDialog(this, "ImageJ", msg); |
| 497 | if (d.cancelPressed()) |
| 498 | return false; |
| 499 | else if (d.yesPressed()) { |
| 500 | FileSaver fs = new FileSaver(imp); |
| 501 | if (!fs.save()) return false; |
| 502 | } |
| 503 | } |
| 504 | closed = true; |
| 505 | if (WindowManager.getWindowCount()==0) { |
| 506 | xloc = 0; |
| 507 | yloc = 0; |
| 508 | } |
| 509 | WindowManager.removeWindow(this); |
| 510 | if (ij!=null && ij.quitting()) // this may help avoid thread deadlocks |
| 511 | return true; |
| 512 | Rectangle bounds = getBounds(); |
| 513 | if (!IJ.isMacro() |
| 514 | && bounds.y<screenHeight/3 && (bounds.y+bounds.height)<=screenHeight |
| 515 | && (bounds.x+bounds.width)<=screenWidth) { |
| 516 | Prefs.saveLocation(LOC_KEY, new Point(bounds.x,bounds.y)); |
| 517 | xbase = -1; |
| 518 | } |
| 519 | dispose(); |
| 520 | if (imp!=null) |
| 521 | imp.flush(); |
| 522 | imp = null; |
| 523 | return true; |
| 524 | } |
| 525 |
no test coverage detected