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

63
LINES

< > BotCompany Repo | #1016034 // Image Info [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (14499L/102K).

1  
!7
2  
3  
sclass ImageInfo extends DynModule {
4  
  S path;
5  
  bool allowedToLook;
6  
  Bool exists;
7  
  Pt size;
8  
9  
  transient JComboBox cbAllowedToLook;
10  
  transient BufferedImage image;
11  
  transient long imageLoaded;
12  
  
13  
  File file() { ret newFile(path); }
14  
  
15  
  JComponent visualize() {
16  
    if (path == null)
17  
      ret jcenteredbutton("Load image...", r {
18  
        selectFile("Load image", voidfunc(File f) {
19  
          setField(path := f2s(f));
20  
          revisualize();
21  
        });
22  
      });
23  
      
24  
    if (cbAllowedToLook == null)
25  
      cbAllowedToLook = yesNoComboBox(allowedToLook,
26  
        voidfunc(bool b) { setField(allowedToLook := b) });
27  
        
28  
    ret makeForm(
29  
      "Image location" := path,
30  
      allowedToLook := cbAllowedToLook,
31  
      +exists,
32  
      "Size", size == null ? null : size.x + "*" + size.y,
33  
      "Loaded" := image != null);
34  
  }
35  
  
36  
  void update {
37  
    if (path != null && allowedToLook) {
38  
      bool change = setField(exists := file().isFile());
39  
      if (!exists)
40  
        change |= setField(size := null);
41  
      else try {
42  
        getImage();
43  
        change |= setField(size := pt(image.getWidth(), image.getHeight()));
44  
      } catch print e {
45  
        change |= setField(size := null);
46  
      }
47  
      if (change)
48  
        revisualize();
49  
    } else
50  
      if (setFields(exists := null, size := null, image := null)) revisualize();
51  
  }
52  
  
53  
  // API for other modules
54  
  File getFile() { ret file(); }
55  
  Image getImage() {
56  
    lock lock;
57  
    if (image == null) {
58  
      imageLoaded = now();
59  
      image = loadImage2(file());
60  
    }
61  
    ret image;
62  
  }
63  
}

Author comment

Began life as a copy of #1015916

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: #1016034
Snippet name: Image Info [Dyn Module]
Eternal ID of this version: #1016034/10
Text MD5: c12f21e84c7c254715c24da302bcb59a
Transpilation MD5: 56291b87d273d442988902524ab6ec71
Author: stefan
Category: javax / gui
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-08 18:38:12
Source code size: 1616 bytes / 63 lines
Pitched / IR pitched: No / No
Views / Downloads: 380 / 530
Version history: 9 change(s)
Referenced in: [show references]