!7 p-substance { if (l(args) != 0) new Viewer().showFile(new File(args[0])); else inputFilePath("Image to view", voidfunc(File file) { new Viewer().showFile(file) }); } sclass Viewer { ImageSurface is; File file; void showFile(final File file) { assertTrue("File not found: " + absolutePath(file), file.exists()); this.file = file; BufferedImage img = loadBufferedImage(file); if (is != null) { is.setImage(img); setFrameTitle(is, file.getName()); } else { is = showImage_centered(file.getName(), img); registerLeftKey(getFrame(is), r { nextFile(-1) }); registerRightKey(getFrame(is), r { nextFile(1) }); registerMinusKeys(is, r { is.zoomOut(1.5) }); registerPlusKeys(is, r { is.zoomIn(1.5) }); registerKey(is, KeyEvent.VK_A, "A", r { is.setZoom(1.0) }); registerKey(is, KeyEvent.VK_W, "W", r { is.zoomToWindow() }); hideConsole(); } } void nextFile(int offset) { L files = asList(listFiles(file.getParentFile())); if (nempty(files)) { int i = indexOfPred(files, func(File f) { eq(f.getName(), file.getName()) }); showFile(get(files, mod(i+offset, l(files)))); } } }