Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

60
LINES

< > BotCompany Repo | #1008774 // Image Viewer

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (30976L/202K).

!7

do not include function list.

p-substance {
  if (l(args) != 0) new Viewer().showFile(new File(join(" ", args)));
  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;
    bool first = is == null;
    is = showImage_centered(is, file.getName(), loadBufferedImage(file));
    awt { is.zoomToWindow(); }
    
    if (first) { // will be in AWT
      pcallF(is.onZoom = r { setFrameTitle(is, Viewer.this.file.getName() + " (" + toint(is.zoomX*100) + "%)") });
      
      // dragger (scroll around by mouse)
      new ImageSurfaceDragger(is);
      
      // register keys
      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() });
      
      // fancy
      componentPopupMenuItem(is, "Run standard function...", r {
        selectStandardFunction(voidfunc(fS sf) {
          thread "Calc" {
            pcall-messagebox {
              O o = callAndMake(sf, is.getImage());
              BufferedImage img = toBufferedImageOpt(o);
              if (img != null)
                showImage(sf, img);
              else
                infoBox("Result is not an image: " + className(o));
            }
          }
        });
      });
      
      hideConsole();
    }
  }
    
  void nextFile(int offset) {
    L<File> files = asList(sortFilesAlphaNum(listImageFiles(file.getParentFile())));
    int i = indexOfPred(files, func(File f) { eq(f.getName(), file.getName()) });
    showFile(get(files, mod(i+offset, l(files))));
  }
}

Author comment

Began life as a copy of #1007760

download  show line numbers  debug dex  old transpilations   

Travelled to 18 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv, znvaruejrphg

No comments. add comment

Snippet ID: #1008774
Snippet name: Image Viewer
Eternal ID of this version: #1008774/17
Text MD5: 87f1c376811324df68acefc35a2af31c
Transpilation MD5: ee49da77fbcbef6ccf1e50e4758be6af
Author: stefan
Category: javax / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-01-31 01:50:53
Source code size: 2004 bytes / 60 lines
Pitched / IR pitched: No / No
Views / Downloads: 576 / 5825
Version history: 16 change(s)
Referenced in: [show references]