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

34
LINES

< > BotCompany Repo | #1006685 // Local Image Viewer (optionally takes image path as argument)

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

Uses 3874K of libraries. Click here for Pure Java version (5287L/37K/136K).

!7

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));
    
    if (first) {  
      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<File> files = asList(listFilesOnly(file.getParentFile()));
    int i = indexOfPred(files, func(File f) { eq(f.getName(), file.getName()) });
    showFile(get(files, mod(i+offset, l(files))));
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006685
Snippet name: Local Image Viewer (optionally takes image path as argument)
Eternal ID of this version: #1006685/16
Text MD5: a9a992fa92f70724a8c42e6e81d82069
Transpilation MD5: 878f4ed52fab3b45090ad4f9c8bb7848
Author: stefan
Category: javax / gui
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-02-05 11:09:05
Source code size: 1140 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 523 / 1878
Version history: 15 change(s)
Referenced in: [show references]