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

65
LINES

< > BotCompany Repo | #1020860 // Editor Tabs v1 using JTabbedPane [pretty decent, but I want a different tab placement]

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

Uses 911K of libraries. Click here for Pure Java version (3993L/20K).

!7

sclass Tab { S name, moduleID; }

compact module Tabs {
  transient NotifyingList<Tab> tabs;
  transient JTabbedPane jtabs;
  S libID = "#1016118/SFEditor";
  
  start {
    tabs = notifyingList(r change + r updateTabs);
    dm_vmBus_onMessage_q('moduleStarted, voidfunc(S moduleID) { addTabForModule(moduleID) });
    dm_vmBus_onMessage_q('deletingModule, voidfunc(O module) { removeTabForModule(dm_moduleID(module)) });
    dm_vmBus_onMessage_q('moduleNameChange, voidfunc(O module, S oldName, S newName) { updateTabForModule(dm_moduleID(module)) });
    dm_q(r { for (S moduleID : dm_listModuleIDs()) addTabForModule(moduleID) });
    dm_vmBus_onMessage_q('newActiveModule, vf<O> selectModule);
  }

  visualize {
    jtabs = jtabs(); updateTabs();
    onTabSelected(jtabs, r {
      Tab tab = get(tabs, selectedTabIndex(jtabs));
      if (tab != null) showModule(tab.moduleID);
    });
    ret withButtonsAbove(jtabs, "+", rThread dm_newEditor);
  }
  
  void updateTabs q {
    if (jtabs == null) ret;
    fillJTabs(jtabs, syncCollect name(tabs));
    for (Component c : tabComponents(jtabs)) jminwidth(100, c/JComponent);
    selectModule(dm_activeModule());
  }

  void addTabForModule(S moduleID) {
    if (eq(dm_moduleLibID(moduleID), libID) && !containsWhere(tabs, +moduleID))
      tabs.add(nu(Tab, name := moduleName(moduleID), +moduleID));
  }
  
  void removeTabForModule(S moduleID) {
    removeWhere(tabs, +moduleID);
  }
  
  void updateTabForModule(S moduleID) {
    Tab tab = firstWhere(tabs, +moduleID);
    if (tab == null) ret;
    tab.name = moduleName(moduleID);
    tabs.change();
  }
  
  S moduleName(O module) {
    ret dropPrefix("Editing: ", dm_moduleName(module));
  }
  
  void selectModule(O module) {
    if (jtabs == null || module == null || dm_isMe(module)) ret;
    selectTab(jtabs, indexOfWhere(tabs, moduleID := dm_moduleID(module)));
  }
  
  void showModule(O module) {
    dm_showModule(module);
    Rect r = dm_bounds(module), me = dm_bounds();
    dm_setBounds(module, me.x, me.y2(), me.w, r.h);
  }
}

Author comment

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: 293 / 519
Version history: 27 change(s)
Referenced in: [show references]