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

63
LINES

< > BotCompany Repo | #1034137 // UIURLSystem - "UI URLs" (free-form case-insensitive URLs to navigate the UI) for Swing [backup]

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

Libraryless. Click here for Pure Java version (9189L/52K).

// Note: renderUIUrl etc are called in Swing thread

srecord noeq UIURLSystem(Enterable owner, SimpleLiveValue<S> uiURL) {
  // key:   ui URL
  // value: component maker
  transient Map<S, IF0<? extends JComponent>> uiMap = syncCIMap();
  
  // these are additionally displayed at the top of the list
  LS preferredURLs = syncList();
  
  settable transient SingleComponentPanel scp;
  JComboBox comboBox;
  
  JComponent urlBar() {
    ret withLabel("Show",
      comboBoxAndButton(
        onSelectedItem(
          bindComboBoxToLiveValue(centerComboBox(
            comboBox = autoComboBox(url(), urlsForComboBox())), uiURL),
          url -> showUIURL(url)
        ),
        "Go", url -> showUIURL(url)));
  }
  
  JComponent renderUIUrl aka renderUIURL aka uiGet(S url) {
    try {
      temp tempEnter(owner);
      var maker = uiMap.get(url);
      var component = callF(maker);
      if (component != null) ret component;
      ret jCenteredLabel("URL not found: " + url);
    } catch print e {
      ret jErrorView(e);
    }
  }
  
  void showUIURL(S url) {
    temp tempEnter(owner);
    setURL(trim(url));
    go();
  }
  
  void go {
    setComponent(scp, renderUIUrl(url()));
  }
  
  S url() { ret uiURL!; }
  void setURL(S url) { uiURL.set(url); }
  
  selfType put(S url, IF0<? extends JComponent> maker) {
    uiMap.put(url, maker);
    this;
  }
  
  LS urlsForComboBox() {
    var sorted = cloneKeys(uiMap);
    ret concatLists(listSetIntersection(preferredURLs, sorted), sorted);
  }
  
  void addPreferredUIURL(S uiURL) {
    preferredURLs.add(uiURL);
  }
}

Author comment

Began life as a copy of #1033790

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

-
Snippet ID: #1034137
Snippet name: UIURLSystem - "UI URLs" (free-form case-insensitive URLs to navigate the UI) for Swing [backup]
Eternal ID of this version: #1034137/3
Text MD5: bc326ccae3473f5652fbc913741808d5
Transpilation MD5: 99c251e22be1257fcb857a9d03f9ac98
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-29 00:08:20
Source code size: 1642 bytes / 63 lines
Pitched / IR pitched: No / No
Views / Downloads: 151 / 232
Version history: 2 change(s)
Referenced in: