Sunday, June 20, 2010

How to get Java FX pop-up items to render correctly on Unix systems

Our environment : JavaFX 1.3 with JRE 1.6 u20 on Ubuntu 10.04/CentOS 5.5

By default JavaFX pop-ups (from menuitems or choicebox) on Unix systemes come up with a white rectangle beneath them.
There have been posts on the web on how to get pop-ups and transparent stages on unix systems to behave correctly.

See Tor Norbye's & Just Java blog.

The solutions hinge around the fact that you can set a property

javafx.allowTransparentStage to true

for JDK > 1.6 u14 to remove the white rectangular area which is shown underneath the elements. In my experience, you also need to set the compositing manager correctly. In GNOME you would have to go to System>Preferences>Appearence>Visual Effects & select the Normal option. (Assuming that you are using compiz)

The fix has the effect of making the menu display look correct. However, when you move your mouse over the popup items, they show terrible flickering. See RT-8819. Which is a not acceptable trade-off either.

After a bit of digging around, it appears that the stylesheet for JavaFX controls - caspian.css - has an image for the border-image - menu-shadow.png - for the .popup-menu selector. This image seems to be the reason for the bad white rectangle beneath the menu. And appears to be the culprit for the excessive flickering when you set transparency via the javafx.allowTransparentStage property

So the workaround to resolve the flickering issue while hovering on menu items AND removal of the white rectangular area under the popup is to not really worry about transparency settings by removing the underlying image beneath the menu. In code this translates to

1. Do not set javafx.stage.transparency property to true
2. Put in the following style in the sylesheet attached to the Scene

.popup-menu {
    -fx-border-image-source: null;
}

Hope this is useful for folks developing FX apps on UNIX systems!

Tuesday, December 22, 2009

Diving into the unknown

If you wanted to find out quickly the interplay of objects in a (Java) code base unknown to you, an elegant way to do it would be to use the DIVER perspective in Eclipse

This quick tutorial walks you through the important steps and some cool features of DIVER. As an aside, I had never played around with Eclipse earlier – having used Visual Studio and Intellij Idea in my previous life :) I’ll talk about some of the unique features of Eclipse that I encountered along the way. I used SQuirreL SQL as my representative project to test drive DIVER and see if I could make sense of the codebase quickly.

The first thing you need to do is to install the DIVER ‘perspective’. We’ll get to the concept of Eclipse perspectives in a minute. The first step is to extend the eclipse IDE with the DIVER perspective. The way to do this in the IDE is to select the option to install new software and then copy-paste the URL of DIVER from their website.





You need to follow the wizard steps but that’s straightforward.

Once the install is done, you can open the DIVER perspective. In Eclipse, a perspective seems to represent a logical collection of views which will help you achieve the goal of the perspective. For example, you have a Debug perspective which will show you your regular debugging aids everyone’s familiar with – call stack window, breakpoints & variables view etc. Similarly in the DIVER perspective, you have the program traces view, the sequence window, the sequence outline and so on. You can come to a perspective from the Window->Open Perspective menu option. Once opened, the list of open perspectives appears as a toolbar at the top. As you get comfortable, you can compact the view to show only the perspective icons.  Also, as you work your way around the perspective, you tend to re-arrange windows and if you might find it difficult to locate a specific window, then the reset perspective option from the Windows menu should help you restore your sanity!


The default DIVER perspective looks like this:




Now, that you have the DIVER perspective installed, the next step would be to get the SQuirreL SQL sources into your workspace. In Eclipse jargon, a workspace represents a physical location on the file system and can contain multiple projects. You can create working sets to filter out what you want to see in the package explorer. To get integration with a source control repository, you would need to install a SVN perspective or a CVS perspective installed just like we did for DIVER.  That’s cool as you use the same UI paradigm for disparate set of tasks. To that extent I am guessing that the Eclipse framework is really bare-bones. The value-add comes from all the installed perspectives. The other nice thing I liked about the SVN/CVS perspective was that you could just paste the connection string from sourceforge websites and that would be automatically mapped to a connection object. Neat! Paste the SQuirreL SQL connection string and checkout the sources into an eclipse project (Identify the folder in the sources which has a .project extension and you will automatically get that recognized in Eclipse as a suitable project to create). 


