Something for the weekend
FrontRow like Carousel Component for Java
Desktop Java is more powerful than most people believe, it can make the seemingly difficult easy. With this is mind, armed with the impressive work being done by the likes of Romain Guy and the SwingX team I thought it would be good to look at how one might re-create the Carosel used in Apple's Front Row application.

When you launch Front Row on your Apple Mac, it presents the [currently] four main options on an invisible carousel that rotates as you click left and right on your remote (or use the cursor keys). This not Itemsonly looks great, but also, well, looks great!

Picture 8
FrontRow Carousel from Apple

So let's go over the key aspects of the carosel that we need to re-create, and how I am going to tackle them in our Java implementation:

1. The carosel acts like a tool bar containing "actionable" items. Well these are just Swing components, I'm not going to try and do anything clever here.
2. Items are placed around a circle, tilted so that all items can be seen. Given that what we have is a rectangular region and we want to layout standard components in it, I'm going to use a Java Layout Manager to do this, after all it's all about layout!
3. Items are rotated to bring a particular items to the front to enable its activation. I'd like our layout manager to manage the animation here, causing itself to revalidate the container. This way we can encapsulate as much as possible associated with layout, in the LayoutManager.
4. It looks sexy! Right, well typical Apple then. So I'm going to pick a couple of the sexy elements... First of all stylish images that scale as they go to the back of the Carosel, and render a reflection over a gradient background. Let's break these down then into two components, the scaling reflected images, and a component (derived from JPanel) JCarosel which lays out item placed into using the CaroselLayout manager and draws the gradients etc.

So there are our targets, I'm going to split these elements across a couple of posts, but I'm guessing you'd like to know it's all working first! So here's our JCarosel component with a few images in place just to convince you it's going to work! First of all I need to give due credit to Brian Zeitler from Pixelnet Design who has drawn the fab application images I'm using (http://www.pixelnetdesign.com/). Many thanks for the permission to re-use his icons for this demonstration.

Picture 2
The Carousel Component in Action

Looks pretty good? Just so you can see how easy it is... Here's the code that sets up the frame for that demonstration:

JCarosel carosel = new JCarosel();
carosel.setBackground(Color.BLACK,Color.DARK_GRAY);
getContentPane().add(carosel, BorderLayout.CENTER);
setSize(600,400);
carosel.add(new ImageIcon(CaroselFinal.class.getResource("/com/blogofbug/examples/carosel/itunes-blue.png")),"Blue Tunes",128,128);
carosel.add(new ImageIcon(CaroselFinal.class.getResource("/com/blogofbug/examples/carosel/itunes-purple.png")),"Purple Tunes",128,128);
carosel.add(new ImageIcon(CaroselFinal.class.getResource("/com/blogofbug/examples/carosel/itunes-olive.png")),"Olive Tunes",128,128);
carosel.add(new ImageIcon(CaroselFinal.class.getResource("/com/blogofbug/examples/carosel/itunes-green.png")),"Green Tunes",128,128);



So hopefully I've wetted your appetite to learn more. The next update will include all of the code for the layout manager (including animated rotations for selection, addition, and removal.
|