Open Source JavaFX Now!

Steve On Java - JavaFX

Hacking Java, JavaFX, and Flash with Agility
  • rss
  • Home
  • About
  • Contact
    • E-mail Steve
    • SC2 Challenge
  • SvJugFX
  • JavaFX Petition
  • JFXtras
    • JFXtras Individual CLA
    • JFXtras Corporate CLA
  • Freedom From XML

JavaOne is Rebuilding Momentum

steveonjava | October 10, 2011

Just finished up an extremely busy week at JavaOne and there was a lot to like about this year’s event.  There were plenty of surprise announcements, lots of good content/sessions, and a lot of improvements on the venue and organization.

For folks who have been patiently waiting for me to publish all my talks, I apologize for the delay…  giving 4 talks + a keynote (plus 3 more talks at Silicon Valley Code Camp yesterday) was a lot more work than I expected.  To make sure I can cover the topics and code in enough detail I am going to publish 1 talk plus commentary a day for the next week.  Please follow me on twitter or rss to catch the updates as they roll out.

To get you started, here are some of the highlights from JavaOne:

JavaFX is back in the spotlight!

After a year of hibernation, JavaFX is back with a 2.0 release, big open source announcement (more on this below), and mobile prototypes on Android and iOS.  For those naysayers who said JavaFX is dead, Oracle has proved that they are going to continue to move the platform forward and support state-of-the art development on Java client technology.  As always, Jasper and the rest of the JavaFX team had some pretty impressive demos and the entire Java community was re-energized about the future of client Java.

If you haven’t already, go download JavaFX 2.0 right now!  It is available in production for Windows and there is a developer preview of Mac OS X, so you have no excuse for not trying it out today.  (unless you are on Linux…  but that is supposed to be coming soon too)

The Open Source Petition Was Successful!

Thanks to all my blog readers who spent the time and energy to sign and support the petition to open source JavaFX.  In part due to the huge community sentiment about the need to open source JavaFX, Oracle has taken action and promised to open source the entire platform.  They are going to start with the controls library as announced last year, and continue to open source the entire platform as part of the OpenJDK project.

This is a huge benefit to JavaFX, which will finally be getting equal treatment with the rest of the Java platform.  They are also actively working on getting JavaFX to be fully redistributable, which will remove yet another obstacle to making JavaFX the standard for desktop development.

Community, Community, Community.

Oracle has been listening to the Java community, and put in place many of the changes and suggestions that were raised.  This was evident in the entire JavaOne conference, which was a huge improvement over last year’s event.  Some of the improvements that I noticed while hanging out at JavaOne this year included:

  • A Community-focused Keynote – While I may have been biased as a participant, I thought the best keynote of the conference was the wrap-up community keynote that Sharat Chander lead.  This included some amazing demos by the Duke’s Choice Winners of audible development for the blind and home automation using Glassfish, a spicy panel that had a lot of positive things to say about the Java Community and OSCON Java, and a surprise appearance by the Java Posse who were at 3/4 of their finest!  (the 1/4 being poor Tor, the Googler)
  • Community Hang Spaces – While navigating the conference it was much easier to bump into folks you know by hanging around one of the many hang spaces that were built out around the venue.  In fact, Dean Iverson and I found ourselves preparing for one of our talks in the hang area, because it was more conducive to collaboration and interaction than the speaker room.
  • Easier Venue Navigation – A couple things contributed to this…  One was that all 3 hotels were reserved for JavaOne talks, so you had more talks concentrated in the same vicinity.  Another was the plethora of helpful staff directing traffic and answering questions (I made quite a lot of use out of this myself).  Finally, the signage and open tent configuration made it much easier to get form Point A to Point B.

And a Few Things to Improve for Next Year…

Everyone has their personal gripes…  here are some of mine:

  • Fewer Sponsored Keynotes – When you pay big $$$ to attend a conference, the last thing you want to do is sit in a session and watch a canned talk by a corporate stooge.  The Juniper Networks talk was a particularly blatant example of something that was not really focused on the Java crowd tossed in as a sales kick-back.  In the future, it would be better to make the sponsors earn the attention of the attendees by labeling the talks as sponsored and giving attendees some alternatives.
  • Better Network Connectivity – It was almost impossible to get on the wifi network in any crowded situation (like a session), and once connected the response times were abysmal. That is until everyone left around Thursday midday and the network started going blazingly fast for those who stuck it out for the last few talks.  :)
  • Improved Tech Support on Talks – I listened to the presenter advice and formatted all my slides in 16:9, which didn’t seem to work for the first couple talks that had big black letter-boxes above and below the slides.  Also, my first talk had no network connectivity on the wired connection (and as I mentioned, wireless was useless).  However, I had to the good fortune of giving way too many talks, so by the time I got to my 3rd and 4th ones they seemed to have figured out how to use the very expensive screen adjustment boxes and got everything tuned just right.  Also, the wired network seemed to work fine in all the other rooms I hi.
  • Patching Things Up With Google – This is the second year that Google has refused to let anyone speak at JavaOne. They blame the lawsuit for this, but at some point the policy is more retaliation than just good legal defense. (Is letting Tor speak on stage in a community setting is really going to jeopardize the Android platform?) The real losers in this battle are the average developer who is missing out on great technology and content from one of the most innovative companies in the world.

