Controlling API - How to save opened model ?

47 views
Skip to first unread message

Anonym us

unread,
Sep 22, 2020, 12:57:05 PM9/22/20
to netlogo-devel
Hello guys and netlogo experts. 

Currently im working with the Controlling API in order to have the opportunity to invoke commands ( e.g setting values for different sliders etc ) by the usage of java. 

I tried the last example with the InterfaceComponent and its working well !
Can be found here https://github.com/NetLogo/NetLogo/wiki/Controlling-API

Now i have the trouble that i want to overwrite the done settings ( changed values ) to my opened model but it seems that there is no kind of method for doing this ?


I made several investigations but there is no solution for me ? 
I would be very glad and thankful for any kind of help or hint !




Seth Tisue

unread,
Sep 23, 2020, 9:41:17 AM9/23/20
to netlogo-devel
`InterfaceComponent` was designed for read-only use. So what you want to do isn't directly supported, and I suspect you'll have to assemble the behavior you want out of pieces that are lying around: read the .nlogo file from disk and break it into sections (ModelReader.parseModel), write out other sections again as-is, but when you get to the widgets section, do something special. InterfaceComponent extends AppletPanel which wraps an InterfacePanel, which has an getWidgetsForSaving method which returns a List<org.nlogo.window.Widget> which you can iterate over and call the save method on each widget for writing to the .nlogo file, as in this code from ModelSaver:

    // widgets
    section {
      for(w <- model.widgets)
        buf ++= (w.save + "\n")
    }

That's a sketch of the most promising solution path I can think of. Perhaps someone on the current development team will have a better idea, not sure.

Seth

Anonym us

unread,
Sep 23, 2020, 2:49:29 PM9/23/20
to netlogo-devel
Thanks for your suggestion Seth, even if it looks quite complicated i will try hehe 

You said the "InterfaceComponent" is rather used for reading. How would it be if i would use the App-Option for the Controlling API ? Is there a specific function to save the opened model ? 

Seth Tisue

unread,
Sep 24, 2020, 10:45:33 AM9/24/20
to netlogo-devel
On Wed, Sep 23, 2020 at 1:49 PM Anonym us <zuro...@web.de> wrote:
> Thanks for your suggestion Seth, even if it looks quite complicated i will try hehe
> You said the "InterfaceComponent" is rather used for reading. How would it be if i would use the App-Option for the Controlling API ?

Yes, that's a good idea, if it's acceptable in your situation.

> Is there a specific function to save the opened model ?

Yes, but I'm afraid I don't recall the details of how you would do
that, maybe look at FileMenu.java for clues?

Seth
Reply all
Reply to author
Forward
0 new messages