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

38
LINES

< > BotCompany Repo | #1017780 // Standard Function/Class Name Auto-Complete [operates on focused component]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (17364L/125K).

!7

sclass SFAutoComplete extends DynObjectTable<S> {
  transient WeakReference<JTextComponent> tc;
  int maxEntries = 100;
  
  start {
    dontPersist();
    doEveryAndNow(1000, r {
      if (!isVisible()) ret;
      JTextComponent c = optCast(JTextComponent, getFocusOwner());
      if (c == null) ret;
      tc = weakRef(c);
      int i = getCaretPosition(c);
      S word = tok_lastTokenIfNoSpaceAfter(takeFirst(getText(c), i));
      new LS list;
      if (nempty(word)) {
        list.addAll(containingIC(standardClassNames_sorted(), word));
        list.addAll(containingIC(standardFunctionNames_sorted(), word));
        list = takeFirst(maxEntries, list);
      }
      setData(list);
    });
  }
  
  void onDoubleClick(S s) ctex {
    final JTextComponent c = getWeakRef(tc);
    if (c != null) {
      int i = getCaretPosition(c);
      Document doc = c.getDocument();
      S word = tok_lastTokenIfNoSpaceAfter(takeFirst(getText(c), i));
      if (swic(s, word))
        doc.remove(i -= l(word), l(word));
      doc.insertString(i, s, null);
      awt { focusComponent(c); } // TODO: doesn't work?
    }
  }
}

Author comment

Began life as a copy of #1017235

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1017780
Snippet name: Standard Function/Class Name Auto-Complete [operates on focused component]
Eternal ID of this version: #1017780/17
Text MD5: f6b20e940d9ecd02c2d2469b80752bd4
Transpilation MD5: 35498e7fe885271cdc366dee34a6c618
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-14 18:40:47
Source code size: 1160 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 380 / 23366
Version history: 16 change(s)
Referenced in: [show references]