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)

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 #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: 123 / 132
Referenced in: [show references]