Edit--@Uri correctly pointed out that this was an abuse of annotations; trying to actually create the menu data itself in annotations is just silly.
They are good for binding however, I think I'll stick with using them to link the text data to the methods (the @Menu ("File") portion) since it's more explicit and flexible than reflecting to a method name. Also I learned quite a bit in messing with it. I'll post the code here in a few days as an answer.
--original post--
I haven't used these new-fangled annotations, but they look amazingly interesting. I'm having trouble figuring out the syntax though (or more appropriately, the best way to use it).
In writing some code in response to this question It occurred to me that my methods are quite outdated.
I used to parse a string to define my method structure, then use reflection to pass it out to classes, but I think annotations could make a much better menu structure.
I'd like to replace my test class in the file with something like this:
@TopMenu("File,Edit")
@Menu(name="File","Save,Load,Print,Preview,Quit")
@Menu(name="Print","Preview,Print")
@Menu(name="Edit","Copy,Paste")
public class TestMenu {
@MenuItem ("Save")
public void save() {
System.out.println("saved");
}
@MenuItem ("Load")
public void load() {
System.out.println("loaded");
}
...
and pass the entire class off to a method that manufactures and returns a JMenuBar bound to the class instance with no further input.
First problem is that I can't figure out how to pass a "Default" of a string, they all want to have (attribute="value") instead of just ("value"), can this be done? I can live without it, but it's a little verbose. It'd be even better if I could get rid of the parens and/or quotes, but I'm not holding my breath (I think to do that I'd have to define an individual interface for each menu item, that's not acceptable).
Secondly it doesn't like the multiple @Menu tags on a single class. I could get around this by parsing a single string, but I was wondering if there was another way.
Most importantly, is there a library that does this already? (If nobody comes up with one, I'll publish code to this thread when I get it working in case anyone else is interested.)