Now that we are all setup, let us run SQuirreL SQL. For that, switch to the Java perspective and create a new 'Run configuration' under Java application (Run -> Run Configurations. Select Java application from the tree and click on New.)





You need to fill in the main class section. Since you don’t really understand this codebase, typically you would search for the main class and then filter on the key-word ‘main’ to guess which would be the right class.




While, we are at it, you may want to create a new configuration for the Java application trace. This will be used by DIVER as well when we enter the DIVER perspective.




Run the squirrel configuration and you should see the application up and running. Now, let’s close the application and go back to the DIVER perspective. Let’s run the squirreltrace configuration just created.The way DIVER works is that it logs all the interesting events in the system and then uses that information to build up a sequence view of the interested path. To use it effectively (Tracing slows the application down), tracing is paused by default. The recommended way to use this tool is to figure out the workflow you are interested in understanding (from a code-perspective). And only trace out that section.


For pedagogical reasons, let us try to understand the code structure for saving SQuirreL SQL preferences. To that extent, we will focus on the workflow for changing the SQL login timeout from 30 seconds to 45 seconds in the global preferences dialog.






To start off a DIVER trace, run the application trace configuration created previously




After the application launches and you have clicked on the global preferences menu, start a trace, change the timeout in the application and then stop a trace.  Do keep in mind that the trace configuration defaults to paused on start. So if you need to see a trace, then you would need to resume it at the interesting points in your application workflow.






Once you have collected the trace information, it’s time to analyze the trace! This is where it gets interesting!

You need to go the Program Traces view, select the trace data you have just collected and activate it



Activating a trace filters methods and classes used in this particular sequence in the Package Explorer. This is extremely good feature to have because even simple traces have an overwhelming amount of information and you need to use the package view and the sequence view together to discover what you are searching for.


Since, we are on the UI thread, most of the fun happens on the AWT-EventQueue-0 thread. So we open up the sequence viewer for that thread.  You notice after expanding a few nodes that the only events in the system are generic java events and they give you real clue on how to move ahead. Unless you have the patience to expand out each and every node or expand all activations (Which could take a while!)



That’s where you need to use the various views in the DIVER perspective effectively. You know you are dealing with a textbox widget and you open the src/ui folders. Notice that this view is already filtered out based on what we have traced. So you are guaranteed that all these methods/classes are going to be used in the sequence diagram. The IntegerField class looks interesting and seems to be a possible candidate to start the exploration.  You can reveal the sequence around this class by using the reveal-in feature




Voila! This expands the sequence diagram to take you to the interesting part of the sequence viewer.



Also, note that you have a small blue line in the time line bar. They represent calls to methods of that class on the timeline. You can center on that particular occurrence in the following way



If you find that this looks messy. If you want you can filter out further. Notice the small W on the top of the window. If you click it, you are shown a hierarchy of packages which you can collapse out in your sequence diagram.



For example, you can filter out the javax.* classes. With some measured filtering, the sequence diagram reduces to



 The tool also allows you see the corresponding code for the clicks you are making in the sequence viewer




As an aside, the other interesting feature is that you can use the up/down arrow keys to quickly find the next occurrence of an activity on a selected lifeline.

That’s a quick roundup and a motivation to use a tool like this. The detailed tutorial for DIVER is here and the author’s blog is here.

This tool does a great job in giving you the ability to filter away un-interesting parts of the sequence diagram - to reduce the noise - so that you can quickly come to the classes and interactions which matter. Having the reveal-in feature and the markings on the timeline allow you to understand the code-structure starting from the classes which could possibly be interesting.

Give it a spin in the (java) sources you want to understand!



It's been a while

since I blogged last. Hope this time around I will be more regular :)

Sunday, January 22, 2006

On a lazy afternoon

The view from the balcony gives a sense of well being and peace...
 
 

Wednesday, July 20, 2005

