Saturday, March 22, 2008

Transparent bordered shell in SWT

I've wanted to get a transparent bordered shell in SWT ever since I saw the transparent bordered video shell in Leopard video quickview.

A shell with alpha support is coming in 3.4. However, I have not looked at the 3.4 material as yet and this sample was built on 3.3.

The shell can be used in the same way that the org.eclipse.swt.custom.PopupList class can be used except that you can place any controls you want and not just a List. Lets see how to do this -

In SWT, a Canvas control can have an alpha value. Thus, the base needs to be a canvas. First, create a control that extends the Canvas. Set the layout for this canvas to a FillLayout. This canvas will contain other controls. It is important to set the margin of the layout. This margin will be the width of your transparent border. Now, set an alpha value for the canvas. The alpha determines how transparent the border will be.

Image -
Now create or load a gradiented (is there such a word?) image. In the paintListener for the Canvas, draw this gradiented image. Because of the alpha on the canvas, the image will be semi-transparent. Now add any controls (typically a composite with controls within it) to the canvas and these will be drawn with a transparent border around them.

To get the real transparency, this canvas needs to be placed inside a shell created with the style SWT.NO_TRIM and SWT.ON_TOP. Also, the canvas needs to be created with the style SWT.NO_BACKGROUND. However, due to these styles, the shell cannot be really moved around. Thus, its useful where no movement is necessary - a transparent menu, infopopups, ...

Thus, to summarize,
1. A shell with styles SWT.NO_TRIM and SWT.ON_TOP contains
2. a canvas with style NO_BACKGROUND, a gradiented image, an alpha value, a margin (border width) contains
3. a control (composite) that is displayed within the canvas.

Saturday, February 23, 2008

Firefox Memory Consumption

I started noticing a performance issue with Firefox while filling out forms and opened Task Manager to see this.


Firefox - one window - four tabs (370 MB)

IE - one window - three tabs (20 MB)

Safari (webkit) - zero windows - don't know where those two processes have come from (121MB + 54 MB)


The second javaw.exe process (218 MB) is Eclipse 3.2 with a pretty huge workspace. The eclipse.exe(200MB) is an instance of Eclipse 3.3 with a relatively smaller workspace. Nice to see someone beating Eclipse in memory consumption :).





Thursday, February 14, 2008

RESTful JSON

In a recent project, I used a REST style interface(PHP) and GWT (Google Widget Toolkit). The first thought for a data exchange format was XML. However, on further rumination, the prospect of writing XML node iteration code was daunting. After having done the whole XML node iteration for multiple projects before this, I was feeling too lazy to do it all over again :). Thats when I thought of using JSON (Javascript Object Notation). The JSON programming model is much simpler to use than XML. The ease with which the data can be transformed into objects eliminates all the node iteration code. This is due to the multitude of libraries (including GWT) available for encoding/decoding the JSON format and the ease with which JSON can be converted to objects.  Finally, I ended up with a REST style interface returning JSON encoded data that gets decoded on the client by GWT. 

JSON seems to be a much simpler data exchange format while XML seems to more suited to storage of data. A good combination is probably an XML database (more flexible than an RDBMS) for storage and JSON for data exchange.

Wednesday, January 23, 2008

4GB iPhone - A Lower Priced iPhone

When Apple reduced the iPhone prices from 599 to 399, they also discontinued the 4GB iPhone and to exhaust their existing stock sold this model at 299. I don't have a whole lot of songs but was interested in the non-iPod related functionality (phone, maps, browser, touchscreen,...). Thus, for me, the price was in the sweet spot and 4GB of memory was just fine. One rarely buys iPod(iPhone) products without accessories (case, earphones,...). Thus, the phone is not really 299 but 299 + taxes + accessory cost.

I end up using the browser, maps, stocks, weather and notes more than the iPod functionality. Someone like me who does not have a whole lot of songs but is more interested in the constant connectivity and the non-iPod functionality would be an ideal candidate for the 4GB version of iPhone. Apple does sell other 4GB iPods - iPod Nano (which is $149). I think there is a market segment that would love to use the iPhone if Apple offered a lower price version - maybe ~ $275. The iPod Touch is great but does not have constant connectivity that an iPhone provides. Maybe once the 3G version is released, they could offer the EDGE model at a lower price. Only time will tell...

  DB Reading BASE: An Acid Alternative: In partitioned databases, trading some consistency for availability can lead to dramatic improvement...