Monday, December 24, 2007

WWJ Annotated Icons

Suppose you have icons around the globe representing some type of events (traffic, rain, fire, ...) and you want to see more information when click on them with the mouse.

Well, I have created the so called AnnotatedIcons with this idea in mind. Note, as suggested here byt Pat, there is another approach to achieve similar effect based only in annotations (one annotation with two or more annotation attribute styles). Unfortunately :( I had done the major part of code when I known the alternative, and anyway I like AnnotatedIcons :)



As you can see in the image (I have no time to make a video), some icons are rendered and when the mouse is over one its associated annotation is shown with more extended information.

You can take the source code from here.

4 comments:

Anonymous said...

I'm using WWJ 0.5.0. Here a some fixes I did....

1. AnnotatedIconLayer should extend IconLayer not AbstractLayer.
2. AnnotatedIcon should call "super.setSize() in the constructor.

Rational:
1. AbstractLayer does not have a removeAllIcons operation.
2. If you extend AnnotatedIcon with your own class and that class has its own setSize operation that accesses entities that have yet to elaborate, you will get a null exception error.

Antonio Santiago said...

Hi Drain, thanks a lot for your comment, I take note on it.
At risk it could seem a poor excuse, please take a look at the readme file.

This little code was developed when WWJ0.4.1 was just released. The IconLayer was improved since then (removeAllIcons is a new method on 0.5).

Also, in the readme I comment the problem why I force to set the icons size (with setSize) in the AnnotatedIcon constructor.

Finally, thanks one more time for your feedback, I'm happy to see this blog is visited for more people than me ;)

Anonymous said...

I added a boolean to AnnotatedIcon named holdOpenAnnotation. With the following listener, the bubble will popup on rollover and stay in place on double-click (remove on next double-click).

public void selected(SelectEvent event) {
if (event.getEventAction().equals(SelectEvent.ROLLOVER)) {
Object object = event.getTopObject();
if (object instanceof AnnotatedIcon) {
AnnotatedIcon selected = (AnnotatedIcon)object;
if (selected != _lastIcon) {
if (_lastIcon != null) {
if (_lastIcon.isHeldOpen() == false)
_lastIcon.setShowAnnotation(false);
}
_lastIcon = selected;
_lastIcon.setShowAnnotation(true);
}
} else {
if (_lastIcon != null) {
if (_lastIcon.isHeldOpen() == false)
_lastIcon.setShowAnnotation(false);
_lastIcon = null;
}
}
} else if (event.getEventAction().equals(SelectEvent.LEFT_DOUBLE_CLICK )) {
Object object = event.getTopObject();
if (object instanceof AnnotatedIcon) {
AnnotatedIcon selected = (AnnotatedIcon)object;
if (selected.isHeldOpen()) {
selected.setHoldOpenAnnotation(false);
} else {
selected.setHoldOpenAnnotation(true);
}
}
}
}

Antonio Santiago said...

Thanks a lot Drain and sorry for my late reply.
Yes, your code could be very useful to show more complex annotations like GE brother ;)