Farewell time

And finally two years come to an end for Sachin and Sapna. Both are going to pursue their MS in the US. It was fun interacting with both of them. Never met a more humorous person than Sachin and a more sincere and meticulous individual like Sapna! Here's wishing them all the best!

Wednesday, May 04, 2005

SmartPhone Thoughts

Why is it important? What’s the big deal? How does it change the way we do work and think? And why is it so important to India?

Let me start off by recounting a personal tale...
[Photo Credit: Vijayendra Vaidya - A Rice Field during the monsoon season in Maharashtra]

I generally travel to Mumbai for my weekends. The train journey takes about 3 to 3.5 hours and descends from the mountains – where Pune is situated - onto the island of Mumbai. Being a regular commuter, it has been a while since I looked out at the scenic beauty of the ghats as the train descends onto the plains. I spend my time reading books I would have loved to read during my weekdays. Very recently, I subscribed to the GPRS service provided by Airtel (A cellular provider in India) at a very reasonable subscription of INR248 per month (~6 USD per month) for unlimited uploads and downloads. (With roaming in India) And at what speeds, you ask? Decent speeds of 40-50K/sec – good enough to listen to crystal clear online radio at VirginRADIO I have a smartphone which runs on Windows - the SPV E200. The neat thing about the hardware is that it is powerful enough as desktop computers of a few years ago. (133 Mhz, 32 MB RAM, 64MB ROM, Pentium V generation Anyone?)

And it runs on familiar Windows software. Imagine! What does that mean to you as an end-user? It means that you would have a huge pool of utility programs you can download off the web and then install them on the phone via the data cable. [As an aside, the Windows phone kit comes with all relevant accessories which help you communicate with your PC. Unlike some major brands wherein you need to buy the data cable separately].

As a software developer, you are going to be using the same tools (Visual Studio), same APIs (Win32, .NET etc) with some limitations/enhancements to cater to the mobile platform. This is where it starts getting interesting for the development community at large. It means that – in one shot - you have innumerable developers who suddenly realize that they can leverage their skills to develop for this new platform. What this translates to is a rapid migration as well as development of applications for this new platform.

Even today, with the proliferation of applications – some free, some shareware and others you need to pay for – you can convert your phone into a very useful device so that your time on the move can be spent productively. And, you know what? You can completely avoid the costs of downloading applications via air and save yourself a tidy fortune. I’m going to list a set of applications which I find highly useful to augment the capabilities of the phone.

Email - On the Move:
An IMAP/POP client is provided with the phone – with SSL support. So you can pop your mails from gmail for example. The email software also gives the capability to download email headers. If you like to read the complete mail, you need to download the mail - which is a seamless process. This in itself should be very exciting for business users within India. Combine this with an email payment system like PayPal and the possibilities are enormous for service sectors.

Entertainment:

Movie Player – BetaPlayer - for example - can be used for playing movies. How do you get full-length movies on the phone’s limited memory? Buy a 1GB SD Card for around ~70$, use pocketdivxencoder to encode your movies to the phone factor and you should be done! Ditto for TV Recordings made with your PVR. In the future, with falling prices, I expect SD Cards to become another distribution media for movies. And a very popular one at that!

Internet Radio – In spite of the SPV not having radio tuning capability, listening to internet radio using the headphones is indeed a very enjoyable way to spend time! And Yes, the streaming happens in the background, so you can yet run your PDA applications and be productive. During my trip to Mumbai, except for a few sectors when the train passed through tunnels, the connection was excellent and I had a marvelous time listening to VirginRADIO. One Crib though; bbc.co.uk/radio has a huge and excellent collection of radio shows in various categories. However, they can be played only on RealPlayer. And yes, there is no port of RealPlayer for the SmartPhone. Yet! ShoutCast would be another place to listen to music. Though, I have not tried it personally, PocketMusic apparently allows you to listen to ShoutCast streams, so that should be fairly exciting as well.

