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

56
LINES

< > BotCompany Repo | #1014713 // showForm_makeComponents

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (9546L/55K).

static LL<JComponent> showForm_makeComponents(Bool internalFrame, O... _parts) {
  IVF1<Component> closeFrame
    = isTrue(internalFrame)
      ? l1 disposeInternalFrame
    : isFalse(internalFrame)
      ? l1 disposeFrame
    : null;

  ret showForm_makeComponents(closeFrame, _parts);
}

static LL<JComponent> showForm_makeComponents(IVF1<Component> closeFrame, O... _parts) {

  new LL<JComponent> l;
  L parts = asList(_parts);
  JButton submitButton = null;
  
  for i over parts:
    if (parts.get(i) instanceof Swingable)
      parts.set(i, ((Swingable) parts.get(i)).visualize());
      
  for i over parts: {
    O o = parts.get(i), next = get(parts, i+1);
    if (o instanceof S && next instanceof Component)
      setComponentID((Component) next, (S) o);
    
    if (o instanceof Component || o instanceof S || next instanceof Component) { // smartAdd accepts strings
      l.add(mapLL wrapForSmartAdd_jComponent(
          o == null ? new JPanel
        : o instanceof S ? humanizeFormLabel((S) o)
        : o, next));
      if (next instanceof JButton && submitButton == null)
        submitButton = (JButton) next;
      i++;
    } else if (isRunnable(o))
      l.add(mapLL wrapForSmartAdd_jComponent(null, submitButton = jbutton(showFormSubmitButtonName(), r {
        O result = call(o);
        print("Result of form runnable: " + result + ". Button:  " + heldInstance(JButton));
        if (neq(Bool.FALSE, result))
          closeFrame?.get(heldInstance(JButton));
      })));
    else print("showForm: Unknown element type: " + getClassName(o));
  }
  if (submitButton != null) {
    final JButton _submitButton = submitButton;
    onEnterInAllTextFields(concatLists(l), r { clickButton(_submitButton) });
  }
  
  // massage labels
  for (L<JComponent> row : l) {
    JComponent left = first(row);
    if (left instanceof JLabel) makeBold((JLabel) left).setVerticalAlignment(JLabel.TOP);
  }
  
  ret l;
}

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: #1014713
Snippet name: showForm_makeComponents
Eternal ID of this version: #1014713/25
Text MD5: 843a7b78185773fd0d95301a30c17a72
Transpilation MD5: 3cf435311f5fbefad36a9decc399379a
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-29 16:01:31
Source code size: 1982 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 510 / 623
Version history: 24 change(s)
Referenced in: [show references]