B4J Library Graphics Library

Discussion in 'B4J Libraries & Classes' started by stevel05, Feb 4, 2015.

  1. stevel05

    stevel05 Expert Licensed User

    This Library wraps the 2Dgraphic elements of JavaFX2 which are:

    Shape, Arc, Circle, CubicCurve, Ellipse, Line, Path, Polygon, Polyline, QuadCurve, Rectangle, SVGPath, and Text. As well as LinearGradient and RadialGradient.

    You can add these in code, or use the SetObject Method to work with Nodes added using Scene Builder.

    The attached GraphicLibTestApp produces this:



    upload_2015-2-4_2-0-13.png


    Download and unzip the jGraphicLib file and copy the jar and xml file to your additional libs directory.

    Depends on: JavaObject.

    I created this as I wanted to use rectangle, and got a bit carried away. So I thought I'd share it.

    For that reason I haven't tested everything thoroughly, please let me know if there are any issues.

    For comprehensive documentation, refer to the Javafx documentation.

    Oh, and full source is also attached.

    Enjoy

    L 176 LS 103
     

    Attached Files:

    Last edited: Dec 18, 2016
  2. stevel05

    stevel05 Expert Licensed User

    Updated to V1.01 added ID and Tag fields. Id accesses the underlying Graphic object so you can access an ID added with the designer. Tag is a wrapper specific field and is not accessible from the native object.
     
    Last edited: Feb 5, 2015
  3. jmon

    jmon Well-Known Member Licensed User

    Hi, thanks for this great libraries.

    One comment though. I think you should write "Get..." and "Set..." of each of you methods in lowercase. Your "get" and "set" methods would be regrouped in one single method (property), thus making the list of methods smaller.

    You can have a look here : http://www.b4x.com/android/forum/threads/classes-tutorial.18626/#content at "Properties". Maybe you know that already?

    Thanks again
    Jmon.
     
  4. stevel05

    stevel05 Expert Licensed User

    Hi jmon, thanks for the reply. I decided to do it that way as it maintains consistency with the java documentation. If you want to change it, download the source and do a global replace on Sub Get and Sub Set (for this library at least) I've just tried it and didn't see a problem afterwards (i.e. it still compiles).
     
    jmon likes this.
  5. jmon

    jmon Well-Known Member Licensed User

    Thanks
    I imagined that there was a reason behind, and I respect it :)
     
    stevel05 likes this.
  6. CHAUVET

    CHAUVET Member Licensed User

    Hello,

    How to draw an arc with the jGraphicLib library ?

    With JavaFX scene Builder, I created an Arc shape and when I run the application I get an error.

    Code:
    #Region  Project Attributes
        
    #MainFormWidth: 500
        
    #MainFormHeight: 500
    #End Region

    Sub Process_Globals
        
    Private fx As JFX
        
    Private MainForm As Form
       
        
    Public circle_stats_1 As GLArc
       
       
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
        MainForm.SetFormStyle(
    "UNIFIED")
        MainForm.RootPane.LoadLayout(
    "dashboard.fxml"'Load the layout file.
        MainForm.Show
       
        circle_stats_1.SetLength(
    90.0)
        circle_stats_1.SetFill(fx.Colors.Magenta)

       
    End Sub

    Sub circle_stats_1_MouseClicked (EventData As MouseEvent)
        circle_stats_1.SetLength(circle_stats_1.GetLength+
    10)
    End Sub
    Program started.
    Error occurred on line: 18 (Main)
    java.lang.ClassCastException: com.stevel05.rtest.glarc cannot be cast to anywheresoftware.b4a.ObjectWrapper
    at anywheresoftware.b4j.objects.FXMLBuilder.setNodeField(FXMLBuilder.java:140)
    at anywheresoftware.b4j.objects.FXMLBuilder.LoadLayout(FXMLBuilder.java:124)
    at anywheresoftware.b4j.objects.PaneWrapper.LoadLayout(PaneWrapper.java:71)
    at b4j.example.main._appstart(main.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:593)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at b4j.example.main.start(main.java:36)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
    at com.sun.javafx.application.LauncherImpl$$Lambda$51/317949656.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
    at com.sun.javafx.application.PlatformImpl$$Lambda$45/1775282465.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
    at com.sun.javafx.application.PlatformImpl$$Lambda$47/1764213640.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
    at com.sun.javafx.application.PlatformImpl$$Lambda$46/2040495657.run(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
    at com.sun.glass.ui.win.WinApplication$$Lambda$37/1558600329.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:745)

    Thanks for your help.
     

    Attached Files:

  7. CHAUVET

    CHAUVET Member Licensed User

    Hi,

    This is my solution (without jGraphicLib and only with JavaObject) :

    Code:
    #Region  Project Attributes
        
    #MainFormWidth: 1000
        
    #MainFormHeight: 800
    #End Region

    Sub Process_Globals
        
    Private fx As JFX
        
    Private MainForm As Form
        
    Private JOarc1 As JavaObject
        
    Private JOarc2 As JavaObject

    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
        MainForm.SetFormStyle(
    "UNIFIED"' UTILITY
        MainForm.Title = "Arc by JO"

        MainForm.Resizable = 
    False
        MainForm.RootPane.LoadLayout(
    "Layout1"'Load the layout file.
        MainForm.Show
       
        
    ' JOarc1 and JOarc2 are created in JavaFX Scene Builder
        SetArc(JOarc1, 00100.0100.090.055)
        SetArc(JOarc2, 
    250100.0100.0270.045)

    End Sub

    Public Sub SetArc(ArcName As JavaObject, CenterX As Double, CenterY As Double, RadiusX As Double, RadiusY As Double, StartAngle As Double, Length As Double)
        ArcName.RunMethod(
    "setCenterX",Array As Object(CenterX))
        ArcName.RunMethod(
    "setCenterY",Array As Object(CenterY))
        ArcName.RunMethod(
    "setRadiusX",Array As Object(RadiusX))
        ArcName.RunMethod(
    "setRadiusY",Array As Object(RadiusY))
        ArcName.RunMethod(
    "setStartAngle",Array As Object(StartAngle))
        ArcName.RunMethod(
    "setLength",Array As Object(Length))
    End Sub
     
  8. stevel05

    stevel05 Expert Licensed User

    Updated to 1.03 : allow setting fill and stroke colours with fx.Colors.RGB and fx.Colors.ARGB
     
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