Peter Pilgrim is professional software developer, designer and architect. Since 1998 he has worked in the financial services industry, investment banking mainly, developing IT for clients. He is a well known specialist in Java Enterprise Edition (Java EE) technology, focused on the server-side and the implementation of electronic commerce. Peter has built professional Java EE apps for top-tier investment banks such as Lloyds Banking Group, UBS, Credit Suisse, Royal Bank of Scotland and Deutsche Bank. Peter is the 91st Oracle Java Champion. Peter is a DZone MVB and is not an employee of DZone and has posted 34 posts at DZone. You can read more from them at their website. View Full User Profile

Devoxx 2008 University Wednesday

12.16.2008
| 4546 views |
  • submit to reddit
The third day of the Devoxx 2008 conference included a keynote from Danny Coward and a great talk on concurrency from Brian Goetz.

 

Keynote: JavaFX: The Platform for Rich Internet Applications

Danny Coward,


Robert Brewin was schedule to give the key note, but unfortunately he had a business meeting. So we all got a very reasonable replacement speaker, Danny Coward. He gave a decent key note speech about the strategy of JavaFX. Clearly the marketing slant of the speech was directed to catch up with Adobe Flex and other nascient technologies.

What was really good was the fact that the FX demonstration were shown in front of live audience for the first time. There were no blow ups as far I as know, unlike JavaOne, earlier this year. Let us not forgot that the European developers, most of them, do not get the chance to fly out to California. JavaFX samples definitely rocked, especially when the video 9 box high definitin video example was pulled out from the browser onto the desktop. The browser was just closed, and the media played on without interruption. My goodness I cannot tell you how proud I was and how grateful I was to see Java client side suddenly rock-and-roll. There were tears in my eye, ever so slightly. Oh yes the example to slaver over, if you ever catch that clever Josh Marinacci, is called Video9Box.

BorderLayout Component

Yours truly recently downloaded the JavaFX 1.0 SDK and much to his chagrin, he found that the kit had no BorderPanel component anymore. This was a major head ache for me,  and I presume other developers wer feeling the pain porting code from Preview to Full Candidate Release. Here is my version of the "missing" BorderLayout.


// XenonBorderPanel.fx, (c) Licence: LGPL: Peter Pilgrim, Created on 08-Dec-2008, 17:31:14

package com.xenonsoft.goliath.game.ui;

import javafx.lang.FX;
import javafx.scene.paint.Color;
import javafx.scene.Node;
import javafx.scene.Group;
import javafx.scene.layout.Container;
import javafx.scene.layout.Resizable;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.ext.swing.SwingButton;
import javafx.ext.swing.SwingComponent;
import java.lang.Math;

/**
 * A class to keep a record of the child constraints
 */
protected class ChildConstraint {
    public var prefWidth: Number = 0;
    public var prefHeight: Number = 0;
    public var resizeWidth: Number = 0;
    public var resizeHeight: Number = 0;

    override function toString(): String {
        return "[width={%7.2f width},height={%7.2f height}, resizeWidth={%7.2f resizeWidth},resizeHeight={%7.2f resizeHeight}]"
    }
}

/**
 * @author Peter Pilgrim
 */

public class XenonBorderPanel extends Container, Resizable {

    public var debug = false;

    protected function updateChildComponent( newChild:Node, oldChild: Node )
    {
        if ( newChild != oldChild ) {
            if ( oldChild != null ) {
                delete oldChild from content;
            }
            if ( newChild != null ) {
                insert newChild into content;
            }
        }
    }

    public var top: Node on replace oldValue {
        updateChildComponent(top,oldValue);
    };
    public var left: Node on replace oldValue {
        updateChildComponent(left,oldValue);
    };
    public var right: Node on replace oldValue {
        updateChildComponent(right,oldValue);
    };
    public var bottom: Node on replace oldValue {
        updateChildComponent(bottom,oldValue);
    };
    public var center: Node on replace oldValue {
        updateChildComponent(center,oldValue);
    };

    // Protected variables to this class and subclasses
    protected var leftChildConstraint: ChildConstraint;
    protected var rightChildConstraint: ChildConstraint;
    protected var topChildConstraint: ChildConstraint;
    protected var bottomChildConstraint: ChildConstraint;
    protected var centerChildConstraint: ChildConstraint;

    /** maximum preferred width of top, center and bottom children */
    protected var maxPrefWidth: Number;
    /** the maximum height of left, center and right children */
    protected var middleHeight;
    /** full width of left, center and right children summed */
    protected var fullWidth;


    public var spacing:Number on replace {
        impl_requestLayout();
    }

    init {
        impl_layout = doBorderLayout;
    }

