B4J Library Graphics Library

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.

Update to V1.04
  • Added classes required to use GLPath and minor bug fixes.
  • Released as a B4xLib.

I will leave the old version as it's a long time since I've looked at it and there may be some small conflicts with the new library. I didn't find any, but just a nagging feeling that it could bite.

Enjoy

L 176 LS 103
 

Attachments

  • GraphicLibTestApp.zip
    1.7 KB · Views: 802
  • jGraphicLib1-03.zip
    56.9 KB · Views: 749
  • jGraphicLibSource1-03.zip
    21.8 KB · Views: 611
  • jGraphicLib-b4xlib.b4xlib
    29.6 KB · Views: 198
Last edited:

stevel05

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

jmon

Well-Known Member
Licensed User
Longtime 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 : https://www.b4x.com/android/forum/threads/classes-tutorial.18626/#content at "Properties". Maybe you know that already?

Thanks again
Jmon.
 

stevel05

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

Well-Known Member
Licensed User
Longtime User
I decided to do it that way as it maintains consistency with the java documentation
Thanks
I imagined that there was a reason behind, and I respect it :)
 

CHAUVET

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

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

Attachments

  • GLArc.zip
    5.2 KB · Views: 441

CHAUVET

Member
Licensed User
Longtime User
Hi,

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

B4X:
#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, 0, 0, 100.0, 100.0, 90.0, 55)
    SetArc(JOarc2, 25, 0, 100.0, 100.0, 270.0, 45)

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
 

stevel05

Expert
Licensed User
Longtime User
Updated to 1.03 : allow setting fill and stroke colours with fx.Colors.RGB and fx.Colors.ARGB
 

gorch

New Member
hello Steve!
can I use this library in B4A?
actually I need the arc-function for a speedometer in a train control device
thanks for your help!
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
hello Steve!
can I use this library in B4A?
actually I need the arc-function for a speedometer in a train control device
thanks for your help!


Hello @gorch It is a bad practice to bump up old threads. Always create new thread for question.

For your Question Check Bitmapcreator https://www.b4x.com/android/forum/threads/b4x-drawing-with-bitmapcreator.98887/
 

stevel05

Expert
Licensed User
Longtime User
Update to V1.04
  • Added classes required to use GLPath and minor bug fixes.
  • Released as a B4xLib. I will leave the old version as it's a long time since I've looked at it and there may be some small conflicts with the new library. I didn't find any, but just a nagging feeling that it could bite.
 
Top