B4J Library TextArea with lined background - Custom View

Discussion in 'B4J Libraries & Classes' started by stevel05, Oct 30, 2018.

  1. stevel05

    stevel05 Expert Licensed User

    I've been wanting to do this for a while for a specific purpose, but it has eluded me, until now. So I thought I'd share it in case it's useful.

    upload_2018-10-30_13-57-58.png


    No other added functionality, the standard TextArea callbacks are replicated. Automatically sizes the background to the pane size and lines to the font size.

    Set the line colour in the designer.

    I hope you find it useful.
     

    Attached Files:

  2. stevel05

    stevel05 Expert Licensed User

    Update: added Prompt and Editable Fields to the designer.
     
  3. panagiotisden2

    panagiotisden2 Active Member Licensed User

    Thank you for this, that's awesome

    I have a little issue this it, It crashes with very big text size (a lot of lines) due to a bug in javafx when trying to snapshot the canvas (see https://bugs.openjdk.java.net/browse/JDK-8088198)

    A workaround is posted in the last post on stackoverflow here but i cant see how to implement this in B4J since i cant get a partial snapshot.

    Any suggestions?


    Thank you.
     
  4. stevel05

    stevel05 Expert Licensed User

    This is a port of the code, I haven't tried it on a large image as I don't know how large it needs to be to fail. Let me know if it works.

    Code:
    Public Sub ExportPng(NJO As JavaObject, FileDir As String, FileName As String, Size As Int)
      
        Sleep(
    0)
      
        
    Dim B As JavaObject = NJO.RunMethod("getLayoutBounds",Null)
        
    Dim W As Int = B.RunMethod("getWidth",Null)
        
    Dim H As Int = B.RunMethod("getHeight",Null)
      
        
    Dim Full As JavaObject
        Full.InitializeNewInstance(
    "javafx.scene.image.WritableImage",Array(W,H))
      
        
    Dim TileWidth As Int = W / Size
        
    Dim TileHeight As Int = H / Size
        
    Dim TileWidthD As Double = TileWidth
        
    Dim TileHeightD As Double = TileHeight
      
        
    For Col = 0 To Size - 1
            
    For Row = 0 To Size - 1
                
    Dim X As Int = Row * TileWidth
                
    Dim Y As Int = Col * TileHeight
                
    Dim XD As Double = X
                
    Dim YD As Double = Y
              
                
    Dim R2D As JavaObject
                R2D.InitializeNewInstance(
    "javafx.geometry.Rectangle2D",Array(XD,YD,TileWidthD,TileHeightD))
              
                
    Dim P As JavaObject
                P.InitializeNewInstance(
    "javafx.scene.SnapshotParameters",Null)
              
                P.RunMethod(
    "setViewport",Array(R2D))
              
                Sleep(
    0)
                Full.RunMethodJO(
    "getPixelWriter",Null).RunMethod("setPixels",Array(X,Y,TileHeight,TileWidth,NJO.RunMethodJO("snapshot",Array(P,Null)).RunMethod("getPixelReader",Null),0,0))
            
    Next
        
    Next
      
        
    Dim Img As Image = Full
        
    Dim OS As OutputStream = File.OpenOutput(FileDir,FileName,False)
        Img.WriteToStream(OS)
        OS.Close
      
    End Sub
     
  5. stevel05

    stevel05 Expert Licensed User

    To Call it
    Code:
    ExportPng(LinedOutput1.GetBase,"D:\","test.png",2)
     
  6. panagiotisden2

    panagiotisden2 Active Member Licensed User

    Thanks for your time.
    Unfortunately is crashes at this line
    Code:
    Full.RunMethodJO("getPixelWriter",Null).RunMethod("setPixels",Array(X,Y,TileHeight,TileWidth,NJO.RunMethodJO("snapshot",Array(P,Null)).RunMethod("getPixelReader",Null),0,0))
    (in the first loop of col and row) and the reason being the same bug in javafx.

    A possible solution is to make a canvas with only the visible x and y of the textArea. and draw it at the scrolled x position, but i dont know if it will cause a porformance issue.
    i will try to code id and post results.

    to give you an idea of what im trying to achieve:
    Untitled.png
    its a HEX compare tool where you can also mark known areas.

    Thanks again.
     
  7. stevel05

    stevel05 Expert Licensed User

    Try increasing the size parameter, it defines the number of rows / columns to split the image into. If it's a problem combining the parts back into a full image, then it's a different matter.

    How big is the view?
     
  8. stevel05

    stevel05 Expert Licensed User

    Just looked at your post, so the aim is not to save the full image?

    If you want to highlight some text, you could use a second canvas and draw an appropriate shape in the correct position with a semi opaque colour to highlight it, taking into account scrolling.
     
  9. panagiotisden2

    panagiotisden2 Active Member Licensed User

    I tried it and it seems no difference whether it's size is 2 or all the way up 80.

    The view's size is 535*70555 but it crashes at about 534*8000 or above.

    No the aim is not to save the image, its to draw it as a background in the textarea as seen in the image in my previous post which is working great for small sizes but not for big ones.

    That's a very good suggestion, i will start working on 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