B4J Library [JRLViews] ToolbarHelper Class for 'Buttons' JSON and Events

Hi there

The JRLViews library is available on this post.

Why I did this Toolbar Helper Class?

The toolbar for the JRLView ButtonToolbar requires a JSON string for the buttons to add to the toolbar in design view, so this helper class helps you create that JSON string for the Buttons property and also the Events manager subroutine. Seeing that I'm exploring using the Toolbar in most of my B4J apps, this will help on the repetitive nature of what I will do and decided to share this. Enjoy. :)

Example:

B4X:
clsTB.Initialize
    clsTB.AddButton48("exit","Close this app","exit.png").AddSeparator
    clsTB.AddButton48("edit","Edit","edit.png").AddSeparator
    clsTB.AddButton48("at","At","0xF1FA").AddSeparator
    clsTB.AddButtonTextOnly("about","About")
    Log(clsTB.Build)
    Log(clsTB.Events("tbl1"))

Ouput JSON output

B4X:
[
{"id":"exit","width":48,"height":48,"tooltiptext":"Close this app","icon":"exit.png"},
{"text":"-"},
{"id":"edit","width":48,"height":48,"tooltiptext":"Edit","icon":"edit.png"},
{"text":"-"},
{"id":"at","width":48,"height":48,"tooltiptext":"At","icon":"0xF1FA"},
{"text":"-"},
{"id":"about","text":"About"}
]

Example Events Sub (then insert your code)

B4X:
Sub tbl1_Action
Select tbl1.ButtonPressed.Id
Case "exit"
Case "edit"
Case "at"
Case "about"
End Select
End Sub

ToolBarHelper.gif
 

Attachments

  • ToolBarHelper.gif
    ToolBarHelper.gif
    55.5 KB · Views: 392
  • ToolbarHelper.zip
    4.1 KB · Views: 402

Mashiane

Expert
Licensed User
Longtime User
The other example:

B4X:
clsTB.Initialize
clsTB.AddButton("dateinsert","32","32","Date Insert","dateinsert16.png")
clsTB.AddButton32("email","EMail","email16.png")
clsTB.AddButton32("android","Android","0xF17B")
Log(clsTB.Build)
log(clsTb.Events("tbl2")

The Output (Copy to Buttons property)

B4X:
[
{"id":"dateinsert","width":32,"height":32,"tooltiptext":"Date Insert","icon":"dateinsert16.png"},
{"id":"email","width":32,"height":32,"tooltiptext":"EMail","icon":"email16.png"},
{"id":"android","width":32,"height":32,"tooltiptext":"Android","icon":"0xF17B"}
]

The Events (copy to your CodeModule)

B4X:
Sub tbl2_Action
Select tbl2.ButtonPressed.Id
Case "dateinsert"
Case "email"
Case "android"
End Select
End Sub

As noted above...

1. You define the class
2. You add the respective buttons for the toolbar with the respective methods
3. You execute the Build method (this generates the JSON string)
4. You execute the Events method passing it the name of your toolbar to generate the Events sub skeleton code.

Ta!
 
Top