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).

1  
!7
2  
3  
sclass Msg {
4  
  S author, text;
5  
  long created = now();
6  
}
7  
8  
concept ItemPage {
9  
  S globalID = aGlobalID();
10  
  S title, imageID;
11  
  long created = now(), occurred;
12  
  L<Msg> comments = listInConcept(this);
13  
}
14  
15  
/*concept ItemPageAsList {
16  
  new Ref<ItemPage> item;
17  
  L<S> items = listInConcept(this);
18  
}*/
19  
20  
static JTextPane textPane;
21  
static JTextField tfComment;
22  
static ItemPage page;
23  
static JButton btnBack, btnNext;
24  
25  
p-subst {
26  
  bootstrapConceptsFrom(#1009748);
27  
  setConsoleInputFontSize(20);
28  
  centerConsoleInput();
29  
  centerBottomConsole();
30  
  db();
31  
  bot("Show Item Page.");
32  
  focusConsole();
33  
  awtOnConceptChanges(consoleFrame(), r {
34  
    consoleTitle(n(countConcepts(ItemPage), "Item Page"))
35  
  });
36  
}
37  
38  
static bool showItemPage(S _word) {
39  
  final new ItemPage p;
40  
  new Matches m;
41  
  if (match("user said *", _word, m)) _word = format("You said: *", $1);
42  
  fS word = trim(_word);
43  
  cset(p, title := word);
44  
  showPage(p);
45  
  focusConsole();
46  
  true;
47  
}
48  
49  
svoid showPage(final ItemPage p) {
50  
  if (p == null) ret;
51  
  swing {
52  
    page = p;
53  
    fS shorter = deUserSaid(p.title);
54  
    JFrame f = getFrame(textPane);
55  
    fS text = p.title + "\n\n";
56  
    L<ItemPage> l = list(ItemPage);
57  
    int idx = l.indexOf(page);
58  
    S frameTitle = shorter + " [" + (idx+1) + "/" + l(l) + "]";
59  
    JTextPane oldTextPane = textPane;
60  
    textPane = jcenteredtextpane(text, style_bold(style_fontSize(24)));
61  
    if (oldTextPane != null) {
62  
      replaceAWTComponent(oldTextPane, textPane);
63  
      setFrameTitle(frameTitle, textPane);
64  
      frameToFront(f);
65  
    } else {
66  
      showFrame(frameTitle, textPane);
67  
      addToFrame(textPane, withLabel("Add Comment:", centerAndEast(tfComment = jtextfield(), jbutton("OK", f addComment))));
68  
      addToFrameNorth(textPane, jcenteredline(
69  
        btnBack = jbutton("<", r { step(-1) }),
70  
        btnNext = jbutton(">", r { step(1) })));
71  
      onEnter(tfComment, f addComment);
72  
    }
73  
    setEnabled(btnBack, idx > 0);
74  
    setEnabled(btnNext, idx < l(l)-1);
75  
      
76  
    textPane.setEditable(false);
77  
    if (p.imageID == null) thread {
78  
      BufferedImage img = quickVisualize(shorter);
79  
      if (p.imageID != null) ret;
80  
      cset(p, imageID := "quickvis/" + urlencode(quickVisualize_preprocess(shorter)) + "/" + md5OfBufferedImage(img));
81  
      showPage(p);
82  
    } else {
83  
      BufferedImage img = quickVisualize(shorter);
84  
      addImageToTextPane(textPane, img); // sync OK, uses swing {}
85  
    }
86  
    
87  
    for (Msg c : p.comments)
88  
      appendToTextPane(textPane, "\n\n" + c.author + ": " + c.text, style_normal());
89  
      
90  
    centerTextPane(textPane);
91  
  }
92  
}
93  
94  
answer {
95  
  if (eq(s, "!list")) { showPagesList(); ret "OK"; }
96  
    
97  
  if "quickrun *" {
98  
    fS prog = $1;
99  
    thread { _run($1); print("[done]"); }
100  
    ret "OK";
101  
  }
102  
  if (showItemPage(s)) ret "OK";
103  
}
104  
105  
svoid addComment {
106  
  S text = getTextTrimAndClear(tfComment);
107  
  if (empty(text)) ret;
108  
  page.comments.add(nuWithValues(Msg, author := 'User, +text));
109  
  showPage(page);
110  
}
111  
112  
// called by child processes
113  
svoid addProgramComment(S programID, ItemPage page, S text) {
114  
  page.comments.add(nuWithValues(Msg, author := programID, +text));
115  
  showPage(page);
116  
}
117  
118  
svoid showPagesList {
119  
  onDoubleClick(showList_updatedOnConceptsChange("Item Pages", func { map(list(ItemPage), func(ItemPage p) {
120  
    p.globalID + " - " + p.title })}), voidfunc(S s) {
121  
      showPage(findConcept(ItemPage, globalID := dropAfterSpace(s)))
122  
    });
123  
}
124  
125  
svoid step(int delta) {
126  
  L<ItemPage> l = list(ItemPage);
127  
  showPage(get(l, l.indexOf(page)+delta));
128  
}

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: 661 / 1523
Version history: 43 change(s)
Referenced in: [show references]