Overall, JavaOne was a great conference this year, and is definitely back on the upswing.  There was mention of improving the venue in the community keynote, and I hope the upper management at Oracle takes this seriously.  The 3-hotel setup is not ideal, and really not large enough to contain the Java community.  It is time to unleash the Java Community in a full conference venue of its own.

 
Comments
1 Comment »
Categories
Events, JavaFX, OSCON Java, Uncategorized
Tags
community, JavaFX, javaone
Comments rss Comments rss
Trackback Trackback

JavaFX 2.0 and Scala, Like Milk and Cookies

steveonjava | September 27, 2011

JavaFX 2.0 and Scala are both great technologies individually, but work even better when used together.  JavaFX 2.0 is a powerful rich client technology with advanced graphics, animation, and media capabilities.  Scala is a simple, yet powerful language with advanced language features for writing domain-specific languages (DSLs).  Add a little Scala UI DSL to your JavaFX 2.0 project and you will be in cookie and cream heaven!

Time Lapse Photography Creative Commons Licensed by Robbie’s Photo Art

JavaFX Colored Circles

I will go into more detail on why Scala in a bit, but I believe this is all best illustrated with a code example.  One of the basic examples of JavaFX 2.0 functionality that comes with the SDK is a sample application called ColorfulCircles.  The full source code can be found here:

Java Colored Circles Code

With the help of Sven Reimers, we ported this to Scala on top of the ScalaFX library.  The working application source can be found here:

ScalaFX Colored Circles Code

Update: Dean Iverson has a great example of the same code in GroovyFX

Feel free to peruse the source code at your leisure, and take note of the following:

1. ScalaFX is More Concise

The ScalaFX version is shorter both in number of lines and more importantly number of characters.

Code Count (excluding licenses and imports):

  • Lines:
    • Java: 48
    • ScalaFX: 42
  • Characters:
    • Java: 1602
    • ScalaFX: 866

This is due to custom tailored DSL language that is fully expressive with less redundancy.  In the Java version of the code you will notice a lot more boilerplate and syntactic repetition that is required by the language.

2. ScalaFX Code Looks Like the Output

While the output of the Colored Circles example is quite simple, it actually hides quite a bit of complexity in the way it is structured.  Here is the output run from JavaFX 2.0 Build 45 using ScalaFX:

What you are actually seeing is a SceneGraph composed of the following layers:

  • A Scene with a black background that contains…
    • A Group that contains
      • 30 semi-transparent Circles covered by…
    • A rainbow-colored Rectangle overlay

When reading the ScalaFX code you get this nesting through the object-literal style declaration of the Nodes in the Scene as excerpted here:

// ScalaFX Scene Excerpt:
scene = new Scene {
  content = Seq(
    new Group {
      circles = for (i <- 0 until 30) yield new Circle { ... }
    }
    new Rectangle { ... }
  )
}

However, the Java version does not give you the same hierarchical representation, and instead uses an imperative series of calls to constructors, getters, and collection methods.

3. Tailored Animation Syntax

Animations are very commonly used in creating good UIs, which is why JavaFX Script had a built-in construct to simplify the creation of animations. ScalaFX has a similar syntax that allows you to quickly and easily create animations, which is used in the ColorfulCircles example:

Seq(
  at(0 s) {circle.centerX -> random * 800},
  at(0 s) {circle.centerY -> random * 600},
  at(40 s) {circle.centerX -> random * 800},
  at(40 s) {circle.centerY -> random * 600}
)

This makes it trivially easy to create complex animations.

4. And the ScalaFX Version Has a Hidden Bonus Feature…

Unlike the JavaFX version, the contents are bound to the width and height of the stage. Binding in ScalaFX is as simple as replacing the assignment operator (=) with the bind operator (<==) as shown here:

// ScalaFX Property Setting:
width <== scene.width
height <== scene.height

While this is a simple operator change in ScalaFX, it requires complex enough code that they decided to omit it from the JavaFX sample. A loose translation to Java would be the following:

// Java Fixed Property Binding
colors.widthProperty().bind(scene.widthProperty())
colors.heightProperty().bind(scene.heightProperty())

Although, the precise equivalent code in Java syntax would actually be the following:

// Java Dynamic Property Binding
colors.widthProperty().bind(Bindings.selectDouble(primaryStage.sceneProperty(), "width"))
colors.heightProperty().bind(Bindings.selectDouble(primaryStage.sceneProperty(), "height"))

Either of these versions is quite a bit more complex and unwieldy than the ScalaFX equivalent, and this is for a very simple binding!

About ScalaFX

ScalaFX is a UI DSL written within the Scala Language that sits on top of JavaFX 2.0 (not to be confused with Ingo Maier’s great work on Functional Reactive Programming for Swing). This means that every ScalaFX application is also a valid Scala application. By extension it supports full interoperability with Java and can run anywhere the Java Virtual Machine (JVM) and JavaFX 2.0 are supported.

Some of the features of ScalaFX include:

A Programmer-Friendly Object-Literal-Like Syntax

ScalaFX uses a simple, hierarchical pattern for creating new objects and building up the scene graph.  Here is a simple example that creates a new stage with a rectangle that changes color based on mouse events:

stage = new Stage {
  title.value = "Hello Stage"
  width = 600
  height = 450
  scene = new Scene {
    fill = Color.LIGHTGREEN
    content = new Rectangle {
      x = 25
      y = 40
      width = 100
      height = 100
      fill <== when (hover) then Color.GREEN otherwise Color.RED
    }
  }
  visible = true
}

