Uses 911K of libraries. Click here for Pure Java version (3993L/20K).
1 | !7 |
2 | |
3 | sclass Tab { S name, moduleID; } |
4 | |
5 | compact module Tabs { |
6 | transient NotifyingList<Tab> tabs; |
7 | transient JTabbedPane jtabs; |
8 | S libID = "#1016118/SFEditor"; |
9 | |
10 | start { |
11 | tabs = notifyingList(r change + r updateTabs); |
12 | dm_vmBus_onMessage_q('moduleStarted, voidfunc(S moduleID) { addTabForModule(moduleID) }); |
13 | dm_vmBus_onMessage_q('deletingModule, voidfunc(O module) { removeTabForModule(dm_moduleID(module)) }); |
14 | dm_vmBus_onMessage_q('moduleNameChange, voidfunc(O module, S oldName, S newName) { updateTabForModule(dm_moduleID(module)) }); |
15 | dm_q(r { for (S moduleID : dm_listModuleIDs()) addTabForModule(moduleID) }); |
16 | dm_vmBus_onMessage_q('newActiveModule, vf<O> selectModule); |
17 | } |
18 | |
19 | visualize { |
20 | jtabs = jtabs(); updateTabs(); |
21 | onTabSelected(jtabs, r { |
22 | Tab tab = get(tabs, selectedTabIndex(jtabs)); |
23 | if (tab != null) showModule(tab.moduleID); |
24 | }); |
25 | ret withButtonsAbove(jtabs, "+", rThread dm_newEditor); |
26 | } |
27 | |
28 | void updateTabs q { |
29 | if (jtabs == null) ret; |
30 | fillJTabs(jtabs, syncCollect name(tabs)); |
31 | for (Component c : tabComponents(jtabs)) jminwidth(100, c/JComponent); |
32 | selectModule(dm_activeModule()); |
33 | } |
34 | |
35 | void addTabForModule(S moduleID) { |
36 | if (eq(dm_moduleLibID(moduleID), libID) && !containsWhere(tabs, +moduleID)) |
37 | tabs.add(nu(Tab, name := moduleName(moduleID), +moduleID)); |
38 | } |
39 | |
40 | void removeTabForModule(S moduleID) { |
41 | removeWhere(tabs, +moduleID); |
42 | } |
43 | |
44 | void updateTabForModule(S moduleID) { |
45 | Tab tab = firstWhere(tabs, +moduleID); |
46 | if (tab == null) ret; |
47 | tab.name = moduleName(moduleID); |
48 | tabs.change(); |
49 | } |
50 | |
51 | S moduleName(O module) { |
52 | ret dropPrefix("Editing: ", dm_moduleName(module)); |
53 | } |
54 | |
55 | void selectModule(O module) { |
56 | if (jtabs == null || module == null || dm_isMe(module)) ret; |
57 | selectTab(jtabs, indexOfWhere(tabs, moduleID := dm_moduleID(module))); |
58 | } |
59 | |
60 | void showModule(O module) { |
61 | dm_showModule(module); |
62 | Rect r = dm_bounds(module), me = dm_bounds(); |
63 | dm_setBounds(module, me.x, me.y2(), me.w, r.h); |
64 | } |
65 | } |
Began life as a copy of #1020847
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1020860 |
Snippet name: | Editor Tabs v1 using JTabbedPane [pretty decent, but I want a different tab placement] |
Eternal ID of this version: | #1020860/28 |
Text MD5: | 0aa6fef4dd93abe1790bcadaf7fb2752 |
Transpilation MD5: | f3d63a9ed848d852d03209be9649b4a1 |
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-01-06 16:01:21 |
Source code size: | 2114 bytes / 65 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 356 / 597 |
Version history: | 27 change(s) |
Referenced in: | [show references] |