Could JavaFX has the common syntax for object literal, anonymous classes, and AOP?

January 16, 2008

Well,
I have one idea, I could not say it is stupid or not, but looks amazing.
What the following construct is?

Frame {
    title: "Ch1 Demo"
    width: 300
    height: 250
    visible: true
}

Well it is equivalent of:

x = Frame;
x.title= "Ch1 Demo"
x.width= 300
x.height= 250
x.visible= true

or Java’s equivalent (informal, because javafx.ui.Frame is not directly avalable in Java):

Frame x = new Frame();
x.setTitle("Ch1 Demo");
x.setWidth(300);
// and so on

Of course this is just one of the possible equiv in Java… “Straight forward” I could say…

But I begin to think about alternative equivalents:

Frame x = new Frame() {
   // there is no way to add new constructor or initialization code, but let us imagine there is overloadable init() method called from Frame constructor:
   @Override;
   protected init() {
       setTitle("Ch1 Demo");
       setWidth(300);
   }
   ...
}

So I propose the following:
Let the object literal construct to allow also method overriding, adding triggers and so on, just for example:
Let’s assume our frame has paint() method (bad example I know — but let assume such method exists). So let it be possible:

Frame {
    title: "Hello, Wolrd!" on replace {
      throw ModificationProhibitedException; // we prohibit further modification of attribute
    }
    width: 300;
    // and so on
    paint() {
      System.out.println("before paint");
      super.paint();
      System.out.println("after paint");
    }
}

Implementation of such feature may be:
1. As I have already introduced via a kind of “anonymous” classes.
2. Via proxifying original class (using mechanism similar to java.lang.reflect.Proxy or LIBGC).

Of course if there is no method overriding or trigger, then object literal will be as simple as object initialization.

OK let’s assume we have variant 2.

Then it would be possible to extend object literal construct to the following.
Say we already have:

var frame = Frame {title: "Name"};

if we allow following syntax:

frame { // from small letter -- because we would like the following will be applied on specified variable only:
     title on replace {
         System.out.println("title is changed :)  ");
     }
     paint() {
         ... // we could intercept paint() method.
     }
}

thus it would be possible to assign a pretty a lot of attributes with one shot:

frame {
    title: "new title"; // frame.title = "new title"
    width: 200; // frame.width = 200;
}

So varialble{} will resemble PASCAL’s WITH operator :) in such usage scenario.
I could evolve this idea even further
we could treat simple block of code in curly brackets as

Void {
    ...
}

because void is nothing this is just a piece of code… — there is no attribute or method to reference.

How all this may be implemented?
Well I think one of the possible way: for each object to have a data record + some “proxy” over it. This proxy will register overriding original methods and triggers… And constructions like frame { … } should be freely casted to original Frame class and may be “frame instanceof Frame” should return true (not like proxies in Java).

What do you think, mates?


Made JavaFX compiled, finally…

January 16, 2008

Contributors and beta-testers are welcomed to javafx project.
However building process is not so easy as someone may expect…

Is your ADSL fast?

I am lucky to have 256mbit/s…
If you just checkout and start to build it you may notice that it starts to download required tools in Maven style but using plain <get> of ANT. Interesting that it fetchs JUnit, ANT (itself!) and ANTLR and some other libs.
In my particular case build was failed because ant.zip was not expanded and it was not expanded because there is only 4.5 MB of 11MB of ZIP file were downloaded. I solved it the following way I download ant.zip from the mirror, which got me all 11MB. (Seems that apache distributive server has a timeout on downloads which my 256mbit/s does not fit)
I changed:

    <target name="ant" depends="prepare">
        <!-- get src="${ant.url}" dest="${ant.zipfile}" /-->
        <unzip src="${ant.zipfile}" dest="${ant.dir}">
            <patternset includes="**/ant.jar"/>
            <mapper type="flatten"/>
        </unzip>
        <!--delete file="${ant.zipfile}" /-->
    </target>

And run bootstrap.xml in the openjfx-compiler project manualy…
Hopefully all other artifacts where downloaded with no problems.
Those who still has 56K should download everything manually and run bootstrap manually, because if it fails it starts from the very beginning. Be accurate and comment out all “delete file” either otherwise ANT will/may delete your artifacts.

