Saturday, 16 January 2010

collections, windows, focus etc

OK, so maybe a List collection is the right way to store all the open JFrames (so we can call requestFocus to switch to it [I think]) and the score name to put in the menu text.

I can see there being a future request to enhance what gets shown in the menu text if a user has two different scores open but both have the same score name, rather than filename. Let's park that for now, I think the hardest bit to get working will be the storing of the JFrames in a suitable collection.

Don't know if by providing it's JFrame object, an editor could tell the control object which entry in the List it is, so it can be deleted if it's closing, or perhaps it's opened a different score and needs to change its title. To be tested.

Got a problem with the menus at the moment in that I thought I could create one central JMenu object for the Window menu and have all the different JFrames menubars hook up to it. Nope, it deregisters from one menubar when added to another. This means almost that if each JFrame has it's own Window menu, the control object has to tell each JFrame when the contents change. Now I know there's an observable mechanism for this, and you can fire a change event, maybe it's as simple as whenever there's a change the control object iterates the list informing each JFrame to rebuild it's Window menu.

Phew could be messy with one object iterating the list and telling each to iterate at the same time. Needs thinking through. What we seem to be coming to is multiple identical lists and any change registered with the control object, requiring the request to be forwarded to each open JFrame, except the one that sent it in?!? More of a pub/sub thing maybe, like guys here's a change, and the JFrames listening for that change. Probably what observable does. This is all getting complicated, and observable collection, which each JFrame registers an interest in, and thus each JFrame implementing the change to its own collection, then regenerating it's Window JMenu.

Given a JMenu can't be shared between multiple JMenuBars I'm struggling with other options. Seems like a lot of work for something very common, e.g. internal frames under a jframe must have a way of maintaining lists or the Window menu - going to go look at some examples.

No comments:

Post a Comment