Jim has posted 66 posts at DZone. You can read more from them at their website. View Full User Profile

The JavaFX SDK Packages are Taking Shape

07.01.2008
| 6104 views |
  • submit to reddit

Now that we're getting close to the Technology Preview Release of the JavaFX SDK, the classes that have been created so far have been organized into a more fine-grained package structure. The impact is mainly in the import statements as you can see in this updated Hello/Goodbye example from a previous post. As a quick reference, the list below at the end of this post, contains the packages in JavaFX and the classes that are contained in each package. By the way, you can download the latest Technology Preview Release here and see the API documentation in more detail.

Some Other Recent/Upcoming Changes

 

There have been a couple of changes to JavaFX language syntax recently:

  • The "not equals" operator used to be <> but has been changed to the Java-style !=
  • The modulus (remainder) operator has been changed from % to mod.

Also, a new web services library is in the works that will make it even easier to communicate with remote services required by your application. As a result, the JSON and XML libraries are being pruned from the Technical Preview Release branch, but they are still available in the SVN repository if you need them. You can read the current thinking about the web services library in this message on the dev@openjfx-compiler.dev.java.net mailing list. As is typical with JavaFX libraries, the likely outcome will be a simplification of the design in that message.

Finally, I'd like to point out something that is very exciting to me -- the fact that JavaFX is migrating to a "node-centric" approach. As you may know, underneath the covers of the JavaFX UI for the desktop are Java Swing (components) and Java2D classes (graphical nodes). Eventually, most UI constructs in JavaFX will be graphical nodes, including the components (e.g. Button) and layout panels (e.g. BorderPanel). This will eliminate the need for using "adapter" classes like Canvas (to place a node on a panel) and ComponentView (to place a component on a Canvas). This will also make it easier to create UIs that have an "iPhone look and feel" that users will increasingly expect. As you can see by the fact that Dialog, Frame and Window exist in two packages (javafx.application and javafx.ext.swing), this migration has already begun. An examination of the JavaFX documentation for the Frame class in the javafx.application package, for example, will show you that the content attribute of its Window superclass contains a sequence of Node objects. Compare this with the Frame class in the java.ext.swing package whose Window superclass has a content attribute that still contains a sequence of Component objects. The latter, by the way, will be around at least until the migration to a node-centric UI is complete.

 

JavaFX Package Listing

javafx.application

  • Applet
  • Application
  • Dialog
  • Frame
  • Window

javafx.animation

  • Interpolatable
  • Interpolator
  • KeyFrame
  • KeyValue
  • SimpleInterpolator
  • Timeline

javafx.async

  • AbstractAsyncOperation
  • RemoteTextDocument

javafx.ext.swing

  • AbstractButton
  • AbstractPanel
  • BorderPanel
  • Button
  • Canvas
  • CheckBox
  • CheckBoxMenuItem
  • Cluster
  • ClusterElement
  • ClusterPanel
  • ComboBox
  • ComboBoxItem
  • Component
  • ComponentView
  • Container
  • ContainerGap
  • Dialog
  • FlowPanel
  • Frame
  • Gap
  • GridPanel
  • Icon
  • Label
  • Layout
  • Layout.Alignment
  • Layout.Relationship
  • List
  • ListItem
  • Menu
  • MenuItem
  • Panel
  • ParallelCluster
  • PreferredGap
  • RadioButton
  • RadioButtonMenuItem
  • ScrollPane
  • ScrollableComponent
  • SelectableButton
  • SequentialCluster
  • Slider
  • TextField
  • ToggleButton
  • ToggleGroup
  • Window

javafx.input

  • KeyCode
  • KeyEvent
  • MouseEvent

javafx.lang

  • DeferredTask
  • Duration
  • Sequences

javafx.scene

  • Cursor
  • CustomNode
  • Font
  • FontStyle
  • Group
  • HorizontalAlignment
  • Node
  • Orientation
  • VerticalAlignment

javafx.scene.image

  • Image
  • ImageView

javafx.scene.paint

  • Color
  • CycleMethod
  • LinearGradient
  • Paint
  • RadialGradient
  • Stop

javafx.scene.transform

  • Affine
  • Rotate
  • Scale
  • Shear
  • Transform
  • Translate

javafx.scene.layout

  • HBox
  • VBox

javafx.scene.geometry

  • Arc
  • ArcTo
  • ArcType
  • Circle
  • ClosePath
  • CubicCurve
  • CurveTo
  • DelegateShape
  • Ellipse
  • FillRule
  • HLineTo
  • Line
  • LineTo
  • MoveTo
  • Path
  • PathElement
  • Polygon
  • Polyline
  • QuadCurve
  • QuadTo
  • Rectangle
  • SVGPath
  • Shape
  • ShapeIntersect
  • ShapeSubtract
  • StrokeLineCap
  • StrokeLineJoin
  • VLineTo

javafx.scene.text

  • Text
  • TextOrigin

javafx.scene.media

  • Media
  • MediaError
  • MediaPlayer
  • MediaTimer
  • MediaView

javafx.scene.effect

  • Blend
  • BlendMode
  • Bloom
  • ColorAdjust
  • DisplacementMap
  • DropShadow
  • Effect
  • FloatMap
  • Flood
  • GaussianBlur
  • Glow
  • Identity
  • InnerShadow
  • InvertMask
  • Lighting
  • MotionBlur
  • PerspectiveTransform
  • Reflection
  • SepiaTone
  • Shadow
  • Source

javafx.scene.effect.light

  • DistantLight
  • Light
  • PointLight
  • SpotLight

javafx.util

  • StringLocalizer


Have fun, and please post a comment if you have any questions!

Published at DZone with permission of its author, Jim Weaver.

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

Tags:

Comments

Jacek Furmankiewicz replied on Tue, 2008/07/01 - 8:50am

I have a simple question: what does JavaFX offer to those who would prefer to develop the UI in pure battle-proven Java instead of risking an investment in JavaFX?

How accessible will the underlying JavaFX plumbing be available to pure Java and to a lesser degree other VM languages such as Groovy, Jython or JRuby?

 

GeekyCoder coder replied on Tue, 2008/07/01 - 11:10am

Jacek,

Developer can continue to stick with Java Language if they prefer. The existence of JavaFX Script doesn't mean that existing Swing developer will be neglected. In fact, one important aftermath of development of JavaFX is that it actually bring Java to more updated technology, like include Java Media Component to play back video, audio, SceneGraph for animation and eye candy, improved and simplified support for XML and JSON etc. It is possible that without JavaFX, all these innovations will be developed in matter of time but the JavaFX give Sun a good reason to accelerate those development and bring them to marketplace faster. By developing on JavaFX, the Swing API and capability is also improved as JavaFX is in fact leveraging on Swing and Java2D infrastructure (If one browse through the source code of JavaFX).

JavaFX Script, part of JavaFX, is designed to be higher abstraction language than Java itself. It is a declarative language that able to replace several line of Java code with single command which make it suitable for designer or developer who doesn't want to know the innate of Swing library etc just to get thing done. For example, a developer mocking up interface may not want to deal with low level call just to createo create a sliding effect or swiping effect we see in Flex application.  He just to create a cool user interface quickly so that he can concentrate on building 'guts' of the system.

For example, a designer/developer might not want to deal with programming for special effect but rather issue the following example command

Frame

{

Effect: Sliding 

}

and leave the implementation to JavaFX to figure out.

 

http://openjfx.java.sun.com/hudson/job/openjfx-compiler-technology-preview/lastSuccessfulBuild/artifact//*zip*/archive.zip

How accessible will the underlying JavaFX plumbing be available to pure Java ? It best to that one download the JavaFX archive file and peek at at the following source code of JavaFX Script code (included in the archive file) to judege the extent.  It can be noted that the script is created by the call of public accessible Java class  (eg Media ) which are exposed to the developer. There it can be seen that the same basically vanilla Java class used to create JavaFX script can also be reused fo JGroovy, jruby.

 package javafx.scene.media;

import javafx.lang.Duration;
import com.sun.media.jmc.MediaProvider;
import com.sun.media.jmc.control.AudioControl;
import java.net.URI;
import java.lang.System;
import java.lang.Exception;

/**
 * The {@code MediaPlayer} class provides the controls for playing media.
 * It is used in combination with the {@code Media} and {@code MediaViewer}
 * classes to display and control media playing.
 * @profile common
 * @see Media MediaViewer
 */
 
public class MediaPlayer {
    attribute mediaProvider:MediaProvider = new MediaProvider();
    private attribute view:MediaView;
    // FIXME: multiple views
   
   /**
    * Defines the source {@code Media} to be played
    * @see Media
    * @profile common
    */
    public attribute media:Media on replace {
        try {
            mediaProvider.setSource(new URI(media.source));
        } catch (e:java.lang.Exception) {
            var error:MediaError;
            error = MediaError.exceptionToError(e);
            handleError(error);
      
           
        }
        view.setComponent();
        startTime.millis = mediaProvider.getStartTime()/1000.0;
       
        stopTime.millis = mediaProvider.getStopTime()/1000.0;
        if (autoPlay) {
            play();
        }       
       
  
    }
   
   /**
    * If {@code autoPlay} is {@code true}, playing will start as soon
    * as possible
    *
    * @profile commom
    */
    public attribute autoPlay:Boolean on replace {
        if (autoPlay) {
            play();
        }
    }

    
   /**
    * Starts or resumes playing
    */
    public
    function play() {
        mediaProvider.play();
        paused = false;
    }
   
   /**
    * Pauses playing
    */
   public
   function pause() {
       mediaProvider.pause();
       paused = true;
   }

   /**
    * Indicated if the player has been paused, either programatically,
    * by the user, or because the media has finished playing
    */
   public attribute paused:Boolean;

   /**
    * Defines the rate at which the media is being played.
    * Rate {@code 1.0} is normal play, {@code 2.0} is 2 time normal,
    * {@code -1.0} is backwards, etc...
    */
   public attribute rate:Number on replace {
       mediaProvider.setRate(rate);
   }

   /**
    * Defines the volume at which the media is being played.
    * {@code 1.0} is full volume, which is the default.
    */
   public attribute volume:Number = 1.0 on replace {
       var ac : AudioControl;
       if ((ac = mediaProvider.getControl(ac.getClass())) <> null) {
           ac.setVolume(volume.floatValue());
       }
   }
   /**
    * Defines the balance, or left right setting,  of the audio output.
    * Value ranges continuously from {@code -1.0} being left,
    * {@code 0} being center, and {@code 1.0} being right.
    */
   public attribute balance:Number=0 on replace {
       ;
   }

   /**
    * The fader, or forward and back setting, of audio output
    * on 4+ channel output.
    * value ranges continuously from {@code -1.0} being rear,
    * {@code 0} being center, and {@code 1.0} being forward.
    */
   public attribute fader:Number on replace {
        ;
    }

   private static attribute  DURATION_UNKNOWN:Duration = -1ms;

   /**
    * Defines the time offset where media should start playing,
    * or restart from when repeating
    */
   public attribute startTime:Duration on replace {
       mediaProvider.setStartTime(1000.0*(startTime.millis));
   }
   /**
    * Defines the time offset where media should stop playing
    * or restart when repeating
    */
   public attribute stopTime:Duration = DURATION_UNKNOWN on replace {
       if (stopTime == DURATION_UNKNOWN) {
            // do nothing for now,
            // mediaProvider.setStopTime(java.lang.Double.POSITIVE_INFINITY);
        } else {
            mediaProvider.setStopTime(1000*stopTime.millis);
        }
   }
  
   /**
    * Defines the current media time
    */
   public attribute currentTime:Duration on replace {
       mediaProvider.setMediaTime(1000 * currentTime.millis);
   }
  
    /**
    * Defines the media timers for this player
    */
   public attribute timers:MediaTimer[];
  
   /**
    * Defines the number of times the media should repeat.
    * if repeatCount is 1 the media will play once.
    * if it is REPEAT_FOREVER, it will repeat indefinitely
    * In this implementation, these are the only values currently supported
    * @profile core
    */
   public attribute repeatCount: Number = 1 on replace {
       if (repeatCount == REPEAT_FOREVER) {
           mediaProvider.setRepeating(true);
       } else {
           mediaProvider.setRepeating(false);
       }
   }
 

   /**
    * Defines the current number of time the media has repeated
    * @profile core
    */
  public attribute currentCount:Number=0; // How many times have we repeated


  /**
   * Value of {@code repeatCount} for no repeating (play once)
   * @profile core
   */
   public static attribute REPEAT_NONE:Number = 1;

    /**
     * Value of {@code repeatCount} to repeat forever
     * @profile core
     */
    public static attribute REPEAT_FOREVER:Integer = -1;//infinity;// where is Number.infinity;
  
   /**
    * Equals {@code true} if the player's audio is muted, false otherwise.
    * @profile core
    * @see volume
    */
   public attribute mute: Boolean on replace {
       var ac : AudioControl;
       if ((ac = mediaProvider.getControl(ac.getClass())) <> null) {
           ac.setMute(mute);
       }
   }

    /**
     * Current status of player
     * @profile core
     */
    public static attribute status:Integer;

    /**
     * Status value when player is paused
     * @profile core
     */
    public static attribute PAUSED:Integer=0;

    /**
     * status value when player is playing
     * @profile core
     */
    public static attribute PLAYING:Integer=2;

    /**
     * Status value when player is buffering.
     * Buffering may occur when player is paused or playing
     * @profile core
     */
    public static attribute BUFFERING: Integer=3;

    /**
     * Status value when player is stalled.
     * {@code STALLED} occurs when media is being played, but
     * data is not being delivered fast enough to continue playing
     * @see onStalled
     * @profile core
     */
    public static  attribute STALLED: Integer=4; // occurs during play
  
    /**
     * The {@code onError} function is called when a {@code mediaError} occurs
     * on this player.
     * @profile common
     * @see MediaError
     */
    public attribute onError: function (e: MediaError):Void; // Error in Media


   /**
     * Invoked when the player reaches the end of media
     * @profile common
     */
    public attribute onEndOfMedia: function():Void; // Media has reached its end.

   /**
     * Invoked when the player reaches the end of media.
     * @profile common
     * @see repeatCount
     */
    public attribute onRepeat:function():Void; // Media has hit the end and is repeating
   
    /**
     * Invoked when the player is buffering data.
     * {@code timeRemaining} is an estimate of how much time it will take before
     * the {@code mediaPlayer} can play the media
     * @profile common
     */
    public attribute onBuffering:function(timeRemaining: Duration):Void;

    /**
     * Invoked when the player has stalled
     * because it was not receiving data fast enough to continue playing.
     * {@code timeRemaining} is an estimate of how much time it will take before
     * the {@code mediaPlayer} can continue playing.
     * @profile common
     */
    public attribute onStalled:function(timeRemaining: Duration):Void;
   
   /**
    * Indicates if this player can have multiple views
    * associated with it.
    * @see MediaView
    * @profile common
    */
    public attribute supportsMultiViews:Boolean;
  

   
   // this can fail, or effect other views
   function addView(view:MediaView) {
       this.view = view;
   }

   private function handleError(error: MediaError):Void {
        if (onError <> null) {
                onError(error);
         }
    }
       
}
 

Jacek Furmankiewicz replied on Tue, 2008/07/01 - 11:34am in response to: GeekyCoder coder

Well, this is my real question: will we be able to use this as easily from within Java?

For your 

Frame

{

Effect: Sliding 

}

exampe,  will I be able to do something as simple in Java, e.g.

myFrame.setEffect(Sliding.getInstance());

or

myFrame.setEfect(new Sliding());

etc, etc.

 

or will I have to create 20 lines of code to do something equivalent. I *tried* using Project Scenegraph in pure Java and it's pretty much a nightmare (not helped by the lack of any docs).

I just think that Sun should focus on enhancing the core Swing components for pure Java *first*(since it is such an established language with such a developer mindshare) and then if it wishes it can offer a more dynamic alternative.