MP3 Player – Either Windows Media Player or PocketMusic. Store your favorite songs on an additional SD card. Also upcoming Windows Phones have the capability to appear as a storage disk when you plug them to your computer. What’s the big deal? No need to install ActiveSync. Just dock the mobile in a USB port and it doubles up as a storage device.

Feed Clients - Clients which suck data from content sources such as SmartFeed (A PodCast client used to listen to/synch up with Podcasts. You would necessarily need an add-on Flash Card to store the podcasts)

Mobile Blogging - Having a camera phone - combined with the fact that you can send regular emails - is a good thing; Now you can upload pictures with a brief description - if not full text - in your blog from the field itself!

Games – Though not a gaming enthusiast, some must-haves in the free category include Pacman, Cell Doom and Chess

And these are just a sampling of interesting things you can do with your phone. Apart from this, you can browse the web with IE. Also you can use it as a regular modem, connect it to your PC or laptop to browse the web at better than dial-up speeds. You have neat integration with Jeyo Mobile Companion, which creates a SMS folder within Outlook and allows you to read and send SMSes from your desktop. As an aside you can even forward your regular email messages as SMSes!

The more I look around, the more I see innovative applications exploiting mobile scenarios. In my mind, the mobile platform is currently going through the same phase as the PC world in the Win 3.1 days. And it is definitely going to be the next platform for development. NTT DoCoMo has done really interesting stuff by having a marriage of barcode readers and a camera phones to completely change the way we will interact with society.

And for India?

And for India, this can represent a tremendous leap in the amount of information available to people, services and has the potential to change the structure of relationships. Why? Firstly, many Indians will probably buy a cell phone before they buy a full-fledged computer. The price-point is attractive. An E200 will set you back by around ~INR 12,000 (~300USD) and a unlimited GPRS pipe will set you back by INR 248 (~6USD) per month. To put things in perspective, a high-end Nokia phone would set you back by around INR 20,000 (~450USD) and will not have the same deep integration with a variety of software and services. And the capability of customizing your phone to your needs is limited and expensive; mainly because software is secondary for Nokia - at least till now. In India, people pay INR 15-30 (~75cents) for downloading music fragments in the form of ring tones, but may not shell out the same amount for buying music CDs and tapes! Now, with cheap internet access via GPRS and a phone which allows for tremendous customization via software, the possibilities are endless. Think banking services, payments, entertainment. If it kicks in, And it will! it will change relationships as we see it today. As Thomas Friedman points out in his book - "The World is Flat", in the first generation of globalization, you went and bought your ticket from a travel agent, in the second generation, the ticket counter was replaced by a computer and in the 3rd generation, you buy your own ticket!

And the beneficiary is the common man. And the elimination of the middle man who feeds on lack of information. Knowledge truly sets one free!

Saturday, November 13, 2004

The Village

What makes certain movies more enjoyable than others is that they offer the possibility of enjoying a meaning beyond the literal story. The Village is one such movie. Though it has an extremely simple and implausible literal story line, it affords a quite different interpretation altogether.

What follows is my rendering of the story behind the story!

The ring of elders represent society who would like it’s people to live according to their rules and customs. Due to their traumatic experiences, they create a world with artificial boundaries and expect everyone to live behind this boundary. To do this, they construct an elaborate myth; a boundary beyond which, lies a forest with the terrible human-eating beasts and an uneasy truce exists between them and the village. And the boundary is made stronger in many ways - horrendous sounds emanating from the jungle, the ritual of gaurds guarding the boundary and even through the game of colors - yellow as our color and protector versus red as their color. And Boundaries! The perfect line of straight trees separating the two worlds. The mentally challenged person is the only one who can't see the boundary but no one believes him anyways. And the key - Even in moments of crisis, the society is unwilling to break its self set rules. Faced with the prospect of losing her lover, a blind girl defies the boundaries to discover the truth. Did the director use a blind girl to suggest that she was blind to the rules? I would like to believe that it was used as a metaphor as she was finding the path out of the world and everyone is blind while charting out new waters. Also noteworthy, is that some of the elders even break the truth to her, but refuse to take any action themselves - thereby suggesting that they are so trapped by their own creation.