Skip to main content

Countdown to Christmas: a Customizable MiniApp

Posted by joshy on October 3, 2004 at 10:33 AM PDT

Back when the Web was just emerging (you know, from the primordial soup of standards) many developers put effort into making it easy for lay people to create websites. While most focused on WYSIWYG development tools or content management systems, some developers tried to sell Applets and JavaScript libraries. These were small programs that could be embedded easily into a website and customized without the use of code. No need to write your own tree control: just set a few properties on this library and you're good to go.

The commercial Applet market never really took off. Maybe because customizable libraries were eventually integrated into development tools. Maybe just because Java didn't work well in the browser until after everyone stopped caring. Whatever the reason, there simply isn't much money to be made with small commercial programs embedded into your webpage.

Still, the idea of simply customized applications still intrigues me. Many programs could be completely reconfigured by an intelligent non-programmer with the help of some config files and some bitmaps. When these thoughts collided with my recent interest in MiniApps I took the logical step and combined the two:

The Countdown Timer



Halloween Counter Webstart Link (safe)



Countdown to Christmas Webstart Link (safe)

What we have here is a single webstart program running out of the same jar files. The only difference between them is their JNLP files. The files contain configuration information says what images, colors, and fonts to use; along with the target date (10/31/2004 for example) and some layout coordinates. I can hand this counter to a non-programmer and he/she could reconfigure it completely with just a text editor. Presto: a new app formed out of the reusable components provided by Java and Webstart.

To keep it simple I have simply passed the configuration properties into the program using commandline arguments, which are then parsed into a hashtable. Here's the setup for the Halloween counter:

<application-desc main-class="org.joshy.countdown.CountdownMain">

    <argument>month=10</argument>
    <argument>year=2004</argument>
    <argument>day=31</argument>
   
    <argument>background.color=#ffffff</argument>
    <argument>background.image=http://code.joshy.org/projects/countdown/halloween.png</argument>
   
    <argument>days.font.href=http://code.joshy.org/projects/countdown/Spiders.ttf</argument>
    <argument>days.font.size=115</argument>
    <argument>days.font.color=#000000</argument>
    <argument>days.tracking=17</argument>
    <argument>days.digits=2</argument>
    <argument>days.x=40</argument>
    <argument>days.y=85</argument>
   
</application-desc>

There are defaults for all of these values so you don't have to specify them all. In typical webfashion any external resource like images and fonts are specified using a URL. Since they are all hosted on the same site as the app itself I didn't have to request any extra permissions.

Here is the configuration for Christmas. This is the only change between the two programs. The jars remain the same.

<application-desc main-class="org.joshy.countdown.CountdownMain">
    <argument>month=12</argument>
    <argument>year=2004</argument>
    <argument>day=25</argument>
   
    <argument>background.color=#ffffff</argument>
    <argument>background.image=http://code.joshy.org/projects/countdown/xmas.png</argument>
   
    <argument>days.font.jar=VIVIAN__.TTF</argument>
    <argument>days.font.size=85</argument>
    <argument>days.font.color=#000000</argument>
    <argument>days.tracking=17</argument>
   
</application-desc>

The more I've been thinking about this the more I realize that client side Java is about to make a comeback. Java Web Start gives us the ability to be platform independent and have non-technical customization, just like Applets, JSP taglibs, Javascript libraries, and Flash all provide. But it also lets you work outside of the browser and get some real work done. Lots of rough edges still, but some great potential. Why don't you try making some counters of your own. Here's the source complete with sample images, fonts, libs and an Ant script.

Webstart notes

I've turned off the transparency effect so the countdown timers can run without needing any extra permissions. The resources are loaded from the same server as well. Perhaps with some support from the javax.jnlp package I could even use relative URLs.

Once you run a couple of these your machine will really start gasping for memory. Shared JVMs is starting to become a necessity.

Icons are truly a pain with Java Web Start. You can specify more than one icon but only the first one is used. (You can use a second image as a splashpage if you set the kind to splash.) The height and width arguments are also ignored. Transparency does seem to be supported, contrary to other reports I've seen, but you can only use GIFs and JPGs. No PNGs. Ack! If you have your Windows desktop set to use large icons then webstart will scale your images down to 32x32 and then back up to 48x48. (all while doing a really bad job of it). Infinitely frustrating. There's got to be a better way to do this. I'd also like to see Frame.setIconImage() use an Icon instead of an Image. That way you could provide the right sized image for each situation. Ex: 16x16 for the taskbar, 32x32 for the tab switcher, 128x128 for the OSX Dock, ?x? for Gnome desktop.

When you make your icons, if you want transparency, I recommend creating them in your image editing program with a stroked border. This will create a nice anti-aliased border without relying too much on the background being a certain color. I found that this removes the small white jaggies that can often form on the edges of your icons.

Related Topics >>