    public function requestLayout():Void {
        impl_requestLayout();
    }

    public function getPreferredSize(node:Node): ChildConstraint {
        var constraint = ChildConstraint{ };
        if ( node != null ) {
            if ( node instanceof SwingComponent) {
                // Swing Component do not initialise the shadow FX variables min/max/prefs
                var component = (node as SwingComponent).getJComponent();
                constraint.prefWidth    = component.getPreferredSize().width;
                constraint.prefHeight   = component.getPreferredSize().height;
                constraint.resizeWidth  = constraint.prefWidth;
                constraint.resizeHeight = constraint.prefHeight;
            }
            else {
                constraint.prefWidth    = node.boundsInLocal.width;
                constraint.prefHeight   = node.boundsInLocal.height;
                constraint.resizeWidth  = constraint.prefWidth;
                constraint.resizeHeight = constraint.prefHeight;
            }
            if (debug) FX.println("getPreferredSize() ) id={node.id} constraint={constraint}");
        }
        return constraint;
    }

    public function setChildBounds( node: Node, x: Number, y: Number, constraint: ChildConstraint): Void
    {
        if (node instanceof Resizable) {
            var resizable = node as Resizable;
            resizable.width  = constraint.resizeWidth;
            resizable.height = constraint.resizeHeight;
        }
        node.impl_layoutX = x;
        node.impl_layoutY = y;
        if (debug) FX.println("setChildBounds() id={node.id} x={%7.2f x}, y={%7.2f y}, constraint={constraint}");
    }

    public function calculatePreferredSize():Void {
        leftChildConstraint   = getPreferredSize(left);
        rightChildConstraint  = getPreferredSize(right);
        topChildConstraint    = getPreferredSize(top);
        bottomChildConstraint = getPreferredSize(bottom);
        centerChildConstraint = getPreferredSize(center);

        // Compute maximum center preferred width
        maxPrefWidth = Math.max(topChildConstraint.prefWidth, centerChildConstraint.prefWidth);
        maxPrefWidth = Math.max(maxPrefWidth,bottomChildConstraint.prefWidth);
        // Computer maximum center preferred height
        middleHeight = Math.max(leftChildConstraint.prefHeight, centerChildConstraint.prefHeight);
        middleHeight = Math.max(middleHeight, rightChildConstraint.prefHeight);

        // Compute the full width of the border layout minimum requirement
        fullWidth = 2*spacing + leftChildConstraint.prefWidth + maxPrefWidth + rightChildConstraint.prefWidth;
        minimumWidth  = fullWidth;
        // Compute the minium height of the border layout
        minimumHeight = 2*spacing + topChildConstraint.prefHeight + middleHeight + bottomChildConstraint.prefHeight;
        preferredWidth  = fullWidth;
        preferredHeight = 2*spacing + topChildConstraint.prefHeight + middleHeight + bottomChildConstraint.prefHeight;
    }


    public function doBorderLayout(g:Group):Void {

        var x:Number = 0;
        var y:Number = 0;

        calculatePreferredSize();

        // calculate the real size
        if ( width > 0.0 and width > preferredWidth and center != null) {
            centerChildConstraint.resizeWidth = width - (2 * spacing + leftChildConstraint.prefWidth + rightChildConstraint.prefWidth);
            maxPrefWidth = Math.max(topChildConstraint.prefWidth, centerChildConstraint.resizeWidth);
            maxPrefWidth = Math.max(maxPrefWidth,bottomChildConstraint.prefWidth);
        }
        if ( height > 0.0 and height > preferredHeight and center != null) {
            centerChildConstraint.resizeHeight = height - (2*spacing + topChildConstraint.prefHeight + bottomChildConstraint.prefHeight);
            middleHeight = Math.max(leftChildConstraint.prefHeight, centerChildConstraint.resizeHeight);
            middleHeight = Math.max(middleHeight, rightChildConstraint.prefHeight);
        }

        fullWidth = 2*spacing + leftChildConstraint.prefWidth + maxPrefWidth + rightChildConstraint.prefWidth;

        if ( top != null ) {

            topChildConstraint.resizeWidth = fullWidth;
            setChildBounds(top, x, y, topChildConstraint);
            y += topChildConstraint.prefHeight + spacing;
        }

        x = 0;
        if ( left != null ) {
            leftChildConstraint.resizeHeight = middleHeight;
            setChildBounds(left, x, y, leftChildConstraint);
            x += leftChildConstraint.prefWidth + spacing;
        }

        if ( center != null ) {
            setChildBounds(center, x, y, centerChildConstraint);
            x += centerChildConstraint.resizeWidth + spacing;
        }

        if ( right != null ) {
            rightChildConstraint.resizeHeight = middleHeight;
            setChildBounds(right, x, y, rightChildConstraint);
            x += rightChildConstraint.prefHeight + spacing;
        }

        x = 0;
        y += middleHeight + spacing;

        if ( bottom != null ) {
            bottomChildConstraint.resizeWidth = fullWidth;
            setChildBounds(bottom, x, y, bottomChildConstraint);
        }

        if (debug) {
            FX.println("boundsInParent={boundsInParent}");
            FX.println("parent.boundsInLocal={parent.boundsInLocal}");
            FX.println("parent.boundsInParent={parent.boundsInParent}");
            FX.println("parent.boundsInScene={parent.boundsInScene}");
        }

    }

}

