B4J Library [Custom View] RichViewfx CodeArea

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.


Update to RichTextview-Print v 1.4 as a b4xlib to work with richtextfx-fat-0.10.5 which is downloadable from :https://github.com/FXMisc/RichTextFX.
I've also uploaded the code in a project file. (RichFX-Print.zip and RichFX-PrintB4xlib)

Information For those wanting to run on java > 8 you will need to add these lines to your project.

B4X:
#VirtualMachineArgs: --add-opens javafx.graphics/javafx.scene.text=ALL-UNNAMED  --add-exports javafx.graphics/com.sun.javafx.text=ALL-UNNAMED
#PackagerProperty: VMArgs = --add-opens javafx.graphics/javafx.scene.text=b4j --add-exports javafx.graphics/com.sun.javafx.text=b4j
249 209
 

Attachments

  • RichTextView.0.2.zip
    8.6 KB · Views: 762
  • RichTextView-print1.3.zip
    15.6 KB · Views: 706
  • RichFX-Print.zip
    12.8 KB · Views: 481
  • RichFX-PrintB4x.b4xlib
    9.3 KB · Views: 534
Last edited:

stevel05

Expert
Licensed User
Longtime 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.
 

stevel05

Expert
Licensed User
Longtime User
Update rfs-print1.1: Improves cut and paste, allows cutting and pasting selections.
 

stevel05

Expert
Licensed User
Longtime 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:

alwaysbusy

Expert
Licensed User
Longtime 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.

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

stevel05

Expert
Licensed User
Longtime User
The visibility is controlled on the base pane of the customview, so you need to do:
B4X:
CodeArea1.BasePane.Visible = True
 

Mashiane

Expert
Licensed User
Longtime 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.

View attachment 40938

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
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.
Thanks a million..., was looking for this...
 

ThRuST

Well-Known Member
Licensed User
Longtime User
How to save and load text from this library and enable line numbering on/off?
 

ThRuST

Well-Known Member
Licensed User
Longtime User
I solved loading and saving myself. Here goes

Save
B4X:
' Save text to file
File.WriteString("c:\", "mytext.txt", CodeArea1.GetText)

Load
B4X:
' 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?
 

stevel05

Expert
Licensed User
Longtime User
It's in the rfxprint demo:

B4X:
CodeArea1.ShowLineNumbers(Checked)
 

stevel05

Expert
Licensed User
Longtime User
It's in the rfxprint demo:

B4X:
CodeArea1.ShowLineNumbers(Checked)
 

ThRuST

Well-Known Member
Licensed User
Longtime 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 [email protected]

Cheers, Roger
 

ThRuST

Well-Known Member
Licensed User
Longtime 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
 

stevel05

Expert
Licensed User
Longtime 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.
 

ThRuST

Well-Known Member
Licensed User
Longtime 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 :)
 

stevel05

Expert
Licensed User
Longtime 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.
 

Attachments

  • SLDialogs.zip
    13.5 KB · Views: 547
  • SnippetManager.zip
    366.8 KB · Views: 612

ThRuST

Well-Known Member
Licensed User
Longtime 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 :)
 

Ferbis

Active Member
Licensed User
Longtime 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.

Thanks Steve for this contribution
 
Top