Any pattern or nice solution to this ...
I have an app which goal is to model UML graphically and generate code from models.
My doubt is explained next:
I have the graphical base component where UML components are drawn. For example Class Diagrams, Interfaces, just the same than Rational Rose.
If I want to create a Class on the graphical component ( draw the class ) I need firt to use the creation bar where all buttons related to create graphical componenets are located.
If I click any of those buttons and then go and click somewhere on the base graphical component I need to check out what button was pressed.
How would be a nice way to perform this ?
I thought about creating a CreatorCmdBarStatus where we can post(currentCmd) and then when the mouse is clicked on the base graphical component, check out that CreatorCmdBarStatus to see which has been the last posted cmd ( either a class creation or interace creation and so on ).
Another solution using some elegant way to resolve this ?
Thanks.
[1022 byte] By [
jfreebsda] at [2007-10-2 14:41:26]

A nice solution would be setting a javax.swing.Action for that button. If the button is clicked, the actionPerformed method of the Action is invoked.
You can create subclasses of the Action class, in which the action is performed.
Creating a button using a helloworld action:
JButton button = new JButton(new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
System.out.println("Hello world");
}
});
> I have an app which goal is to model UML graphically
> and generate code from models.
>
> My doubt is explained next:
>
> I have the graphical base component where UML
> components are drawn. For example Class Diagrams,
> Interfaces, just the same than Rational Rose.
>
> If I want to create a Class on the graphical
> component ( draw the class ) I need firt to use the
> creation bar where all buttons related to create
> graphical componenets are located.
>
> If I click any of those buttons and then go and click
> somewhere on the base graphical component I need to
> check out what button was pressed.
>
> How would be a nice way to perform this ?
>
> I thought about creating a CreatorCmdBarStatus where
> we can post(currentCmd) and then when the mouse is
> clicked on the base graphical component, check out
> that CreatorCmdBarStatus to see which has been the
> last posted cmd ( either a class creation or interace
> creation and so on ).
>
> Another solution using some elegant way to resolve
> this ?
>
> Thanks.
It might not be exactly the same thing, but I wondered if there was a JRadioButton pattern for "ButtonGroup.getSelected(Radio)Button()...doSomethingWithIT()"
You wouldn't want to try something with (J)ToggleButton in a ButtonGroup (there you would even have user (UI) feedback)?