Unlike the builders you find in the core JavaFX APIs, the ScalaFX object declaration syntax uses the normal object API. This means that you can use the same operators and convenient syntax to create and modify your scene graph. Also, anything that is permissible in a Scala block (such as variable declarations, method calls, binding, etc.) can also be done inline while constructing objects. For JavaFX builders you need to declare binding after you finish creating your objects, which leads to disassociated and hard to maintain code.

Natural Language Bind Expressions

One of the greatest advantages of using the Scala language as a DSL is the rich support for operators as methods. This is similar to the C++ concept of operator overloading, but much more uniform and clean in its application.

The ScalaFX bind library exposes normal operators such as &&, ||, +, -, *, / on top of all bindable objects. Also, Scala supports operator precedence, so it looks and feels like you are writing normal expressions even though you are creating bound objects under the covers. As a result, you have the full functionality available from the JavaFX 2.0 binding libraries with code that looks akin to mathematical expressions and operators.

Here are some examples of what you can do with the ScalaFX bind API:

Infix Addition/Subtraction/Multiplication/Division/etc.

height <== rect1.height + rect2.height

Aggregate Operators

width <== max(rect1.width, rect2.width, rect3.width)

Conditional Expressions

color <== when (hover) then Color.GREEN otherwise Color.RED

Complex Boolean Expressions and String Concatenation

text <== when (rect.hover || circle.hover && !disabled) then textField.text + " is enabled" otherwise "disabled"

Free-form Invalidation and Change Handlers

rect.hover onInvalidate {
  needsRepaint = true
}

Fully Type-Safe APIs

This may seem like an insignificant point…  Type safety is something that Java developers have always had (and often take for granted), and developers in other scripting languages live without (and unknowingly suffer with runtime errors as a result). However, it is a critical feature if you are developing applications that cannot have unexpected runtime errors and bugs after deployment.

A good compiler will be able to pick up many common coding mistakes through comparison of expected and actual types, and a great compiler (like Scala) will automatically infer types for you so you don’t have to tediouisly repeat them throughout your code.

ScalaFX gets the best of both worlds with a scripting-like DSL syntax where you can rarely have to explicitly type objects, with the strong type-safety of the Scala compiler that will infer and check the types of every expression and API call. This means less time spent debugging weird code bugs and misspellings, and higher quality code right out of the gate!

Seamless JavaFX/ScalaFX Interoperability

It is often the case that you do not have complete freedom about the predominant language of the codebase, or of the libraries you are including functionality from.  Even in a mixed environment codebase where you have Java, Scala, and possibly other JVM languages, ScalaFX will seamlessly convert and interoperate.

ScalaFX gets this functionality through the implicit operator capabilities of Scala.  Anywhere your program expects a JavaFX typed object, it will automatically insert the code to convert from ScalaFX wrapped objects to JavaFX native classes.  Any time you use a ScalaFX specific feature, the compiler automatically creates a ScalaFX wrapper object that allows you to call advanced methods and access the full functionality. This all happens behind the scenes, letting you focus on writing clean code, and not fussing about integration and interoperability.

With all this interoperability magic happening behind the scenes, there is some additional overhead on your application. We have taken pains to minimize this using features like @specialize in the Scala language, which allows us to avoid boxing and unboxing costs on primitives. However, without real benchmarks it is hard to tell just how good of a job we have done. Hopefully more on this in a future post.

Finding out More About ScalaFX

The ScalaFX project site is hosted by Google Code including a couple mailing lists that you should join if you are interested:

  • ScalaFX Users
  • ScalaFX Developers

At the time of writing we do not have a bundled release, but are interested in early adopter feedback.  If you would like to give it a try, please download the source and give it a quick spin!

I will have more details about ScalaFX at my upcoming JavaOne session with Dean Iverson entitled “JavaFX 2.0 With Alternative Languages“.  Come to hear more about Scala, Groovy, and other JVM languages you can use to write simpler, cleaner code.

 
Comments
10 Comments »
Categories
JavaFX, ScalaFX
Tags
dsl, JavaFX, javafx 2.0, ScalaFX
Comments rss Comments rss
Trackback Trackback

Steveonjava Track at JavaOne

steveonjava | September 1, 2011

The JavaOne Session Builder is now up and available for setting up your sessions. If you are not used to the JavaOne ritual, it is always a good idea to sign-up for sessions well in advance so you don’t get bumped out of the more popular ones. This also helps them fix the room allocation so popular talks get the right size room.

I put together my own schedule of all the JavaFX-related content I plan to attend, and published it on Google Calendar. It is also a pretty good guide to some of the top JavaFX content that is being featured at JavaOne this year. — Apologies to my fellow speakers with conflicting session slots. I wish I could be in multiple places at once, but even rich client technology is not that advanced — yet.

Note: Click for details — sessions I am actually giving are highlighted in green.

Also, for those of you brave enough to attempt to use the schedule builder, it is no simple feat. The UI is fairly convoluted, so getting your schedule tweaked to be just right takes a lot of time and experimentation. Fortunately, I did a lot of this work for you and have figured out the happy path through the system.

JavaOne Schedule Builder Happy Path:

  1. Login to the system and go to the JavaOne Content Catalog
  2. Setup your filters to get the sessions you want (if you are reading this, you probably want to search on “javafx”)
  3. Click on the stars to pick the sessions you are interested in — this adds them to the “My interests” list
  4. Finally, click on “Schedule My Interests” and follow the little wizard UI

