Friday, July 21, 2006

ToolDockLayout

Continuing the work on JAnimationShop, i found the need to dock the toolbars at various edges of the Application window. In Java, as far as i know, there's only one way of automatically doing this, using BorderLayout.
Unfortunately, as explained in How to Use Tool Bars and many other similar resources on the internet, The window edges where you wan't to dock your toolbars should not contain any other component!
This restriction comes from the BorderLayout class, to make this more clear i have given below 2 excerpts from Sun's Java documentation!

With most look and feels, the user can drag out a tool bar into a separate window (unless the floatable property is set to false). For drag-out to work correctly, it is recommended that you add JToolBar instances to one of the four "sides" of a container whose layout manager is a BorderLayout, and do not add children to any of the other four "sides".


A border layout lays out a container, arranging and resizing its components to fit in five regions: north, south, east, west, and center. Each region may contain no more than one component, and is identified by a corresponding constant: NORTH, SOUTH, EAST, WEST, and CENTER.


So to overcome this deficiency, i decided to write my own extension of BorderLayout to achieve the ability to add multiple components at each edge! This proved to be a wrong approach since BorderLayout only supports 5 components to be added directly to the container using it!

Finally, i made up my mind that there was no way out other than writing my own Layout manager to do the needful.

One fine day i sat for about 20 minutes in front of my computer fiddling around with JAnimationShop code and wrote a brand new Layout Manager called ToolDockLayout. This layout manager can dock multiple compoents at various edges of a container, and is very simple to use. Below are some screenshots of JAnimationShop revved up with ToolDockLayout. Will add in more details and the code at a later point.



0 comments: