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

63
LINES

< > BotCompany Repo | #1007441 // AI Clipboard (with translation of concept language to english)

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

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (8942L/62K).

!7

static JFrame frame;
static S imageMD5, text;

sS title = "AI Clipboard";

p-substance {
  framesBot();
  frame = showFrame(title);
  
  // TODO: update less often if a non-text is in clipboard
  installTimer(frame, 1000, 0, r {
    update();
  });
  hideConsoleIfMainProgram();
}

svoid update {
  BufferedImage img = getImageFromClipboard();
  if (img != null) {
    S md5 = md5OfRGBImage(new RGBImage(img));
    if (neq(md5, imageMD5)) {
      imageMD5 = md5;
      text = null;
      setFrameContents(frame, jscroll(new ImageSurface(img)));
      setFrameTitle(frame, title + ": " + img.getWidth() + "*" + img.getHeight() + " px image");
    }
    ret;
  }
  imageMD5 = null;
  S s = getTextFromClipboard();
  if (s != null) {
    if (neq(text, s)) {
      text = s;
      JComponent x = explainText(s);
      JTextArea ta = typeWriterTextArea(s);
      setFrameContents(frame, x != null ? vsplit(x, ta) : ta);
      setFrameTitle(frame, title + ": " + quote(escapeNewLines(shorten(s, 256))));
    }
    ret;
  }
  text = null;
  // empty clipboard or unknown contents
  setFrameContents(frame, new JPanel);
  
  Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
  setFrameTitle(frame, transferable != null ? "Unknown clipboard contents (" + join(", ", mimeTypes(transferable)) + ")" : "Empty clipboard");
}

static JComponent explainText(S s) null on exception {
  Collection<S> ids = collectPossibleGlobalIDs(s);
  if (empty(ids)) null;
  new L<S> l;
  aiConceptsMap_clearCache(60);
  for (S id : ids) {
    S name = conceptToName(id);
    if (neq(id, name))
      l.add(id + " = " + name);
  }
  if (empty(l)) null;
  ret makeBold(jTextArea(lines(l)));
}

Author comment

Began life as a copy of #1006099

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1007441
Snippet name: AI Clipboard (with translation of concept language to english)
Eternal ID of this version: #1007441/13
Text MD5: f57eaecf02ef8d2f0fa90a656aba159c
Transpilation MD5: 2f6ced2e90df3119ae4a67f9ece1e4fd
Author: stefan
Category: javax / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-24 11:58:36
Source code size: 1773 bytes / 63 lines
Pitched / IR pitched: No / No
Views / Downloads: 445 / 1210
Version history: 12 change(s)
Referenced in: [show references]