JavaFX - SVGPath


We recently celebrated Holi - Festival of Colours. It was real fun! Now lets try to celebrate Holi with JavaFX!.

You can create an SVG path in JavaFX using SVGPath class. It accepts content which is a string formatted as specified here.

SVGPath {
    content: "M48.859,43.518c8.424,17.64,2.736,140.832-7.128,184.032"
             "c-9.864,43.272-19.728,98.28-22.032,144.576c-1.008,19.728,"
             "2.016,27.504,14.904,27.504c22.752,0,51.624-47.952,87.84-46.872"
             "c36.288,1.08,47.808,55.008,64.8,54.648c16.992-0.36,30.672-6.264,"
             "30.816-58.752C218.563,191.981,87.235,64.973,48.859,43.518"
             "L48.859,43.518L48.859,43.518L48.859,43.518z"
    fill: Color.BLACK
}

We can combine a series of SVGPath to create the final image. Now we can manipulate attributes of individual SVGPath such as fill, stroke, strokeWidth etc. I'm using the same ColorChooser code as in previous post.

<script src="http://dl.javafx.com/1.1/dtfx.js"></script> <script src="/rakeshmenonp/resource/SVGPath/SVGPath.js"></script>

For Applet mode, click on above image

For standalone mode

To paint Duke select any part of Duke and then select a color from color chooser. Now you can play Holi with Duke! Have fun!

Source

<script type="text/javascript">var dzone_url = "http://blogs.sun.com/rakeshmenonp/entry/javafx_svgpath";</script> <script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script>

Comments:

Very nice. I am not able to deselect it. Is it possible to deselect on next click because that selected line, not allow me to see the duke nicely with other colors.

Posted by Vaibhav on March 14, 2009 at 09:26 AM IST #

Nice demo
Please check my demo i created in JavaFX my first Demo on my website
"www.jfxstudio.741.com"
i will enhance this demo to complete website in JavaFX ur help will be needed

Posted by Farrukh Obaid on March 14, 2009 at 08:40 PM IST #

@Vaibhav Thanks! Added toggle selection

Posted by Rakesh Menon on March 16, 2009 at 10:51 AM IST #

@Farrukh Thatz cool! Great start.. 'll definitely help you.

Posted by Rakesh Menon on March 16, 2009 at 10:57 AM IST #

thanks Rakesh
Questions
1) how to embed True Type Font(ttf) in JavaFX
i think we can embed in FXZ format by using
Font.fontFromURL(path,size) i check this works but i want to use in normal fx file it is not working..

2) first time we see applet it chached in the system i update file and upload again "with the same name" when i browse applet it load previoud version in order to see new one i delete the file from cache is there any method to tackle this...

Posted by Farrukh Obaid on March 16, 2009 at 09:21 PM IST #

@Farrukh (1) I think its not supported, I didn't find any public APIs. Yes, there are some internal APIs, but that is not recommended. I'll confirm this and get back to you. (2) By default the cache system depends on timestamp, so ideally it must load the new jar after few minutes. This is not reliable, also may fail on slow network. The check times out after few seconds. You need to use versioning for reliable mechanism.
http://java.sun.com/javase/technologies/desktop/javawebstart/reference/techart/index.html

Posted by Rakesh Menon on March 17, 2009 at 03:29 AM IST #

@Farrukh Thanks for your question. I have a new post on how to use ttf font - http://blogs.sun.com/rakeshmenonp/entry/javafx_custom_fonts

Posted by Rakesh Menon on March 20, 2009 at 05:16 AM IST #

Post a Comment:
Comments are closed for this entry.
About


The views expressed on this blog are my own and do not necessarily reflect that of my organization

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today