Just about any other path through the system (scheduling by time, resolving conflicts as you add sessions, etc.) is fraught with peril, so be warned. :)

Enjoy, and I hope to see you at JavaOne!

 
Comments
1 Comment »
Categories
Events, JavaFX, JFXtras, Presentation, Visage
Tags
JavaFX, javaone, JFXtras, Visage
Comments rss Comments rss
Trackback Trackback

OSCON Java Makes a Difference

steveonjava | August 1, 2011

What was the last conference you went to where you felt like you actually had a positive impact on the larger technical community? A lot of conferences feel like corporate marketing where companies (usually the ones that pay the big sponsorship $$$) are pushing you to buy services or product. Other conferences feel like brainwashing where the message is constrained by a “Ministry of Truth” that limits the topics and speakers to those that align to their world view. No matter how many big parties and aging rock stars they truck in to woo the masses, you leave the conference feeling like you have been sold a technical lemon.

If you were fortunate enough to be at OSCON Java this past week, you were able to experience a different type of conference first hand.  Here are some of the ways in which OSCON Java was not just another technical conference…

Hacking for a Purpose

What was the last time you got to sit down side-by-side with a conference speaker and technical guru such as Joe Darcy, Stuart Marks, Bob Lee, and Jeff Genender, and hack out some code?  We setup and experimental hacking session where we did exactly this, pairing up attendees 1-to-1 with expert hackers to convert an open source codebase to use Java 7 features.  For this project we chose Google Guice (no surprise) and by the end of the session had converted several source files to use new Java 7 features such as strings in switch, the diamond operator, and try with resources.

In addition, we also had a follow-on event after the very successful OSCON JVM Languages Symposium to work through a technical solution for JVM language interoperability. Normally this is something that could take months of technical debate to come up with a few possible solutions, but with the collective brainpower of several compiler authors and some technical herding by Ben Evans, they came up with a solution after only several hours.

No Corporate Shills

At OSCON Java you got to see leaders from across the industry standing side by side up on stage, and being transparent about how their corporate strategies affect technology and open-source. Steve Harris, SVP at Oracle, was bluntly honest about his corporation’s failings in communicating to the Java community and made the point with some funny, self-deprecating slides, such as the “Oracle Threat Level” diagram:

However, he ended his speech on a high note with enthusiastic support for the Java community and Java User Groups in particular:

“Java User Groups Rock!”

And Some Geeky Fun

A good technical conference would not be complete without good, geeky fun. For this, we converted one of the exhibition halls into a giant carnival, complete with clowns, games to test your strength, obstacle courses, and of course plenty of carnival food. It was quite a stark difference from being in a tech conference surrounded by screens and computer, and was a great break from typical networking events.

My money in the above race is definitely on Fabiane Nardon (center), Brazilian Java User Group Leader. Once she sets her mind on something, she is extremely determined! :)


As you can see, OSCON Java is not your average technical conference. I owe the O’Reilly folks a huge debt of gratitude for being supportive of doing a different style of conference. They have a great culture of innovation and are far enough away from the corporate politics of Java that they can bring everyone to the table or the mutual benefit of the community.

While you may have missed out on one of the greatest Java events since the collapse of Sun, you can still catch some of the best parts on the OSCON video site:

http://www.youtube.com/user/OreillyMedia#grid/user/93FC98105B19725C

Also, all the speaker slides are now available for the presentations:

http://www.oscon.com/oscon2011/public/schedule/proceedings

See you at OSCON Java next year!!!

 
Comments
No Comments »
Categories
JavaFX, OSCON Java
Tags
carnival, java 7, jvm languages, oscon, OSCON Java
Comments rss Comments rss
Trackback Trackback

Improving Java 1 Bytecode at a Time

steveonjava | July 25, 2011

This past weekend we held the very first OSCON JVM Languages Symposium.

This was truly a meeting of minds with a huge brain trust of language authors, JVM hackers, and professional developers tackling some of the biggest issues for the Java community at large.

I think we had a pretty good recipe for success that went something like this:

  • We ate some yummy Voodoo Donuts
    • (while discussing the impact of Java 7++ on JVM languages)
  • Washed down our donut remains with some of Portland’s finest Stumptown coffee
    • (while discussing JVM language interoperability)
  • Had some tasty pizza and drinks on a private patio
    • (while pontificating on JVM community dynamics)
  • And then back for some more Voodoo Donuts…

As you can see, we took our work (and play) very seriously.

Thanks to our sponsors, Typesafe and OSCON, this event was entirely free to the participants.

The full proceedings of our event can be found below… given the success, I am looking forward to making this a long standing OSCON Java tradition!

OSCON JVM Language Proceedings

 
Comments
No Comments »
Categories
Events, JavaFX, OSCON Java
Tags
jvm languages, oscon, stumptown coffee, voodoo donuts
Comments rss Comments rss
Trackback Trackback

The Frugal Geek’s Guide to Conference Crashing

steveonjava | July 24, 2011

Conferences are expensive…  they assume you work for a stacked megacorporation that believes the fastest path to increasing their shareholder value is investing in your individual career training.  If your employer is not having a great year or has had a surge of resignations from last year’s crew of esteemed conference goers, chances are that you won’t be getting reimbursed to attend your local geek-fest.

Fortunately for you, I happen to know the inside secrets to enjoying all the conference perks at OSCON without handing over a single Benjamin.

