B4J Library [Custom View] RichViewfx CodeArea

Discussion in 'B4J Libraries & Classes' started by stevel05, Jan 26, 2016.

  1. stevel05

    stevel05 Expert Licensed User

    This is a custom view and very light wrapper for the RichTextFX Codearea from Thomas Mikula on github. There is enough in here to display code, useful for a snippets manager or similar.

    RichViewfx.jpg

    It is based on the example provided here: https://github.com/TomasMikula/RichTextFX#automatic-highlighting-of-java-keywords and modified with some, but I'm certain not all, B4x keywords and types.

    It should provide a start to using the rest of the available views in that library.

    You need to download the fat jar from the website listed under Manual Download from here:
    https://github.com/TomasMikula/RichTextFX#download

    and add it you your additional libraries folder.

    In case they release a new version, make sure it's the same filename as in the additionalJar declaration at the top of the Main Module in the app. Otherwise, change the declaration.

    The customview is usable from the designer and from code, and provides an editable CodeArea. It is simple to make it read only in the designer or in code (see the demo)

    Requires B4j 4.20 Beta or later.

    Have fun

    Update: Added rfx-print, allows saving loading and printing of files and displaying Tabs as spaces.

    rfxPrint requires:

    jfx8Print ,

    (Others Part of B4j distribution)
    jSQL
    jRandomAccessFile


    Uses Standard Utilities (Included in the project file):
    CSSUtils
    KeyValueStore

    Update rfx-print1.1: Improves cut and paste, allows cutting and pasting selections.
    Update rfx-print1.2:
    Add / Remove line numbers
    Improved regex matching
    Reposition cursor after cut / paste
    Printer font size is a better match to the screen display​
    Update RichTextView0.2 and RichTextView-print1.3 updated to work with the latest fat-jar libraries (0,8.2 +) Also tested with 0.9.0

    Note: if the combo box displays downwards - off the screen, then you need to download the latest Java jdk. This was a bug which has now been fixed.

    249 209
     

    Attached Files:

    Last edited: Jul 12, 2018
    ilan, Johan Hormaza, Ferbis and 12 others like this.
  2. DonManfred

    DonManfred Expert Licensed User

    WOW. Cool! Thank you for sharing :)
     
    stevel05 likes this.
  3. stevel05

    stevel05 Expert Licensed User

    Added a second demo app which allows loading and saving of files, printing and changing font size. See first post for dependencies.

    There is also a little more formatting using regex, and because the RichText suite doesn't allow changes to tab sizes, I've added the ability to display Tabs as a definable number of spaces.

    The printing was quite tricky to implement and required a second CodeArea that is not attached to the Stage, it was difficult to get it to size correctly ready for the first page to render, So you will always get a blank page through the printer first. The text is parsed into measured pages and then rendered and printed one at a time, there are a series of callbacks to allow time for the Gui thread to render each page. In addition, a timer is used as it takes time for the color highlighting to be rendered on each page before it can be printed.

    I've always wondered why it sometimes takes a while for programs to print what seems like a simple page of text, now I know :).

    If you try it, let me know how you get on with it.
     
    BPak and jmon like this.
  4. stevel05

    stevel05 Expert Licensed User

    Update rfs-print1.1: Improves cut and paste, allows cutting and pasting selections.
     
    BPak and somed3v3loper like this.
  5. stevel05

    stevel05 Expert Licensed User

    Update rfs-print1.2:
    Add / Remove line numbers
    Improved regex matching
    Reposition text after cut / paste
    Printer font size is a better match to the screen display
     
    Last edited: Jan 30, 2016
    BPak likes this.
  6. alwaysbusy

    alwaysbusy Expert Licensed User

    Great control! I'm trying to add visibility to it, but although I don't get an error, the control does not show.

    Note: I've set the visibility in the designer at startup to false.

    Code:
    Sub MenuBar1_Action
       
    Dim mi As MenuItem = Sender
       
    Select Case mi.Tag
         
    Case "View"
           LoadDefaultView(mi.Text)      
         
    Case "Theme"  
        
       
    End Select  
       
    Dim jObj As JavaObject = CodeArea1.GetObjectJO
       jObj.RunMethod(
    "setVisible"Array As Object(True))  
    End Sub
     
  7. stevel05

    stevel05 Expert Licensed User

    The visibility is controlled on the base pane of the customview, so you need to do:
    Code:
    CodeArea1.BasePane.Visible = True
     
    Erel, DonManfred and alwaysbusy like this.
  8. alwaysbusy

    alwaysbusy Expert Licensed User

    Excellent! Thank you :)
     
  9. Mashiane

    Mashiane Expert Licensed User

    Thanks a million..., was looking for this...
     
  10. ThRuST

    ThRuST Well-Known Member Licensed User

    How to save and load text from this library and enable line numbering on/off?
     
  11. ThRuST

    ThRuST Well-Known Member Licensed User

    I solved loading and saving myself. Here goes

    Save
    Code:
    ' Save text to file
    File.WriteString("c:\""mytext.txt", CodeArea1.GetText)
    Load
    Code:
    ' Load text from file
    Dim s As String = File.ReadString("c:\""mytext.txt")
    CodeArea1.ReplaceText(
    0,CodeArea1.Length, s)
    How to toggle line numbering on/off?
     
  12. stevel05

    stevel05 Expert Licensed User

    It's in the rfxprint demo:

    Code:
    CodeArea1.ShowLineNumbers(Checked)
     
  13. stevel05

    stevel05 Expert Licensed User

    It's in the rfxprint demo:

    Code:
    CodeArea1.ShowLineNumbers(Checked)
     
  14. ThRuST

    ThRuST Well-Known Member Licensed User

    Hey!! :) I'm very impressed by your work and you can read all about my postings Here
    I did spend the whole day to find a solution and thanks to all great people here in this forum I was directed here. Amazing.
    I want to use your solution in my project and so I would like to add you to Facebook or mail. Please contact me at rogerlindfors@hotmail.com

    Cheers, Roger
     
  15. ThRuST

    ThRuST Well-Known Member Licensed User

    Hey Steve, I need a stripped version of your excellent custom view because I want to implemented in my project so I'd like to only use the coloring of text function supported by CSS and bake it into a codearea made in Scene builder 2. Do you mind to arrange a compatible solution I can use. I don't need the printer functions just the autocolor of text for an codesnippets editor I'm working on. Cheers Roger
     
  16. stevel05

    stevel05 Expert Licensed User

    Hi Roger,

    I don't have time to do much coding at the moment I'm afraid, working on other projects. All the code is there and you can do with it what you like. You'll need to create the Regex matcher and css file for the css keywords. This evening I'll post a snippet manager I've been using that does Java highlighting if it will help I need to sort out a library to attach.
     
  17. ThRuST

    ThRuST Well-Known Member Licensed User

    To wrap this up in a library seems like a great idea. I appreciate your excellent work on this and look forward to any updates you may post here.
    I found your method to be the perfect solution I've been looking for however rfx-print 1.2 seemed a bit complex to dig into without some minor guidance.
    Since I am using Scene builder 2 with splitpanes I just have to find a way to implement it as a custom control into one of the views. Your code is awesome Steve :)
     
  18. stevel05

    stevel05 Expert Licensed User

    Here is the snippet manager I have been using, you will need the SLDialogs library to run it. I'm afraid I don't currently have the time to do anything to it, but I hope the code helps you in some way.
     

    Attached Files:

  19. ThRuST

    ThRuST Well-Known Member Licensed User

    Awesome Steve, it's faschinating to see that we're working towards the same goal which share some common methods to achieve this.
    I've been using a prototype application for two years that I wrote in C sharp but I now rewrite it for B4J to make it multiplatform so I
    am quite familiar with the concepts strengh and weakness. However if you chose to work in privacy with your tool I totally respect that.
    But if you want to share ideas, code snippets and assist me in my project, you're welcome to drop me a mail to see where it leads to.
    The community will benefit from our work either way and they can later decide which tool to use, either one or both, since they're both useful.
    I am going to release a beta version of my project sometime early next year that is the plan. It will be advertised on my webpage at duologic.se

    Best regards,
    Roger :)
     
  20. Ferbis

    Ferbis Member Licensed User

    Thanks Steve for this contribution
     
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