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

128
LINES

< > BotCompany Repo | #1009782 // Item Pages With Comments [OK]

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

Download Jar. Uses 4489K of libraries. Click here for Pure Java version (10666L/76K).

!7

sclass Msg {
  S author, text;
  long created = now();
}

concept ItemPage {
  S globalID = aGlobalID();
  S title, imageID;
  long created = now(), occurred;
  L<Msg> comments = listInConcept(this);
}

/*concept ItemPageAsList {
  new Ref<ItemPage> item;
  L<S> items = listInConcept(this);
}*/

static JTextPane textPane;
static JTextField tfComment;
static ItemPage page;
static JButton btnBack, btnNext;

p-subst {
  bootstrapConceptsFrom(#1009748);
  setConsoleInputFontSize(20);
  centerConsoleInput();
  centerBottomConsole();
  db();
  bot("Show Item Page.");
  focusConsole();
  awtOnConceptChanges(consoleFrame(), r {
    consoleTitle(n(countConcepts(ItemPage), "Item Page"))
  });
}

static bool showItemPage(S _word) {
  final new ItemPage p;
  new Matches m;
  if (match("user said *", _word, m)) _word = format("You said: *", $1);
  fS word = trim(_word);
  cset(p, title := word);
  showPage(p);
  focusConsole();
  true;
}

svoid showPage(final ItemPage p) {
  if (p == null) ret;
  swing {
    page = p;
    fS shorter = deUserSaid(p.title);
    JFrame f = getFrame(textPane);
    fS text = p.title + "\n\n";
    L<ItemPage> l = list(ItemPage);
    int idx = l.indexOf(page);
    S frameTitle = shorter + " [" + (idx+1) + "/" + l(l) + "]";
    JTextPane oldTextPane = textPane;
    textPane = jcenteredtextpane(text, style_bold(style_fontSize(24)));
    if (oldTextPane != null) {
      replaceAWTComponent(oldTextPane, textPane);
      setFrameTitle(frameTitle, textPane);
      frameToFront(f);
    } else {
      showFrame(frameTitle, textPane);
      addToFrame(textPane, withLabel("Add Comment:", centerAndEast(tfComment = jtextfield(), jbutton("OK", f addComment))));
      addToFrameNorth(textPane, jcenteredline(
        btnBack = jbutton("<", r { step(-1) }),
        btnNext = jbutton(">", r { step(1) })));
      onEnter(tfComment, f addComment);
    }
    setEnabled(btnBack, idx > 0);
    setEnabled(btnNext, idx < l(l)-1);
      
    textPane.setEditable(false);
    if (p.imageID == null) thread {
      BufferedImage img = quickVisualize(shorter);
      if (p.imageID != null) ret;
      cset(p, imageID := "quickvis/" + urlencode(quickVisualize_preprocess(shorter)) + "/" + md5OfBufferedImage(img));
      showPage(p);
    } else {
      BufferedImage img = quickVisualize(shorter);
      addImageToTextPane(textPane, img); // sync OK, uses swing {}
    }
    
    for (Msg c : p.comments)
      appendToTextPane(textPane, "\n\n" + c.author + ": " + c.text, style_normal());
      
    centerTextPane(textPane);
  }
}

answer {
  if (eq(s, "!list")) { showPagesList(); ret "OK"; }
    
  if "quickrun *" {
    fS prog = $1;
    thread { _run($1); print("[done]"); }
    ret "OK";
  }
  if (showItemPage(s)) ret "OK";
}

svoid addComment {
  S text = getTextTrimAndClear(tfComment);
  if (empty(text)) ret;
  page.comments.add(nuWithValues(Msg, author := 'User, +text));
  showPage(page);
}

// called by child processes
svoid addProgramComment(S programID, ItemPage page, S text) {
  page.comments.add(nuWithValues(Msg, author := programID, +text));
  showPage(page);
}

svoid showPagesList {
  onDoubleClick(showList_updatedOnConceptsChange("Item Pages", func { map(list(ItemPage), func(ItemPage p) {
    p.globalID + " - " + p.title })}), voidfunc(S s) {
      showPage(findConcept(ItemPage, globalID := dropAfterSpace(s)))
    });
}

svoid step(int delta) {
  L<ItemPage> l = list(ItemPage);
  showPage(get(l, l.indexOf(page)+delta));
}

Author comment

Began life as a copy of #1009748

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1009782
Snippet name: Item Pages With Comments [OK]
Eternal ID of this version: #1009782/44
Text MD5: 5b4f82651f06c59a4d25961d89f2a4f2
Transpilation MD5: f24b3a1b67ff741272ea08ea450076f1
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-18 19:27:14
Source code size: 3604 bytes / 128 lines
Pitched / IR pitched: No / No
Views / Downloads: 466 / 1076
Version history: 43 change(s)
Referenced in: [show references]