Secret 1:  Conference pre-events are free and easily crashable!

Today I dropped in completely unexpectedly on the Community Leadership Summit today, and even after boldly announcing myself as a party crasher was awarded with a super-secret badge (a.k.a. index card w/sharpie etchings).  This gave full access to their sessions and let me attend the after-party for free drinks!

Tomorrow I am planning on crashing the free OSCON JVM Languages Symposium…  I hear they have some of Portland’s scariest pastries being brought in and might even be doing a free lunch outing thanks to their sponsor, Typesafe.

It helps that both of these events have an unbelievably high Rockstar to attendee ratio…  more on why this matters a little later.

Secret 2:  The best type of conference pass is the free type

There are 9! different OSCON passes available for you to choose from on the registration site.  While this is a bewildering array of options, but if you pay attention to the price it is quite an easy decision.  Click the “Register Now” button below and you are good to go:

Register
Register now for a FREE Expo Hall Pass (use code EXPOPASS)

So what are you missing out on with an Expo Pass?  Well…  you can’t sit with the rest of the attendees and listen to a canned lecture, but you can hang out with your new Rockstar friends in the hallways.  Which takes us to Secret 3…

Secret 3:  Conference value = # of Rockstars / # of Attendess

This makes sense if you think about it…  if you were the only attendee, surrounded by a cluster of speakers and geniuses waiting to impart their knowledge on you, it would be infinitely valuable.  Most conferences you are one speck of sand in a huge pool of attendees vying for a little bit of wisdom to be imparted on your section of the audience.  The smaller the audience, the more chance you might actually get something of value out of the experience.

So what does this mean for the value you get from difference conference events?

  • Keynote = 1 speaker to 1000 attendees:  Avoid this at all costs…  you can always get the highlights off twitter, so who cares.  [as you can see, my days as a conference chair are clearly numbered.  :) ]
  • Technical Session = 1 speaker to 100 attendees:  This is slightly better, but still the odds are clearly against you!  [yes, and now my days as a speaker are coming to an end as well...  see if anyone invites me to give a technical talk again]
  • Birds of a Feather Sessions = 1 speaker to 30 attendees:  A slightly better ratio, more focused, and absolutely free!
  • Ignite = 30 speakers to 300 attendees:  Ignite talks are for the speaker grazer in all of us…  yeah, talk your heart out…  for 5 minutes.  If you haven’t impressed us in that amount of time, at 40 minute session will not change our opinion.  It also helps that this event is absolutely free!
  • Unconference = 20 speakers to 100 attendees:  Now we are talking.  With this many technical gurus walking around you are virtually bound to learn something…  without even without trying!  This includes the JVM Languages Symposium and Community Leadership Summit, both of which are free!
  • OSCON Hallways = 1 speaker to 1 attendee:  When you bump into Martin Odersky in the hallways after having had some good times over beer and pizza at the JVM Languages Symposium you are at a ratio where the real value comes in!  (and didn’t pay a dime to start the conversation)

If you were paying attention, you probably noticed an interesting relationship…  the most valuable parts of the conference were the parts that cost absolutely nothing to get into.  (don’t let your megacorp friends know about this, or all the wonderful corporate sponsorships that pay for all these extras might dry up!)

Secret 4:  Free stuff is the open source way

Open source is all about giving software out for free, right?  Well, maybe there is more to it than that, but there is still plenty of free conference stuff flying around that you can take advantage of with over 60 exhibitors waiting to hand you prizes just for the privilege of scanning your free badge!

Secret 5:  And parties galore!

While all those folks who paid for the high priced admission tickets may think they are special, the reality is that from a sponsor’s point of view, their eyeball is worth exactly the same as yours.  This means that you have an equal opportunity to take advantage of the most important part of any conference experience…  the parties!

Here are some of the free events that you won’t want to miss out on:

  • Opening Reception – Grab a drink and mingling with exhibitors and fellow attendees
  • OSCON Carnival – Join us for food, drinks, entertainment, and lots of good old fashioned fun
  • Puppet Labs Party at their headquarters in Portland’s Pearl District.
  • OpenStack Party – Join OpenStack for cocktails and hors d’oeuvres at the Spirit of 77
  • Surprise Attendee Event on Wednesday evening (sorry, we can’t tell you anything else about this event because it’s a secret)
  • Booth Crawl where you can quench your thirst with vendor-hosted libations and snacks while you check out all the cool stuff in the expo hall.
  • Media Temple Party at the Jupiter Hotel with open bar, music, and all you can eat tacos!

Final Secret:  Everyone can be a Rockstar

What makes the difference between a Rockstar speaker and an attendee?  Just the drive to do something with technology and be proud of it.  You can be an open-source contributor, user group leader, and technical speaker if you simply apply the skills you already have to the benefit of the community.  Don’t expect to get paid much, but at least it is a really easy way to get invited to conferences around the world.

—-

While this article is all meant in good humor, on a serious note I want to thank the O’Reilly folks for putting on OSCON, offering discounted expo tickets, and compiling this great list of free events.

 
Comments
1 Comment »
Categories
Events, Flash, JavaFX, OSCON Java
Tags
conferences, crashing, free, oscon
Comments rss Comments rss
Trackback Trackback

Turbocharging Performance with Caching

steveonjava | July 21, 2011

This is the third installation of my Flex Mobile series.  In my first post I talked about multitouch, and my second post I dug in on how to control the soft keyboard.  This post goes into detail on performance, specifically caching.

