<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JavaFX News, Demos and Insight // FX Experience &#187; Uncategorized</title>
	<atom:link href="http://fxexperience.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://fxexperience.com</link>
	<description>Sharing the Experience of JavaFX</description>
	<lastBuildDate>Mon, 21 May 2012 03:34:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Fun JavaFX 2.0 Audio Player</title>
		<link>http://fxexperience.com/2012/01/fun-javafx-2-0-audio-player/</link>
		<comments>http://fxexperience.com/2012/01/fun-javafx-2-0-audio-player/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 08:10:11 +0000</pubDate>
		<dc:creator>Jasper Potts</dc:creator>
				<category><![CDATA[Controls]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[UI Design]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fxexperience.com/?p=1586</guid>
		<description><![CDATA[I was inspired by Dean Iverson&#8217;s tweet with a audio equalizer in JavaFX: #JavaFX rocks. Literally. An example from our upcoming Pro JavaFX 2 book: pic.twitter.com/tSI4Vry4 and the equalizer view from that Pro JavaFX 2 example app: pic.twitter.com/T6jxvrf9 . updated pic.twitter.com/FqzgVimG So wanted to have a go at doing one my self, so little while later [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://fxexperience.com/wp-content/uploads/2012/01/FXExperiencePlayer-BG.png"><img class="aligncenter size-medium wp-image-1587" title="FXExperiencePlayer" src="http://fxexperience.com/wp-content/uploads/2012/01/FXExperiencePlayer-BG-300x190.png" alt="" width="300" height="190" /></a></p>
<p>I was inspired by <a href="http://twitter.com/deanriverson">Dean Iverson&#8217;s</a> tweet with a audio equalizer in JavaFX:</p>
<blockquote><p>#JavaFX rocks. Literally. An example from our upcoming Pro JavaFX 2 book: <a href="http://pic.twitter.com/tSI4Vry4">pic.twitter.com/tSI4Vry4</a><br />
and the equalizer view from that Pro JavaFX 2 example app: <a href="http://pic.twitter.com/T6jxvrf9">pic.twitter.com/T6jxvrf9</a><br />
. updated <a href="http://pic.twitter.com/FqzgVimG">pic.twitter.com/FqzgVimG</a></p></blockquote>
<p>So wanted to have a go at doing one my self, so little while later I have a design and built a working application. Demo video after the break.</p>
<p><span id="more-1586"></span></p>
<p><iframe src="http://www.youtube.com/embed/QhFXd3Ost3w?rel=0&amp;hd=1" frameborder="0" width="960" height="720"></iframe></p>
<h3>The Design</h3>
<p>I started the design with a free Photoshop file from Diego Monzon:</p>
<p><a href="http://dribbble.com/shots/146460-UI-Rack-Pro-7-Freebie"><img class="alignnone" title="Starting Free PSD" src="http://dribbble.com/system/users/11040/screenshots/146460/ui7.jpg?1309482012" alt="" width="400" height="300" /></a></p>
<p>You will see that some of it like the cool VU meters made it direct though to my design but then I played around with the other parts. I have added a link to the Photoshop file I created so you can see what I have done if you are intrested. From the photoshop file I produced a few PNG files which are used in the application, you can see them in the src images directory. I found a free LCD dot matrix font from dafont which is what I am using for the text on the screen. You can see in the code how this is loaded in JavaFX.</p>
<p><a title="Photoshop design" href="http://fxexperience.com/applications/FXExperiencePlayer-BG.psd.zip">Download the Photoshop File</a> 18Mb</p>
<h4>The Code</h4>
<p>The application did not take that long to build, guess about a day in total and about 800 lines of code. I think it is fully working other than the balance is a little fiddly with the mouse. All the control customizations should have full keyboard navigation <img src='http://fxexperience.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . It is mostly standard UI Controls just styled with Images and CSS. The round knobs like balance and volume I had to do something special for and created a knob skin for the Slider control. There was a bunch of the standard logic to load and parse M3U and XML playlists, a very simple data model object PlayList which just contains a url which it was loaded from and a observable list of Pairs, each Pair being a name for the song and a url to the song. We did not have all the low level media API I needed for the VU meters but as they are only really for show I made of some data from what we can get from AudioSpectrumListener.</p>
<p><a title="Source and NB Project" href="http://fxexperience.com/applications/FxExperiencePlayer.zip">Download the source and Netbeans Project</a> 1.5Mb</p>
<p>Hope you enjoy playing with this fun little app as much as I did creating it. Hope it goes to show that you can create pretty much any UI that you can imagine in JavaFX 2.0 and even use standard controls so you maintain keyboard navigation, accessibility etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://fxexperience.com/2012/01/fun-javafx-2-0-audio-player/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>2012 JavaFX Resolutions</title>
		<link>http://fxexperience.com/2012/01/2012-javafx-resolutions/</link>
		<comments>http://fxexperience.com/2012/01/2012-javafx-resolutions/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 20:05:18 +0000</pubDate>
		<dc:creator>Richard Bair</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fxexperience.com/?p=1580</guid>
		<description><![CDATA[Ok, hokey title. Jonathan wrote up a really great retrospective on 2011 for JavaFX, and it inspired me to want to write a post detailing the plans and goals I have for JavaFX in the new year (and I&#8217;m sure Jonathan and Jasper would concur). Without further ado, my top 10 list of goals for [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, hokey title. Jonathan wrote up a <a href="http://fxexperience.com/2011/12/an-fx-experience-retrospective/" title="An FX Experience Retrospective">really great retrospective on 2011</a> for JavaFX, and it inspired me to want to write a post detailing the plans and goals I have for JavaFX in the new year (and I&#8217;m sure Jonathan and Jasper would concur).</p>
<p>Without further ado, my top 10 list of goals for 2012!</p>
<p><a href="http://fxexperience.com/wp-content/uploads/2012/01/2012.png"><img src="http://fxexperience.com/wp-content/uploads/2012/01/2012.png" alt="" title="Happy New Year 2012" width="619" height="443" class="aligncenter size-full wp-image-1581" /></a></p>
<p><span id="more-1580"></span></p>
<h2>Number 10: Bug Fixes</h2>
<p>Ah, bug fixes! This is an area that we could really use your help with! We&#8217;re getting the bug reports, which is good, but I&#8217;d love to see some folks step up and contribute patches as well. We&#8217;ve devoted the majority of 2.0.2 and 2.1 and 2.2 for bug fixing (although there is plenty of feature work going on there as well, most of it is supposed to be about fixing bugs). The situation we want to avoid is one where we have an ever increasing bug count. I want to see the actual total number of bugs go down, before we start adding significant amounts of new features. This is a difficult thing to do &#8212; as adoption increases, so does the pressure to add features that real developers need to complete real projects. But without discipline, we&#8217;ll spend all our time on new features! Focusing on bug fixes now will reduce our technical debt. Getting out of debt is a classic new year&#8217;s goal, right?!</p>
<h2>Number 9: More (Regular) Blog Posts</h2>
<p>Like losing weight (which is also one of this year&#8217;s resolutions, ahem) this is a perennial favorite. There&#8217;s always so much interesting stuff to talk about, and it seems, so little time to do it in. It is easier now that we&#8217;re open source &#8212; we can talk about things as they come up instead of having to &#8220;buffer them up&#8221; until the next release. So three cheers for open source!</p>
<h2>Number 8: Infrastructure Improvements</h2>
<p>I have a long list of things I&#8217;d like to see improved in the <a href="http://openjdk.java.net/projects/openjfx/" title="OpenJFX">OpenJFX</a> project to make it easier for people to participate and contribute. These would not just be improvements &#8220;for open source folks&#8221; but really for all of us (since we are going to be using the exact same tools as we move to developing completely in OpenJFX). For example, I want to get the full set of Atlassian tools in place, so that we have code reviews via Cruicible, bugs via JIRA, Green Hopper for agile planning, Confluence for WIKI, and so forth. I also want to get FindBugs completely integrated with the build system, externalize the hudson server for building OpenJFX binaries and doing the test runs, releasing the SQE functional tests and testing framework, and more.</p>
<h2>Number 7: Performance</h2>
<p>Performance is always one of those things I&#8217;m interested in seeing improvements on. JavaFX is in decent shape, but there is a lot of room for improvement. From the lowest levels of graphics performance to the highest levels of UI controls and the scene graph, there is plenty of work to be done. Most of the really obvious stuff has already been done, but there is a lot more we could do. We have a really great performance team that keeps tabs on everything, getting the tools we use released so that everybody working on OpenJFX can use them would be awesome.</p>
<h2>Number 6: Documentation</h2>
<p>I have a personal goal to provide reams of documentation on the OpenJFX WIKI, as soon as we have one! We do have some <a href="http://docs.oracle.com/javafx/">great documentation</a> produced by our professional writers, and we have fairly good API coverage. But there are two areas that I think need improvement. First, the OpenJFX project needs a large and robust set of developer documentation detailing the architecture and design decisions, naming conventions, and so on used in the project. There is a lot of institutional knowledge and experience trapped in our heads that needs to be put down so that anybody coming to OpenJFX knows the back story and rationale and can understand the code and, most importantly, contribute to the project in a way that is consistent with the design center for JavaFX.</p>
<p>Secondly, we need to improve the quality of much of our API documentation (javadoc). Some areas are very well covered, but others are not. I&#8217;d like to see very rich example sections for every class indicating not only what the class is, but how it is intended to be used. I also like these sorts of examples in the documentation because if you have to cheat and cut corners to make the documentation examples clear (using pseudo code) then that is often a very good indicator that you don&#8217;t have an API that is really all that easy to use. So writing all that sample code is pretty instructive both for the reader and for the author.</p>
<p>Also, I want to see much more in depth documentation on the package level. The <code>controls</code> package should have documentation describing how to use controls in an MVC application, for example, using FXML and so forth and how to bind the controls to various data models.</p>
<h2>Number 5: Embedded</h2>
<p>As announced at JavaOne 2011, the new embedded platforms coming from Oracle (CDC) will be using JavaFX as the UI technology. That is slated for final release in 2013 along with Java 8 and JavaFX 3. However, there is a lot of work that has to be done this year to make this a reality, including adding touch event support to the platform. Having working embedded prototypes for this year is high on the list of goals for JavaFX!</p>
<h2>Number 4: Linux</h2>
<p>You&#8217;ve been heard. Linux was always on the roadmap, but delivering the final GA product this year, and beta binaries <em>very soon</em> is my goal. Oracle has already committed to releasing the Linux version this year, so that&#8217;s good to go. The holdup on getting the 2.1 weekly builds of Linux released is just some quality sanity checks by the team (they&#8217;d rather have something halfway usable than DOA when the first weekly builds go out). I suspect they&#8217;re farther along than they&#8217;re letting on, they&#8217;re a bright group of engineers <img src='http://fxexperience.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h2>Number 3: Mac</h2>
<p>I&#8217;ve been on a Mac for going on 5 years now, I think. JavaFX and Java on Mac is making great progress. With Linux (GTK) and Mac support, added to the existing Windows support, we&#8217;ll finally be able to truly claim cross platform desktop development. With the upcoming embedded support, we&#8217;ll be able to also claim cross platform on embedded devices.</p>
<h2>Number 2: Scene Builder</h2>
<p>The absolute #1 pain point I have when writing JavaFX applications right now is laying out my windows. It isn&#8217;t so much the API &#8212; I hate doing manual layout in code, regardless of the API. I have always been of the opinion that you use the right tool for the job &#8212; you use Photoshop or Illustrator for designing graphics, you use Maya for 3D animations, you use code for writing logic, and you use a layout tool such as Scene Builder to visually construct your application.</p>
<p>Initially we&#8217;re focusing Scene Builder on the task of layout. After we&#8217;ve absolutely nailed that, we&#8217;ll move on to data binding and other such functionality. At the same time, we&#8217;re working to add more application framework API to JavaFX, and will build Scene Builder around these APIs, so that you can use a visual tool with no compromises &#8212; solid MVC app support using visual construction and code for business logic.</p>
<p>There will be a public beta, and there will be a GA for Scene Builder this year. And it will be free.</p>
<h2>Number 1: Open Source</h2>
<p>Finally, my #1 goal for this year is to fully and completely open source JavaFX. Much like the JDK, we will likely have some proprietary bits that are used the final JavaFX binaries that we ship (such as Ductus for shape rasterization instead of Open Pisces), but I want to eliminate even that. </p>
<p>We have at times used language like &#8220;the open source community&#8221; and &#8220;outside contributors&#8221; &#8212; as if there is a difference between &#8220;us&#8221; and &#8220;them&#8221;. I&#8217;ve used such language myself! My goal for 2012 is to completely erase this boundary. There will no longer be an &#8220;us&#8221; and &#8220;them&#8221;, but just &#8220;us&#8221;. Those of us working on OpenJFX, whether from Oracle or from anywhere else, will operate as a single team with shared access to information and bugs and code. There will at times need to be some distinction (security bugs for example must, of necessity, be treated differently) but in all material aspects OpenJFX should be a completely open development project.</p>
<p>I hope that was useful and you have a prosperous 2012, and enjoy using JavaFX! And more importantly, that you come and help on OpenJFX!</p>
]]></content:encoded>
			<wfw:commentRss>http://fxexperience.com/2012/01/2012-javafx-resolutions/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>OpenJDK Discussion About JavaFX</title>
		<link>http://fxexperience.com/2011/10/openjdk-discussion-about-javafx/</link>
		<comments>http://fxexperience.com/2011/10/openjdk-discussion-about-javafx/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 23:25:24 +0000</pubDate>
		<dc:creator>Richard Bair</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fxexperience.com/?p=1475</guid>
		<description><![CDATA[I just sent the following letter to the OpenJDK community &#8220;discuss&#8221; mailing list: Hi OpenJDK community! As announced at JavaOne we (Oracle) would love to contribute JavaFX into OpenJDK as a new project called &#8220;JFX&#8221;. For some who have been following along, we&#8217;ve talked about this for a long time but finally (finally!) we&#8217;re ready [...]]]></description>
			<content:encoded><![CDATA[<p>I just sent the following letter to the OpenJDK community &#8220;discuss&#8221; mailing list:</p>
<blockquote><p>
Hi OpenJDK community!</p>
<p>As announced at JavaOne we (Oracle) would love to contribute JavaFX into OpenJDK as a new project called &#8220;JFX&#8221;. For some who have been following along, we&#8217;ve talked about this for a long time but finally (finally!) we&#8217;re ready to act on it and open source the platform. We are not just interested in open sourcing the code, however, we also want to move into an open development model. We already have an open bug database[1]. The project uses Mercurial, so we should fit in pretty well into OpenJDK.</p>
<p>Our basic motivation for wanting to open source JFX is to built a community and ecosystem support and adoption around JavaFX by increasing transparency. Of course we are also interested in getting patches and early feedback from the community[2]! Our goal is to provide the next-generation Java client toolkit, and JFX would be the next step along that path, which hopefully culminates in a JSR for the Java 9 timeframe and including JFX as proper part of the JDK. I would be the initial Project lead for JFX.</p>
<p>A little bit about our project:<br />
It is a significant contribution to the corpus of open source code<br />
It includes over 6000+ public API members (methods / constructors / etc)<br />
It includes over 11,500 unit tests<br />
Core libraries such as observable collections and binding<br />
Scene graph, effects, graphics<br />
CSS support for JavaFX<br />
Media<br />
WebView<br />
Prism (hardware accelerated graphics, including openGL and D3D and java2D implementations)<br />
Glass (windowing system, base porting layer, including mac, linux, and windows implementations)<br />
UI Controls and Charts</p>
<p>Our builds are all Ant, with JUnit for testing (there is some &#8216;make&#8217; in there for native parts). We also have NetBeans projects setup for each area. There is a lot of code that we&#8217;ll be releasing, so as a matter of practicality we&#8217;re going to release different parts of JavaFX over the course of the next few months, starting with UI controls followed by charts. We&#8217;ll put up a full roadmap onto our project pages, should we be approved to become part of OpenJDK. We&#8217;ll make sure that the open source code is always fully buildable by anybody using the sources + a binary plug (which will become unnecessary as we open source the remaining pieces). All of the above listed modules will be open sourced and fully buildable.</p>
<p>What do you think? I&#8217;d love to hear any issues and hopefully be able to resolve those prior to requesting an official vote.</p>
<p>Thanks<br />
Richard</p>
<p>[1] http://javafx-jira.kenai.com<br />
[2] A good example of the sort of interesting stuff going on out there can be found here: http://jroller.com/neugens/entry/embed_swing_inside_javafx_2
</p></blockquote>
<p>This is the first step towards open sourcing JavaFX into OpenJDK. First I wanted to talk with the community about it, and if it looks favorable, I&#8217;ll follow up with an official project proposal. Here&#8217;s hoping! If you are a subscriber to &#8220;discuss&#8221;, please go and throw in some good word for the  idea and if you have any questions I&#8217;d like to hear those too. If you aren&#8217;t a member of &#8220;discuss&#8221;, go join <img src='http://fxexperience.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . You can do so <a href="http://mail.openjdk.java.net/mailman/listinfo/discuss">here</a>.</p>
<p>It feels good to finally be getting this all out in the open source!</p>
]]></content:encoded>
			<wfw:commentRss>http://fxexperience.com/2011/10/openjdk-discussion-about-javafx/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>FXML + Guice</title>
		<link>http://fxexperience.com/2011/10/fxml-guice/</link>
		<comments>http://fxexperience.com/2011/10/fxml-guice/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 05:55:02 +0000</pubDate>
		<dc:creator>Richard Bair</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fxexperience.com/?p=1435</guid>
		<description><![CDATA[There has been a very interesting thread in the JavaFX OTN forums about FXML and dependency injection. I went and downloaded Google Guice and wrote a small sample to try it all out. Things are not perfect quite yet (I still need full Unified Expression Language support added to FXML), but so very, very, very [...]]]></description>
			<content:encoded><![CDATA[<p>There has been a very interesting thread in the JavaFX OTN forums about <a href="https://forums.oracle.com/forums/thread.jspa?threadID=2299217&#038;tstart=0">FXML and dependency injection</a>. I went and downloaded <a href="http://code.google.com/p/google-guice/">Google Guice</a> and wrote a small sample to try it all out. Things are not perfect quite yet (I still need <a href='http://javafx-jira.kenai.com/browse/<a href="http://javafx-jira.kenai.com/browse/RT-14880">RT-14880</a>'>full Unified Expression Language</a> support added to FXML), but so very, very, very close!</p>
<p><a href="http://fxexperience.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-21-at-10.38.27-PM.png"><img src="http://fxexperience.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-21-at-10.38.27-PM.png" alt="" title="FXML Guiced" width="319" height="262" class="alignright size-full wp-image-1437" /></a></p>
<p>What I ultimately hope to accomplish with FXML and CSS in JavaFX enterprise applications is that we (a) fully separate the visuals from the &#8220;controller&#8221;, (b) are left with a very simple &#8220;controller&#8221; that is highly testable, and (c) everything is highly modular.</p>
<p>CSS allows the designer to come in after the fact and modify the look of a UI without the developer&#8217;s help, and without a full build cycle. FXML allows a developer or designer to alter the structure of the view without a full build cycle. So (a) should be well in hand, especially if the controller itself can be injected rather than declared directly in the FXML file as it is today. (I&#8217;m OK with, even prefer, saying &#8220;I would like to have a FooController for this FXML file, if you please&#8221;, but what would really rock is if the FooController were an interface or abstract class rather than always being a concrete class, such that a DI framework like Guice could find the appropriate implementation and supply it).<br />
<span id="more-1435"></span><br />
For (b) to work, I want to get to the point where I don&#8217;t use the @FXML annotation at all. Right now we have to use it for binding things up, but when <a href='http://javafx-jira.kenai.com/browse/<a href="http://javafx-jira.kenai.com/browse/RT-14880">RT-14880</a>'><a href="http://javafx-jira.kenai.com/browse/RT-14880">RT-14880</a></a> is fixed and we have some implicit reference to the controller, then I&#8217;ll be able to have very powerful bindings defined in the FXML document back to state located on the Controller, and I won&#8217;t need to handle it manually in java code anymore. This is going to be a big win.</p>
<p>A good dependency injection system like Guice makes (c) dead easy. I like Guice because it is all still very type safe and there is only a minimal amount of magic &#8212; in fact I found it very easy to understand. I have a very contrived example here which shows the bare-bones basics, and some simplified use case. Because <a href="http://javafx-jira.kenai.com/browse/RT-14880">RT-14880</a> hasn&#8217;t been implemented, I can&#8217;t use the really slick binding the way I&#8217;d like to, so instead I am using some scripting inside the FXML document to produce the text for the button. This sample revolves around a very simple POJO called Person:</p>
<p><i>Person.java</i></p>
<pre class="brush: java; title: ; notranslate">
package fxmlapp;

public class Person {
    private String firstName = &quot;Richard&quot;;
    public final String getFirstName() { return firstName; }
}</pre>
<p><i>SampleController.java</i></p>
<pre class="brush: java; title: ; notranslate">
package fxmlapp;

import javax.inject.Inject;

public class SampleController {
    /**
     * This domain data model is supplied in the constructor
     */
    private final Person person;

    /**
     * Notice this constructor is using JSR 330 Inject annotation,
     * which makes it &quot;Guice Friendly&quot;.
     * @param person
     */
    @Inject public SampleController(Person person) {
        this.person = person;
    }

    /**
     * Used within the FXML document. This is just some state which the
     * controller wants to expose for the view to bind to or use.
     * @return
     */
    public final String getPersonName() {
        return person.getFirstName();
    }

    /**
     * Some method which I will call from the FXML file.
     */
    public void print() {
        System.out.println(&quot;Well done, &quot; + getPersonName() + &quot;!&quot;);
    }
}</pre>
<p>First is the controller. SampleController is exceedingly simple. It has some model data which is supplied in the constructor, in this case, a Person object. The person is just a good old fashioned POJO in this case, but could be a more complicated object, or perhaps created by JAX-RS or it could be a JDBC ResultSet &#8212; anything you like. There is a method &#8220;getPersonName&#8221; which I added for the sake of the FXML file. Also there is a method called &#8220;print&#8221; which will print a message. You could use any method here you want. For example you might have a &#8220;submit&#8221; method which posts back to a server or a &#8220;refresh&#8221; method which fetches data.</p>
<p>Next up, the FXML file.</p>
<p><i>Sample.fxml</i></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

&lt;?language javascript?&gt;
&lt;?import javafx.scene.control.*?&gt;
&lt;?import javafx.scene.layout.*?&gt;

&lt;StackPane fx:id=&quot;root&quot; xmlns:fx=&quot;http://javafx.com/fxml&quot;&gt;
    &lt;children&gt;
        &lt;Button fx:id=&quot;printBtn&quot; onAction=&quot;controller.print()&quot; /&gt;
        &lt;fx:script&gt;printBtn.text = 'Click Me ' + controller.getPersonName() + '!';&lt;/fx:script&gt;
    &lt;/children&gt;
&lt;/StackPane&gt;</pre>
<p>I create a StackPane who&#8217;s id is going to be &#8220;root&#8221;, and give it a single Button as a child. The button has also been given an id, which is important because that is the name by which I can refer to this button in the embedded JavaScript code. The button has an onAction handler which will invoke the print() method on the controller. Notice that this onAction handler is just some JavaScript.</p>
<p>Speaking of which, you will notice there is a processing instruction here which tells FXML that the scripting in this document will be JavaScript. Because I don&#8217;t yet have the ability to do complex binding expressions (and in this case I want to do a string concatenation for the Button text), I use an embedded script to get the person name from the controller and concatenate it with some text. And that&#8217;s it, very, very simple.</p>
<p>Now I have a Controller (SampleController) and an FXML file (Sample.fxml), but where is the code which associates the one with the other? This code lives in my SampleApp.</p>
<p><i>SampleApp.java</i></p>
<pre class="brush: java; title: ; notranslate">
package fxmlapp;

import com.google.inject.Guice;
import com.google.inject.Injector;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 * A Guice based sample FXML Application
 */
public class SampleApp extends Application {
    /**
     * Create the Guice Injector, which is going to be used to supply
     * the Person model.
     */
    private final Injector injector = Guice.createInjector(new Module());

    @Override public void start(Stage stage) throws Exception {
        // Create a new Guice-based FXML Loader
        GuiceFXMLLoader loader = new GuiceFXMLLoader(injector);
        // Ask to load the Sample.fxml file, injecting an instance of a SampleController
        Parent root = (Parent) loader.load(&quot;Sample.fxml&quot;, SampleController.class);

        // Finish constructing the scene
        final Scene scene = new Scene(root, 320, 240);
        // Load up the CSS stylesheet
        scene.getStylesheets().add(getClass().getResource(&quot;fxmlapp.css&quot;).toString());
        // Show the window
        stage.setScene(scene);
        stage.setTitle(&quot;Guiced&quot;);
        stage.show();
    }

    // Standard launcher
    public static void main(String[] args) {
        launch(args);
    }
}</pre>
<p>The first thing I do when the SampleApp is created is I create an instance of a Guice Injector. I need to feed it a &#8220;Module&#8221;, which looks like this:</p>
<p><i>Module.java</i></p>
<pre class="brush: java; title: ; notranslate">
package fxmlapp;

import com.google.inject.AbstractModule;

/**
 *
 * @author Richard
 */
public class Module extends AbstractModule {
    @Override
    protected void configure() {
        bind(Person.class);
    }
}</pre>
<p>The Module, essentially, just tells Guice &#8220;hey, if somebody comes looking for a Person class, give it to them&#8221;. You can read more about it on the Guice website. But once I&#8217;ve created my Injector, it is time to use it.</p>
<p>In the &#8220;start&#8221; method of the SampleApp, I create a new GuiceFXMLLoader. This is another utility class of my creation which makes it easier to use Guice with FXML loading. I&#8217;ll show that class in a minute. With my newly created GuiceFXMLLoader, I&#8217;m going to call its &#8220;load&#8221; method, passing in the FXML file to load along with the type of Controller I&#8217;d like to create. The GuiceFXMLLoader then parses the FXML document. Guice then does its magic. It attempts to construct an instance of SampleController, but discovers that the @Inject annotated constructor requires a Person object. It then looks up in the Module, discovers a rule regarding Person objects, and goes off to create a Person object. Once it has the new Person, it creates a new SampleController, which then gets associated with the FXML document, and the root object is returned. I place this in a Scene and show it in the Stage.</p>
<p>Now in the screenshot above, you no doubt noticed things had also been styled via CSS. I didn&#8217;t have to do <strong>anything</strong> in the FXML document, or in the Controller, to style this application. I simply wrote a style sheet and loaded it in the SampleApp. Since my FXML document already had id&#8217;s and style classes in place, I didn&#8217;t have to do anything special.</p>
<p><i>fxmlapp.css</i></p>
<pre class="brush: css; title: ; notranslate">
.root {
    -fx-background-color: linear-gradient(from 0% 0% to 0% 100%, #cbd0d7 0%, white 100%);
}

#printBtn {
    -fx-text-fill: #e4f3fc;
    -fx-font: 20pt &quot;Tahoma Bold&quot;;
    -fx-padding: 10;
    -fx-base: #2d4b8e
}

#printBtn:hover{
    -fx-base: #395bae;
}</pre>
<p>I hope you enjoyed this post and maybe it has stimulated your interest to try out dependency injection via Guice (or Spring, though I haven&#8217;t tried it in a client context yet) with FXML and JavaFX. In the 2.1 release coming up in the first half of 2012 we&#8217;ll fix the above mentioned issues in FXML such that we&#8217;ll have more powerful binding and an implicit reference to the controller from FXML, such that you won&#8217;t need to use JavaScript in the FXML document to get this behavior. We&#8217;ll also have simplified the FXML somewhat such that the &#8220;<children>&#8221; element isn&#8217;t required. All in all, I think there is a lot to be excited about with JavaFX and FXML and Dependency Injection. One of my thought-projects for the next few days will be how we can ensure that this sort of development fits perfectly into the Scene Builder RAD tool experience.</p>
<p>In my parting shot, here is the GuiceFXMLLoader. It is just a hacked up proof of concept, but you&#8217;ll need to to try these classes out on your own <img src='http://fxexperience.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<p><i>GuiceFXMLLoader</i></p>
<pre class="brush: java; title: ; notranslate">
package fxmlapp;

import com.google.inject.Injector;
import java.io.InputStream;
import java.net.URL;
import javafx.fxml.FXMLLoader;
import javax.inject.Inject;

/**
 * Uses Guice to inject model state. Basically you create an instance of
 * GuiceFXMLLoader supplying an Injector, and then call load. The load
 * method takes the FXML file to load, and the controller to create and
 * associate with the FXML file.
 */
public class GuiceFXMLLoader {
    private final Injector injector;

    @Inject public GuiceFXMLLoader(Injector injector) {
        this.injector = injector;
    }

    // Load some FXML file, using the supplied Controller, and return the
    // instance of the initialized controller...?
    public Object load(String url, Class&lt;?&gt; controller) {
        Object instance = injector.getInstance(controller);
        FXMLLoader loader = new FXMLLoader();
        loader.getNamespace().put(&quot;controller&quot;, instance);
        InputStream in = null;
        try {
            try {
                URL u = new URL(url);
                in = u.openStream();
            } catch (Exception e) {
                in = controller.getResourceAsStream(url);
            }
            return loader.load(in);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) try { in.close(); } catch (Exception ee) { }
        }
        return null;
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://fxexperience.com/2011/10/fxml-guice/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>JavaFX Technical Keynote at JavaOne Video</title>
		<link>http://fxexperience.com/2011/10/javafx-technical-keynote-at-javaone-video/</link>
		<comments>http://fxexperience.com/2011/10/javafx-technical-keynote-at-javaone-video/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 19:21:50 +0000</pubDate>
		<dc:creator>Richard Bair</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fxexperience.com/?p=1412</guid>
		<description><![CDATA[This past Monday in technical keynote at JavaOne 2011 we made a series of announcements, which I referred to in the recent posting. The video for the keynote can be seen (along with a lot of other videos) on the Oracle Media Network pages. The video starts off with Mark Reinhold talking about Java 7 [...]]]></description>
			<content:encoded><![CDATA[<p>This past Monday in technical keynote at JavaOne 2011 we made a series of announcements, which I referred to in the recent <a href="http://fxexperience.com/2011/10/javafx-2-0-released/" title="JavaFX 2.0 Released"></a> posting. The video for the keynote can be seen (along with a lot of other videos) on the <a href="http://medianetwork.oracle.com/media/show/17257">Oracle Media Network</a> pages. <a href="http://medianetwork.oracle.com/media/show/17257"><img src="http://fxexperience.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-06-at-12.13.19-PM-300x169.png" alt="" title="JavaFX 2.0 Keynote Labs Demo" width="300" height="169" class="aligncenter size-medium wp-image-1413" /></a></p>
<p><span id="more-1412"></span></p>
<p>The video starts off with Mark Reinhold talking about Java 7 and Java 8 with a cameo by Charles Nutter &#038; JRuby. There are some great things there if you didn&#8217;t have a chance to see his part of the keynote.</p>
<p>The JavaFX keynote portion starts at the 38 minute mark and runs about 22 minutes. Watching the video it is clear that the speaker should refrain from clapping when mic&#8217;d up. Doh, will need to remember that for next time (got a bit carried away <img src='http://fxexperience.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ). </p>
<p>Reading the press about JavaFX over the past couple days I&#8217;ve noticed a few inaccuracies. One thing to pay attention to during Jasper&#8217;s Labs demo at the end is that some of the demos have a &#8220;JavaFX 2.0&#8243; sticker on them, and others have &#8220;JavaFX Labs&#8221; sticker. Those with the blue 2.0 sticker are 100% runnable on the currently released stack. The red ones with &#8220;labs&#8221; are future work that we&#8217;re looking at for an update release or 3.0.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://fxexperience.com/2011/10/javafx-technical-keynote-at-javaone-video/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t use impl!</title>
		<link>http://fxexperience.com/2011/10/dont-use-impl/</link>
		<comments>http://fxexperience.com/2011/10/dont-use-impl/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 17:55:45 +0000</pubDate>
		<dc:creator>Richard Bair</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fxexperience.com/?p=1409</guid>
		<description><![CDATA[I was just working my way through the last few days of posts on the JavaFX OTN forums and noticed somebody who was trying to learn how to write a custom layout pane and included the following code in the forum posting: public class MyLayout extends Pane { @Override protected void layoutChildren() { // TODO [...]]]></description>
			<content:encoded><![CDATA[<p>I was just working my way through the last few days of posts on the <a href="https://forums.oracle.com/forums/forum.jspa?forumID=1385&amp;start=0">JavaFX OTN forums</a> and noticed somebody who was trying to learn how to write a custom layout pane and included the following code in the forum posting:</p>
<p><code><br />
    public class MyLayout extends Pane {<br />
        @Override protected void layoutChildren() {<br />
            // TODO<br />
        }</p>
<p>        @Override protected void layoutInArea(Node arg0, double arg1, double arg2,<br />
                                              double arg3, double arg4, double arg5,<br />
                                              HPos arg6, VPos arg7) {<br />
            // TODO<br />
        }</p>
<p>        @Override protected void impl_layoutBoundsChanged() {<br />
            // TODO<br />
        }<br />
}</code></p>
<p>This reminded me that I had failed to write a blog warning of the perils of using impl_ methods in JavaFX 2.0. <strong><em>DON&#8217;T EVER USE THEM!!</em></strong></p>
<p><span id="more-1409"></span></p>
<p>In JavaFX we had several places where we needed to have methods which were technically public, but which needed to be excluded from the &#8220;public API&#8221; requirements of backwards compatibility. Basically we needed friend methods. There is a pattern for this, but we didn&#8217;t get it implemented in time for the 2.0 release. We carefully did 3 things to make sure these methods were very clearly not part of the public API and to tell people not to use them, so that we could fix them in an update release (and remove them from the public API entirely):</p>
<ol>
<li>We gave them all an impl_ prefix ugly name</li>
<li>We hid them all from the JavaDocs. We didn&#8217;t just omit docs, we actively prohibit the doclet from generating documentation for them at all.</li>
<li>Knowing many people (including myself) tend not to read docs but use code completion, we also marked them all as Deprecated and included deprecation text that indicates they will be removed and should not be used</li>
</ol>
<p>So please, do not under any circumstances rely on these methods. They will be removed soon! If there is some functionality there that you really need, be sure to file an RFE with <a href="http://javafx-jira.kenai.com">JIRA</a> so that we can add the appropriate functionality as a proper public API!</p>
]]></content:encoded>
			<wfw:commentRss>http://fxexperience.com/2011/10/dont-use-impl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JavaFX 2.0 Released</title>
		<link>http://fxexperience.com/2011/10/javafx-2-0-released/</link>
		<comments>http://fxexperience.com/2011/10/javafx-2-0-released/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 22:06:12 +0000</pubDate>
		<dc:creator>Richard Bair</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fxexperience.com/?p=1407</guid>
		<description><![CDATA[Whoa! It is kind of embarrassing that we haven&#8217;t yet blogged about the fact that JavaFX 2.0 has been released! In our defense, it has been a very busy past few days. At the JavaOne Technical keynote Monday morning I announced 4 things: GA Release of JavaFX 2.0 (32 bit XP, 32 &#038; 64 bit [...]]]></description>
			<content:encoded><![CDATA[<p>Whoa! It is kind of embarrassing that we haven&#8217;t yet blogged about the fact that JavaFX 2.0 has been released! In our defense, it has been a very busy past few days. At the JavaOne Technical keynote Monday morning I announced 4 things:</p>
<ul>
<li>GA Release of JavaFX 2.0 (32 bit XP, 32 &#038; 64 bit Windows Vista and Windows 7)</li>
<li>Developer Preview release of JavaFX 2.0 for Mac OS X</li>
<li>Early Access (for partners) of JavaFX Scene Builder (RAD tool)</li>
<li>Netbeans 7.1 Beta with support for JavaFX</li>
</ul>
<p>In addition, on Tuesday Adam Messinger (VP Java SE, Java Client, Java ME &#8212; my bosses boss) announced that <b>we are open sourcing all of JavaFX</b>. We are asking the OpenJDK community for a new project where we will put JavaFX. In addition, we will be working with the JCP to propose JavaFX as an official standard part of the Java platform (probably targeted for Java 9).</p>
<p>There was also a very exciting demo which you probably have already seen, where Nandini Ramani (VP Java Client, my boss) showed JavaFX running on both a Samsung Galaxy Tab (atop Android) and an iPad. Needless to say, this has generated quite a bit of buzz. I&#8217;ll blog separately about how this works and why (I gave a session on the subject on Tuesday).</p>
<p>We&#8217;ll also be blogging with our slides from the conference. In the meantime, the conference is ongoing, and I&#8217;m late for a session I wanted to attend. I&#8217;ll also post some slides from the Monday Keynote and Tuesday keynote (if I can get my hands on them)</p>
]]></content:encoded>
			<wfw:commentRss>http://fxexperience.com/2011/10/javafx-2-0-released/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

