B4J Library [B4X] BalConverter - Convert the layouts files to JSON (and vice versa)

BalConverter is a B4J app (desktop app) that converts between the designer layout files and JSON format.

This allows you to edit the layout with a text editor. Note that the format is not so simple as the layout files were not designed to be edited this way.

The converter app is simple. You choose a folder and it will convert all layout files from one format to another. The original files are not deleted.
It filters the files based on the extension (bal or bal.json).

SS-2014-06-01_17.03.59.png


The JSON format is made of three main elements:

SS-2014-06-01_17.08.40.png


The Data element is a tree of views. All the views properties are stored here.

The first view is the Activity view. The other views are stored under the :kids node (recursively). Note that the fields order is not important and is not consistent.

SS-2014-06-01_17.11.10.png


The Variants element is a list of the variants. You will probably won't need to edit this section.

The LayoutHeader element holds other information about the layout file. Note that all the views names are stored in this section under ControlsHeaders. This means that if you change the name of a view then you need to change it here and in the Data element.

The b4j project is attached.

It is recommended to backup your layout files before working with this tool.

Updates

v2.30 - Designer script is now decoded and encoded. This means that it can be modified in the json file.
- Layout recreated with the internal designer.
- FontAwesome / Material Icons usage is preserved.
 

Attachments

  • BalConverter.zip
    6.3 KB · Views: 1,669
Last edited:

ilan

Expert
Licensed User
Longtime User
Sounds like a bad idea. You should learn how to use anchors and designer script...

i do know how to use anchors. for me anchors is not the way i want to work with. i like more my approach and the results are much better. i agree that if i do an app for ipad and iphone then i will get bad results but this i solve with variants or 2 different layouts 1 for ipads and 1 for iphones.
 

hwatech

Member
Licensed User
Longtime User
I created a number of JSON files in the Forms Builder and now I would like to convert those to layouts for another project but I'm having trouble using this utility. All my libs are up to date and I'm running B4J 8.90. Initially when I ran the app I got the following error
Waiting for debugger to connect...
Program started.
ConvertJsonToBal: expenses.bal.json
Error occurred on line: 199 (BalConverter)
java.lang.RuntimeException: Object should first be initialized (Map).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:32)
at anywheresoftware.b4a.objects.collections.Map.Get(Map.java:67)
at b4j.example.balconverter._writelayoutheader(balconverter.java:659)
at b4j.example.balconverter._convertjsontobalinmemory(balconverter.java:604)
at b4j.example.balconverter._convertjsontobal(balconverter.java:151)
at b4j.example.main._btnconvert_action(main.java:227)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA$1.run(BA.java:216)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)

It didn't seem as though I should have needed to but after I made a change to initialize the Map, I got a bit further but then this error occurs
Waiting for debugger to connect...
Program started.
ConvertJsonToBal: expenses.bal.json
Error occurred on line: 201 (BalConverter)
java.lang.RuntimeException: Object should first be initialized (Map).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:32)
at anywheresoftware.b4a.objects.collections.Map.Get(Map.java:67)
at b4j.example.balconverter._writelayoutheader(balconverter.java:664)
at b4j.example.balconverter._convertjsontobalinmemory(balconverter.java:609)
at b4j.example.balconverter._convertjsontobal(balconverter.java:156)
at b4j.example.main._btnconvert_action(main.java:227)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA$1.run(BA.java:216)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)

I'm not exactly sure what to do at this point...
 

hwatech

Member
Licensed User
Longtime User
Just realized that the 2 errors I included in my previous post are the same error. I guess the code I put in to initialize the Map didn't do anything except make the error appear 2 lines later
 

hwatech

Member
Licensed User
Longtime User
OK, sorry for the trouble , but the first line of this this thread is

BalConverter is a B4J app (desktop app) that converts between the designer layout files and JSON format.

And the first line of the thread in which you announced this utility

is
Can we modify a batch of layout files in any way?

and since the FormBuilder saves as JSON file and is Loaded in the code...

You might see where a bad assumption could be made


so, where do I find the specification of the binary format of the layout files? I'd like to write a utility that converts some VS Designer files if possible

I may still be interested in this utility because I have 100s of programs that I have written in visual studio, some with fairly large form designs. I would just like to save some time if I convert them to to B4X. I already have the designer files in JSON but this utility doesn't like them either, it might help if I could go directly to the binary format

I'm an old C guy so binary formats don't bother me.

Larry
 

iHunner

New Member
Is the Exe still in the attached files? I downloaded the zip but don't see it. Apologies if this is a dumb question, I'm rather new here
 

xiaoyao

Active Member
Licensed User
Longtime User
Is there any other third-party software that can achieve this, such as a more advanced visual form interface designer developed with VB.NET, C#, or python? You can see the effect immediately after modifying the title or picture.

likie this,it's like :winform ui to python ui controls:

2801aardio窗体设计器转换成PYTHON窗体元素.jpg
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is there any other third-party software that can achieve this, such as a more advanced visual form interface designer developed with VB.NET, C#, or python? You can see the effect immediately after modifying the title or picture.

likie this,it's like :winform ui to python ui controls:
Your post has nothing to do with this thread.
 

xiaoyao

Active Member
Licensed User
Longtime User
For example, I can design the interface using a third-party tool like VB.NET or C# on WINFORM, convert it to the XML or JSON format supported by B4A, and then convert it to the BAL file format. That's my idea. The principle of the picture I posted is to use a third-party IDE like Visual Studio and WINFORM controls to convert to Python code or XML configuration files. The same principle can be applied to convert to the B4A format, of course, but it will take a lot of time to match.
 
Top