Flash applications tend to use a lot more vector graphics than other UI platforms. This is a great thing for designers who can directly use all their path art and graphics.  However, on mobile devices it increases the challenge to build high performing applications.

Fortunately, there is a feature of the Flash platform called cacheAsBitmap (and its newer sibling, cacheAsBitmapMatrix) that lets you speed up rendering performance at the expense of memory.

Cache as Bitmap

CacheAsBitmap is a boolean property of DisplayObject, and by extension all the visual elements you use in Flash and Flex includings Sprites and UIComponents, have access to this variable. When set to true, each time the DisplayObject or one of its children changes it will take a snapshot of the current state and save it to an offscreen buffer. Then for future rendering operations it will redraw off the saved offscreen buffer, which can be orders of magnitude faster for a complicated portion of the scene.

To enable cacheAsBitmap on a DisplayObject you would do the following:

cacheAsBitmap = true;

Flex UIComponents have a cache policy that will automatically enable cacheAsBitmap based on a heuristic. You can override this behavior and force cacheAsBitmap to be enabled by doing the following:

cachePolicy = UIComponentCachePolicy.ON;

While cacheAsBitmap is a very powerful tool for optimizing the redraw of your application, it is a double-edged sword if not used properly. A full size screen buffer is kept and refreshed for each DisplayObject with cacheAsBitmap set to true, which can consume a lot of device memory or exhaust the limited GPU memory if you are running in graphics accelerated mode.

Also, if you have an object that updates frequently or has a transform applied, then cacheAsBitmap will simply slow down your application with unnecessary buffering operations.

Cache as Bitmap Matrix

CacheAsBitmapMatrix is also a property on DisplayObject, and works together with cacheAsBitmap. For cacheAsBitmapMatrix to have any effect cacheAsBitmap must also be turned on.

CacheAsBitmap does not work when a transformation, such as a rotation or a skew, is applied to the object. The reason for this is that applying such a transformation to a saved bitmap produces scaling artifacts that would degrade the appearance of the final image. Therefore, if you would like to have caching applied to objects with a transform applied, Flash requires that you also specify a transformation matrix for the bitmap that is stored in the cacheAsBitmapMatrix property.

For most purposes, setting cacheAsBitmapMatrix to the identify matrix will do what you expect. The offscreen bitmap will be saved in the untransformed position and any subsequent transforms on the DisplayObject will be applied to that bitmap. The following code shows how to set cacheAsBitmapMatrix to the identify transform:

cacheAsBitmap = true;
cacheAsBitmapMatrix = new Matrix();

Tip: If you plan on setting cacheAsBitmapMatrix on multiple objects, you can reuse the same matrix to get rid of the cost of the matrix creation.

The downside to this is that the final image may show some slight aliasing, especially if the image is enlarged or straight lines are rotated. To account for this, you can specify a transform matrix that scales the image up prior to buffering it. Similarly, if you know that the final graphic will always be rendered at a reduced size you can specify a transform matrix that scales down the buffered image to save on memory usage.

If you are using cacheAsBitmapMatrix to scale the image size down you need to be careful that you never show the DisplayObject at the original size. The following figure shows an example of what happens if you set a cache matrix that reduces and rotates the image first, and then try to render the object at its original size:

Notice that the final image has quite a bit of aliasing from being scaled up. Even though you are displaying it with a one-to-one transform from the original, Flash will upscale the cached version resulting in a low fidelity image.

The optimal use of cacheAsBitmapMatrix is to set it slightly larger than the expected transform so you have enough pixel information to produce high quality transformed images.

Flash Mobile Bench

The Flash Mobile Bench is a simple application that lets you test the affect of different settings on the performance of your deployed mobile application.

The functionality that it lets you test includes the following:

  • Addition of a large number of shapes to the display list
  • Animation speed of a simple x/y translation
  • Animation speed of a simple clockwise rotation
  • Impact of cacheAsBitmap on performance
  • Impact of cacheAsBitmapMatrix on performance
  • Impact of the automatic Flex cache heuristic on performance

The code that updates the cache behavior of the shape group is shown below:

private var identityMatrix:Matrix = new Matrix();

private function cacheOff():void {
  shapeGroup.cachePolicy = UIComponentCachePolicy.OFF;
}

private function cacheAuto():void {
  shapeGroup.cachePolicy = UIComponentCachePolicy.AUTO;
}

private function cacheAsBitmapX():void {
  shapeGroup.cachePolicy = UIComponentCachePolicy.ON;
  shapeGroup.cacheAsBitmapMatrix = null;
}

private function cacheAsBitmapMatrixX():void {
  shapeGroup.cachePolicy = UIComponentCachePolicy.ON;
  shapeGroup.cacheAsBitmapMatrix = identityMatrix;
}

Even though we have only one instance of an object to apply the cacheAsBitmapMatrix on, we follow the best practice of reusing a common identity matrix to avoid extra memory and garbage collection overhead.

Upon running the Flash Mobile Bench, you will immediately see the FPS counter max out on your given device. Click on the buttons to add some shapes to the scene, set the cache to your desired setting, and see how your device performs. The following figure shows the Flash Mobile Bench application running on a Motorola Droid 2 with 300 circles rendered using cacheAsBitmapMatrix:

How does the performance of your device compare?

 
Comments
5 Comments »
Categories
AIR, Flash, Flex, Mobile
Tags
Android, caching, Flex, Mobile, performance
Comments rss Comments rss
Trackback Trackback

