Share My Creation FTP-WebServer-Text-Editor with backup history

Discussion in 'B4J Share Your Creations' started by birnesoft, Mar 19, 2015.

  1. birnesoft

    birnesoft Active Member Licensed User

    This is my IDE to progam PHP, HTML and CSS Files on my Server.
    Sure there are better tools, but I love easy IDE with big fonts and nice colors :)


    [​IMG]


    Code:
    Sub Process_Globals
    Dim ftp1 As FTP
    Private fx As JFX
    Private MainForm As Form
    Dim TextAreaLeft,TextAreaRight As TextArea
    Dim iSearchCounterLeft,iSearchCounterRight As Int  
    Dim TSearch As TextField
    Dim TFileLeft As TextField
    Dim TFileRight As TextField
    Dim BloadFileLeft As Button
    Dim BloadFileRight As Button
    Dim BSearchLeft As Button
    Dim BSearchRight As Button
    Dim BUploadFiles As Button
    Dim BSaveFiles As Button
    Dim BEnd As Button
    Dim pToolBar As Pane

    Dim BackupPath="w:\ServerFileBackup\"
    Dim    sFileLeft="w:\index.php" As String
    Dim sFileRight="w:\style.css" As String
    Dim sServer="ftp.myserver.de" As String
    Dim sUser="www-data" As String
    Dim sPassword="*********" As String
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)

       
    If File.Exists("",BackupPath)=False Then File.MakeDir("",BackupPath)
       
    If File.Exists(File.DirApp,"textFileNameLeft.txt"Then sFileLeft=File.ReadString(File.DirApp,"textFileNameLeft.txt")
       
    If File.Exists(File.DirApp,"textFileNameRight.txt"Then sFileRight=File.ReadString(File.DirApp,"textFileNameRight.txt")
       MainForm = Form1
       
    Dim jmf As JavaObject = MainForm
       
    Dim stage As JavaObject = jmf.GetField("stage")
       stage.RunMethod(
    "setFullScreen"Array As Object(True))
       MainForm.Show
       
    Dim sFontName As String
       
    Dim lFonts As List
       TSearch.Initialize(
    "TSearch")
       TFileLeft.Initialize(
    "TFileLeft")
       TFileRight.Initialize(
    "TFileRight")
       TFileLeft.Text=sFileLeft
       TFileRight.Text=sFileRight
       BloadFileLeft.Initialize(
    "BloadFileLeft")
       BloadFileLeft.text=
    "load"
       BloadFileRight.Initialize(
    "BloadFileRight")
       BloadFileRight.text=
    "load"
     
       BSearchLeft.Initialize(
    "BSearchLeft")
       BSearchLeft.Text=
    "suc"
       BSearchRight.Initialize(
    "BSearchRight")
       BSearchRight.Text=
    "hen"
       BUploadFiles.Initialize(
    "BUploadFiles")
       BUploadFiles.Text=
    "upload"
     
       BSaveFiles.Initialize(
    "BSaveFiles")
       BSaveFiles.Text=
    "save"
       BEnd.Initialize(
    "BEnd")
       BEnd.Text=
    "end"
     
       
    'select font Nr 23
       lFonts=fx.GetAllFontFamilies
       sFontName=lFonts.Get(
    23)
     

           TextAreaLeft.Initialize(
    "TextAreaLeft")
        
    If File.Exists("",sFileLeft) Then TextAreaLeft.Text=File.ReadString("",sFileLeft)
        TextAreaLeft.Style=
    "-fx-font-weight:bold;-fx-background-color: linear-gradient(#2211FF, #4433DE);-fx-text-fill: cyan;-fx-font-size:21;-fx-font-family:'"&sFontName&"'"
        MainForm.RootPane.AddNode(TextAreaLeft,
    0,0,MainForm.Width/2.1,MainForm.Height)
      
        TextAreaRight.Initialize(
    "TextAreaRight")
        
    If File.Exists("",sFileRight) Then TextAreaRight.Text=File.ReadString("",sFileRight)
        TextAreaRight.Style=
    "-fx-font-weight:bold;-fx-background-color: linear-gradient(#2211FF, #4433DE);-fx-text-fill: cyan;-fx-font-size:21;-fx-font-family:'"&sFontName&"'"
        MainForm.RootPane.AddNode(TextAreaRight,MainForm.Width/
    1.93,0,MainForm.Width/2.1,MainForm.Height)
      
        pToolBar.Initialize(
    "")
        pToolBar.Style=
    "-fx-background-color: linear-gradient(#2211FF, #ff33DE);"
        MainForm.RootPane.AddNode(pToolBar,MainForm.Width/
    2.1,0,77,MainForm.Height)
        pToolBar.AddNode(TSearch,
    0,0,77,22)
        pToolBar.AddNode(TFileLeft,
    0,210,77,22)
        pToolBar.AddNode(BloadFileLeft,
    0,183,47,22)
        pToolBar.AddNode(BloadFileRight,
    30,273,47,22)
        pToolBar.AddNode(TFileRight,
    0,250,77,22)
        pToolBar.AddNode(BSearchLeft,
    0,30,38,22)
        pToolBar.AddNode(BSearchRight,
    38,30,38,22)
        pToolBar.AddNode(BSaveFiles,
    0,60,77,22)
        pToolBar.AddNode(BUploadFiles,
    0,90,77,22)
        pToolBar.AddNode(BEnd,
    0,MainForm.Height-33,77,22)
      
          
    End Sub
    Sub BloadFileLeft_MouseClicked (EventData As MouseEvent)

    sFileLeft=TFileLeft.Text
    File.writeString(File.DirApp,"textFileNameLeft.txt",sFileLeft)
    TextAreaLeft.Text=
    File.ReadString("",sFileLeft)
    End Sub
    Sub BloadFileRight_MouseClicked (EventData As MouseEvent)

    sFileRight=TFileRight.Text
    File.writeString(File.DirApp,"textFileNameRight.txt",sFileRight)
    TextAreaRight.Text=
    File.ReadString("",sFileRight)

    End Sub
    Sub TSearch_TextChanged (Old As String, New As String)

    iSearchCounterRight=
    0
    iSearchCounterLeft=
    0
      
    End Sub

    Sub BSearchRight_MouseClicked (EventData As MouseEvent)
        
    Dim d2 = TextAreaRight.Text As String
        
    Dim uu As Int
        
    Dim nn=TSearch.Text As String
      
        d2=d2.ToLowerCase
        nn=nn.ToLowerCase
        uu=d2.IndexOf2(nn,iSearchCounterRight)
        iSearchCounterRight=uu
        TextAreaRight.SetSelection(iSearchCounterRight,iSearchCounterRight+nn.Length)
        iSearchCounterRight=iSearchCounterRight+
    1
      
    End Sub
    Sub BSearchLeft_MouseClicked (EventData As MouseEvent)
        
    Dim d1 = TextAreaLeft.Text As String
        
    Dim uu As Int
        
    Dim nn=TSearch.Text As String
      
        d1=d1.ToLowerCase
        nn=nn.ToLowerCase
        uu=d1.IndexOf2(nn,iSearchCounterLeft)
        iSearchCounterLeft=uu
        TextAreaLeft.SetSelection(iSearchCounterLeft,iSearchCounterLeft+nn.Length)
        iSearchCounterLeft=iSearchCounterLeft+
    1
      
    End Sub
    Sub BSaveFiles_MouseClicked (EventData As MouseEvent)

        
    Dim d1 = TextAreaLeft.Text As String
        
    Dim d2 = TextAreaRight.Text As String
        
    File.WriteString("",sFileLeft,d1)
        
    File.WriteString("",sFileRight,d2)

    End Sub
    Sub BEnd_MouseClicked (EventData As MouseEvent)
        
    ExitApplication
    End Sub
    Sub BUploadFiles_MouseClicked (EventData As MouseEvent)
    Dim ff As String
    ftp1.Initialize(
    "ftp1",sServer,21,sUser,sPassword)
        
    Dim d1 = TextAreaLeft.Text As String
        
    Dim d2 = TextAreaRight.Text As String
        
    Dim f1 =sFileLeft.SubString(3As String
        
    Dim f2 =sFileRight.SubString(3)
      
    'make Backup in the BackupPath\DateTime-Path
        Dim titi = DateTime.Now As Long
        ff=
    DateTime.GetYear(titi)&DateTime.GetMonth(titi)&DateTime.GetDayOfMonth(titi)&"_"&DateTime.GetHour(titi)&"-"&DateTime.GetMinute(titi)&"-"&DateTime.GetSecond(titi)
        
    File.MakeDir(BackupPath,ff)
        
    File.WriteString(BackupPath&ff,f1,d1)
        
    File.WriteString(BackupPath&ff,f2,d2)
      
    'Write Local  
      File.WriteString("",sFileLeft,d1)
      
    File.WriteString("",sFileRight,d2)
      ftp1.UploadFile(
    "",sFileLeft, True, f1)
      ftp1.UploadFile(
    "",sFileRight, True, f2)

    End Sub

    Sub FTP1_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
        
    'If Total > 0 Then s = s & " out of " & Round(Total / 1000) & "KB"
        'Log(s)
    End Sub
    Sub FTP1_UploadCompleted (ServerPath As String, Success As Boolean)
        
    Log(ServerPath & ", Success=" & Success)
        
    If Success = False Then Log(LastException.Message)
      
    End Sub
     

    Attached Files:

    Last edited: Mar 21, 2015
    JakeBullet70 likes this.
  2. birnesoft

    birnesoft Active Member Licensed User

    There is not much docu about TextAreas in the Forum.

    my Questions:

    How can I change the TextArea.width while runtime?
    How can I set the focus back on the TextArea.

    How can I get the cursor position and the Line Number
    mayby with the javaobject?
    class TextArea extends TextComponent .getCaretPosition()
     
  3. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi,

    examples. Change TextArea to your TextArea Control name TextAreaLeft or TextAreaRight.

    Q: How can I change the TextArea.width while runtime?
    A: By changing the TextArea properties:
    Code:
    TextArea.PrefHeight = number
    TextArea.PrefWidth = number
    Q: How can I set the focus back on the TextArea.
    A: By using the TextArea method:
    Code:
    TextArea.RequestFocus
    Q: How can I get the cursor position
    A: By making use of an API method from class java.awt.TextComponent:
    Code:
    Dim joTA As JavaObject = TextArea
    Dim cursorpos As Int = joTA.RunMethod("getCaretPosition"Null)
    Note: the class offers many more methods, which can be used like previous. Go here for more.

    Q: How to get the Line Number
    A: Do not have a proper solution found. May be someone else can help here.
     
    birnesoft likes this.
  4. birnesoft

    birnesoft Active Member Licensed User

    Thanks a lot. That helps me very much.:):):):):)
     
  5. birnesoft

    birnesoft Active Member Licensed User

    Everything works fine.

    Now I want to show the Line Number when I change the cursor position.

    But the function getLineOfOffset(int offset) is in the upper class

    (public class JTextArea extends JTextComponent)

    how can I reach this?

    Björn


    Code:
    Sub TextAreaLeft_TextChanged (Old As String, New As String)

        
    Dim joTA As JavaObject = TextAreaLeft
        
    Dim cursorpos As Int = joTA.RunMethod("getCaretPosition"Null)    ':)

    '  Don't works (java.lang.RuntimeException: Method: getLineOfOffset not found in: javafx.scene.control.TextArea)

        
    Dim o(1As Object
        o(
    0)=cursorpos
        
    Dim linepos As Int = joTA.RunMethod("getLineOfOffset",o)   ':(
        lPos.text=linepos

    End Sub
     
  6. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi,

    may be not the best solution, but give a try.

    Code:
    Sub Process_Globals
        
    Public joInline As JavaObject = Me
    Code:
    #If JAVA
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.*;

    /*
    *    Return the line number at the Caret position.
    *    (Replace TextArea below by the TextArea defined)
    *    Usage B4J:
    *    Dim joTA As JavaObject = TextArea
    *    Dim cursorpos As Int = joTA.RunMethod("getCaretPosition", Null)
    *    Dim linepos As Int = joInline.RunMethod("getLineAtCaret", Array(TextArea.Text, cursorpos))
    */
    public static int getLineAtCaret(String content, int caretpos)
         {
             int linenum = -1;
            JTextArea editArea = new JTextArea(content);
            try {
                linenum = editArea.getLineOfOffset(caretpos);
                linenum += 1;
            }
            catch(Exception ex) { }
        return linenum;
        }
    #End If
     
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