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

89
LINES

< > BotCompany Repo | #1035449 // JG22NetworkElement - Swing representation of a G22NetworkElement

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

Uses 2164K of libraries. Click here for Pure Java version (54222L/283K).

srecord noeq JG22NetworkElement(G22Utils g22utils, JG22Network parent, G22NetworkElement element) is Swingable {
  //JExtendedTabbedPane tabs;
  JTabbedPane tabs;
  JLeftArrowScriptIDE ide;
  SingleComponentPanel scpContent = scp();

  cachedVisualize {
    ide = g22utils.leftArrowIDE();
    ide.makeParser = -> {
      var parser = ide.makeParser_base();
      element.configureParser(parser);
      ret parser;
    };
    ide.withResultPanel(false);
    ide.lvScript(element.varCode());
    ide.runScript = -> {
      var result = ide.freshCompileResult();
      if (result.runnable()) {
        var parsedScript = result!;
        var visualizeFunction = parsedScript.getFunction("visualize");
        
        O elementInstance = null;
        var ni = parent.networkInstance;
        if (ni != null)
          elementInstance = ni.elementsByBlueprint.get(element);
        reMutable elementInstance;
          
        Component visualized = null;
        if (visualizeFunction != null) {
          // TODO: timeout?
          RunResultWithTimestamps<O> value = runResultWithTimestamps(-> wrap(
            visualizeFunction.call(
              new FlexibleVarContext, elementInstance)));
          ide.showScriptResult(value);
          if (value.isOK())
            visualized = wrap(value!);
          else
            visualized = jErrorView(value.error());
        } else
          visualized = new G22JavaObjectVisualizer(g22utils, elementInstance).visualize();

        print(+visualized);
        scpContent.set(visualized);
        selectTabComponent(tabs, scpContent);
      }
    };
    
    tabs = jtabs/*jExtendedTabs*/(
      //"Hello", jCenteredSection("Hello", jpanel()),
      "Code", northAndCenter(
        withSideMargin(withLabel("Node identifier:", jVarTextField(element.varIdentifier()))),
        ide.visualize()),
      //"Hello", jCenteredSection("Hello", jpanel()),
      "Content", jCenteredSection("Content" := scpContent));
    
    var popDownButton = withRightMargin(jfullcenter(
      jPopDownButton_noText(
        "Delete node" := rThread deleteElement
      )));
      
    //var box = tabs.visualize();
    var box = centerAndEastWithMargin(tabs, popDownButton);
    //tabs.setComponentBesideTabs(popDownButton);
    
    jMinSize(80, 50, box);
    setBorder(box, BorderFactory.createLineBorder(Color.green, 5);
    
    onMouseDown(tabs/*.tabs*/, event -> {
      if (!mouseEventIsInBorder(event))
        new ComponentDragger(box, event).bringToFront(true).start();
    });
    
    new ComponentResizeDragger(box, box);
    var bounds = or(element.bounds, rect(50, 50, 400, 300));
    setBounds(box, bounds);
    
    onBoundsChange(box, r {
      element.bounds(toRect(getBounds(box)));
      element.network.change();
      parent.mainPanel.revalidateMe();
    });
    
    ret box;
  }
  
  void deleteElement {
    parent.deleteElement(this);
  }
}

Author comment

Began life as a copy of #1035443

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1035449
Snippet name: JG22NetworkElement - Swing representation of a G22NetworkElement
Eternal ID of this version: #1035449/46
Text MD5: a64cbe0b44fcc02014904c2c775a1574
Transpilation MD5: 8122feb5097de2f8d23ba0a0ea8d04d0
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-14 03:38:54
Source code size: 2986 bytes / 89 lines
Pitched / IR pitched: No / No
Views / Downloads: 63 / 155
Version history: 45 change(s)
Referenced in: [show references]