public function run(): Void {
    var border: XenonBorderPanel;
    var stage: Stage;
    var scene: Scene;

    stage = Stage {
        title: "Test XenonBorderPanel"
        width: 600;
        height: 800;
        onClose: function() {
            FX.exit();
        }
        scene: scene = Scene {
            content: border = XenonBorderPanel {
                width: bind scene.width
                height: bind scene.height
                top: SwingButton {
                    // foreground:  Color.AZURE
                    id: "Top"
                    text: "Top"
                    action: function(): Void {
                        FX.println("Top");
                    }
                }
                center: SwingButton {
                    id: "Center"
                    text: "Center"
                    action: function(): Void {
                        FX.println("Center");
                    }
                }
                bottom: SwingButton {
                    id: "Bottom"
                    text: "Bottom"
                    action: function(): Void {
                        FX.println("Bottom");
                    }
                }
                left: SwingButton {
                    id: "Left"
                    text: "Left"
                    action: function(): Void {
                        FX.println("Left");
                    }
                }
                right: SwingButton {
                    id: "Right"
                    text: "Right"
                    action: function(): Void {
                        FX.println("Right");
                    }
                }
            }
        }
    }
}
// The End


I make no guarantees for its complete operation. If you have had experience developing user interfaces before, for example X Windows / OSF Motif then it should be really easy to work it out. See my other Blog on Devoxx Thursday for some bullet point items on this BorderLayout.

From Concurrent to Parallel

Brian Goetz

I really enjoyed this presentation, because it was explained the concept of virtual machines so clearly. The jist of Goetz piece was the fact that we are moving from time sliced single CPU machines to the multiple cores CPU machine, where truly parallel operation is physically possible. This presentation would not have made any sense, without a chart of the Moore's law and Goetz explaining how the processor speed has stagnated and in some "chip" line have actually decreased year to year, whereas the number of cores on a chip are doubling. We already have quad-core on desktop and some high end enterprise profile have rack based systems with 768 cores.

Goetz argued that it is not about utilising every single core simultaneously on the machine for our program, but can we, as software engineers, can keep pace with the hardware innovations. He pointed out that the Javac used to have a least often used optimisation flags, but as the Sun Hotspot JVM got better optimising byte code dynamically, it turns out that a compiler can churn badly organised byte code. HotSpot will reorganise the byte code with its adaptive profiling and regeneration algorithms.

A subsequent part of Goetz talk was about the JSR 166y proposal, which includes the new concurrent utilitities, such as Fork-Join. Overall this was talk not to be missed.

Al Coda

Visual VM looks like the ultimate profiling tool. It rocks!

Shout Outs!


Jo Voereendecker, JAVAWUG speaker and member.
Fabrizio Giudici,  Italian blogger supremo
Alex Buckley, good talking to you about closures lack of appearance in JDK 7 and various other small language changes.

From http://www.jroller.com/peter_pilgrim/

Published at DZone with permission of Peter Pilgrim, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

William Gibson replied on Mon, 2009/03/30 - 6:07am

He gave a decent key note speech about the strategy of JavaFX.
Personal Essay | Thesis | Research Paper Writing

William Gibson replied on Wed, 2009/04/01 - 5:55am

We already have quad-core on desktop and some high end enterprise profile have rack based systems with 768 cores.
Cause and Effect Essay | Argumentative Essay

asasa sasa replied on Wed, 2009/07/01 - 12:40pm

Great post. If you need posts you can buy it at writing service : to buy an essays lab

asasa sasa replied on Wed, 2009/07/01 - 12:41pm

Great post. you can buy any posts or
<a href="http://www.essayslab.com/">buy essays</a> here

asasa sasa replied on Wed, 2009/07/01 - 12:41pm

We offer you to <a href="http://www.qualityessay.com">buy essay</a>  or best <a href="http://www.exclusivepapers.com">custom essays</a>

Yuu Ungifo replied on Fri, 2009/08/28 - 6:09am

This is really confusing to be honest. Free PS3 Slim | Free PSP Go

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.