The Source for Java Technology Collaboration
User: Password:



Joshua Marinacci

Joshua Marinacci's Blog

Countdown to Christmas: a Customizable MiniApp

Posted by joshy on October 03, 2004 at 10:33 AM | Comments (8)

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.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • I think that bug 4307550 is the main problem for no png support. Votings for it are welcome.

    Posted by: lordy on October 03, 2004 at 11:15 AM

  • Odd. The bug seems to refer to loading PNGs with ImageIcon.I have used PNGs with transparency through ImageIcon before with no problems. My guess is this has more to do with native code, since the Java Web Start environment has to generate an actual .ico resource at some point to tell Windows what to do. I should try this out on OSX and see what it does there.

    Posted by: joshy on October 03, 2004 at 11:19 AM

  • i search a little the bug db and found these bugs: 4720754, 4625362 , 4409085

    Also see here: http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/syntax.html#information

    If you only would high qulity icons on Mac OS X, you can set a nativ Mac OS X icon, with the downsite that the Application Manager and the Startup Window don't show the icon, but the dock have high quality. With 1.5 you now can set the information tag for os, but help nothing befor no java 1.5 for mac os x exists.

    Think we need a RFE describes the need of support nativ icons or support to translation png in high quality nativ icons.

    Posted by: lordy on October 03, 2004 at 01:03 PM

  • Go Joshy Go!

    Very nice :-)

    Happy Holidays!

    PS One small suggestion, please review your repainting algorithm; otherwise it might be best to make your mini-app window non-resizable.

    Posted by: cajo on October 03, 2004 at 03:41 PM

  • I still wonder what is the purpose of the width and height attributes. They are there in HTML so that the browser can reserve the space for the image before hand. With webstart, however, it doesn't do incremental painting and there is no layout to be concerned with. The splash screen is always by itself so size isn't an issue. The icon is always 32x32, so size isn't an issue. So why have the attributes?!!1

    Posted by: joshy on October 03, 2004 at 04:48 PM

  • I think that I will make the windows non-resizable since the content isn't resizable. Hmm. I wonder how difficult it would be to actually make the contents be resizable. It's essentially a background image and one absolutely positioned label. Scaling the label's coordinates and font size wouldn't be too hard. Hmm....

    Posted by: joshy on October 03, 2004 at 04:49 PM

  • " gasping for memory"

    You'll find Java1.5 (I refuse to call it Java 5 until I actually Sun changes the download from Java 1.5 to Java 5) shared memory (classes, maybe more) can noticably help here. This is partially responsible for the much faster startup times too.

    Note to editor: the single quote character wrecks the preview.

    Posted by: markswanson on October 04, 2004 at 08:37 PM

  • You might want to check out POD (http://xito.sourceforge.net/), it seems to fill most of your requirements...

    Posted by: phaero on October 13, 2004 at 10:52 AM





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds