Friday, 29 October 2010

Pause for breath

Reworked the code for the abstract base class that sits under the page level components, i.e. the text, image and score line widgets. Having taken reference from many different examples it needed harmonising a bit. Bottom line is I now have a component which sits in a JPanel which is DnD draggable and can be resized by the user. Still lots to do though and I stopped to think through how the mouse interactions were all going to work.

At the page level you want to be able to move those components around and drop new graphics or text in but you don't want them moving when you're manipulating the individual note elements, either dragging them about or creating a selection of a group of notes with the mouse by dragging a selection rectangle across the page. If the component which represents the score line is draggable then clicking and dragging within it's bounds would mean picking it up and moving it rather than drawing a selection rectangle - and how would the code tell the difference? Maybe the user was dragging the line about!

I thought of a couple of ways of approaching this. Firstly I thought we could set an "anchor" property on the line so that it locks it in place thus interpreting any mouse drags as select attempts This would be achieve by having a border which became visible when the mouse entered the component area which would hold the lock / anchor icon. User can then "unlock" the component and move it about, then lock when finished. OK, could work, bit of a funny sort of paradigm for a drummer to have to learn.

Next thought was to create the ability to lock all page level components. This could be achieved by menu action, or properties dialog of some sort. The paradigm then becomes "OK lay out titles, authors etc and any graphic logos etc, plus all the lines you want on the page then exit page layout mode and go into score editing mode" or words to that effect. I think that seems easier from a user perspective, i.e. consciously take an action to lay out the bits and pieces then switch to doing the score content itself.

I'm going to code up the latter one I think. Should be a case of setting a property in each page level component (of which there won't be too many) whenever the menu selection is made to switch modes. Could even put a special border or something round the page if in layout mode so it's easy to see.

Further thoughts included snap to grid functionality, i.e. when in page layout mode there's a faded grid in the background to which all component align themselves as they are being dragged (or more accurately as drop zones are tested by DnD). Could be interesting to figure out if that's something best implemented using a custom layout manager or if the components become aware of their position relative to the parent panels grid lines, i.e. code it up in the drop test function.

The component abstract class is becoming quite complex having to implement all the DnD interfaces, plus mouse handling and clipboard etc. Jeez not even gone anywhere near copy and paste yet! Or keyboard interface!

Am probably thinking ahead too much but the note elements could be implemented in the same way as Docs are in the swing text components ..... needs research as I've not really done anything with those components before, just read how they work.

Should probably post some of the component code up here to show how I've managed to make this work, seems to be a common problem on the forums. One thing I have had to stick on the backburner is zooming the view - turns out using AffineTransform is really easy to implement the scaling but you can't invert the scaling for mouse handling in the Swing DnD system - there's just been no thought put into that in the design of DnD or if there has, it's not apparent to anybody out there. Plan B is to iterate all components and apply resize ratios on zoom - expensive task in capacity terms as it's a piece of batch work that needs to complete before the user has a perspective again - think this is going to be one of those heavy GUIs when finished! Or at least until someone discovers how to make scaling a point and paint pastime ...

Anyway if anybody reads this stuff, and wants to see the code please just ask so in the comments.

No comments:

Post a Comment