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).

1  
!7
2  
3  
do not include function list.
4  
5  
p-substance {
6  
  if (l(args) != 0) new Viewer().showFile(new File(join(" ", args)));
7  
  else inputFilePath("Image to view", voidfunc(File file) { new Viewer().showFile(file) });
8  
}
9  
10  
sclass Viewer {
11  
  ImageSurface is;
12  
  File file;
13  
14  
  void showFile(final File file) {
15  
    assertTrue("File not found: " + absolutePath(file), file.exists());
16  
    this.file = file;
17  
    bool first = is == null;
18  
    is = showImage_centered(is, file.getName(), loadBufferedImage(file));
19  
    awt { is.zoomToWindow(); }
20  
    
21  
    if (first) { // will be in AWT
22  
      pcallF(is.onZoom = r { setFrameTitle(is, Viewer.this.file.getName() + " (" + toint(is.zoomX*100) + "%)") });
23  
      
24  
      // dragger (scroll around by mouse)
25  
      new ImageSurfaceDragger(is);
26  
      
27  
      // register keys
28  
      registerLeftKey(getFrame(is), r { nextFile(-1) });
29  
      registerRightKey(getFrame(is), r { nextFile(1) });
30  
      registerMinusKeys(is, r { is.zoomOut(1.5) });
31  
      registerPlusKeys(is, r { is.zoomIn(1.5) });
32  
      registerKey(is, KeyEvent.VK_A, "A", r { is.setZoom(1.0) });
33  
      registerKey(is, KeyEvent.VK_W, "W", r { is.zoomToWindow() });
34  
      
35  
      // fancy
36  
      componentPopupMenuItem(is, "Run standard function...", r {
37  
        selectStandardFunction(voidfunc(fS sf) {
38  
          thread "Calc" {
39  
            pcall-messagebox {
40  
              O o = callAndMake(sf, is.getImage());
41  
              BufferedImage img = toBufferedImageOpt(o);
42  
              if (img != null)
43  
                showImage(sf, img);
44  
              else
45  
                infoBox("Result is not an image: " + className(o));
46  
            }
47  
          }
48  
        });
49  
      });
50  
      
51  
      hideConsole();
52  
    }
53  
  }
54  
    
55  
  void nextFile(int offset) {
56  
    L<File> files = asList(sortFilesAlphaNum(listImageFiles(file.getParentFile())));
57  
    int i = indexOfPred(files, func(File f) { eq(f.getName(), file.getName()) });
58  
    showFile(get(files, mod(i+offset, l(files))));
59  
  }
60  
}

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: 582 / 5836
Version history: 16 change(s)
Referenced in: [show references]