!7 sclass ImageInfo extends DynModule { S path; bool allowedToLook; Bool exists; Pt size; transient JComboBox cbAllowedToLook; transient BufferedImage image; transient long imageLoaded; File file() { ret newFile(path); } JComponent visualize() { if (path == null) ret jcenteredbutton("Load image...", r { selectFile("Load image", voidfunc(File f) { setField(path := f2s(f)); revisualize(); }); }); if (cbAllowedToLook == null) cbAllowedToLook = yesNoComboBox(allowedToLook, voidfunc(bool b) { setField(allowedToLook := b) }); ret makeForm( "Image location" := path, allowedToLook := cbAllowedToLook, +exists, "Size", size == null ? null : size.x + "*" + size.y, "Loaded" := image != null); } void update { if (path != null && allowedToLook) { bool change = setField(exists := file().isFile()); if (!exists) change |= setField(size := null); else try { getImage(); change |= setField(size := pt(image.getWidth(), image.getHeight())); } catch print e { change |= setField(size := null); } if (change) revisualize(); } else if (setFields(exists := null, size := null, image := null)) revisualize(); } // API for other modules File getFile() { ret file(); } Image getImage() { lock lock; if (image == null) { imageLoaded = now(); image = loadImage2(file()); } ret image; } }