B4J Library Input Dialog Class

Discussion in 'B4J Libraries & Classes' started by ilan, Jul 22, 2019.

  1. ilan

    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:

    Code:
    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:

    Code:
    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 FormEvent 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: Jul 22, 2019
  2. inakigarm

    inakigarm Well-Known Member Licensed User

  3. ilan

    ilan Expert Licensed User

    joulongleu likes this.
  4. Johan Hormaza

    Johan Hormaza Active Member Licensed User

  5. Johan Hormaza

    Johan Hormaza Active Member Licensed User

  6. ilan

    ilan Expert Licensed User

  7. Johan Hormaza

    Johan Hormaza Active Member Licensed User

    Ok, I'm sorry.
    But these Dialogs are very good.
     
    ilan likes this.
  8. ilan

    ilan Expert Licensed User

    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
     
  9. Johan Hormaza

    Johan Hormaza Active Member Licensed User

    I know.
    The important thing is that DonManfred has not noticed because if he does not scold you, hahaha.
     
    Harris, XbNnX_507 and Jorge M A like this.
  10. XbNnX_507

    XbNnX_507 Active Member Licensed User

    Hahahaha Lol.
    @DonManfred he would have said THE SEARCH IS WORKING!! Lmao.
     
    Harris likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice