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

89
LINES

< > BotCompany Repo | #1035456 // JG22NetworkElement - Swing representation of a G22NetworkElement (backup with tabs)

JavaX fragment (include)

1  
srecord noeq JG22NetworkElement(G22Utils g22utils, JG22Network parent, G22NetworkElement element) is Swingable {
2  
  //JExtendedTabbedPane tabs;
3  
  JTabbedPane tabs;
4  
  JLeftArrowScriptIDE ide;
5  
  SingleComponentPanel scpContent = scp();
6  
7  
  cachedVisualize {
8  
    ide = g22utils.leftArrowIDE();
9  
    ide.makeParser = -> {
10  
      var parser = ide.makeParser_base();
11  
      element.configureParser(parser);
12  
      ret parser;
13  
    };
14  
    ide.withResultPanel(false);
15  
    ide.lvScript(element.varCode());
16  
    ide.runScript = -> {
17  
      var result = ide.freshCompileResult();
18  
      if (result.runnable()) {
19  
        var parsedScript = result!;
20  
        var visualizeFunction = parsedScript.getFunction("visualize");
21  
        
22  
        O elementInstance = null;
23  
        var ni = parent.networkInstance;
24  
        if (ni != null)
25  
          elementInstance = ni.elementsByBlueprint.get(element);
26  
        reMutable elementInstance;
27  
          
28  
        Component visualized = null;
29  
        if (visualizeFunction != null) {
30  
          // TODO: timeout?
31  
          RunResultWithTimestamps<O> value = runResultWithTimestamps(-> wrap(
32  
            visualizeFunction.call(
33  
              new FlexibleVarContext, elementInstance)));
34  
          ide.showScriptResult(value);
35  
          if (value.isOK())
36  
            visualized = wrap(value!);
37  
          else
38  
            visualized = jErrorView(value.error());
39  
        } else
40  
          visualized = new G22JavaObjectVisualizer(g22utils, elementInstance).visualize();
41  
42  
        print(+visualized);
43  
        scpContent.set(visualized);
44  
        selectTabComponent(tabs, scpContent);
45  
      }
46  
    };
47  
    
48  
    tabs = jtabs/*jExtendedTabs*/(
49  
      //"Hello", jCenteredSection("Hello", jpanel()),
50  
      "Code", northAndCenter(
51  
        withSideMargin(withLabel("Node identifier:", jVarTextField(element.varIdentifier()))),
52  
        ide.visualize()),
53  
      //"Hello", jCenteredSection("Hello", jpanel()),
54  
      "Content", jCenteredSection("Content" := scpContent));
55  
    
56  
    var popDownButton = withRightMargin(jfullcenter(
57  
      jPopDownButton_noText(
58  
        "Delete node" := rThread deleteElement
59  
      )));
60  
      
61  
    //var box = tabs.visualize();
62  
    var box = centerAndEastWithMargin(tabs, popDownButton);
63  
    //tabs.setComponentBesideTabs(popDownButton);
64  
    
65  
    jMinSize(80, 50, box);
66  
    setBorder(box, BorderFactory.createLineBorder(Color.green, 5);
67  
    
68  
    onMouseDown(tabs/*.tabs*/, event -> {
69  
      if (!mouseEventIsInBorder(event))
70  
        new ComponentDragger(box, event).bringToFront(true).start();
71  
    });
72  
    
73  
    new ComponentResizeDragger(box, box);
74  
    var bounds = or(element.bounds, rect(50, 50, 400, 300));
75  
    setBounds(box, bounds);
76  
    
77  
    onBoundsChange(box, r {
78  
      element.bounds(toRect(getBounds(box)));
79  
      element.network.change();
80  
      parent.mainPanel.revalidateMe();
81  
    });
82  
    
83  
    ret box;
84  
  }
85  
  
86  
  void deleteElement {
87  
    parent.deleteElement(this);
88  
  }
89  
}

Author comment

Began life as a copy of #1035449

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035456
Snippet name: JG22NetworkElement - Swing representation of a G22NetworkElement (backup with tabs)
Eternal ID of this version: #1035456/1
Text MD5: a64cbe0b44fcc02014904c2c775a1574
Author: stefan
Category: javax / gazelle 22
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-17 19:32:47
Source code size: 2986 bytes / 89 lines
Pitched / IR pitched: No / No
Views / Downloads: 125 / 134
Referenced in: [show references]