B4J Library Input Dialog Class

ilan

Expert
Licensed User
i was really surprised that i could not find any input dialog for b4j. i searched for maybe 15minutes the forum but could not find a single class or lib for it so i created a very simple one. it is enough for my needs for now but if you like you can edit/extend it.

use:

B4X:
    Dim input As inputdialog
    input.Initialize(MainForm,"scxinput")
'    input.setOkButton("OK") 'if no text is entered it will use default values
'    input.setTitleLabel("Input Dialog") 'if no text is entered it will use default values
'    input.setInfoLabel("Please enter your text.") 'if no text is entered it will use default values
     input.show
class:

B4X:
Sub Class_Globals
    Private fx As JFX
    Private pnl As Pane
    Private sendForm As Form
    Private callEvent As String
    Private okbtn As Button
    Private titleLbl, infoLbl As Label
    Private tf As TextArea
    Private vpW, vpH As Float
    Private pnlW, pnlH As Float
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(Form As Form, Event As String)
    sendForm = Form
    callEvent = Event
    vpW = Form.Width
    vpH = Form.Height
    pnl.Initialize("pnl")
    infoLbl.Initialize("")
    titleLbl.Initialize("")
    okbtn.Initialize("okbtn")
    tf.Initialize("")
    pnl.Alpha = 0
    pnl.Style = "-fx-background-color: #FFFFE4C4"
    pnlW = vpW*0.55
    pnlH = vpH*0.45
    setAllNodes
    resetAll
End Sub

Private Sub setAllNodes
    titleLbl.TextColor = fx.Colors.White
    titleLbl.Style =  "-fx-background-color: #FF4682B4"
    titleLbl.TextSize = 11
    titleLbl.Alignment = "CENTER"

    infoLbl.TextColor = fx.Colors.Black
    infoLbl.TextSize = 13
    infoLbl.Alignment = "CENTER" ' "TOP_LEFT"
   
    okbtn.Alignment = "CENTER"
    okbtn.TextColor = fx.Colors.Black
    okbtn.TextSize = 13
   
    pnl.AddNode(titleLbl,0,0,pnlW,pnlH*0.125)
    pnl.AddNode(infoLbl,pnlW*0.1,pnlH*0.175,pnlW*0.8,pnlH*0.15)
    pnl.AddNode(tf,pnlW*0.1,pnlH*0.35,pnlW*0.8,pnlH*0.325)
    pnl.AddNode(okbtn,pnlW*0.3,pnlH*0.75,pnlW*0.4,pnlH*0.125)
End Sub

Public Sub setTitleLabel(txt As String)
    titleLbl.Text = txt
End Sub

Public Sub setInfoLabel(txt As String)
    infoLbl.Text = txt
End Sub

Public Sub setOkButton(txt As String)
    okbtn.Text = txt
End Sub

Public Sub show
    sendForm.RootPane.AddNode(pnl,(vpW/2) - (vpW*0.225),(vpH/2) - (vpH*0.175),-1,-1)
    pnl.SetSize(pnlW,pnlH)
    BringToFront(pnl)  
    tf.RequestFocus
    pnl.SetAlphaAnimated(300,1)
    'Log("pnl nodes count: " & pnl.NumberOfNodes)
End Sub

Public Sub getTitleLbl As Label
    Return titleLbl
End Sub

Public Sub getInfoLbl As Label
    Return infoLbl
End Sub

Public Sub getokButton As Button
    Return okbtn
End Sub

Private Sub okbtn_Click
    If SubExists(Main,callEvent & "_Input") Then
        CallSubDelayed2(Main,callEvent & "_Input",tf.Text)
        pnl.SetAlphaAnimated(300,0)
        Sleep(400)
        pnl.RemoveAllNodes
        pnl.RemoveNodeFromParent
    End If
End Sub

Private Sub resetAll
    titleLbl.Text = "Input Dialog" 'default value
    infoLbl.Text = "Please enter your text." 'default value
    okbtn.Text = "OK" 'default value
    tf.Text = ""
End Sub

Private Sub pnl_Click
    'do nothing
End Sub

Sub BringToFront(n As Node)
    Dim parent As Pane = n.Parent
    n.RemoveNodeFromParent
    parent.AddNode(n, n.Left, n.Top, n.PrefWidth, n.PrefHeight)
End Sub

inputdialog.png
 
Last edited:

ilan

Expert
Licensed User
Ok, I'm sorry.
But these Dialogs are very good.
yeah i see it iwas joking ;)
just to let you know, i did found that page when i was looking for a dialog class or lib but because of no images in the first post i ignored it. it would be much more clear if you would add some screenshots of your dialogs.

thanx for that lib
 
Top