<?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>Chui's counterpoint &#187; javafx</title>
	<atom:link href="http://www.redmountainsw.com/wordpress/archives/category/java/javafx/feed" rel="self" type="application/rss+xml" />
	<link>http://www.redmountainsw.com/wordpress</link>
	<description>pulling the rug</description>
	<lastBuildDate>Thu, 02 Sep 2010 08:20:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Identifying JavaFX 1.3&#8217;s Amble Font</title>
		<link>http://www.redmountainsw.com/wordpress/archives/amble-font</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/amble-font#comments</comments>
		<pubDate>Sat, 24 Apr 2010 09:47:49 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[javafx]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=928</guid>
		<description><![CDATA[I haven&#8217;t heard of the Amble font before. With the help of WhatTheFont, I uploaded this little section, 

And the best matched turned out to be Robusta Pro SemiCond
Identifont suggested Anivers but I thought it was way off mark.
What do you think Amble was?
]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t heard of the Amble font before. With the help of <a href="http://www.myfonts.com/WhatTheFont/">WhatTheFont</a>, I uploaded this little section, </p>
<p><img class="aligncenter size-full wp-image-929" title="amble-font" src="http://www.redmountainsw.com/wordpress/wp-content/uploads/amble-font.png" alt="" width="1401" height="105" /></p>
<p>And the best matched turned out to be <a href="http://www.myfonts.com/fonts/tilde/robusta-pro/semicond/">Robusta Pro SemiCond</a></p>
<p>Identifont suggested <a href="http://www.identifont.com/identify?18+%20+58D+4C+30D+97+6X5+1UA+4A+1KU+1KK+11+6XA+1A+53M+9Z+1R0+42+1U+8R2+M">Anivers</a> but I thought it was way off mark.</p>
<p>What do you think Amble was?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/amble-font/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Interactive JavaFX Script shell</title>
		<link>http://www.redmountainsw.com/wordpress/archives/interactive-javafx-script-shell</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/interactive-javafx-script-shell#comments</comments>
		<pubDate>Thu, 25 Mar 2010 23:04:57 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[javafx]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=897</guid>
		<description><![CDATA[One thing I don&#8217;t like about JavaFX (compared to HTML) is the edit, recompile, launch, debug cycle. In HTML, it is a matter of editing the file and refreshing with F5.
Imagine my delight when I found the JavaFX SDK ships with an interactive shell.

C:\javafx-sdk1.2\&#62;java -Djava.ext.dirs=lib/desktop;lib/shared/ com.sun.tools.javafx.script.
ScriptShell
/*fx1*/ def circle = javafx.scene.shape.Circle {centerX: 50 centerY: 50 radius:80 [...]]]></description>
			<content:encoded><![CDATA[<p>One thing I don&#8217;t like about JavaFX (compared to HTML) is the edit, recompile, launch, debug cycle. In HTML, it is a matter of editing the file and refreshing with F5.</p>
<p>Imagine my delight when I found the JavaFX SDK ships with an interactive shell.</p>
<pre class="brush: bash">
C:\javafx-sdk1.2\&gt;java -Djava.ext.dirs=lib/desktop;lib/shared/ com.sun.tools.javafx.script.
ScriptShell
/*fx1*/ def circle = javafx.scene.shape.Circle {centerX: 50 centerY: 50 radius:80 fill:javafx.scene.paint.Color.PURPLE }
le
/*fx2*/ def stage = javafx.stage.Stage { title: &quot;Interactive stage&quot; width: 400 height: 300 }
fx.stage.Stage@c7057c
/*fx3*/ import javafx.scene.Scene;
/*fx4*/ stage.scene = Scene {content: circle};
fx.scene.Scene@19e733e
</pre>
<p><a href="http://www.redmountainsw.com/wordpress/wp-content/uploads/javafx-interactive.png"><img src="http://www.redmountainsw.com/wordpress/wp-content/uploads/javafx-interactive.png" alt="" title="javafx-interactive" width="400" height="300" class="aligncenter size-full wp-image-899" /></a></p>
<p>Why do this? </p>
<p>Firstly, if you make any syntax errors, they get caught straight away. So explore away, saving the working snippets into your final source file.</p>
<p>Secondly, results are immediate. There is no need to restart the javafx application. Time is money.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/interactive-javafx-script-shell/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaFX experiment</title>
		<link>http://www.redmountainsw.com/wordpress/archives/javafx-experiment</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/javafx-experiment#comments</comments>
		<pubDate>Wed, 01 Apr 2009 20:12:24 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[javafx]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=739</guid>
		<description><![CDATA[I was having a lot of problems getting the simplest test case below to run without throwing an odd exception:

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.*;
import javafx.ext.swing.SwingTextField;
import javafx.ext.swing.SwingButton;

Stage {
    title : &#34;MyApp&#34;
    scene: Scene {
        width: 200
        height: [...]]]></description>
			<content:encoded><![CDATA[<p>I was having a lot of problems getting the simplest test case below to run without throwing an odd exception:</p>
<pre class="brush: java">
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.*;
import javafx.ext.swing.SwingTextField;
import javafx.ext.swing.SwingButton;

Stage {
    title : &quot;MyApp&quot;
    scene: Scene {
        width: 200
        height: 200
        content: [
            VBox{
                content:
                [
                SwingTextField {
                columns: 10
                text: &quot;TextField&quot;
                editable: true
                },
                SwingButton {
                text: &quot;Button&quot;
                action: function() {  }
                }]
            }

        ]
    }
}
</pre>
<p>SwingTextField barfs like this:</p>
<pre>
Exception in thread "AWT-EventQueue-1" java.lang.IllegalArgumentException: Zero length string passed to TextLayout constructor.
        at java.awt.font.TextLayout.<init>(TextLayout.java:364)
        at sun.font.FontDesignMetrics.charsWidth(FontDesignMetrics.java:487)
        at javax.swing.text.Utilities.getTabbedTextWidth(Utilities.java:262)
        at javax.swing.text.Utilities.getTabbedTextWidth(Utilities.java:191)
        at javax.swing.text.PlainView.modelToView(PlainView.java:335)
        at javax.swing.text.FieldView.modelToView(FieldView.java:248)
        at javax.swing.plaf.basic.BasicTextUI$RootView.modelToView(BasicTextUI.java:1496)
        at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:1034)
        at javax.swing.text.DefaultCaret.paint(DefaultCaret.java:600)
        at javax.swing.plaf.basic.BasicTextUI.paintSafely(BasicTextUI.java:730)
        at javax.swing.plaf.basic.BasicTextUI.paint(BasicTextUI.java:868)
        at javax.swing.plaf.basic.BasicTextUI.update(BasicTextUI.java:847)
        at javax.swing.JComponent.paintComponent(JComponent.java:758)
        at javafx.ext.swing.JTextFieldImpl.paintComponent(JTextFieldImpl.java:77)
        at javax.swing.JComponent.paint(JComponent.java:1022)
        at javax.swing.JComponent.paintChildren(JComponent.java:859)
        at javax.swing.JComponent.paint(JComponent.java:1031)
        at com.sun.embeddedswing.EmbeddedPeer.paint(EmbeddedPeer.java:135)
        at com.sun.scenario.scenegraph.SGComponent.paint(SGComponent.java:121)
        at com.sun.scenario.scenegraph.SGLeaf.render(SGLeaf.java:179)
        at com.sun.scenario.scenegraph.SGWrapper.render(SGWrapper.java:122)
        at com.sun.scenario.scenegraph.SGGroup.render(SGGroup.java:222)
        at com.sun.scenario.scenegraph.SGWrapper.render(SGWrapper.java:122)
        at com.sun.scenario.scenegraph.SGGroup.render(SGGroup.java:222)
        at com.sun.scenario.scenegraph.SGGroup.render(SGGroup.java:222)
        at com.sun.scenario.scenegraph.JSGPanel.paintComponent(JSGPanel.java:582)
        at javax.swing.JComponent.paint(JComponent.java:1022)
        at javax.swing.JComponent.paintChildren(JComponent.java:859)
        at javax.swing.JComponent.paint(JComponent.java:1031)
        at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)
        at javax.swing.JComponent.paintChildren(JComponent.java:859)
        at javax.swing.JComponent.paintToOffscreen(JComponent.java:5111)
        at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1386)
        at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1317)
        at javax.swing.RepaintManager.paint(RepaintManager.java:1132)
        at javax.swing.JComponent.paint(JComponent.java:1008)
        at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
        at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
        at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
        at java.awt.Container.paint(Container.java:1797)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:738)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:667)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at com.sun.embeddedswing.EmbeddedEventQueue.dispatchEvent(EmbeddedEventQueue.java:369)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)</pre>
<p>Running javafx with the verbose switch pointed the fault out</p>
<pre>javafx -verbose:class test
:
:
[Loaded java.awt.Container$EventTargetFilter from c:\Progra~1\Java\jdk1.6.0\jre\lib\rt.jar]
:
</pre>
<p>I was running an old version of the JDK!<br />
Unsetting the JAVA_HOME resolved the problem.<br />
I hope this helps somebody.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/javafx-experiment/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaFX Custom Cursors</title>
		<link>http://www.redmountainsw.com/wordpress/archives/javafx-custom-cursors</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/javafx-custom-cursors#comments</comments>
		<pubDate>Mon, 30 Mar 2009 01:00:47 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[javafx]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/archives/javafx-custom-cursors</guid>
		<description><![CDATA[Setting custom cursors with JavaFx is relatively straightforward, but for one little catch. Your image has to be 32&#215;32. If you want a 16&#215;16 icon, simply leave the rest of the image transparent.

import java.awt.Toolkit;
import javafx.scene.Cursor;
import javafx.scene.image.Image;

public class ColorChooser extends Cursor
{
    public override function impl_getAWTCursor(): java.awt.Cursor {

       [...]]]></description>
			<content:encoded><![CDATA[<p>Setting custom cursors with JavaFx is relatively straightforward, but for one little catch. <span style="font-style: italic;">Your image has to be 32&#215;32</span>. If you want a 16&#215;16 icon, simply leave the rest of the image transparent.</p>
<pre class="brush: java">
import java.awt.Toolkit;
import javafx.scene.Cursor;
import javafx.scene.image.Image;

public class ColorChooser extends Cursor
{
    public override function impl_getAWTCursor(): java.awt.Cursor {

        def url = &quot;{__DIR__}eyedropper.png&quot;;

        var toolkit = Toolkit.getDefaultToolkit();

        var image = Image{width:32 height:32 url:url}.bufferedImage;
        var hotspot = new java.awt.Point(0,15);
        var cursor = toolkit.createCustomCursor(image, hotspot, &quot;colorpicker&quot;);
        return cursor;
    }
}

public def ColorChooserCursor=ColorChooser{};

public function run()
{
    javafx.scene.shape.Rectangle
    {
        x:5 y:5
        width:200 height:200
        cursor:ColorChooserCursor
    }
}
</pre>
<p><!-- technorati tags begin -->
<p style="font-size:10px;text-align:right;">Tags: <a href="http://technorati.com/tag/javafx" rel="tag">javafx</a></p>
<p><!-- technorati tags end --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/javafx-custom-cursors/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JavaFX Introspection</title>
		<link>http://www.redmountainsw.com/wordpress/archives/javafx-introspection</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/javafx-introspection#comments</comments>
		<pubDate>Mon, 23 Mar 2009 14:59:58 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[javafx]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/archives/javafx-introspection</guid>
		<description><![CDATA[Just sharing some code snippets for deserialization of JavaFX objects.

function getValueType(obj:Object,name:String):String
{
    var context:FXLocal.Context=FXLocal.getContext();
    var objectValue:FXLocal.ObjectValue = new FXLocal.ObjectValue(obj,context);
    var cls:FXClassType = objectValue.getClassType();
    var varType:FXType = cls.getVariable(name).getType();
    println(&#34;{name} {varType}&#34;);
    if (varType instanceof FXSequenceType)
    {
  [...]]]></description>
			<content:encoded><![CDATA[<p>Just sharing some code snippets for deserialization of JavaFX objects.</p>
<pre class="brush: java">
function getValueType(obj:Object,name:String):String
{
    var context:FXLocal.Context=FXLocal.getContext();
    var objectValue:FXLocal.ObjectValue = new FXLocal.ObjectValue(obj,context);
    var cls:FXClassType = objectValue.getClassType();
    var varType:FXType = cls.getVariable(name).getType();
    println(&quot;{name} {varType}&quot;);
    if (varType instanceof FXSequenceType)
    {
        return &quot;array&quot;;
    } else if (varType instanceof FXClassType) {
        return &quot;element&quot;;
    } else {
        return &quot;value&quot;;
    }
}
</pre>
<p>Thanks to James Weaver for tips on <a href="http://learnjavafx.typepad.com/weblog/2009/03/answering-reader-mail-about-the-javafx-reflection-api.html">JavaFX Reflection API</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/javafx-introspection/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaFX binding in sequences</title>
		<link>http://www.redmountainsw.com/wordpress/archives/javafx-binding-in-sequences</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/javafx-binding-in-sequences#comments</comments>
		<pubDate>Fri, 20 Mar 2009 12:41:29 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[javafx]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=729</guid>
		<description><![CDATA[I had a Group of circles, i.e.
var circles:Circle[];
var group:Group = Group { content: [circles] };
strangely, I couldn&#8217;t get newly inserted circles to render. 
It turns out that you have to bind group.content to ensure that changes in circles are reflected in group.content.
Here&#8217;s a test routine.

import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.stage.*;

var lines = for (i in [1..10])
 [...]]]></description>
			<content:encoded><![CDATA[<p>I had a Group of circles, i.e.</p>
<p><code>var circles:Circle[];<br />
var group:Group = Group { content: [circles] };</code></p>
<p>strangely, I couldn&#8217;t get newly inserted circles to render. </p>
<p>It turns out that you have to bind group.content to ensure that changes in circles are reflected in group.content.</p>
<p>Here&#8217;s a test routine.</p>
<pre class="brush: java">
import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.stage.*;

var lines = for (i in [1..10])
    Line {startX:i*30 startY:20 endX:i*20 endY:500};

var circles = for (i in [1..10])
    Circle {centerX:i*30 centerY:50 radius:20};

Stage
{
    scene: Scene
    {
        content: Group
        {
            content: // bind
            [

                Rectangle {fill:Color.YELLOW width:800 height:500}
                circles,
                lines,

            ]

            onMouseClicked: function(e)
            {
                println(&#039;clicked&#039;);
                insert Circle {fill:Color.RED centerX:e.x centerY:e.y radius:20} into circles;
            }

        }

    }
}
</pre>
<p>Uncomment the <b>//bind</b> and observe the difference.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/javafx-binding-in-sequences/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaFX redux</title>
		<link>http://www.redmountainsw.com/wordpress/archives/javafx-redux</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/javafx-redux#comments</comments>
		<pubDate>Tue, 17 Feb 2009 22:41:27 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[javafx]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=698</guid>
		<description><![CDATA[Having spent a few weeks experimenting with JavaFX, and creating several examples, here is an assessment of whether JavaFX succeeds in it&#8217;s objective of being a graphics DSL. Bear in mind that I am evaluating it in terms of it&#8217;s ease in being a graphics DSL &#8211; if it makes my life easier, it succeeds. [...]]]></description>
			<content:encoded><![CDATA[<p>Having spent a few weeks experimenting with JavaFX, and <a href="http://jfxstudio.wordpress.com/2009/02/17/lights-camera-action/">creating</a> <a href="http://jfxstudio.wordpress.com/2009/02/12/visualizing-sub-prime-losses/">several</a> <a href="http://jfxstudio.wordpress.com/2009/02/09/experimenting-with-smaller-form-factors/">examples</a>, here is an assessment of whether JavaFX succeeds in it&#8217;s objective of being a graphics DSL. Bear in mind that I am evaluating it in terms of it&#8217;s ease in being a graphics DSL &#8211; if it makes my life easier, it succeeds. Where it makes my life harder than developing web apps &#8211; it fails.</p>
<p>On with the list.</p>
<h2>Wins</h2>
<ul>
<li><strong>bind keyword &#8211; </strong>it took a while, but finally concepts from sloppy tools like Excel is making it&#8217;s way into mainstream programming languages. Programmers should never have to do the work that a computer can do just as well.</li>
<li><strong>First class support for animations</strong> The language simplifies the process of creating keyframe-styled animations, without having to launch background threads, worry about EDT and having to write callback code for timers.</li>
<li><strong>Object initializer syntax</strong> Using keyword-style arguments suits objects which has tonnes of properties</li>
<li><strong>effect</strong> property in Nodes makes it straightforward to add &#8220;bling&#8221; to a project without having to rearrange program layout</li>
<li><strong>strong support for functional-style programming</strong> List comprehensions, filter, map. Built into the language.</li>
</ul>
<h2>Losses</h2>
<ul>
<li><strong>Javaesque layouts, not Webesque</strong> &#8211; containers are emphasised over styles. This is not going to win any points with the semantic crowd.</li>
<li><strong>Difficulty in adding extension points</strong> &#8211; I would have favoured seeing C# static extension methods in the language. It would have made adding behaviors easier. For instance, centering a piece of text takes more effort than it should, and once done it could not be easily refactored and added to other elements. I regard this as a wart in a DSL that aims to support animators.</li>
<li><strong>Difficulty in adding behaviors</strong> &#8211; adding behaviors like &#8220;clickable&#8221;, &#8220;hoverable&#8221;, &#8220;draggable&#8221; requries programmatic intervention, rather than being able to declaratively do this. This is due to the absence of extension points above, and the absence of namespacing from the YAML syntax. XML-style syntax would have been kinder to these kind of mashups.</li>
<li>The DSL may be suited for laying out standard blocky objects, but (I was working with Vim and) it was hard to lay things out by hand. One still <strong>needs to fall back on a graphic editor to create most of the resources</strong>.</li>
<li><strong>The story on accessibility is still unclear</strong> &#8211; granted that JavaFX is a DSL for graphics and animations, however, it&#8217;s target is to be a platform for developing applications. Without a clear accessibility story, JavaFX will never see the doors of a government application, or a public-facing application of large corporations.</li>
<li><strong>event handlers</strong> &#8211; there is only one for each event. I couldn&#8217;t figure out why. onclick=&#8221;&#8230;&#8221; is so 1997.</li>
</ul>
<h2>Recommendations</h2>
<ul>
<li><strong>Tools support is essential</strong> The language compiler project should make the abstract syntax trees available so that third parties can easily develop tools to parse the language. Currently, it is a one-way conversion from Adobe/SVG to FXD. Syntax sugar in the Timeline, duration may be cutesy, but we need parsers please.</li>
<li><strong>Extend language</strong> to make it easy for developers to add custom attributes and behaviors to graphical nodes. The OpenJFX developers should wrap Centering layout code for each graphical shape to see how weak JavaFX is in this area.</li>
<li><strong>More support to attract web developers</strong> &#8211; the people who are writing the specs come from a Java development background, and it shows. The JavaFX language team needs a few web developers on the advisory board to make it easy to attract this particular constituent.</li>
<li><strong>more interfaces and less inheritance</strong> &#8211; when writing layout code, I&#8217;m frequently stymied by containers like scene and stage which do not have the same base classes, making it hard to measure width and height.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/javafx-redux/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaFX TextAlignment Gotcha</title>
		<link>http://www.redmountainsw.com/wordpress/archives/javafx-textalignment-gotcha</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/javafx-textalignment-gotcha#comments</comments>
		<pubDate>Fri, 13 Feb 2009 10:35:49 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[javafx]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/archives/javafx-textalignment-gotcha</guid>
		<description><![CDATA[Here is a minimal test case illustrating how exasperating the default JavaFX Text node can be, especially when aligning text. 
You&#8217;d be surprised to note that both pieces of text below are aligned using TextAlignment.CENTER.


import javafx.scene.text.*;
import javafx.scene.layout.*;

VBox
{
    translateY:10
    content:
    [
    Text {
  [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a minimal test case illustrating how exasperating the default JavaFX Text node can be, especially when aligning text. </p>
<p>You&#8217;d be surprised to note that both pieces of text below are aligned using TextAlignment.CENTER.</p>
<p><a href="http://www.redmountainsw.com/wordpress/wp-content/uploads/javafx_textalign.gif"><img src="http://www.redmountainsw.com/wordpress/wp-content/uploads/javafx_textalign.gif" alt="Problems With TextAlign in JavaFX" title="Problems With TextAlign in JavaFX" width="149" height="103" class="aligncenter size-full wp-image-687" /></a></p>
<pre class="brush: java">
import javafx.scene.text.*;
import javafx.scene.layout.*;

VBox
{
    translateY:10
    content:
    [
    Text {
        textAlignment:TextAlignment.CENTER
        content: &quot;A New World&quot;
    }
    ,
    Text {
        textAlignment:TextAlignment.CENTER
        content: &quot;A Mighty Pub\nwith\nAbsolutely No Bitter Beer&quot;
    }
    ]
}
</pre>
<p>Apparently, the state of the art work-around is to calculate the mid-point using myTextNode.boundsInLocal.width, and then position using translateX.</p>
<p>Not good enough, Sun.  Not good enough.</p>
<p>Here&#8217;s the worked around code</p>
<pre class="brush: java">
import javafx.scene.*;
import javafx.scene.text.*;
import javafx.scene.layout.*;

var scene:Scene;
scene=Scene
{
    content:
    {
        VBox
        {
            translateY:10
            content:
            [
            Text {
                id: &quot;label1&quot;
                translateX: bind (scene.width-scene.lookup(&quot;label1&quot;).boundsInLocal.width)/2
                textAlignment:TextAlignment.CENTER
                content: &quot;A New World&quot;
            },
            Text {
                id: &quot;label2&quot;
                translateX: bind (scene.width-scene.lookup(&quot;label2&quot;).boundsInLocal.width)/2
                textAlignment:TextAlignment.CENTER
                content: &quot;A Mighty Pub\nwith\nAbsolutely No Bitter Beer&quot;
            },
            ]
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/javafx-textalignment-gotcha/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaFX Experiments &#8211; Order of Declaration Matters</title>
		<link>http://www.redmountainsw.com/wordpress/archives/javafx-experiments-order-of-declaration-matters</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/javafx-experiments-order-of-declaration-matters#comments</comments>
		<pubDate>Thu, 12 Feb 2009 13:39:21 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[javafx]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=684</guid>
		<description><![CDATA[Given the following piece of JavaFX Script

import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import java.lang.Math.sqrt;

class C extends CustomNode
{
    // Test #1: Commented out
    //var node: Group = Group {};

    protected override function create():Node
    {
        return node;
   [...]]]></description>
			<content:encoded><![CDATA[<p>Given the following piece of JavaFX Script</p>
<pre class="brush: java">
import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import java.lang.Math.sqrt;

class C extends CustomNode
{
    // Test #1: Commented out
    //var node: Group = Group {};

    protected override function create():Node
    {
        return node;
    }

    public var data:Number[] on replace olddata
    {
        for (item in data)
        {
            var side:Number = sqrt(item);
            insert Rectangle{
                width:side height:side
                stroke:Color.RED strokeWidth:2 fill:Color.TEAL
            }
            into node.content;
        }
    }

    // Test 2: Comment out
    var node: Group = Group {};
}

C { data: [21000, 10000]; }
</pre>
<p>One of these declares <b>node</b> at the end of the class, and the other declares it at the beginning of the class. Take a look at it for a while and see if you can guess the difference in behaviour?</p>
<p><span id="more-684"></span></p>
<h2>Answer</h2>
<p>The &#8220;on replace&#8221; trigger for <b>data</b> attribute does not throw an exception in Test #2 <i>despite</i> the fact that <strong>node is null</strong>.</p>
<h2>Moral of the story</h2>
<p>Order of initialization matters. Make sure you initialize variables before triggers are defined.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/javafx-experiments-order-of-declaration-matters/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaFX Fidelity</title>
		<link>http://www.redmountainsw.com/wordpress/archives/javafx-fidelity</link>
		<comments>http://www.redmountainsw.com/wordpress/archives/javafx-fidelity#comments</comments>
		<pubDate>Tue, 03 Feb 2009 22:42:30 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[javafx]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=672</guid>
		<description><![CDATA[JavaFX gets to start on a clean slate, without burdens of compatibility with browsers. However, how well does it paint itself? 
How are &#8211; say &#8211; Rectangles defined? 
Is the startX based on center lines? or is it from the origin? 
What about borders? Are borders painted to the bottom right of the origin? 
How [...]]]></description>
			<content:encoded><![CDATA[<p>JavaFX gets to start on a clean slate, without burdens of compatibility with browsers. However, how well does it paint itself? </p>
<p>How are &#8211; say &#8211; Rectangles defined? </p>
<p>Is the startX based on center lines? or is it from the origin? </p>
<p>What about borders? Are borders painted to the bottom right of the origin? </p>
<p>How is the boundsInLocal defined?</p>
<p>Here is a piece of test code.</p>
<pre class="brush: java">
Rectangle
{
    strokeWidth:50 fill:null stroke:Color.BLACK
    x:0 y:0 width:200 height:200
}
</pre>
<p>and I didn&#8217;t like what I saw:</p>
<p><a href="http://www.redmountainsw.com/wordpress/wp-content/uploads/rect11.png"><img src="http://www.redmountainsw.com/wordpress/wp-content/uploads/rect11.png" alt="Rectangle with 50-pixel thick border" title="Rectangle with 50-pixel thick border" width="243" height="279" class="aligncenter size-full wp-image-673" /></a></p>
<p>Overlaying a grid, we could see that the X and Y origins are indeed based on center lines.<br />
<a href="http://www.redmountainsw.com/wordpress/wp-content/uploads/rect21.png"><img src="http://www.redmountainsw.com/wordpress/wp-content/uploads/rect21.png" alt="rect2" title="rect2" width="309" height="335" class="aligncenter size-full wp-image-674" /></a></p>
<p>The big disappointment  comes from the boundsInLocal measurements:</p>
<pre>
Rectangle2D [
minX = -35.85533905029297,
minY=-35.85533905029297,
maxX=235.85535430908203,
maxY=235.85535430908203,
width=271.710693359375,
height=271.710693359375]
</pre>
<p>This doesn&#8217;t make any sense at all, and is going to make laying out components properly that much harder.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/archives/javafx-fidelity/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
