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

59
LINES

< > BotCompany Repo | #1006063 // ImageChooser

JavaX fragment (include)

sclass ImageChooser extends SingleComponentPanel {
  new ImageSurface is;
  new JTextField tfPath;
  
  *(BufferedImage img) {
    this();
    setImage(img);
  }
  
  *(RGBImage img) { this(img.getBufferedImage()); }
  
  ifclass PNGFile
    *(PNGFile png) { this(png == null ? null : png.getImage()); }
  endif
  
  *() {
    bindToComponent(this, r { is.zoomToWindow() });
    is.loadFromClipboard();
    //setComponent(withLabel("Path to image or snippet ID:", tfPath));
    setComponent(jMinSize(100, 100, jscroll(is)));
    
    componentPopupMenu(is, voidfunc(JPopupMenu menu) {
      addMenuItem(menu, "Screenshot in 3", r {
        thread "Screenshot in 3" {
          sleep(3000);
          final BufferedImage img = shootScreen2();
          awt {
            is.setImage(img);
            infoMessage("Screenshot taken (" + img.getWidth() + "*" + img.getHeight() + " px)", 2);
          }
        }
      });
      
      addMenuItem(menu, "Load snippet or file...", r {
        final new JTextField tf;
        showFormTitled("Load image from snippet or file",
          "Path or snippet ID", tf,
          r {
            is.setImage(loadImage2(tf.getText().trim()));
            is.zoomToDisplaySize();
          });
      });
    });
  }
  
  bool hasImage() { ret is.getImage() != null && is.getImage().getWidth()*is.getImage().getHeight() > 1; }
  
  BWImage getBWImage() { ret is.getImage() == null ? null : new BWImage(is.getImage()); }
  
  BufferedImage getImage() { ret hasImage() ? is.getImage() : null; }
  
  void setImage(BufferedImage img) { is.setImage(img); is.zoomToWindow(); }
  
  ifclass PNGFile
    PNGFile createPNGFile() { ret hasImage() ? new PNGFile(getImage()) : null; }
  endif
  
  void setTitleForUpload(S title) { is.titleForUpload = title; }
}

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: #1006063
Snippet name: ImageChooser
Eternal ID of this version: #1006063/12
Text MD5: 7dbc51ed1bb79f9f17c5a2ddd44a5ef1
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-28 09:46:52
Source code size: 1845 bytes / 59 lines
Pitched / IR pitched: No / No
Views / Downloads: 642 / 1432
Version history: 11 change(s)
Referenced in: [show references]