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

55
LINES

< > BotCompany Repo | #1004147 // Screenshot Quick Select - make a screenshot and allow selection immediately

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

Libraryless. Click here for Pure Java version (9786L/69K/233K).

!752

concepts.

static ImageSurface imageSurface;
static JButton btnUpload;
static JFrame frame;
static JLabel lStatus;

concept Title {
  S title;
}

p-awt { // << seems important
  concepts();
  BufferedImage img = shootScreen2();
  
  ImageSurface.verbose = true;
  
  imageSurface = new ImageSurface(img) {
    public void setSelection(Rectangle r) {
      super.setSelection(r);
      btnUpload.setText(r != null ? "Upload (selected area)" : "Upload");
      lStatus.setText(r == null ? "" : str(new Rect(r)));
    }
  };
  
  JPanel buttons = jcenteredline(
    lStatus = jlabel(),
    btnUpload = jbutton("Upload", r {
      String title = or2(uniq(Title).title, "A screenshot");
      title = JOptionPane.showInputDialog(null, "Please enter screenshot title", title);
      if (title == null) return;
      BufferedImage image = imageSurface.getImage();
      if (imageSurface.getSelection() != null)
        image = new RGBImage(image).clip(imageSurface.getSelection()).getBufferedImage();
      cset(uniq(Title), +title);
      S id = uploadImage(title, toPNG(image));
      popup("Image uploaded: " + shortSnippetLink(id));
    }),
    jbutton("Shoot again", r {
      hideFrame(frame);
      swingLater(1000, r {
        imageSurface.setImage(shootScreen2());
        makeFrameVisible(imageSurface);
        maximizeFrame(imageSurface);
      });
    })
  );

  frame = showMaximizedFrame(centerAndSouth(
    new JScrollPane(imageSurface), buttons));
    
  if (amFirstProgram()) hideConsole();
}

download  show line numbers  debug dex  old transpilations   

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

1 comment(s) hidden. show

Snippet ID: #1004147
Snippet name: Screenshot Quick Select - make a screenshot and allow selection immediately
Eternal ID of this version: #1004147/1
Text MD5: e7f138d801d1a9cec3264a3017f1853f
Transpilation MD5: 472ce5038dba34a33556497508a4b6e7
Author: stefan
Category: javax / gui
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-16 16:52:38
Source code size: 1563 bytes / 55 lines
Pitched / IR pitched: No / No
Views / Downloads: 1293 / 1833
Referenced in: [show references]