Something for the weekend
Feb 2007
What happens next...?
As I've hinted in one of the comments on a recent blog, I've been setting up a dev.java.net project for the blog code. It's proved more work than I expected, largely because I've had to set up one thing or another (CVS repositories, last time I did anything like this by had was writing sccs bash scripts to make it easy to manage a group project!). All that aside, once the project has been approved I'll post the link here.

I'm also going on a bit of a document and re-factor effort to try and get things in shape as I am getting more requests to use the components (open-source dudes, do what you like!) I feel I should at least make them more usable and, well, better documented. In the meantime I'm (as usual) fiddling with one or two ideas that will hopefully mature enough to be added into the library.
|
First real application of java carousel
I've mentioned a couple of times that I've spent a few days working with Krill on some bits and bobs for substance, and I have to say it's great to see the carousel (and for me the carousel menu) having a real (and useful) application. So head on over to Krill's blog and check out what he has done...

KrillPreview
Sweet Happy

|
Improved Dock Panel and Coder Stupidity
When I first publish my dock example, it was implemented in a glass pane. Which is fine. I also went through some hoops with AWT listeners to stop it sucking all the events away from the component below. I wrote some event forwarders. I added listeners. I did a lot of stuff. The whole time something was niggling away at the back of my mind. It just shouldn't be this hard. It wasn't.

There is a magical method for each container, that can cause it to NOT hog mouse events. It simply dictates whether or not there is a component at a particular x,y co-ordinate. If there's not, Swing doesn't pass the mouse event on. After all, there's nothing there. Here it is (you can over-ride it)

public boolean contains(int x, int y);

That's it. If it returns false, then no events are passed on and the clicks fall through. I had started fiddling with this, but then stopped hitting a recursive dead end when I called getComponentAt(int x,int y) inside it. Of course, all I should have done is a little bit of work to implement my own getComponentAt() and I would have had my solution. Find out if there is something in the dock panel that isn't a spacer that's at that co-ordinate... if there's not return false and pretend it's got nothing to do with me.

Here's the implementation:

public boolean contains(int x, int y) {
Rectangle rect=new Rectangle();
//Have to implement our own componentAt here
for (Component comp : getComponents()){
rect=comp.getBounds(rect);
if (rect.contains(x,y)){
if (comp instanceof JSpacer){
mouseMoved(new Point(-1,-1));
return false;
}
return true;
}
}
//A little non-intuitive. If it's not over a normal component or a spacer, it's in the dock area
return true;
}

The final return true is a little bit tricky (it's after all like saying, I didn't find anything but yes send me the message). This stops the mouse going over little gaps causing a problem, in general, if it's over a spacer pretend I'm not there, otherwise consume the event. Doing this enabled me to remove the GlassPaneDock class entirely, and a WHOLE load of complexity went with it. It's also enabled me to do something else I wanted to, add the dock into a Frame's layered pane. This is useful because it means I can make things like combo-box drop downs and pop-up menus appear over it (play with the demo to make it happen if you wish). Which might be more appropriate in some cases. In the screen shot below see how the combo-box appears OVER the dock.

Layered Dock Pane

This "perfect" message handling has one problem, the mouse can still fall between the cracks of dock icons from time to time, but that's part of another tweak I'm working towards. For now, the usual web-start and source code update has been done!

webstart-small2

|
Updates to JCarouselMenu and some bug fixes...
It's been an interesting 48 hours, with Krill using the Java Carousel, and then starting to use the Carousel Menu he spotted quite a few more items that needed tidying. With those changes applied, I went back to my inbox to find someone else spotting the same problem (Sebastien) with the carousel menu needing to be able to handle more items than could fit on the screen.

scrolling menu

I've also added Mouse Wheel support to the carousel, which is pretty funky (well I think so!). Another big thanks to Krill and Sebastien, it's all looking better than it was.

webstart-small2

|
Updating Blog Jar and New Features to Carousel
What happens when bloggers team up? Interesting things!!! Kirill Grouchnikov recently asked if he could use JCarousel in one of his projects, and of course I was delighted to agree. During the day Krill would send me some updates, suggest improvements, and the end result is subtly but substantially improved.

Quite a few changes have been made here and there, one of my favourites was Krill's idea to add mouse wheel functionality, now why didn't I think of that? All very simple in the code as well....

public void mouseWheelMoved(MouseWheelEvent mouseWheelEvent) {

if (mouseWheelEvent.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
int amount = mouseWheelEvent.getWheelRotation();
if (lastWheeledTo==null){
lastWheeledTo=getFrontmost();
}
int lastPosition = layout.getComponentIndex(lastWheeledTo);
int frontMostPosition = layout.getComponentIndex(getComponent(0));
//Don't over spin
if (Math.abs(lastPosition-frontMostPosition)>layout.getComponentCount()/4){
return;
}
if (amount > 0) {
lastWheeledTo=layout.getPreviousComponent(lastWheeledTo);
} else {
lastWheeledTo=layout.getNextComponent(lastWheeledTo);
}
bringToFront(lastWheeledTo,true);
}
}

Basically all the code does is look for the mouse wheel to be rolled and try and bring the next component along to the front. I bet your are wondering about the over-spin bit? Well, the carousel always looks for the shortest route to be bringing a component to the front, so racing too far ahead suddenly spins it backwards, not what I wanted, but if we never let it go further than a quarter of the way around, it's always quickest to carry on moving in the same direction.

The next item, and I think you'll see it to great effect in Krill's application, is to improve how text is rendered and labels generated. Nice alpha blended backdrop in a rounded rectangle. Once again, there were a few e-mails backwards and forwards before we hit on the right solution. Fun!

Updated Dock zoomed


Finally (and what started it all) items further back are now more transparent (something I know a few of you had raised) not to mention a couple of bad practice items Krill had highlighted (laziness on my part, but when you realize someone else is doing things with your code!)

Updated Dock

I have updated the source, as well the web-start demo....

webstart-small2

|