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

71
LINES

< > TinyBrain | #1007383 - Encyclopedia 1 [WORKS]

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

Uses 2245K of libraries. Click here for Pure Java version (10439L/74K).

!7

static JTextField tf;
static SingleComponentPanel scp;
static Canvas canvas;
static Q q; // action queue
static volatile bool boss; // boss mode (after pressing Escape)
static L<AIConcept> aiConcepts;

!include #1007377 // traits for CirclesAndLines

p-substance-thread {
  aiConcepts = loadAIConcepts();
  //final S word = getString(random(aiConcepts), /*"name"*/"globalID");
  final S word = "paul + marie";
  swing {
    q = new Q(true);
    JFrame frame = showFrame(northAndCenter(tf = setTextFieldFontSize(jCenteredTextField(word), 20), scp = new SingleComponentPanel));
    registerEscape(frame, r { boss = true; tf.setText(""); scp.noComponent(); });
    centerFrame(frameInnerSize(frame, 600, 600));
    addMenu(frame, "Menu!", "Show AI Concepts", r { startOrActivate(#1006463) });
    
    onEnterAndNow(tf, r {
      boss = false;
      awt { tf.selectAll(); }
      final S text = getTextTrim(tf);
      q.add(r {
        if (boss) ret;
        long time = sysNow();
        loading {
          final CirclesAndLines cal = renderText(text);
          if (boss) ret;
          awt {
            scp.setComponent(centerAndSouth(
              /*jscroll_centered*/(cal.makeCanvas()),
              setFont(sansSerifBold(20), jcenteredlabel(text))));
          }
        }
        sleepUntilSys(time+1000); // min display time
      });
    });
    hideConsole();
  }
}

static CirclesAndLines renderText(S text) {
  if (possibleGlobalID(text)) {
    AIConcept c = findWhere(aiConcepts, globalID := text);
    if (c != null) {
      print("Have concept (" + c.globalID + " - " + c.name + ")");
      ret renderConcept(c);
    }
  }
  
  new CirclesAndLines cal;
  for (S s : splitAtPlus(text)) cal.circle_autoVis(s, 0.5, 0.5);
  autoPositionCircles(cal);
  ret cal;
}

static CirclesAndLines renderConcept(AIConcept c) {
  new CirclesAndLines cal;
  BufferedImage img = getConceptImage(c);
  Circle cc;
  if (img != null)
    cc = cal.circle(img, 0.5, 0.5, c.name);
  else
    cc = cal.circle_autoVis(c.name, 0.5, 0.5);
  cc.addTrait(c.globalID);
  ret cal;
}

Author comment

Began life as a copy of #1007146

download  show line numbers  debug dex   

Travelled to 2 computer(s): cfunsshuasjs, tvejysmllsmz

No comments. add comment

Snippet ID: #1007383
Snippet name: Encyclopedia 1 [WORKS]
Eternal ID of this version: #1007383/29
Text MD5: 917cf667dd5b13cd0875456d12176459
Transpilation MD5: 00cc2d08e301f2275a02cf2e9f3176b9
Author: stefan
Category: javax / a.i. / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-24 12:14:33
Source code size: 2140 bytes / 71 lines
Pitched / IR pitched: No / No
Views / Downloads: 73 / 205
Version history: 28 change(s)
Referenced in: [show]