Get more memory to your NB

I forgot to mention that you need NetBeans to build all the stuff.
Most probable that with default settings it will fail to run because of out-of-memory error.
Go to /usr/local/netbeans-6.0/etc and edit netbeans.conf (note: is actually one line, I just wrapped it for readability):

netbeans_default_options="-J-Dorg.netbeans.modules.tomcat.autoregister.token=1200072112148 -J-Dorg.netbeans.modules.tomcat.autoregister.catalinaHome=\"/usr/local/apache-tomcat-6.0.14\"
-J-Dcom.sun.aas.installRoot=\"/usr/local/glassfish-v2\" -J-client -J-Xss2m
-J-Xms200m -J-XX:PermSize=32m
-J-Xmx600m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true"

So I requested 200MB of starting heap size and 600MB of limit. I didn’t investigated how much is actually required, but this limits were enough.

After that I got it successfully compiled and famous bubble test runs, it produces 96fps on my Fedora 8 (built-in Intel 915 GA and Intel T5500 processor — Dual Core).

That is all for now.


Втихоря спешно клепается новая версия JavaFX

January 15, 2008

… а по сути дела другой язык. Где-то в новостях проскакивало, что сам старина Гослинг взялся за JavaFX. Очень может быть. некоторые вещи кардинально пересмотрены. Что обидно; ни где, ни слова об этом нет. Короче жизнь кипит в https://openjfx-compiler.dev.java.net/ это и по email листам видно.


How to escape curly brackets (braces) in JavaFX? I know how, but this is dull…

January 14, 2008

Well I need to write something like:

System.out.println("NewClass{} is just a way to call NewClass constructor");

of course it fails to compile because it expects some code in the curly brackets, then it would execute it and replace curly bracketed code with execution result. How to avoid it?
I found one way to escape it:

System.out.println("NewClass\u007B\u007D is just a way to call NewClass constructor");

However it looks pretty dull (as if I tried to embed some Unicode charter which does not fit current encoding or hard to find on keyboard :) )
May be there is a better way to escape? (Octal and hex escapes are also considered dull :) )
\{ \} is not working, alas…


Bug or somebody has an explanation?

January 13, 2008

Well, seems JavaFX processor (it is not yet a compiler I guess) behaves strangely.
I have simple ClassChild inheriting from ClassParent:

ClassParent.fx
package strangeinheritance;

class ClassParent {
    attribute a: Number;
    attribute b: String;
}
ClassChild.fx
package strangeinheritance;

class ClassChild extends ClassParent {
    attribute b: Integer;
    attribute c: String;
}

attribute ClassChild.b = 100;
attribute ClassChild.c = "any text";

and simple usage scenario:

Main.fx
package strangeinheritance;

import java.lang.System;
var cc = ClassChild{};
var cp = ClassParent{};
System.out.println("cc.a = {cc.a}, cc.a.class = {cc.a.class}");
System.out.println("cc.b = {cc.b}, cc.b.class = {cc.b.class}");
System.out.println("cp.b = {cp.b}, cp.b.class = {cp.b.class}");
System.out.println("cp.a = {cp.a}, cp.a.class = {cp.a.class}");

I really surprised that this code runs, but it does:

cc.a = 0, cc.a.class = class Integer extends Number {
        // intrinsic java.lang.Number
        operation byteValue() : Integer;
        operation doubleValue() : Number;
        operation floatValue() : Number;
        operation intValue() : Integer;
        operation longValue() : Integer;
        operation shortValue() : Integer;
}

MIN_LONG : Integer = -9.223372036854776E18
MIN_SHORT : Integer = -32768.0
MIN_BYTE : Integer = -128.0
MAX_INT : Integer = 2.147483647E9
MAX_LONG : Integer = 9.223372036854776E18
MIN_INT : Integer = -2.147483648E9
MAX_SHORT : Integer = 32767.0
MAX_BYTE : Integer = 127.0
cc.b = 100, cc.b.class = class Integer extends Number {
        // intrinsic java.lang.Number
        operation byteValue() : Integer;
        operation doubleValue() : Number;
        operation floatValue() : Number;
        operation intValue() : Integer;
        operation longValue() : Integer;
        operation shortValue() : Integer;
}