You make it sound like all the easy stuff will be available via JavaFX only and achieving the same result via Java will be very complicated. if that's the case, then someone at Sun has done Java a great disservice by making it a second class citizen on its own platform.

People are already complaining that java features are not keeping up with let's say Ruby or C#...splitting Sun's limited resources across two separate languages instead of focusing on the one that is already successful is surely not going to help that situation, is it?

Microsoft didn't drop C# when it came up with Silverlight/WPF/XAML, so I don't quite understand why Sun decided it had to suddenly stop enhancing Java to compete in the RIA space and come up with something brand new instead.

P.S. I won't even go into the fact that if you want to entice Java developers to try a new language you'd better have some darn good Eclipse plugins for JavaFX, since Eclipse is so dominant. So far I see Netbeans-only efforts in this direction, which once again makes selling JavaFX a tall order for any established Java shop.

 

 

 

Andres Almiray replied on Tue, 2008/07/01 - 12:06pm

@Jacek: the answer to your question is unknown until we find out how compiled JavaFX Script works alongside Java. In truth many posts out there show how easily you can refer Java code from a JavaFX Script, but the other way around is scarcely shown, at best you will see it integrated via javax.scripting, a nightmare IMHO as it is not a direct usage of the JavaFX Script classes.

Without a doubt, the "plumbing" Java classes belonging to the JavaFX platform will be accesible from other languages as Groovy/JRuby. Again we will have to wait on the Java side of the integration story so that other languages get clues on how to integrate JavaFX Script classes too.

Regarding tooling support in Eclipse, I too agree that is a must. Sun promotes NetBeans as "the only IDE you need", which is hardly the truth in the IDE market. Eclipse owns the market, period. It doesn't matter if it is or not the best IDE or the only IDE you ever need. Without JavaFX Script support in Eclipse the adoption will be slow. I'm hoping there is a group of Eclipse developers waiting for the final Java FX SDK to start working on an integration plugin. Seeing that both APIs and language syntax are still being changed so close to the release (wasn't it supposed to happen in June??) it looks to be a safe bet to watch from the sideline for the time being.

Jacek Furmankiewicz replied on Tue, 2008/07/01 - 12:14pm in response to: Andres Almiray

Between you and me, I don't understand why JavaFX was even created when such powerful dynamic languages as  Groovy and JRuby already exist...enhancing these already established higher level languages to support FX would be a much easier task (especially since Groovy is already scheduled to be made a standard via a JSR).

Looks like NIH (Not Invented Here) syndrome strikes again.

And as for Netbeans being the only IDE one would ever need...to quote a famous Philip K. Dick saying "Reality is such, that when you ignore it, it doesn't go away".

 

Andres Almiray replied on Tue, 2008/07/01 - 12:30pm in response to: Jacek Furmankiewicz

[quote=Jacek]

Looks like NIH (Not Invented Here) syndrome strikes again.

[/quote]

Sun should consider changing its name to NIH once and for all ;-)

Seriously, having open sourced Java I don't see a reason for NIH still happeing in Sun's open code. Though jfx is supposed to be open, it is not so yet (words from Chris Olivierat http://blogs.sun.com/chrisoliver/entry/key_frame_animation Dec 2007), hopefully that will change soon.

I agree that other languages may provide a good abstraction level, in the case of Groovy/JRuby their metaprogramming facilities are (IMHO) a great tool for productivity and eye-candy (problem is IDE support too). But JavaFX Script has it unique features, for instance everything is an expression, so you can bind to the result of a for loop. You can't do that with other languages (Groovy will provide a better binding construct in a future release. JFX also runs all your code in the EDT(which is good when creating UIs) but very bad when you need to run lengthy operations. Thecurrent alternative is to drop down to Java and call those operations from jfx. Joshua Marinacci commented at J1 that the jfx team is working on a better solution, think of it as creating threads (or registering callbacks) from jfx code, we will have to wait for the final release.

Yeah, waiting seems to go in tandem with jfx since 2007 </rant>

Jacek Furmankiewicz replied on Tue, 2008/07/01 - 12:36pm in response to: Andres Almiray

And in the meantine Flex is running away like the wind...

Comment viewing options

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