Basically all the component does is extend JButton,
over-riding a few key methods. The first thing it
does is add something to hold the multiple actions,
and identify the selected action.
It then adds a certain amount on to the returned
minimum size etc to ensure it has enough space to
draw the down arrow on the right (which allows the
multiple selection), and of course overrides the
paint method to draw the triangle (this needs some
real work and cross L&F testing right now) and a
line between the triangle and the action when the
mouse is hovering.
That line tells the user that clicking on the left
will have a different effect to clicking on the
right. In order to deliver that we simple check to
see if they should fire the current action (on the
left) or show a menu of all of the actions (on the
right).
/**
* Overridden so that a check can be made to see if
the current action should be fired, or the
* list of available actions should be shown.
* @param actionEvent The action event
*/
protected void fireActionPerformed(ActionEvent
actionEvent) {
if (this.getMousePosition().x>boundary){
JPopupMenu popup = new JPopupMenu();
for (Action action : actions){
popup.add(new ActionOptionWrapper(action));
}
popup.show(this,0,getHeight());
} else {
super.fireActionPerformed(actionEvent);
}
}
And that's it. The ActionOptionWrapper just sets the
selected action as the current action, and then fires
it. Simple really! Any how, I'll develop this one and
I do have "Rich" plans for it, but given this one can
be useful out the box, and I haven't had a chance to
do cross platform testing (hint hint).