### Sample Subs

Sample subs for adding nodes to a Toolbar created via JavaFX API methods.
' Add a button with text to the toolbar.
' Text - Text to display
' Tag - Unique tag used for the toolbar action
' BackgroundColor - Background color
' TextColor - Text color
`Sub ToolBar_Button_Text(EventName As String, Text As String, Tag As Object, BackgroundColor As Paint, TextColor As Paint, ToolTipText As String) As Button
Dim btn As Button
btn.Initialize(EventName)
btn.Tag = Tag
btn.Text = Text
btn.TooltipText = ToolTipText
If BackgroundColor.IsInitialized Then CSSUtils.SetBackgroundColor(btn, BackgroundColor)
If TextColor.IsInitialized Then CSSUtils.SetStyleProperty(btn, "-fx-text-fill", CSSUtils.ColorToHex(TextColor))
btn.Top = 0
btn.PrefHeight = 30
btn.PrefWidth = 100
Return btn
End Sub`
' Add a button with font awesome icon to the toolbar.
' Text - Fontawesome chartacter to display, i.e. example for a clock icon Chr(0xF017)
' Tag - Unique tag used for the toolbar action
' BackgroundColor - Background color
' TextColor - Text color
`Sub ToolBar_Button_FontAwesome(Eventname As String, Text As String, Tag As Object, ToolTipText As String) As Button
Dim btn As Button
btn.Initialize(Eventname)
btn.Tag = Tag
btn.Font = fx.CreateFontAwesome(12)
btn.Text = Text
btn.Top = 0
btn.PrefHeight = 30
btn.PrefWidth = 30
' btn.Alignment = "CENTER"
btn.TooltipText = ToolTipText
CSSUtils.SetBackgroundColor(btn, fx.Colors.Transparent)
Return btn
End Sub`
' Add a combobox to the toolbar.
' Eventname - Unique eventname for the toolbar
' Items - List of items
' Tag - Unique tag used for the toolbar action
' Width - Set width. If -1 then width is set by the toolbar object
' BackgroundColor - Background color
' TextColor - Text color
' ToolTipText - Set the tooltip text
`Sub ToolBar_Combobox(EventName As String, Items As List, Tag As Object, Width As Double, BackgroundColor As Paint, TextColor As Paint, ToolTipText As String) As ComboBox
Dim cb As ComboBox
cb.Initialize(EventName)
cb.Tag = Tag
cb.Items.AddAll(Items)
cb.TooltipText = ToolTipText
If BackgroundColor.IsInitialized Then CSSUtils.SetBackgroundColor(cb, BackgroundColor)
If TextColor.IsInitialized Then CSSUtils.SetStyleProperty(cb, "-fx-text-fill", CSSUtils.ColorToHex(TextColor))
cb.Top = 0
cb.PrefHeight = 30
If Width <> -1 Then cb.PrefWidth = Width
If cb.Items.Size > 0 Then cb.SelectedIndex = 0
Return cb
End Sub`
`Sub Editor_Toolbar_Functions_Create
Dim EventName As String = "Editor_Toolbar_Functions"
' Init the toolbar object
JavaObject_Editor_Toolbar_Functions.InitializeNewInstance("javafx.scene.control.ToolBar", Null)
' Create list of buttons to add to the toolbar
Dim l As List
l.Initialize
'The unique tag is used to determine which action to execute in sub ToolbarButton_Action.
l.Add(ToolBar_Button_FontAwesome(EventName, Chr(0xF0C4), 1, "Cut selected text."))
'Add the toolbar JavaObject to the mainform with a height of 30.0
Pane_HTMLEditor.AddNode(JavaObject_Editor_Toolbar_Functions, 0, 0, TextArea_Editor.Width, 30)
End Sub`
'Handle ToolbarButton Actions by selecting the unique button tag
`Sub Editor_Toolbar_Functions_Action
If Sender Is Button Then
Dim b As Button = Sender
Select b.Tag
' Cut, Copy, Paste
Case 1
Utils.TextArea_Cut(TextArea_Editor)
End Select
End If
TextArea_Editor.RequestFocus
End Sub`

Changed: , Category: ToolBar, File: T6C270M2010.htm, ID: 2010