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).

1  
// Note: renderUIUrl etc are called in Swing thread
2  
3  
srecord noeq UIURLSystem(Enterable owner, SimpleLiveValue<S> uiURL) {
4  
  // key:   ui URL
5  
  // value: component maker
6  
  transient Map<S, IF0<? extends JComponent>> uiMap = syncCIMap();
7  
  
8  
  // these are additionally displayed at the top of the list
9  
  LS preferredURLs = syncList();
10  
  
11  
  settable transient SingleComponentPanel scp;
12  
  JComboBox comboBox;
13  
  
14  
  JComponent urlBar() {
15  
    ret withLabel("Show",
16  
      comboBoxAndButton(
17  
        onSelectedItem(
18  
          bindComboBoxToLiveValue(centerComboBox(
19  
            comboBox = autoComboBox(url(), urlsForComboBox())), uiURL),
20  
          url -> showUIURL(url)
21  
        ),
22  
        "Go", url -> showUIURL(url)));
23  
  }
24  
  
25  
  JComponent renderUIUrl aka renderUIURL aka uiGet(S url) {
26  
    try {
27  
      temp tempEnter(owner);
28  
      var maker = uiMap.get(url);
29  
      var component = callF(maker);
30  
      if (component != null) ret component;
31  
      ret jCenteredLabel("URL not found: " + url);
32  
    } catch print e {
33  
      ret jErrorView(e);
34  
    }
35  
  }
36  
  
37  
  void showUIURL(S url) {
38  
    temp tempEnter(owner);
39  
    setURL(trim(url));
40  
    go();
41  
  }
42  
  
43  
  void go {
44  
    setComponent(scp, renderUIUrl(url()));
45  
  }
46  
  
47  
  S url() { ret uiURL!; }
48  
  void setURL(S url) { uiURL.set(url); }
49  
  
50  
  selfType put(S url, IF0<? extends JComponent> maker) {
51  
    uiMap.put(url, maker);
52  
    this;
53  
  }
54  
  
55  
  LS urlsForComboBox() {
56  
    var sorted = cloneKeys(uiMap);
57  
    ret concatLists(listSetIntersection(preferredURLs, sorted), sorted);
58  
  }
59  
  
60  
  void addPreferredUIURL(S uiURL) {
61  
    preferredURLs.add(uiURL);
62  
  }
63  
}

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: 58 / 97
Version history: 2 change(s)
Referenced in: [show references]