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

40
LINES

< > BotCompany Repo | #1015278 // JNavigation

JavaX fragment (include)

1  
sclass JNavigation extends JPanel {
2  
  JList list;
3  
  SingleComponentPanel scp;
4  
  Map<S, F0<JComponent>> contentMakers = synchroMap();
5  
  S lastItem = "";
6  
  bool autoOpenFirstPage = true;
7  
8  
  *() {
9  
    list = jlist();
10  
    scp = singleComponentPanel();
11  
    makeFakeSingleComponentPanel(this, jhsplit(list, scp));
12  
    onSelectionChangedAndNow(list, voidfunc(S item) {
13  
      if (eq(item, lastItem)) ret;
14  
      lastItem = item;
15  
      JComponent content = pcallF(contentMakers.get(item));
16  
      if (content == null) content = jcenteredimage(#1101244);
17  
      scp.setComponent(content);
18  
    });
19  
  }
20  
  
21  
  void addPage(fS name, JComponent content) {
22  
    addPage(name, f0_const(content));
23  
  }
24  
  
25  
  void addPageOnTop(fS name, final F0<JComponent> makeContent) {
26  
    swing {
27  
      contentMakers.put(name, makeContent);
28  
      insertListItem(list, 0, name);
29  
      if (jlistSize(list) == 1) setSelectedIndex(list, 0);
30  
    }
31  
  }
32  
  
33  
  void addPage(fS name, final F0<JComponent> makeContent) {
34  
    swing {
35  
      contentMakers.put(name, makeContent);
36  
      addListItem(list, name);
37  
      if (jlistSize(list) == 1) setSelectedIndex(list, 0);
38  
    }
39  
  }
40  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1015278
Snippet name: JNavigation
Eternal ID of this version: #1015278/10
Text MD5: 03292551023581b77f31cdd885f0f154
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-13 12:11:21
Source code size: 1168 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 319 / 909
Version history: 9 change(s)
Referenced in: [show references]