MIN_LONG : Integer = -9.223372036854776E18
MIN_SHORT : Integer = -32768.0
MIN_BYTE : Integer = -128.0
MAX_INT : Integer = 2.147483647E9
MAX_LONG : Integer = 9.223372036854776E18
MIN_INT : Integer = -2.147483648E9
MAX_SHORT : Integer = 32767.0
MAX_BYTE : Integer = 127.0
cp.b = 0, cp.b.class = class Integer extends Number {
        // intrinsic java.lang.Number
        operation byteValue() : Integer;
        operation doubleValue() : Number;
        operation floatValue() : Number;
        operation intValue() : Integer;
        operation longValue() : Integer;
        operation shortValue() : Integer;
}

MIN_LONG : Integer = -9.223372036854776E18
MIN_SHORT : Integer = -32768.0
MIN_BYTE : Integer = -128.0
MAX_INT : Integer = 2.147483647E9
MAX_LONG : Integer = 9.223372036854776E18
MIN_INT : Integer = -2.147483648E9
MAX_SHORT : Integer = 32767.0
MAX_BYTE : Integer = 127.0
cp.a = 0, cp.a.class = class Integer extends Number {
        // intrinsic java.lang.Number
        operation byteValue() : Integer;
        operation doubleValue() : Number;
        operation floatValue() : Number;
        operation intValue() : Integer;
        operation longValue() : Integer;
        operation shortValue() : Integer;
}

MIN_LONG : Integer = -9.223372036854776E18
MIN_SHORT : Integer = -32768.0
MIN_BYTE : Integer = -128.0
MAX_INT : Integer = 2.147483647E9
MAX_LONG : Integer = 9.223372036854776E18
MIN_INT : Integer = -2.147483648E9
MAX_SHORT : Integer = 32767.0
MAX_BYTE : Integer = 127.0

Looks as if interpreter knows nothing about b:String declaration in ClassParent :)
What I found and what surprised me much, I added only 2 lines to Main.fx:

package strangeinheritance;

import java.lang.System;
import strangeinheritance.ClassChild;
import strangeinheritance.ClassParent;
var cc = ClassChild{};
var cp = ClassParent{};
System.out.println("cc.a = {cc.a}, cc.a.class = {cc.a.class}");
System.out.println("cc.b = {cc.b}, cc.b.class = {cc.b.class}");
System.out.println("cp.b = {cp.b}, cp.b.class = {cp.b.class}");
System.out.println("cp.a = {cp.a}, cp.a.class = {cp.a.class}");

And I got (as one should expect):

Error in file:/home/alex/NetBeansProjects/StrangeInheritance/src/strangeinheritance/ClassChild.fx:8: incompatible types: expected String, found Integer in 100

This behaviour looks correct. Any idea why? or just a bug?


JavaFX

January 12, 2008

Так уж сложилось чтобы Sun не придумала, что бы не предложило сообществу, мне оно всегда нравится или симпотично. Всегда хочется взять это, покрутить, повертеть. Году эдак в 2002 меня так например увлёк проект JXTA, не то что бы я сильно разобрался в этой технологии (более того, я забросил это изучение в конце-концов, так как это не клеилось с моей основной работой ну никак), но я освоил много разных тулов, которые я бы никогда не попробовал в тесном мирке Visual Age, который тогда господствовал (будь он проклят :) ). Так я освоил ANT, вкусил DocBook, вообще узнал что есть оказывается жизнь за границами корпоративных тулов и библиотек — мир open-source…

Вот и JavaFX зацепил маленько: наверное маркетологи Sun грамотно работают… толи название зацепило, толи то, что технология новая, толи то, что она на главной странице java.sun.com висит, вообщем попробуем поизучать посмотрим что из этого получится :) Так что решено, с сегодняшнего дня постараюсь уделять этой технологии своё свободное время.