Taking Control of the Flex Soft Keyboard

steveonjava | July 14, 2011

This is part 2 of my Flex Mobile series.  Please see my first post for information on getting started.

When using the text components, the Android soft keyboard will automatically trigger upon focus as you would expect. However, sometimes you need finer grained control over when the soft keyboard gets triggered and what happens when it gets activated.

The soft keyboard in Flex is controlled by the application focus. When a component that has the needsSoftKeyboard property set to true is given the focus, the soft keyboard will come to the front and the stage will scroll so that the selected component is visible. When that component loses focus, the soft keyboard will disappear and the stage will return to its normal position.

With the understanding of the focus, you can control the soft keyboard by doing the following:

  • To show the soft keyboard declaratively – Set needsSoftKeyboard to true for your component
  • To show the soft keyboard programmatically – Call requestSoftKeyboard() on a component that already has needsSoftKeyboard set.
  • To hide the soft keyboard – Call setFocus() on a component that does not have needsSoftKeyboard set.

This works fine for components that do not normally trigger the soft keyboard; however, for components that automatically raise the keyboard, setting needsSoftKeyboard to false has no effect. A workaround to prevent the keyboard from popping up on these components is to listen for the activating event and suppressing it with code like the following:

<fx:Script>
  <![CDATA[
    private function preventActivate(event:SoftKeyboardEvent):void {
      event.preventDefault();
    }
  ]]>
</fx:Script>
<s:TextArea text="I am a text component, but have no keyboard?"
  softKeyboardActivating="preventActivate(event)"/>

This code catches the softKeyboardActivating event on the TextArea component and suppresses the default action of raising the soft keyboard.

In addition to getting events on activation, you can also catch softKeyboardActivate and softKeyboardDeactivate events in order to perform actions based on the soft keyboard status.

The following is the full code listing for a soft keyboard sample application that demonstrates all these techniques used together to take complete control over the soft keyboard.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
         xmlns:s="library://ns.adobe.com/flex/spark"
         splashScreenImage="@Embed('ProAndroidFlash400.png')">
  <fx:Script>
    <![CDATA[
      [Bindable]
      private var state:String;

      [Bindable]
      private var type:String;

      private function handleActivating(event:SoftKeyboardEvent):void {
        state = "Activating...";
        type = event.triggerType;
      }

      private function handleActivate(event:SoftKeyboardEvent):void {
        state = "Active";
        type = event.triggerType;
      }

      private function handleDeactivate(event:SoftKeyboardEvent):void {
        state = "Deactive";
        type = event.triggerType;
      }

      private function preventActivate(event:SoftKeyboardEvent):void {
        event.preventDefault();
      }
    ]]>
  </fx:Script>
  <s:VGroup left="20" top="20" right="20" gap="15"
        softKeyboardActivating="handleActivating(event)"
        softKeyboardActivate="handleActivate(event)"
        softKeyboardDeactivate="handleDeactivate(event)">
    <s:HGroup>
      <s:Label text="Keyboard State: " fontWeight="bold"/>
      <s:Label text="{state}"/>
    </s:HGroup>
    <s:HGroup>
      <s:Label text="Trigger Type: " fontWeight="bold"/>
      <s:Label text="{type}"/>
    </s:HGroup>
    <s:Button id="needy" label="I Need the Keyboard" needsSoftKeyboard="true" emphasized="true"/>
    <s:TextArea text="I am a text component, but have no keyboard?"
          softKeyboardActivating="preventActivate(event)"/>
    <s:HGroup width="100%" gap="15">
      <s:Button label="Hide Keyboard" click="{setFocus()}" width="50%"/>
      <s:Button label="Show Keyboard" click="{needy.requestSoftKeyboard()}" width="50%"/>
    </s:HGroup>
  </s:VGroup>
</s:Application>

This code creates several controls and attaches actions to them so that you can hide and show the soft keyboard at will, as well as see the current soft keyboard state as reported by the events that trickle up. When you run the application it should look like this:

Notice that the TextArea control, which normally triggers the soft keyboard no longer brings it up, while the highlighted button immediately raises the soft keyboard whenever it gets focus. The two buttons at the bottom to show and hide the keyboard merely play focus tricks to get Flash to show and hide the keyboard at will.

You can use the same techniques in your own application to take full control over the soft keyboard.

 
Comments
5 Comments »
Categories
AIR, Flash, Flex, Mobile
Tags
Android, Flex, keyboard, Mobile
Comments rss Comments rss
Trackback Trackback

Celebrating Java 7 with 7 Reasons to Attend OSCON Java

steveonjava | July 7, 2011

OSCON Java is a new conference that I am helping to kick off as co-chair this July.  While there are plenty of conferences out there that you could attend, I am confident that this is the one you won’t want to miss.

To celebrate the Java 7 release, I put together 7 reasons why you should attend OSCON Java.  Also, make sure to use the 20% discount code of “OS11COM” when you register:

Register now

1. Come Celebrate the First New Java Release in Half a Decade!

The last major release of Java was Java 6, which came out 5 years ago on December 11, 2006. After only a year of the Sun acquisition, Oracle has already made a major Java release happen with another scheduled in a year’s time.

