Sunday, September 9, 2007

dragging a bit around

After the A JChemPaint Hack-a-thon a week ago it was time to make something more interesting then dumping the nearest IAtom to STDOUT. So I went on coding to make it possible to move Atoms around.
The new architecture had no way yet make the renderer 'repaint' the window. My first attempt was using the Component from a MouseEvent and after that dragging worked ok for Swing. Egon reminded me that with SWT it is probably not possible that way and unfortunately that was true. So we added a new Interface IViewEventRelay which currently only exist of updateView(). The swing implementation SwingEventRelay is added to the Controller2DHub so Controller2DModules can use updateView() now and the Controller2DHub will know which IViewEventRelay to use.
Because Java2DRenderer calculated the atom boundaries again on a repaint() it showed strange behaviour. If you moved one atom, the other ones would move most likely aswell. Also it was impossible to move atoms 'out of the screen' instead everything would be drawn smaller. So Java2DRenderer is now only calculating new boundaries if the window is new or is resized. If you resize the window it will make sure all atoms/bounds are visible again.
In the video you can see how dragging looks like now. The dragging isn't perfect yet, at some moments when moving an atom 'over' another one it will continu to drag the other atom.
This also shows that the location of the H symbol isn't always correct and that a charge symbol at some point ends up in 'the air'.
If you want to give the new architecture a test run, look for the TestEditor application.

1 comment:

Egon Willighagen said...

Thanx! This is a perfect example of the new architecture [1,2]. Now comes the work of porting all old editing features to the new framework.

I have put up a wiki page to coordinate porting of the editing code to the new module architecture:

http://wiki.cubic.uni-koeln.de/cdkwiki/doku.php?id=jcp_controller_modules.

1.http://wiki.cubic.uni-koeln.de/cdkwiki/doku.php?id=renderer2dredesign
2.http://wiki.cubic.uni-koeln.de/cdkwiki/doku.php?id=jcp_hack_20070902