1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5 <title>javafx.beans.binding</title> 6 </head> 7 <body> 8 <p>Provides classes that create and operate on a {@link Binding Binding} 9 that calculates a value that depends on one or more sources.</p> 10 <h1>Characteristics of Bindings</h1> 11 <p>Bindings are assembled from one or more sources, usually called 12 their dependencies. A binding observes its dependencies for changes 13 and updates its own value according to changes in the dependencies.</p> 14 <p>Almost all bindings defined in this library require 15 implementations of {@link javafx.beans.Observable} for their 16 dependencies. There are two types of implementations already provided, 17 the properties in the package {@link javafx.beans.property} and the 18 observable collections ({@link javafx.collections.ObservableList} and 19 {@link javafx.collections.ObservableMap}). Bindings also implement 20 {@code Observable} and can again serve as sources for other bindings 21 allowing to construct very complex bindings from simple ones.</p> 22 <p>Bindings in our implementation are always calculated lazily. 23 That means, if a dependency changes, the result of a binding is not 24 immediately recalculated, but it is marked as invalid. Next time the 25 value of an invalid binding is requested, it is recalculated.</p> 26 <h1>High Level API and Low Level API</h1> 27 <p>The Binding API is roughly divided in two parts, the High Level 28 Binding API and the Low Level Binding API. The High Level Binding API 29 allows to construct simple bindings in an easy to use fashion. 30 Defining a binding with the High Level API should be straightforward, 31 especially when used in an IDE that provides code completion. 32 Unfortunately it has its limitation and at that point the Low Level 33 API comes into play. Experienced Java developers can use the Low Level 34 API to define bindings, if the functionality of the High Level API is 35 not sufficient or to improve the performance. The main goals of the 36 Low Level API are fast execution and small memory footprint.</p> 37 <p>Following is an example of how both APIs can be used. Assuming 38 we have four instances of {@link 39 javafx.beans.property.DoubleProperty} {@code a}, {@code b}, {@code 40 c} , and {@code d}, we can define a binding that calculates {@code a*b 41 + c*d} with the High Level API for example like this:</p> 42 <p>{@code NumberBinding result = Bindings.add (a.multiply(b), 43 c.multiply(d)); }</p> 44 <p>Defining the same binding using the Low Level API could be done 45 like this:</p> 46 <pre> 47 <code> 48 DoubleBinding foo = new DoubleBinding() { 49 50 { 51 super.bind(a, b, c, d); 52 } 53 54 @Override 55 protected double computeValue() { 56 return a.getValue() * b.getValue() + c.getValue() * d.getValue(); 57 } 58 }; 59 </code> 60 </pre> 61 </body> 62 </html>