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

Method close

ij/src/main/java/ij/gui/ImageWindow.java:468–524  ·  view source on GitHub ↗

Removes this window from the window list and disposes of it. Returns false if the user cancels the "save changes" dialog.

()

Source from the content-addressed store, hash-verified

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

Callers 3

closeMethod · 0.95
convertStackToImagesMethod · 0.95
ImageWindowMethod · 0.95

Calls 15

setMethod · 0.95
waitMethod · 0.95
getAppletMethod · 0.95
isBatchModeMethod · 0.95
macroRunningMethod · 0.95
cancelPressedMethod · 0.95
yesPressedMethod · 0.95
saveMethod · 0.95
getWindowCountMethod · 0.95
removeWindowMethod · 0.95
isMacroMethod · 0.95
saveLocationMethod · 0.95

Tested by

no test coverage detected