We have broad coverage of the Java 7 release with a keynote and technical session by Joe Darcy, and technical sessions on OpenJDK and Coin by Dalibor Topic and Stuart Marks. I have been pretty impressed with Stuart’s coverage of topics from a developer’s perspective and am looking forward to his talk myself. :)

2. Because Google Matters

Regardless of what you think about the Android lawsuit, I think the biggest detriment has been the lack of good content on Google technologies at Java conferences. We are an independent conference, so it allows us to bring content that you would otherwise not find, such as an exclusive keynote from Joshua Bloch and several mobile Android sessions to help you leverage your Java skills on modern devices.

3. You Think JVM Languages are Cool

It has been said that the crown jewel of the Java platform is the JVM, not the language. Java 7 has further solidified this with better support for dynamic languages. Come find out what is the latest and greatest on the alternative language front with a keynote and some meaty sessions from Martin Odersky, deep technical sessions on Groovy, Clojure, Scala, and other languages, and some bytecode hacking with Charles Nutter.

4. And You Wouldn’t Mind Hanging out with JVM language Authors for a Day…

On the Sunday before OSCON we are organizing a free JVM Languages Symposium that many of the speakers will be attending.  This is a great opportunity to hang out with JVM language authors and the movers and shakers in the industry in an informal unconference atmosphere.  Events like this are what I believe sets apart community-driven conferences from large corporate events, and provide a lot more value to the attendees than simply one-way content.  If you happen to be in the Portland area, you can drop by for this free event with no obligation to stay for OSCON.

5. Your Boss Won’t Let You Fly to Belgium

I travel to speak at different conferences around the world and I would have to say that the golden standard for Java conferences is Devoxx. They have an amazing venue — it is great to see your slides on a huge movie screen, and relaxing for attendees to take it in from nice, plush seats. They attract an international audience… not only Belgium, but Italy, France, Germany, and citizens of many of the other surrounding countries consider Devoxx their home conference. Even though Devoxx is a wildly successful conference, they still have a small-conference feel, run by a very tight knit conference committee that acts more like a user group than an organization. This makes the entire conference experience much more personalized.

OSCON Java has a lot of similarities with Devoxx. It has a small, enthusiastic program committee with folks who really care about Java technologies. We are also following the Devoxx model of recording and posting talks online afterwards, so even if you miss a great talk because you are in the room next door, you can always watch it online later. Finally, since we are an independent conference, you get the full experience of Java, Android, and other technologies that you would otherwise have to go to multiple conferences to see.

6. OSCON is a Pretty Sweet Conference as Well…


OSCON 2011

The O’Reilly OSCON conference has been underrepresented in the Java community, but is a pretty huge event in its own right.  They have some amazing content around emerging languages and mobile platforms.  Plus, you can get OSCON, OSCON Java, and OSCON Data all wrapped up in one neat package with the OSCON Superpass.

7. There is Only One Inaugural Year!


OSCON Java 2011

This is our first year putting on OSCON Java, so we are pulling out all the stops with the best speakers, tutorials, content, and events.  You will have a unique opportunity to participate in the creation of a new Java tradition, and a decade from now can brag to your friends about being a founding attendee of the biggest open-source Java conference in the world.

 
Comments
No Comments »
Categories
Android, Announcements, Events, JavaFX, Mobile, OSCON Java
Tags
Android, java 7, jvm languages, oscon, OSCON Java
Comments rss Comments rss
Trackback Trackback

Flash Android Touch Checker

steveonjava | June 16, 2011

This is the first in a 3 part blog series I am doing on Flash Mobile technology. With the release of Flash Builder 4.5, Flash and Flex now have support for building mobile applications that target Android and, with an update coming out on 6/20, also iPhone and Blackberry devices. In my opinion, this is now the best platform for building cross-platform mobile applications available today.

When targeting applications for mobile development you both have different constraints due to screen size and limited CPU/memory, as well as additional opportunities for enhancing your application by taking advantage of features like multitouch, the accelerometer, and the GPS. In this blog I chose to focus on multitouch, because it is something that every application should take advantage of.

Flash supports 5 different multitouch gestures. The following table describes the gestures and includes a figure demonstrating the multitouch action needed to trigger it.

Gesture Name Event Description
Pan gesturePan Place two fingers on the screen, and drag left or right; commonly used for scrolling the contents of the whole screen
Rotate gestureRotate Touch the screen with two fingers, and move them in an arc. This is an interactive gesture that will often be used to perform arbitrary rotation of objects.
Zoom gestureZoom Place two fingers on the screen, and move them apart or together along a single line. Moving the fingers apart indicates zooming in, and moving the fingers together indicates zooming out.
Swipe gestureSwipe Place one finger on the screen, and quickly swipe it in a single line of travel. Swipes are commonly used to change the screen contents or take an alternate action, such as deleting an item from a list.
Two-Finger Tap gestureTwoFingerTap Lightly tap the screen with two fingers, making only brief contact. This can be used as an alternative or secondary click where more than one action is required.

Read the rest of this entry »

 
Comments
No Comments »
Categories
AIR, Flash, Flex
Tags
Android, Blackberry, Flex 4.5, iPhone, multitouch
Comments rss Comments rss
Trackback Trackback

« Previous Entries

Publications

   

Upcoming Talks

JavaOne 2011

Android Open
Use code "WIDGETFX"
for 20% off!

JavaOne 2011

Steve On…

  • Everything
  • Agile
  • Flash
  • JavaFX

Archives

Affiliations

Awards

2009 JavaOne Rock Star!

rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox