Archives for posts tagged ‘javafx’

JavaFX experiment

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 : "MyApp"
scene: Scene {
width: 200
height: [...]

JavaFX Introspection

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("{name} {varType}");
if (varType instanceof FXSequenceType)
{
[...]

JavaFX binding in sequences

I had a Group of circles, i.e.
var circles:Circle[];
var group:Group = Group { content: [circles] };
strangely, I couldn’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’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])
[...]

JavaFX redux

Having spent a few weeks experimenting with JavaFX, and creating several examples, here is an assessment of whether JavaFX succeeds in it’s objective of being a graphics DSL. Bear in mind that I am evaluating it in terms of it’s ease in being a graphics DSL – if it makes my life easier, it succeeds. [...]

Visualizing Sub Prime Losses with JavaFX

Click on image above to launch via WebStart
Drawing rectangles is pretty straightforward in JavaFX. I decided to add a little bit of animation so that the pieces of the puzzle “fall” into place. This is done by applying ParallelTransition which combines ScaleTransition, RotateTransition and TranslateTransition.

Launching JavaFX script via a jar file

Steps:
1. Use javafxpackager to create the .jar file (it will be created in the dist directory). Make sure the dist directory is empty, or you’ll find your jar file growing bigger each time.

javafxpackager -appClass fisheye -src .

2. Launch the jar file, and don’t forget to include the path to the JavaFX libraries

java [...]

JavaFX TextAlignment Gotcha

Here is a minimal test case illustrating how exasperating the default JavaFX Text node can be, especially when aligning text.
You’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 {
[...]

JavaFX Experiments – Order of Declaration Matters

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;
[...]

JavaFX Fidelity

JavaFX gets to start on a clean slate, without burdens of compatibility with browsers. However, how well does it paint itself?
How are – say – 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 [...]

JavaFX for Web Developers

For java developers, JavaFX is a breath of fresh air in terms of conciseness and power. A lot more could be expressed in much less lines.
However, for a web developer, the effort involved in creating some text bounded with a rectangular box on JavaFX is considerably higher compared with HTML.
I recommend starting off with a [...]

javafx and mutability

There seems to be some misconceptions about mutability rules with JavaFX sequences (see here for example).
We can see what is going on under the hood by using the java disassembler (javap).

// seq.fx
var mylist = [1..3];
insert 4 into mylist;

compiling using javafxc seq.fx and then disassembling it with javap -c seq shows us what goes on under [...]

Binding UI representations of Data to Data in JavaFX

I’ve been playing with JavaFX, trying to figure out how to write applications which fetch a list from a database and represent them graphically.
For example, let’s say I’ve fetched a list of numbers from the database, and I wish to represent each number like so:
where the radius becomes bigger the bigger the number is.
There are [...]

JavaFX 1.0 considered

JavaFX 1.0 is finally out of the gate. There are probably many Java engineers and architects who are trying to figure out this technology and see how it could apply to their existing projects. Here is my assessment. Note this applies to JavaFX 1.0.
JavaFX 1.0 is not ready as a Flash replacement in public-facing projects
While [...]

Has the JVM design been holding back Java?

Update:Looks like the post has been linked from DZone. Tell me what you think? What kind of projects would you choose Java applets over Flash or AJAX?

After all these years, Java’s applet has not seen much adoption, while Flash continue to gain mindshare. Applets suffer from slow start up times, crashing browsers, heavy resource usage. [...]

Browsers will Rule Mobile Devices

Five years ago, when prototyping some apps for PDAs, I’d never consider HTML + javascript. This is because there are enough form factor issues as well as browser incompatibilities to keep one awake all night.
Things have changed.
WebKit seems to have gained ground in the mobile space, giving compatibility a much needed shot in the [...]

A concrete proposal for inlining JavaFX

Jan Erik calls me the “high IQ” type. Unfortunately, I think he means “impractical” and “living in an invory tower”.
The idea of a inlining JavaFX script is actually a smaller and incremental goal. It is practical and is achievable. It will allow people who don’t have the JavaFX SDK to experiment with the technology, within [...]

JavaFX and Disembodied Reality

Jan Erik opined insightfully about JavaFX’s prospect:
Java.net is disconnected with reality. For every guy who knows Swing/Java there are a 1000 guys who know HTML/DOM/CSS/Javascript. Silverlight is only marginally important because Microsoft controls 90 percent of the desktop marked and is the company behind C#.
JavaFX will ride the JRE in the same way AIR is [...]

JavaFX Coverflow Part 2

Continuing with our previous example, we now create a CustomNode Coverflows, which contain 11 covers.
A new function called positiveOrZero is introduced so that the tilt angle can be negative.
A fill attribute is introduced to the Cover class and it is bound to the Rectangle.

/**
* Coverflow.fx
**/
package coverflow;

import javafx.application.*;
import javafx.animation.*;
import javafx.input.*;
import javafx.scene.geometry.*;
import javafx.scene.*;
import javafx.scene.paint.*;
import [...]

JavaFX and Unicode source files

The JavaFX compiler supports unicode source files, just as Java compiler does. To use them you need to

make sure the source does not include the three-byte byte-order-mark
call javafxc with the -encoding parameter

javafxc -encoding UTF-8 Chinese.fx
javafx Chinese

And now for the example

import javafx.application.*;
import javafx.scene.Font;
import javafx.scene.text.Text;
import javafx.scene.paint.Color;

Frame {
title: "JavaFX Unicode Example"
width: 400 height: 300
stage: [...]

JavaFX Coverflow Part 1

Warning: Apple Inc apparently has a patent on this. I’m merely doing this for performance comparison purposes and for self-education only.
It’s been about 2 weeks since my first JavaFX session. My initial distaste for the YAML syntax is largely gone. I have avoided using Netbeans, as vim is sufficient. The absence of closing tags in [...]