<?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>Just Java &#187; JavaFX</title>
	<atom:link href="http://blog.cedarsoft.com/category/java/javafx/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cedarsoft.com</link>
	<description>A blog about Java and (related) Open Source tools...</description>
	<lastBuildDate>Wed, 25 Jan 2012 12:02:25 +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>JavaFX 2.* for Linux is coming&#8230;</title>
		<link>http://blog.cedarsoft.com/2012/01/javafx-2-for-linux-is-coming/</link>
		<comments>http://blog.cedarsoft.com/2012/01/javafx-2-for-linux-is-coming/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 12:02:25 +0000</pubDate>
		<dc:creator>Johannes Schneider</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[preview]]></category>

		<guid isPermaLink="false">http://blog.cedarsoft.com/?p=515</guid>
		<description><![CDATA[Yeah. Finally:
http://blogs.oracle.com/javafx/entry/javafx_2_0_is_cross
Download:
http://www.oracle.com/technetwork/java/javafx/downloads/devpreview-1429449.html
I think I will take a closer look in a few days&#8230;
]]></description>
			<content:encoded><![CDATA[<p>Yeah. Finally:</p>
<p><a title="Announcement" href="http://blogs.oracle.com/javafx/entry/javafx_2_0_is_cross">http://blogs.oracle.com/javafx/entry/javafx_2_0_is_cross</a></p>
<p>Download:</p>
<p><a href="http://www.oracle.com/technetwork/java/javafx/downloads/devpreview-1429449.html">http://www.oracle.com/technetwork/java/javafx/downloads/devpreview-1429449.html</a></p>
<p>I think I will take a closer look in a few days&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cedarsoft.com/2012/01/javafx-2-for-linux-is-coming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaFX2Java Bridge added to JFXtras (step 2)</title>
		<link>http://blog.cedarsoft.com/2010/07/javafx2java-bridge-added-to-jfxtras-step-2/</link>
		<comments>http://blog.cedarsoft.com/2010/07/javafx2java-bridge-added-to-jfxtras-step-2/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 07:52:12 +0000</pubDate>
		<dc:creator>Johannes Schneider</dc:creator>
				<category><![CDATA[JFXtras]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[bridge]]></category>

		<guid isPermaLink="false">http://blog.cedarsoft.com/?p=364</guid>
		<description><![CDATA[Thanks to Stephen: He has prepared a branch for the upcoming 0.7 release of JFXtras. Now it has been possible to merge the latest changes to the JFXtras default branch.
There are a lot of changes waiting in line. While the 0.7 release will be a huge step, I am really looking forward for 0.8&#8230;
So if [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to Stephen: He has prepared a branch for the upcoming 0.7 release of JFXtras. Now it has been possible to merge the latest changes to the JFXtras default branch.</p>
<p>There are a lot of changes waiting in line. While the 0.7 release will be a huge step, I am really looking forward for 0.8&#8230;</p>
<p>So if you want to take a look at the latest changes, just check out the source code at <a href="http://code.google.com/p/jfxtras/source/checkout">http://code.google.com/p/jfxtras/source/checkout</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cedarsoft.com/2010/07/javafx2java-bridge-added-to-jfxtras-step-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaFX2Java Bridge added to JFXtras (step 1)</title>
		<link>http://blog.cedarsoft.com/2010/07/javafx2java-bridge-added-to-jfxtras-step-1/</link>
		<comments>http://blog.cedarsoft.com/2010/07/javafx2java-bridge-added-to-jfxtras-step-1/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 19:09:54 +0000</pubDate>
		<dc:creator>Johannes Schneider</dc:creator>
				<category><![CDATA[JFXtras]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[bridge]]></category>

		<guid isPermaLink="false">http://blog.cedarsoft.com/?p=359</guid>
		<description><![CDATA[It has taken a long time since I promised to integrate the JavaFX2Java bridge to JFXtras until I finally did it&#8230;
At the moment the code is located at a clone that will be integrated as soon as JFXtras 0.7 has been released.
The clone can be accessed there:
https://js-mavenization.googlecode.com/hg/
The package is named &#8220;org.jfxtras.bridge&#8221;.
]]></description>
			<content:encoded><![CDATA[<p>It has taken a long time since I promised to integrate the <a href="http://blog.cedarsoft.com/2010/05/closing-the-gap-between-java-and-javafx/">JavaFX2Java bridge</a> to JFXtras until I finally did it&#8230;</p>
<p>At the moment the code is located at a clone that will be integrated as soon as JFXtras 0.7 has been released.</p>
<p>The clone can be accessed there:</p>
<p>https://js-mavenization.googlecode.com/hg/</p>
<p>The package is named &#8220;org.jfxtras.bridge&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cedarsoft.com/2010/07/javafx2java-bridge-added-to-jfxtras-step-1/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JFXtras: 0.7 RC1 released</title>
		<link>http://blog.cedarsoft.com/2010/06/jfxtras-0-7-rc1-released/</link>
		<comments>http://blog.cedarsoft.com/2010/06/jfxtras-0-7-rc1-released/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 08:21:44 +0000</pubDate>
		<dc:creator>Johannes Schneider</dc:creator>
				<category><![CDATA[JFXtras]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://blog.cedarsoft.com/?p=354</guid>
		<description><![CDATA[Hi guys,
the first release candidate for JFXtras 0.7 has been released. This version is (should be) fully functional with JavaFX 1.3
Downloads can be found at http://jfxtras.org/
]]></description>
			<content:encoded><![CDATA[<p>Hi guys,</p>
<p>the first release candidate for JFXtras 0.7 has been released. This version is (should be) fully functional with JavaFX 1.3<br />
Downloads can be found at <a href="http://jfxtras.org/">http://jfxtras.org/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cedarsoft.com/2010/06/jfxtras-0-7-rc1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Closing the gap between Java and JavaFX</title>
		<link>http://blog.cedarsoft.com/2010/05/closing-the-gap-between-java-and-javafx/</link>
		<comments>http://blog.cedarsoft.com/2010/05/closing-the-gap-between-java-and-javafx/#comments</comments>
		<pubDate>Tue, 11 May 2010 14:39:20 +0000</pubDate>
		<dc:creator>Johannes Schneider</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[binding]]></category>

		<guid isPermaLink="false">http://blog.cedarsoft.com/?p=330</guid>
		<description><![CDATA[There is a huge gap between Java and JavaFX: While it is very easy to bind JavaFX objects to each other there has been no way to bind JavaFX objects to Java properties (and vice versa).
It has taken me some time to figure out how this could be solved. And at the moment I am [...]]]></description>
			<content:encoded><![CDATA[<p>There is a huge gap between Java and JavaFX: While it is very easy to bind JavaFX objects to each other there has been no way to bind JavaFX objects to Java properties (and vice versa).</p>
<p>It has taken me some time to figure out how this could be solved. And at the moment I am in the progress of adding that stuff to the <a href="http://jfxtras.org/">JFXtras</a> project.<br />
This will take some time until I have taken all necessary steps.</p>
<p>Until then i want to give you a quick jar that can be used to try that stuff&#8230;</p>
<p>To try it, download that jar and add it to the classpath of your JavaFX project:<br />
<a href='http://blog.cedarsoft.com/wp-uploads/2010/05/bridge-1.0.0-SNAPSHOT-jar-with-dependencies.jar'>bridge-1.0.0-SNAPSHOT-jar-with-dependencies</a></p>
<p>There are two ways of synchronization. At first it is possible to listen for changes to Java objects and update an JavaFX object accordingly. At the moment I have implemented two ways to listen for updates.</p>
<h2>Java to JavaFX</h2>
<ul>
<li>PropertyChangeEvents: This is the recommended way: Just make your Java bean fire PropertyChangeEvents whenever a property has changed.</li>
<li>Busy waiting: I have added a hackish way of busy waiting. This should not be used in production code. But it offers a fast way to test things</li>
</ul>
<h2>JavaFX to Java</h2>
<p>The reverse way has also two ways implemented:</p>
<ul>
<li>Calling of setters: If a JavaFX var is updated, this bridge calls the corresponding setter of your Java object (using reflection or optionally your own optimized implementation).</li>
<li>PropertyChangeEvents: It is possible to create a bridge that converts the JavaFX binding<br />
updates to PropertyChangeEvents.</li>
</ul>
<h2>With inverse&#8230;</h2>
<p>Of course it is also possible (and most of the time necessary) to create bindings with inverse. I give you a small sample how this might work here:</p>
<p>We create our Java &#8220;model&#8221;:<br />
[cc lang="java"]package fxbindingtest;</p>
<p>import java.beans.PropertyChangeListener;<br />
import java.beans.PropertyChangeSupport;</p>
<p>public class JavaClass {<br />
  private float amount = 99;</p>
<p>  public float getAmount() {<br />
    return amount;<br />
  }</p>
<p>  public void setAmount(float amount) {<br />
    pcs.firePropertyChange(&#8220;amount&#8221;, this.amount, this.amount=amount);<br />
    System.out.println(&#8220;Changed amount to &#8221; + amount );<br />
  }</p>
<p>  final PropertyChangeSupport pcs = new PropertyChangeSupport(this);</p>
<p>  public void addPropertyChangeListener( PropertyChangeListener listener) {<br />
    pcs.addPropertyChangeListener(listener);<br />
  }</p>
<p>  public void removePropertyChangeListener( PropertyChangeListener listener) {<br />
    pcs.removePropertyChangeListener(listener);<br />
  }<br />
}<br />
[/cc]</p>
<p>And here comes our JavaFX stage. This stage contains just a slider that is bound to the Java object (with inverse).<br />
Every five seconds the model object is updated (amount+=10) &#8211; and reflected by the slider.</p>
<p>[cc lang="c"]package fxbindingtest;</p>
<p>import javafx.stage.Stage;<br />
import javafx.scene.Scene;<br />
import javafx.scene.control.Slider;<br />
import com.cedarsoft.fx.JavaFxBridge;<br />
import com.sun.javafx.runtime.FXObject;<br />
import javafx.animation.Timeline;<br />
import javafx.animation.KeyFrame;</p>
<p>/**<br />
 * @author johannes<br />
 */<br />
var slider: Slider;</p>
<p>//The java model class. Contains the property &#8220;amount&#8221; and a PropertyChangeSupport<br />
def javaModel = new JavaClass();</p>
<p>Stage {<br />
  title: &#8220;Application title&#8221;<br />
  scene: Scene {<br />
    width: 800<br />
    height: 600<br />
    content: [<br />
      slider = Slider {<br />
          min: 1<br />
          max: 100<br />
          snapToTicks: true<br />
        }<br />
    ]<br />
  }<br />
}</p>
<p>//Create the binding from the java model to the slider<br />
//Using the defaults:<br />
// Java &#8211;> FX: PropertyChangeEvents<br />
// FX &#8211;> Java: Calling setters by reflection<br />
JavaFxBridge.bridge( javaModel ).to( slider as FXObject ).connecting(<br />
  JavaFxBridge.bind( &#8220;amount&#8221; ).to( &#8220;value&#8221; ).withInverse()<br />
); //sorry for the stupid API &#8211; needs some polishing&#8230;</p>
<p>//Add a timeline to simulate changes to the model<br />
Timeline {<br />
  repeatCount: Timeline.INDEFINITE<br />
  keyFrames: [<br />
    KeyFrame {<br />
      time: 5s<br />
      action: function() {<br />
        println("changing amount on model");<br />
        javaModel.setAmount( javaModel.getAmount() + 10 );<br />
      }<br />
    }<br />
  ];<br />
}.play();<br />
[/cc]</p>
<p>And here a JNLP to run the demo (open Java Console to see the updates printed to System.out):<br />
<a href='http://blog.cedarsoft.com/wp-uploads/2010/05/FxBindingTest.jnlp'><img src="http://java.sun.com/products/jfc/tsc/sightings/images/webstart.small.jpg" alt="webstart" /></a></p>
<p><strong>Disclaimer:</strong><br />
This is just a working-in-some-situations-prototype. It is not production-ready by far.<br />
But if you have any comments/ideas/bugs, please mail me.</p>
<p>The source code can be <a href='http://blog.cedarsoft.com/wp-uploads/2010/05/bridge-1.0.0-SNAPSHOT-project.zip'>downloaded here</a>. But I will add that stuff to JFXtras very soon&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cedarsoft.com/2010/05/closing-the-gap-between-java-and-javafx/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Binding PropertyChangeSupport to JavaFX objects transparently</title>
		<link>http://blog.cedarsoft.com/2010/05/binding-propertychangesupport-to-javafx-objects/</link>
		<comments>http://blog.cedarsoft.com/2010/05/binding-propertychangesupport-to-javafx-objects/#comments</comments>
		<pubDate>Sat, 08 May 2010 20:03:48 +0000</pubDate>
		<dc:creator>Johannes Schneider</dc:creator>
				<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[bean]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[bridge]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[pcs]]></category>
		<category><![CDATA[property]]></category>
		<category><![CDATA[PropertyChangeEvent]]></category>

		<guid isPermaLink="false">http://blog.cedarsoft.com/?p=316</guid>
		<description><![CDATA[Binding is one of the best features in JavaFX. The possibility to class Java APIs from JavaFX is another one.
But unfortunately there is no easy way to combine JavaFX binding and Java PropertyChangeEvents. Therefore I have taken a look at the JavaFX code and I think I have found a possible solution:
The manual way
Of course [...]]]></description>
			<content:encoded><![CDATA[<p>Binding is one of the best features in JavaFX. The possibility to class Java APIs from JavaFX is another one.<br />
But unfortunately there is no easy way to combine JavaFX binding and Java PropertyChangeEvents. Therefore I have taken a look at the JavaFX code and I think I have found a possible solution:</p>
<h2>The manual way</h2>
<p>Of course you can add on replace triggers on every var and fire your events manually:<br />
[cc lang="c"]<br />
class Customer{<br />
  public var name:String = &#8220;&#8221; on replace old {<br />
    pcs.firePropertyChange(&#8220;name&#8221;, old, name );<br />
  };<br />
  public var address:String = &#8220;&#8221; on replace old {<br />
    pcs.firePropertyChange(&#8220;address&#8221;, old, address );<br />
  };<br />
  public var mail:Email on replace old {<br />
    pcs.firePropertyChange(&#8220;mail&#8221;, old, mail );<br />
  };<br />
  public-read def pcs = new PropertyChangeSupport( this );<br />
}<br />
[/cc]</p>
<p>This has at least three disadvantages:</p>
<ul>
<li>At first your code becomes very ugly. A lot of boilerplate code without any type checking. Very easy to make faults. Very hard to find them.</li>
<li>But the second problem is even worse &#8211; if you don&#8217;t know for sure whether there is a listener registered. This approach destroys lazy binding which has been introduced in JavaFX 1.3. Every time the binding is invalidated, the replace trigger forces an update &#8211; even if nobody is registered at the PropertyChangeSupport.</li>
<li>It can&#8217;t be &#8220;attached&#8221; to existing JavaFX classes.</li>
</ul>
<h1>Using an automated bridge</h1>
<p>I have created a bridge that can be attached to every JavaFX object. This bridge uses the JavaFX binding stuff and translates the binding updates to PropertyChangeEvents.<br />
There is no reflection involved when vars are updated (just when setting it up). So performance shouldn&#8217;t be a problem.<br />
(Of course this approach also prevents lazy bindings since the events have to be created every time the vars change). So only attach the bridge if it is necessary.</p>
<p>The bridge can be used like that:<br />
[cc lang="java"]<br />
 * FXObject fxObject = &#8230;<br />
 * Fx2PropertyChangeEvent bridge = Fx2PropertyChangeEvent.bindProperties( &#8220;name&#8221;, &#8220;id&#8221; ).to( fxObject );<br />
 * bridge.addPropertyChangeListener( &#8220;name&#8221;, new PropertyChangeListener(){&#8230;} );<br />
[/cc]</p>
<p>Of course the bridge can also be used within your JavaFX scripts/classes.</p>
<p>And here comes the code: Feel free to use it:</p>
<p>[cc lang="java"]<br />
package com.cedarsoft.fx;</p>
<p>import com.sun.javafx.runtime.DependentsManager;<br />
import com.sun.javafx.runtime.FXBase;<br />
import com.sun.javafx.runtime.FXObject;<br />
import com.sun.javafx.runtime.annotation.Public;<br />
import org.jetbrains.annotations.NonNls;<br />
import org.jetbrains.annotations.NotNull;<br />
import org.jetbrains.annotations.Nullable;</p>
<p>import java.beans.PropertyChangeEvent;<br />
import java.beans.PropertyChangeListener;<br />
import java.beans.PropertyChangeSupport;<br />
import java.util.ArrayList;<br />
import java.util.List;</p>
<p>/**<br />
 * This is a bridge that connects a PropertyChangeSupport to one or more JavaFX vars.<br />
 *
<p/>
 * This bridge does use reflection only to set things up! Whenever a var is updated there no(!) reflection is used!<br />
 * Therefore the performance is quite good.<br />
 *
<p/>
 *
<p/>
 * The Code might look like that:<br />
 *
<pre>
 * FXObject fxObject = ...
 * Fx2PropertyChangeEvent bridge = Fx2PropertyChangeEvent.bindProperties( "name", "id" ).to( fxObject );
 * bridge.addPropertyChangeListener( "name", new PropertyChangeListener(){...} );
 * </pre>
<p> */<br />
@Public<br />
public class Fx2PropertyChangeEvent extends FXBase {<br />
  @NotNull<br />
  private final PropertyChangeSupport pcs;<br />
  @NotNull<br />
  private final List<entry> entries = new ArrayList<entry>();<br />
  @NotNull<br />
  private final FXObject bindee;</p>
<p>  public Fx2PropertyChangeEvent( @NotNull FXObject bindee ) {<br />
    this( bindee, null );<br />
  }</p>
<p>  public Fx2PropertyChangeEvent( @NotNull FXObject bindee, @Nullable PropertyChangeSupport pcs ) {<br />
    super( false );<br />
    this.bindee = bindee;<br />
    this.pcs = pcs == null ? new PropertyChangeSupport( this ) : pcs;<br />
    initialize$( true );<br />
  }</p>
<p>  /**<br />
   * Convert to property change events.<br />
   *<br />
   * @param propertyName the name of the property (var)<br />
   */<br />
  void bindTo( @NotNull String propertyName ) {<br />
    try {<br />
      String fieldName = &#8220;$&#8221; + propertyName;<br />
      bindee.getClass().getField( fieldName );<br />
    } catch ( Exception ignore ) {<br />
      throw new IllegalArgumentException( &#8220;Invalid property name <" + propertyName + ">&#8221; );<br />
    }</p>
<p>    try {<br />
      String varNumFieldName = &#8220;VOFF$&#8221; + propertyName;<br />
      Integer varNumField = ( Integer ) bindee.getClass().getField( varNumFieldName ).get( null );</p>
<p>      int index = addEntry( propertyName, varNumField );<br />
      DependentsManager.addDependent( bindee, varNumField, this, index );<br />
    } catch ( Exception e ) {<br />
      throw new RuntimeException( e );<br />
    }<br />
  }</p>
<p>  @Override<br />
  public boolean update$( FXObject src, int depNum, int startPos, int endPos, int newLength, int phase ) {<br />
    Entry entry = getEntry( depNum );<br />
    if ( phase == 65 ) {<br />
      Object oldValue = src.get$( entry.getVarNumField() );<br />
      entry.setOldValue( oldValue );<br />
    } else if ( phase == 92 ) {<br />
      Object newValue = src.get$( entry.getVarNumField() );<br />
      pcs.firePropertyChange( new PropertyChangeEvent( src, entry.getPropertyName(), entry.getOldValue(), newValue ) );<br />
    } else {<br />
      throw new IllegalStateException( &#8220;Invalid phase: &#8221; + phase );<br />
    }</p>
<p>    super.update$( src, depNum, startPos, endPos, newLength, phase );<br />
    return true;<br />
  }</p>
<p>  private int addEntry( @NotNull @NonNls String propertyName, int varNumField ) {<br />
    int index = entries.size();<br />
    entries.add( new Entry( propertyName, varNumField ) );<br />
    return index;<br />
  }</p>
<p>  @NotNull<br />
  private Entry getEntry( int depNum ) {<br />
    return entries.get( depNum );<br />
  }</p>
<p>  public void addPropertyChangeListener( PropertyChangeListener listener ) {<br />
    pcs.addPropertyChangeListener( listener );<br />
  }</p>
<p>  public void removePropertyChangeListener( PropertyChangeListener listener ) {<br />
    pcs.removePropertyChangeListener( listener );<br />
  }</p>
<p>  public void addPropertyChangeListener( String propertyName, PropertyChangeListener listener ) {<br />
    pcs.addPropertyChangeListener( propertyName, listener );<br />
  }</p>
<p>  public void removePropertyChangeListener( String propertyName, PropertyChangeListener listener ) {<br />
    pcs.removePropertyChangeListener( propertyName, listener );<br />
  }</p>
<p>  @NotNull<br />
  public FXObject getBindee() {<br />
    return bindee;<br />
  }</p>
<p>  @NotNull<br />
  public PropertyChangeSupport getPcs() {<br />
    return pcs;<br />
  }</p>
<p>  public static class Entry {<br />
    private final String propertyName;<br />
    private final int varNumField;<br />
    private Object oldValue;</p>
<p>    public Entry( String propertyName, int varNumField ) {<br />
      this.propertyName = propertyName;<br />
      this.varNumField = varNumField;<br />
    }</p>
<p>    public String getPropertyName() {<br />
      return propertyName;<br />
    }</p>
<p>    public int getVarNumField() {<br />
      return varNumField;<br />
    }</p>
<p>    public Object getOldValue() {<br />
      return oldValue;<br />
    }</p>
<p>    public void setOldValue( Object oldValue ) {<br />
      this.oldValue = oldValue;<br />
    }<br />
  }</p>
<p>  /**<br />
   * Binds the given property names<br />
   *<br />
   * @param propertyNames the property names<br />
   * @return the fluent factory used to create a Fx2PropertyChangeEvent<br />
   */<br />
  @NotNull<br />
  public static FluentFactory bindProperties( @NotNull @NonNls String&#8230; propertyNames ) {<br />
    return new FluentFactory( propertyNames );<br />
  }</p>
<p>  /**<br />
   * Binds the given property names<br />
   *<br />
   * @param propertyNames the property names<br />
   * @return the fluent factory used to create a Fx2PropertyChangeEvent<br />
   */<br />
  @NotNull<br />
  public static FluentFactory bind( @NotNull @NonNls String&#8230; propertyNames ) {<br />
    return bindProperties( propertyNames );<br />
  }</p>
<p>  /**<br />
   * Fluent factory implementation<br />
   */<br />
  public static class FluentFactory {<br />
    @NotNull<br />
    private final String[] propertyNames;</p>
<p>    private FluentFactory( @NonNls @NotNull String[] propertyNames ) {<br />
      //noinspection AssignmentToCollectionOrArrayFieldFromParameter<br />
      this.propertyNames = propertyNames;<br />
    }</p>
<p>    /**<br />
     * Binds the property names to the given bindee<br />
     *<br />
     * @param bindee the bindee the properties are bound to<br />
     * @return the bridge<br />
     *<br />
     * @noinspection InstanceMethodNamingConvention<br />
     */<br />
    @NotNull<br />
    public Fx2PropertyChangeEvent to( @NotNull FXObject bindee ) {<br />
      if ( propertyNames.length == 0 ) {<br />
        throw new IllegalArgumentException( &#8220;Need at least one property to bind to&#8221; );<br />
      }</p>
<p>      Fx2PropertyChangeEvent bridge = new Fx2PropertyChangeEvent( bindee );<br />
      for ( String propertyName : propertyNames ) {<br />
        bridge.bindTo( propertyName );<br />
      }<br />
      return bridge;<br />
    }<br />
  }<br />
}</p>
<p>/**<br />
 * Copyright (C) cedarsoft GmbH.<br />
 *<br />
 * Licensed under the GNU General Public License version 3 (the &#8220;License&#8221;)<br />
 * with Classpath Exception; you may not use this file except in compliance<br />
 * with the License. You may obtain a copy of the License at<br />
 *<br />
 *         http://www.cedarsoft.org/gpl3ce<br />
 *         (GPL 3 with Classpath Exception)<br />
 *<br />
 * This code is free software; you can redistribute it and/or modify it<br />
 * under the terms of the GNU General Public License version 3 only, as<br />
 * published by the Free Software Foundation. cedarsoft GmbH designates this<br />
 * particular file as subject to the &#8220;Classpath&#8221; exception as provided<br />
 * by cedarsoft GmbH in the LICENSE file that accompanied this code.<br />
 *<br />
 * This code is distributed in the hope that it will be useful, but WITHOUT<br />
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or<br />
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License<br />
 * version 3 for more details (a copy is included in the LICENSE file that<br />
 * accompanied this code).<br />
 *<br />
 * You should have received a copy of the GNU General Public License version<br />
 * 3 along with this work; if not, write to the Free Software Foundation,<br />
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.<br />
 *<br />
 * Please contact cedarsoft GmbH, 72810 Gomaringen, Germany,<br />
 * or visit www.cedarsoft.com if you need additional information or<br />
 * have any questions.<br />
 */</p>
<p>[/cc]</p>
<p>I will upload a complete project very soon (Monday). This will contain several samples and unit tests&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cedarsoft.com/2010/05/binding-propertychangesupport-to-javafx-objects/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JavaFX Internals Part 2</title>
		<link>http://blog.cedarsoft.com/2010/05/javafx-internals-part-2/</link>
		<comments>http://blog.cedarsoft.com/2010/05/javafx-internals-part-2/#comments</comments>
		<pubDate>Sat, 08 May 2010 13:15:34 +0000</pubDate>
		<dc:creator>Johannes Schneider</dc:creator>
				<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[internals]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.cedarsoft.com/?p=309</guid>
		<description><![CDATA[Yesterday I wrote about some JavaFX Internals&#8230;. Today comes the second part.
Today we start to use some of the JavaFX classes by Java. Therefore I just added all JavaFX jars to the classpath.
Extending FXBase
It is a very good idea to extend FXBase. We just have to figure out which methods have to be called for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.cedarsoft.com/2010/05/analyzing-javafx/">Yesterday I wrote about some JavaFX Internals&#8230;</a>. Today comes the second part.</p>
<p>Today we start to use some of the JavaFX classes by Java. Therefore I just added all JavaFX jars to the classpath.</p>
<h2>Extending FXBase</h2>
<p>It is a very good idea to extend FXBase. We just have to figure out which methods have to be called for initialization. Following the samples, our class could look like that:</p>
<p>[cc lang="java"]<br />
import com.sun.javafx.runtime.FXBase;<br />
import com.sun.javafx.runtime.FXObject;<br />
import com.sun.javafx.runtime.annotation.Public;</p>
<p>@Public<br />
public class Run extends FXBase implements FXObject {<br />
  public static void main( String[] args ) {<br />
    System.out.println( &#8220;Starting!&#8221; );</p>
<p>    System.out.println( &#8220;Finished&#8221; );<br />
  }</p>
<p>  public Run() {<br />
    this( false );<br />
    initialize$( true );<br />
  }</p>
<p>  public Run( boolean paramBoolean ) {<br />
    super( paramBoolean );<br />
  }<br />
}[/cc]</p>
<h2>Approaching that binding stuff</h2>
<p>As mentioned yesterday the magic happens within the DependentsManager. Thankfully that sources are available&#8230;<br />
One key is the <em>WeakBinderRef</em> that can be stored within each <em>FXObject</em> and be retrieved calling <em>getThisRef$internal$()</em>.<br />
There is a static method that creates those refs lazyly: <em>WeakBinderRef.instance()</em>.</p>
<p>This WeakBinderRef contains the dependencies for this object. The field <em>bindees</em> contains a chain of Dep instances. Interestingly the <em>WeakBinderRef</em> for test does not contain any <em>bindees</em> as one might have expected. Those are the reverse dependencies!</p>
<p>The &#8220;real&#8221; dependencies are stored within each object within the field <em>DepChain$internal$</em> (of type <em>DepChain</em>).<br />
Relevant is the <em>bindeeVarNum</em>. Here is the var num stored that dependency is based upon.</p>
<h2>Process of dependency notification</h2>
<p>Whenever a var is changed, there are two calls made to <em>notifyDependents$</em>. They can be distinguished by the <em>phase</em> (argument).<br />
That methods uses the <em>DependentsManager</em> to call invalidate on all depending objects. Those simply change the flag so that the next time the var is accessed, it can be resolved again.</p>
<p>While the binding performance in JavaFX is much better in 1.3 it is still not really lazy. There happen a lot of calls until the value is marked as invalid.<br />
So I assume that the performance has just been increased for complex binding expressions. Just binding one var to another shouldn&#8217;t be much faster now (this is just an assumption!)&#8230;</p>
<h2>Adding dependencies manually</h2>
<p>Now we try to add a dependency manually. It is possible by simply calling &#8220;<em>DependentsManager.addDependent()</em>&#8220;.<br />
Of course it does not have any visible effects (besides that the update/invalidate methods are called). Because the values are fetched from the original objects&#8230; But the debugger shows us, that it is possible to use that bind mechanism from Java.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cedarsoft.com/2010/05/javafx-internals-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Analyzing JavaFX</title>
		<link>http://blog.cedarsoft.com/2010/05/analyzing-javafx/</link>
		<comments>http://blog.cedarsoft.com/2010/05/analyzing-javafx/#comments</comments>
		<pubDate>Wed, 05 May 2010 20:23:40 +0000</pubDate>
		<dc:creator>Johannes Schneider</dc:creator>
				<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[javap]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://blog.cedarsoft.com/?p=302</guid>
		<description><![CDATA[Today I wanted to analyze the internals of JavaFX. This post is the documentation &#8211; primarily made for myself. But maybe useful for somebody else, too&#8230;
Simple class
At first I tried to create a simple class with just one var of type String:
[cc lang="c"]public class Test{
  var value:String = &#8220;asdf&#8221;;
}[/cc]
And then I tried to take [...]]]></description>
			<content:encoded><![CDATA[<p>Today I wanted to analyze the internals of JavaFX. This post is the documentation &#8211; primarily made for myself. But maybe useful for somebody else, too&#8230;</p>
<h2>Simple class</h2>
<p>At first I tried to create a simple class with just one var of type String:</p>
<p>[cc lang="c"]public class Test{<br />
  var value:String = &#8220;asdf&#8221;;<br />
}[/cc]</p>
<p>And then I tried to take a look at the internals. Of course I did not decompile that stuff. Instead I used javap and Reflection to analyze it myself. The result could look like that:</p>
<p>[cc lang="java"]<br />
import com.sun.javafx.runtime.FXBase;<br />
import com.sun.javafx.runtime.FXObject;<br />
import com.sun.javafx.runtime.annotation.Public;<br />
import com.sun.javafx.runtime.annotation.ScriptPrivate;<br />
import com.sun.javafx.runtime.annotation.SourceName;</p>
<p>@Public<br />
public class Test extends FXBase implements FXObject {<br />
  @ScriptPrivate<br />
  @SourceName( &#8220;value&#8221; )<br />
  private String $value;</p>
<p>  public Test() {<br />
    this( false );<br />
    initialize$( true );<br />
  }</p>
<p>  public Test( boolean paramBoolean ) {<br />
    super( paramBoolean );<br />
    this.$value = &#8220;asdf&#8221;;<br />
  }<br />
}[/cc]</p>
<p>So, what is interesting about this?<br />
At first the name of the field is not so nice. Very hard to access using Reflection&#8230; But probably that is intended.<br />
Every JavaFX class extends FXBase (or implement FXObject if extending another Java class).</p>
<p>Well, those information can be found within the sources of FXBase (look at src.zip)&#8230;</p>
<h2>Changing var to def</h2>
<p>What is the difference? There is just an annotation (@Def) added to the field&#8230;<br />
<span id="more-302"></span></p>
<h2>Simple binding</h2>
<p>Of course binding is the most interesting part for me. So let&#8217;s create add simple binding. Therefore we create a second var (&#8220;boundValue&#8221;) and bind it to value using <em>bind value</em>.</p>
<p>And now here comes the wow. Look at that monster javafxc has created:<br />
[cc lang="java"]import com.sun.javafx.runtime.Checks;<br />
import com.sun.javafx.runtime.FXBase;<br />
import com.sun.javafx.runtime.FXObject;<br />
import com.sun.javafx.runtime.annotation.Public;<br />
import com.sun.javafx.runtime.annotation.ScriptPrivate;<br />
import com.sun.javafx.runtime.annotation.SourceName;</p>
<p>@Public<br />
public class Test extends FXBase implements FXObject {<br />
  private static int VCNT$ = 2;<br />
  public static final int VOFF$value = 0;<br />
  public static final int VOFF$boundValue = 1;<br />
  private short VFLG$value;<br />
  private short VFLG$boundValue;</p>
<p>  @ScriptPrivate<br />
  @SourceName( &#8220;value&#8221; )<br />
  private String $value;</p>
<p>  @ScriptPrivate<br />
  @SourceName( &#8220;boundValue&#8221; )<br />
  private String $boundValue;</p>
<p>  public static int VCNT$() {<br />
    return 2;<br />
  }</p>
<p>  public int count$() {<br />
    return 2;<br />
  }</p>
<p>  private String get$value() {<br />
    return this.$value;<br />
  }</p>
<p>  private void invalidate$value( int paramInt ) {<br />
    int i = this.VFLG$value &#038; 0&#215;7;<br />
    int j = ( ( i &#038; paramInt ) == i ) ? 1 : 0;<br />
    if ( j == 0 ) return;<br />
    this.VFLG$value = ( short ) ( this.VFLG$value &#038; 0xFFFFFFF8 | paramInt >> 4 );<br />
    paramInt &#038;= -35;<br />
    notifyDependents$( 0, paramInt );<br />
    invalidate$boundValue( paramInt );<br />
  }</p>
<p>  private String get$boundValue() {<br />
    if ( ( this.VFLG$boundValue &#038; 0&#215;18 ) == 0 ) {<br />
      this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue | 0&#215;400 );<br />
    } else if ( ( this.VFLG$boundValue &#038; 0&#215;104 ) == 260 ) {<br />
      int i = this.VFLG$boundValue;<br />
      this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue &#038; 0xFFFFFFE7 | 0&#215;0 );<br />
      String str = get$value();<br />
      this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue | 0&#215;200 );<br />
      if ( ( this.VFLG$boundValue &#038; 0&#215;5 ) == 4 ) {<br />
        this.VFLG$boundValue = ( short ) i;<br />
        return str;<br />
      }<br />
      this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue &#038; 0xFFFFFFF8 | 0&#215;19 );<br />
      this.$boundValue = str;<br />
    }<br />
    return this.$boundValue;<br />
  }</p>
<p>  private void invalidate$boundValue( int paramInt ) {<br />
    int i = this.VFLG$boundValue &#038; 0&#215;7;<br />
    int j = ( ( i &#038; paramInt ) == i ) ? 1 : 0;<br />
    if ( j == 0 ) return;<br />
    if ( ( ( paramInt &#038; 0&#215;8 ) == 8 ) &#038;&#038; ( ( this.VFLG$value &#038; 0&#215;5 ) == 4 ) ) return;<br />
    this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue &#038; 0xFFFFFFF8 | paramInt >> 4 );<br />
    paramInt &#038;= -35;<br />
  }</p>
<p>  public void applyDefaults$( int paramInt ) {<br />
    if ( !varTestBits$( paramInt, 56, 8 ) ) return;<br />
    switch ( paramInt ) {<br />
      case 0:<br />
        String str = this.$value;<br />
        int i = this.VFLG$value;<br />
        this.VFLG$value = ( short ) ( this.VFLG$value | 0&#215;18 );<br />
        if ( ( !Checks.equals( str, &#8220;asdf&#8221; ) ) || ( ( i &#038; 0&#215;10 ) == 0 ) ) {<br />
          invalidate$value( 97 );<br />
          this.$value = &#8220;asdf&#8221;;<br />
          invalidate$value( 94 );<br />
        }<br />
        this.VFLG$value = ( short ) ( this.VFLG$value &#038; 0xFFFFFFF8 | 0&#215;1 );<br />
        return;<br />
      case 1:<br />
        invalidate$boundValue( 65 );<br />
        invalidate$boundValue( 92 );<br />
        if ( ( this.VFLG$boundValue &#038; 0&#215;440 ) != 0 ) get$boundValue();<br />
        return;<br />
    }<br />
    super.applyDefaults$( paramInt );<br />
  }</p>
<p>  public Object get$( int paramInt ) {<br />
    switch ( paramInt ) {<br />
      case 0:<br />
        return get$value();<br />
      case 1:<br />
        return get$boundValue();<br />
    }<br />
    return super.get$( paramInt );<br />
  }</p>
<p>  public void set$( int paramInt, Object paramObject ) {<br />
    switch ( paramInt ) {<br />
      case 0:<br />
        this.$value = ( ( String ) paramObject );<br />
        return;<br />
      case 1:<br />
        this.$boundValue = ( ( String ) paramObject );<br />
        return;<br />
    }<br />
    super.set$( paramInt, paramObject );<br />
  }</p>
<p>  public void invalidate$( int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5 ) {<br />
    switch ( paramInt1 ) {<br />
      case 0:<br />
        invalidate$value( paramInt5 );<br />
        return;<br />
      case 1:<br />
        invalidate$boundValue( paramInt5 );<br />
        return;<br />
    }<br />
    super.invalidate$( paramInt1, paramInt2, paramInt3, paramInt4, paramInt5 );<br />
  }</p>
<p>  public int varChangeBits$( int paramInt1, int paramInt2, int paramInt3 ) {<br />
    switch ( paramInt1 ) {<br />
      case 0:<br />
        return this.VFLG$value = ( short ) ( this.VFLG$value &#038; ( paramInt2 ^ 0xFFFFFFFF ) | paramInt3 );<br />
      case 1:<br />
        return this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue &#038; ( paramInt2 ^ 0xFFFFFFFF ) | paramInt3 );<br />
    }<br />
    return super.varChangeBits$( paramInt1, paramInt2, paramInt3 );<br />
  }</p>
<p>  public Test() {<br />
    this( false );<br />
    initialize$( true );<br />
  }</p>
<p>  public Test( boolean paramBoolean ) {<br />
    super( paramBoolean );<br />
    this.VFLG$value = 1;<br />
    this.VFLG$boundValue = 769;</p>
<p>    this.$value = &#8220;&#8221;;<br />
    this.$boundValue = &#8220;&#8221;;<br />
  }<br />
}[/cc]</p>
<p>Very interesting. Let&#8217;s take a deeper look:<br />
First two fields are created as expected.</p>
<h4>Dirty flags</h4>
<p>Additionally for both fields a short &#8220;VFLG$&#8221; has been generated. Those hold the dirty state of the var. There is also a static field (int) prefixed with &#8220;VOFF&#8221; for every var. Seems to hold some sort of index?</p>
<h4>Getters</h4>
<p>And now there have been created (private!) getters. The getter for the unbound var is simple. Just returns the field. The getter for <em>boundValue</em> is more interesting:<br />
It contains some checks about its state using <em>VFLG$boundValue</em>. Depending on that state the field is updated (see line 61) using the getter for <em>value</em>. Here we can see that bindings are in fact lazy.</p>
<h4>Invalidate methods</h4>
<p>For every var there has been created an invalidate method. Those change the dirty flag and call <em>notifyDependents$</em>. That method delegates to <em>DependentsManager</em>.<br />
Very interesting: The invalidate method for boudnValue does not call <em>notifyDepenents</em>. This is probably an optimization because the scope of the vars is script.</p>
<h4>Generic methods</h4>
<p>There are generic get/set/invalidate methods that delegate to the corresponding methods based on the index.</p>
<h4>applyDefaults</h4>
<p>This method is also interesting. It is called from FXBase#applyDefaults which itself is called within the constructor. I don&#8217;t know if it is called sometimes else. But probably it is&#8230;</p>
<h4>Constructor</h4>
<p>The constructor is different. It does not initialize the the fields. Instead they are set to their default values.</p>
<h2>One var with <em>on replace</em></h2>
<p>To verify that thought we go one step back: Just one var, but this time we add a <em>on replace</em> method.</p>
<p>[cc lang="java"]import com.sun.javafx.runtime.Checks;<br />
import com.sun.javafx.runtime.FXBase;<br />
import com.sun.javafx.runtime.FXObject;<br />
import com.sun.javafx.runtime.annotation.Public;<br />
import com.sun.javafx.runtime.annotation.ScriptPrivate;<br />
import com.sun.javafx.runtime.annotation.SourceName;<br />
import javafx.lang.Builtins;</p>
<p>@Public<br />
public class Test extends FXBase implements FXObject {<br />
  private static int VCNT$ = 1;<br />
  public static final int VOFF$value = 0;<br />
  private short VFLG$value;</p>
<p>  @ScriptPrivate<br />
  @SourceName( &#8220;value&#8221; )<br />
  private String $value;</p>
<p>  public static int VCNT$() {<br />
    return 1;<br />
  }</p>
<p>  public int count$() {<br />
    return 1;<br />
  }</p>
<p>  private String get$value() {<br />
    return this.$value;<br />
  }</p>
<p>  private void onReplace$value( String paramString1, String paramString2 ) {<br />
    Builtins.println( String.format( &#8220;value changed to %s&#8221;, new Object[]{get$value()} ) );<br />
  }</p>
<p>  public void applyDefaults$( int paramInt ) {<br />
    if ( !varTestBits$( paramInt, 56, 8 ) ) return;<br />
    switch ( paramInt ) {<br />
      case 0:<br />
        String str = this.$value;<br />
        int i = this.VFLG$value;<br />
        this.VFLG$value = ( short ) ( this.VFLG$value | 0&#215;18 );<br />
        if ( ( !Checks.equals( str, &#8220;asdf&#8221; ) ) || ( ( i &#038; 0&#215;10 ) == 0 ) ) {<br />
          this.$value = &#8220;asdf&#8221;;<br />
          onReplace$value( str, &#8220;asdf&#8221; );<br />
        }<br />
        return;<br />
    }<br />
    super.applyDefaults$( paramInt );<br />
  }</p>
<p>  public Object get$( int paramInt ) {<br />
    switch ( paramInt ) {<br />
      case 0:<br />
        return get$value();<br />
    }<br />
    return super.get$( paramInt );<br />
  }</p>
<p>  public void set$( int paramInt, Object paramObject ) {<br />
    switch ( paramInt ) {<br />
      case 0:<br />
        this.$value = ( ( String ) paramObject );<br />
        return;<br />
    }<br />
    super.set$( paramInt, paramObject );<br />
  }</p>
<p>  public int varChangeBits$( int paramInt1, int paramInt2, int paramInt3 ) {<br />
    switch ( paramInt1 ) {<br />
      case 0:<br />
        return this.VFLG$value = ( short ) ( this.VFLG$value &#038; ( paramInt2 ^ 0xFFFFFFFF ) | paramInt3 );<br />
    }<br />
    return super.varChangeBits$( paramInt1, paramInt2, paramInt3 );<br />
  }</p>
<p>  public Test() {<br />
    this( false );<br />
    initialize$( true );<br />
  }</p>
<p>  public Test( boolean paramBoolean ) {<br />
    super( paramBoolean );<br />
    this.VFLG$value = 65;<br />
    this.$value = &#8220;&#8221;;<br />
  }<br />
}[/cc]</p>
<p>What is the difference?<br />
The same stuff is created as in the last example. Of course this is necessary because the on replace method is part of the binding stuff. The difference is, that there has been created a <em>onReplace$value</em> method with two parameters (don&#8217;t know what those parameters represent).<br />
This method is only called in <em>applyDefaults</em>. Probably another optimization.</p>
<h2>Two public-read vars with a on replace method</h2>
<p>This results in something like that:</p>
<p>[cc lang="java"]package com.cedarsoft.collustra;</p>
<p>import com.sun.javafx.runtime.Checks;<br />
import com.sun.javafx.runtime.FXBase;<br />
import com.sun.javafx.runtime.FXObject;<br />
import com.sun.javafx.runtime.annotation.Public;<br />
import com.sun.javafx.runtime.annotation.PublicReadable;<br />
import com.sun.javafx.runtime.annotation.ScriptPrivate;<br />
import com.sun.javafx.runtime.annotation.SourceName;<br />
import javafx.lang.Builtins;</p>
<p>@Public<br />
public class Test extends FXBase implements FXObject {<br />
  private static int VCNT$ = 2;<br />
  public static int VOFF$value = 0;<br />
  public static int VOFF$boundValue = 1;<br />
  public short VFLG$value;<br />
  public short VFLG$boundValue;</p>
<p>  @PublicReadable<br />
  @ScriptPrivate<br />
  @SourceName( &#8220;value&#8221; )<br />
  public String $value;</p>
<p>  @PublicReadable<br />
  @ScriptPrivate<br />
  @SourceName( &#8220;boundValue&#8221; )<br />
  public String $boundValue;</p>
<p>  public static int VCNT$() {<br />
    return 2;<br />
  }</p>
<p>  public int count$() {<br />
    return 2;<br />
  }</p>
<p>  public String get$value() {<br />
    return this.$value;<br />
  }</p>
<p>  public String set$value( String paramString ) {<br />
    if ( ( this.VFLG$value &#038; 0&#215;200 ) != 0 ) restrictSet$( this.VFLG$value );<br />
    String str = this.$value;<br />
    int i = this.VFLG$value;<br />
    this.VFLG$value = ( short ) ( this.VFLG$value | 0&#215;18 );<br />
    if ( ( !Checks.equals( str, paramString ) ) || ( ( i &#038; 0&#215;10 ) == 0 ) ) {<br />
      invalidate$value( 97 );<br />
      this.$value = paramString;<br />
      invalidate$value( 94 );<br />
      onReplace$value( str, paramString );<br />
    }<br />
    this.VFLG$value = ( short ) ( this.VFLG$value &#038; 0xFFFFFFF8 | 0&#215;1 );<br />
    return this.$value;<br />
  }</p>
<p>  public void invalidate$value( int paramInt ) {<br />
    int i = this.VFLG$value &#038; 0&#215;7;<br />
    int j = ( ( i &#038; paramInt ) == i ) ? 1 : 0;<br />
    if ( j == 0 ) return;<br />
    this.VFLG$value = ( short ) ( this.VFLG$value &#038; 0xFFFFFFF8 | paramInt >> 4 );<br />
    paramInt &#038;= -35;<br />
    notifyDependents$( VOFF$value, paramInt );<br />
    invalidate$boundValue( paramInt );<br />
    if ( ( ( paramInt &#038; 0&#215;8 ) != 8 ) || ( ( this.VFLG$value &#038; 0&#215;40 ) != 64 ) ) return;<br />
    get$value();<br />
  }</p>
<p>  public void onReplace$value( String paramString1, String paramString2 ) {<br />
    Builtins.println( String.format( &#8220;value changed to %s&#8221;, new Object[]{get$value()} ) );<br />
  }</p>
<p>  public String get$boundValue() {<br />
    if ( ( this.VFLG$boundValue &#038; 0&#215;18 ) == 0 ) {<br />
      this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue | 0&#215;400 );<br />
    } else if ( ( this.VFLG$boundValue &#038; 0&#215;104 ) == 260 ) {<br />
      int i = this.VFLG$boundValue;<br />
      this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue &#038; 0xFFFFFFE7 | 0&#215;0 );<br />
      String str1 = get$value();<br />
      this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue | 0&#215;200 );<br />
      if ( ( this.VFLG$boundValue &#038; 0&#215;5 ) == 4 ) {<br />
        this.VFLG$boundValue = ( short ) i;<br />
        return str1;<br />
      }<br />
      String str2 = this.$boundValue;<br />
      this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue &#038; 0xFFFFFFF8 | 0&#215;19 );<br />
      if ( ( !Checks.equals( str2, str1 ) ) || ( ( i &#038; 0&#215;10 ) == 0 ) ) {<br />
        this.$boundValue = str1;<br />
        onReplace$boundValue( str2, str1 );<br />
      }<br />
    }<br />
    return this.$boundValue;<br />
  }</p>
<p>  public String set$boundValue( String paramString ) {<br />
    if ( ( this.VFLG$boundValue &#038; 0&#215;200 ) != 0 ) restrictSet$( this.VFLG$boundValue );<br />
    this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue | 0&#215;200 );<br />
    String str = this.$boundValue;<br />
    int i = this.VFLG$boundValue;<br />
    this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue | 0&#215;18 );<br />
    if ( ( !Checks.equals( str, paramString ) ) || ( ( i &#038; 0&#215;10 ) == 0 ) ) {<br />
      invalidate$boundValue( 97 );<br />
      this.$boundValue = paramString;<br />
      invalidate$boundValue( 94 );<br />
      onReplace$boundValue( str, paramString );<br />
    }<br />
    this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue &#038; 0xFFFFFFF8 | 0&#215;1 );<br />
    return this.$boundValue;<br />
  }</p>
<p>  public void invalidate$boundValue( int paramInt ) {<br />
    int i = this.VFLG$boundValue &#038; 0&#215;7;<br />
    int j = ( ( i &#038; paramInt ) == i ) ? 1 : 0;<br />
    if ( j == 0 ) return;<br />
    if ( ( ( paramInt &#038; 0&#215;8 ) == 8 ) &#038;&#038; ( ( this.VFLG$value &#038; 0&#215;5 ) == 4 ) ) return;<br />
    this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue &#038; 0xFFFFFFF8 | paramInt >> 4 );<br />
    paramInt &#038;= -35;<br />
    notifyDependents$( VOFF$boundValue, paramInt );<br />
  }</p>
<p>  public void onReplace$boundValue( String paramString1, String paramString2 ) {<br />
  }</p>
<p>  public void applyDefaults$( int paramInt ) {<br />
    if ( !varTestBits$( paramInt, 56, 8 ) ) return;<br />
    switch ( paramInt ) {<br />
      case 0:<br />
        set$value( &#8220;asdf&#8221; );<br />
        return;<br />
      case 1:<br />
        invalidate$boundValue( 65 );<br />
        invalidate$boundValue( 92 );<br />
        if ( ( this.VFLG$boundValue &#038; 0&#215;440 ) != 0 ) get$boundValue();<br />
        return;<br />
    }<br />
    super.applyDefaults$( paramInt );<br />
  }</p>
<p>  public Object get$( int paramInt ) {<br />
    switch ( paramInt ) {<br />
      case 0:<br />
        return get$value();<br />
      case 1:<br />
        return get$boundValue();<br />
    }<br />
    return super.get$( paramInt );<br />
  }</p>
<p>  public void set$( int paramInt, Object paramObject ) {<br />
    switch ( paramInt ) {<br />
      case 0:<br />
        set$value( ( String ) paramObject );<br />
        return;<br />
      case 1:<br />
        set$boundValue( ( String ) paramObject );<br />
        return;<br />
    }<br />
    super.set$( paramInt, paramObject );<br />
  }</p>
<p>  public void invalidate$( int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5 ) {<br />
    switch ( paramInt1 ) {<br />
      case 0:<br />
        invalidate$value( paramInt5 );<br />
        return;<br />
      case 1:<br />
        invalidate$boundValue( paramInt5 );<br />
        return;<br />
    }<br />
    super.invalidate$( paramInt1, paramInt2, paramInt3, paramInt4, paramInt5 );<br />
  }</p>
<p>  public int varChangeBits$( int paramInt1, int paramInt2, int paramInt3 ) {<br />
    switch ( paramInt1 ) {<br />
      case 0:<br />
        return this.VFLG$value = ( short ) ( this.VFLG$value &#038; ( paramInt2 ^ 0xFFFFFFFF ) | paramInt3 );<br />
      case 1:<br />
        return this.VFLG$boundValue = ( short ) ( this.VFLG$boundValue &#038; ( paramInt2 ^ 0xFFFFFFFF ) | paramInt3 );<br />
    }<br />
    return super.varChangeBits$( paramInt1, paramInt2, paramInt3 );<br />
  }</p>
<p>  public Test() {<br />
    this( false );<br />
    initialize$( true );<br />
  }</p>
<p>  public Test( boolean paramBoolean ) {<br />
    super( paramBoolean );<br />
    this.VFLG$value = 65;<br />
    this.VFLG$boundValue = 769;</p>
<p>    this.$value = &#8220;&#8221;;<br />
    this.$boundValue = &#8220;&#8221;;<br />
  }<br />
}[/cc]</p>
<p>And now (see line 51) the call to <em>onReplace</em> has been added to the setter for <em>value</em>. Now we also understand the meaning of the parameters. The first one is the old value while the second one is the new one.</p>
<p>Interestingly there also has been genereated an empty <em>onReplace</em> method for <em>boundValue</em>. Propably because of overriding stuff?</p>
<p>The getter and setter are both public now. But I just set the scope to public-read. So don&#8217;t understand exactly why it is necessary to make the setter public, too.</p>
<h2>Binding from other class</h2>
<p>Now we create a sample where we bind from another class. Maybe we can learn something new.</p>
<p>[cc lang="c"]<br />
public class Test2{<br />
  var test = Test{};<br />
  public var otherBound = bind test.value;<br />
}<br />
[/cc]</p>
<p>And here is the pseudo java code:</p>
<p>[cc lang="java"]<br />
import com.sun.javafx.runtime.Checks;<br />
import com.sun.javafx.runtime.FXBase;<br />
import com.sun.javafx.runtime.FXObject;<br />
import com.sun.javafx.runtime.annotation.Public;<br />
import com.sun.javafx.runtime.annotation.ScriptPrivate;<br />
import com.sun.javafx.runtime.annotation.SourceName;</p>
<p>@Public<br />
public class Test2 extends FXBase implements FXObject {<br />
  private static int VCNT$ = 2;<br />
  public static final int VOFF$test = 0;<br />
  public static int VOFF$otherBound = 1;<br />
  private short VFLG$test;<br />
  public short VFLG$otherBound;</p>
<p>  @ScriptPrivate<br />
  @SourceName( &#8220;test&#8221; )<br />
  private Test $test;</p>
<p>  @Public<br />
  @SourceName( &#8220;otherBound&#8221; )<br />
  public String $otherBound;<br />
  private static int DCNT$ = 1;<br />
  public static final int DEP$test$_$value = 0;</p>
<p>  public static int VCNT$() {<br />
    return 2;<br />
  }</p>
<p>  public int count$() {<br />
    return 2;<br />
  }</p>
<p>  private Test get$test() {<br />
    return this.$test;<br />
  }</p>
<p>  private void invalidate$test( int paramInt ) {<br />
    int i = this.VFLG$test &#038; 0&#215;7;<br />
    int j = ( ( i &#038; paramInt ) == i ) ? 1 : 0;<br />
    if ( j == 0 ) return;<br />
    this.VFLG$test = ( short ) ( this.VFLG$test &#038; 0xFFFFFFF8 | paramInt >> 4 );<br />
    paramInt &#038;= -35;<br />
    notifyDependents$( 0, paramInt );<br />
    invalidate$otherBound( paramInt );<br />
  }</p>
<p>  private void onReplace$test( Test paramTest1, Test paramTest2 ) {<br />
    int i = Test.VOFF$value;<br />
    FXBase.switchDependence$( this, paramTest1, i, paramTest2, i, 0 );<br />
  }</p>
<p>  public String get$otherBound() {<br />
    if ( ( this.VFLG$otherBound &#038; 0&#215;18 ) == 0 ) {<br />
      this.VFLG$otherBound = ( short ) ( this.VFLG$otherBound | 0&#215;400 );<br />
    } else if ( ( this.VFLG$otherBound &#038; 0&#215;104 ) == 260 ) {<br />
      int i = this.VFLG$otherBound;<br />
      this.VFLG$otherBound = ( short ) ( this.VFLG$otherBound &#038; 0xFFFFFFE7 | 0&#215;0 );<br />
      String str1 = ( get$test() != null ) ? get$test().get$value() : &#8220;&#8221;;<br />
      this.VFLG$otherBound = ( short ) ( this.VFLG$otherBound | 0&#215;200 );<br />
      if ( ( this.VFLG$otherBound &#038; 0&#215;5 ) == 4 ) {<br />
        this.VFLG$otherBound = ( short ) i;<br />
        return str1;<br />
      }<br />
      String str2 = this.$otherBound;<br />
      this.VFLG$otherBound = ( short ) ( this.VFLG$otherBound &#038; 0xFFFFFFF8 | 0&#215;19 );<br />
      if ( ( !Checks.equals( str2, str1 ) ) || ( ( i &#038; 0&#215;10 ) == 0 ) ) {<br />
        this.$otherBound = str1;<br />
        onReplace$otherBound( str2, str1 );<br />
      }<br />
    }<br />
    return this.$otherBound;<br />
  }</p>
<p>  public String set$otherBound( String paramString ) {<br />
    if ( ( this.VFLG$otherBound &#038; 0&#215;200 ) != 0 ) restrictSet$( this.VFLG$otherBound );<br />
    this.VFLG$otherBound = ( short ) ( this.VFLG$otherBound | 0&#215;200 );<br />
    String str = this.$otherBound;<br />
    int i = this.VFLG$otherBound;<br />
    this.VFLG$otherBound = ( short ) ( this.VFLG$otherBound | 0&#215;18 );<br />
    if ( ( !Checks.equals( str, paramString ) ) || ( ( i &#038; 0&#215;10 ) == 0 ) ) {<br />
      invalidate$otherBound( 97 );<br />
      this.$otherBound = paramString;<br />
      invalidate$otherBound( 94 );<br />
      onReplace$otherBound( str, paramString );<br />
    }<br />
    this.VFLG$otherBound = ( short ) ( this.VFLG$otherBound &#038; 0xFFFFFFF8 | 0&#215;1 );<br />
    return this.$otherBound;<br />
  }</p>
<p>  public void invalidate$otherBound( int paramInt ) {<br />
    int i = this.VFLG$otherBound &#038; 0&#215;7;<br />
    int j = ( ( i &#038; paramInt ) == i ) ? 1 : 0;<br />
    if ( j == 0 ) return;<br />
    if ( ( ( paramInt &#038; 0&#215;8 ) == 8 ) &#038;&#038; ( ( this.VFLG$test &#038; 0&#215;5 ) == 4 ) ) return;<br />
    this.VFLG$otherBound = ( short ) ( this.VFLG$otherBound &#038; 0xFFFFFFF8 | paramInt >> 4 );<br />
    paramInt &#038;= -35;<br />
    notifyDependents$( VOFF$otherBound, paramInt );<br />
  }</p>
<p>  public void onReplace$otherBound( String paramString1, String paramString2 ) {<br />
  }</p>
<p>  public void applyDefaults$( int paramInt ) {<br />
    if ( !varTestBits$( paramInt, 56, 8 ) ) return;<br />
    switch ( paramInt ) {<br />
      case 0:<br />
        Test localTest1 = new Test();<br />
        Test localTest2 = this.$test;<br />
        int i = this.VFLG$test;<br />
        this.VFLG$test = ( short ) ( this.VFLG$test | 0&#215;18 );<br />
        if ( ( localTest2 != localTest1 ) || ( ( i &#038; 0&#215;10 ) == 0 ) ) {<br />
          invalidate$test( 97 );<br />
          this.$test = localTest1;<br />
          invalidate$test( 94 );<br />
          onReplace$test( localTest2, localTest1 );<br />
        }<br />
        this.VFLG$test = ( short ) ( this.VFLG$test &#038; 0xFFFFFFF8 | 0&#215;1 );<br />
        return;<br />
      case 1:<br />
        invalidate$otherBound( 65 );<br />
        invalidate$otherBound( 92 );<br />
        if ( ( this.VFLG$otherBound &#038; 0&#215;440 ) != 0 ) get$otherBound();<br />
        return;<br />
    }<br />
    super.applyDefaults$( paramInt );<br />
  }</p>
<p>  public static int DCNT$() {<br />
    return 1;<br />
  }</p>
<p>  public boolean update$( FXObject paramFXObject, int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5 ) {<br />
    switch ( paramInt1 ) {<br />
      case 0:<br />
        if ( paramFXObject == this.$test ) {<br />
          invalidate$otherBound( paramInt5 );<br />
          return true;<br />
        }<br />
    }<br />
    return super.update$( paramFXObject, paramInt1, paramInt2, paramInt3, paramInt4, paramInt5 );<br />
    return false;<br />
  }</p>
<p>  public Object get$( int paramInt ) {<br />
    switch ( paramInt ) {<br />
      case 0:<br />
        return get$test();<br />
      case 1:<br />
        return get$otherBound();<br />
    }<br />
    return super.get$( paramInt );<br />
  }</p>
<p>  public void set$( int paramInt, Object paramObject ) {<br />
    switch ( paramInt ) {<br />
      case 0:<br />
        this.$test = ( ( Test ) paramObject );<br />
        return;<br />
      case 1:<br />
        set$otherBound( ( String ) paramObject );<br />
        return;<br />
    }<br />
    super.set$( paramInt, paramObject );<br />
  }</p>
<p>  public void invalidate$( int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5 ) {<br />
    switch ( paramInt1 ) {<br />
      case 0:<br />
        invalidate$test( paramInt5 );<br />
        return;<br />
      case 1:<br />
        invalidate$otherBound( paramInt5 );<br />
        return;<br />
    }<br />
    super.invalidate$( paramInt1, paramInt2, paramInt3, paramInt4, paramInt5 );<br />
  }</p>
<p>  public int varChangeBits$( int paramInt1, int paramInt2, int paramInt3 ) {<br />
    switch ( paramInt1 ) {<br />
      case 0:<br />
        return this.VFLG$test = ( short ) ( this.VFLG$test &#038; ( paramInt2 ^ 0xFFFFFFFF ) | paramInt3 );<br />
      case 1:<br />
        return this.VFLG$otherBound = ( short ) ( this.VFLG$otherBound &#038; ( paramInt2 ^ 0xFFFFFFFF ) | paramInt3 );<br />
    }<br />
    return super.varChangeBits$( paramInt1, paramInt2, paramInt3 );<br />
  }</p>
<p>  public Test2() {<br />
    this( false );<br />
    initialize$( true );<br />
  }</p>
<p>  public Test2( boolean paramBoolean ) {<br />
    super( paramBoolean );<br />
    this.VFLG$test = 1;<br />
    this.VFLG$otherBound = 769;<br />
    this.$otherBound = &#8220;&#8221;;<br />
  }</p>
<p>}[/cc]</p>
<p>The most interesting part is at line 52: There a call to <em>FXBase.switchDependence$</em> is made every time the test reference is changing. This method delegates to <em>DependentsManager#addDependent</em>.</p>
<p>This is where the magic happens. I think I will take a deeper look at that stuff later.</p>
<h2>Initialzing objects with parameters</h2>
<p>If objects are created using the object literal, the JavaFX compiler generates the calls to set the initial value and calls <em>complete$()</em> on the newly created object finally.<br />
Within complete$() the userInit$() and postInit$() methods are called.</p>
<h2>Conclusion regarding binding</h2>
<p>I hoped to find a way how to bind JavaFX objects to Java objects providing PropertyChangeEvents. Investigating the DependentsManager further might give further hints.<br />
At the moment it looks a little bit difficult since the DependentsManager is working on FXObjects. So it is very probable that at least some kind of adapter objects is necessary&#8230; But who knows&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cedarsoft.com/2010/05/analyzing-javafx/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JavaFX: Template for resizable CustomNode</title>
		<link>http://blog.cedarsoft.com/2010/05/javafx-template-for-resizable-customnode/</link>
		<comments>http://blog.cedarsoft.com/2010/05/javafx-template-for-resizable-customnode/#comments</comments>
		<pubDate>Sat, 01 May 2010 13:31:52 +0000</pubDate>
		<dc:creator>Johannes Schneider</dc:creator>
				<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[CustomNode]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://blog.cedarsoft.com/?p=296</guid>
		<description><![CDATA[Creating a CustomNode is very easy. A template is unnecessary. But when this CustomNode shall be Resizable things start to become a little bit more complicated.
Therefore I have created a template that can be used:
[cc lang="c"]
public class MyCustomNode extends CustomNode, Resizable {
  override var width on replace { requestLayout() }
  override var height [...]]]></description>
			<content:encoded><![CDATA[<p>Creating a CustomNode is very easy. A template is unnecessary. But when this CustomNode shall be Resizable things start to become a little bit more complicated.</p>
<p>Therefore I have created a template that can be used:</p>
<p>[cc lang="c"]<br />
public class MyCustomNode extends CustomNode, Resizable {<br />
  override var width on replace { requestLayout() }<br />
  override var height on replace { requestLayout() }<br />
  override var layoutBounds = bind BoundingBox {<br />
        width: this.width<br />
        height: this.height<br />
    }</p>
<p>  init {<br />
    children =[<br />
      Rectangle {<br />
        width: bind width<br />
        height: bind height<br />
      }<br />
    ]<br />
  }</p>
<p>  override function getPrefWidth( number ) {<br />
    //return your pref width &#8211; hard coded values are ok for most cases<br />
  }</p>
<p>  override function getPrefHeight( number ) {<br />
    //return your pref height &#8211; hard coded values are ok for most cases<br />
  }</p>
<p>  /*<br />
  //It is not absolutly necessary to override those methods, but strongly recommended.<br />
  override function getMaxWidth() {<br />
    //Return the max width<br />
  }</p>
<p>  override function getMaxHeight() {<br />
    //Return the max height<br />
  }</p>
<p>  override function getMinWidth() {<br />
    //Return the min width<br />
  }</p>
<p>  override function getMinHeight() {<br />
    //Return the min height<br />
  }*/<br />
}<br />
[/cc]</p>
<p>There is a post containing a <a href="http://blog.cedarsoft.com/2010/04/javafx-1-3-template-for-custom-controls/">template for CustomControls here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cedarsoft.com/2010/05/javafx-template-for-resizable-customnode/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaFX: Making a CustomNode resizable</title>
		<link>http://blog.cedarsoft.com/2010/05/javafx-making-a-customnode-resizable/</link>
		<comments>http://blog.cedarsoft.com/2010/05/javafx-making-a-customnode-resizable/#comments</comments>
		<pubDate>Sat, 01 May 2010 13:24:31 +0000</pubDate>
		<dc:creator>Johannes Schneider</dc:creator>
				<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[boundsInLocal]]></category>
		<category><![CDATA[CustomNode]]></category>
		<category><![CDATA[Layout]]></category>
		<category><![CDATA[layoutBounds]]></category>
		<category><![CDATA[resizable]]></category>

		<guid isPermaLink="false">http://blog.cedarsoft.com/?p=294</guid>
		<description><![CDATA[Creating a CustomNode is quite easy. There are no gotchas, extending CustomNode and adding some children is enough.
But of course that node is not resizable&#8230;
So this post shows what is necessary to create a CustomNode that extends Resizable. We follow the same setting: The custom node is placed within a Stack.
Step 1: Extending Resizable
Resizable enforces [...]]]></description>
			<content:encoded><![CDATA[<p>Creating a <em>CustomNode</em> is <a href="http://blog.cedarsoft.com/2010/05/javafx-how-to-extend-customnode-properly/">quite easy</a>. There are no gotchas, extending <em>CustomNode</em> and adding some children is enough.<br />
But of course that node is not resizable&#8230;</p>
<p>So this post shows what is necessary to create a <em>CustomNode</em> that extends <em>Resizable</em>. We follow the same setting: The custom node is placed within a <em>Stack</em>.</p>
<h2>Step 1: Extending Resizable</h2>
<p><em>Resizable</em> enforces us to implement the <em>getPrefWidth/Height</em> methods. We just return some hard coded values and try to find out what happens:<br />
The <em>width/height</em> of the <em>CustomNode</em> are set to the values returned by <em>getPrefWidth/Height</em>. But the <em>boundsInLocal</em> and <em>layoutBounds</em> don&#8217;t respect that. They still just depend on the children.</p>
<h2>Step 2: Requesting Layout</h2>
<p>The doc of <em>Resizable</em> tells us that we have to call <em>requestLayout()</em> every time the width/height of the node is changed. Doing this doesn&#8217;t make any difference in this context (within a <em>Stack</em>). But when placed in other layouts this is necessary!</p>
<p>[cc lang="c"]<br />
 override var width on replace { requestLayout() }<br />
  override var height on replace { requestLayout() }<br />
[/cc]</p>
<h2>Step 3: Connecting layoutBounds to width/height</h2>
<p>As we have learned when <a href="http://blog.cedarsoft.com/2010/04/javafx-custom-controls-in-1-3/">looking at <em>CustomControls</em></a> it is a very good idea to bind the <em>layoutBounds</em> to the <em>width/height</em>. This is necessary to avoid difficult layout bugs that will only occur in some situations and are very hard to track down.</p>
<p>[cc lang="c"] override var layoutBounds = bind BoundingBox {<br />
         minX: 0<br />
         minY: 0<br />
         width: this.width<br />
         height: this.height<br />
     }<br />
[/cc]</p>
<p>Now the <em>layoutBounds</em> fit to the <em>width/height</em> of the Node. But of course the sizes of the rectangle(s) are still independent. And the <em>boundInLocal</em> don&#8217;t fit them neither.</p>
<h2>Step 4: Children depend on <em>width/height</em></h2>
<p>Now we connect the <em>width/height</em> of the children to the width/height of our <em>CustomNode</em>.<br />
Now the three values (<em>width/height</em>, <em>layoutBounds</em>, <em>boundsInLocal</em>) correspond correctly with each other.</p>
<p>Important: As <a href="http://blog.cedarsoft.com/2010/04/javafx-about-bounds/">mentioned before</a> it is necessary that width/height always correspond with the <em>layoutBounds</em>. Always! But the <em>boundsInLocal</em> may be different from them (larger or smaller) but have to be influenced by them.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cedarsoft.com/2010/05/javafx-making-a-customnode-resizable/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

