I'm trying to make a simple drawing application with the MVP pattern. Let's consider I want to be able to draw a circle and drag (move) the circle around on a JPanel. After the drag, the model should be updated. Further, in a second panel the center position (x,y) of the circle should be updated as well. Altough it seems to be overkill, I'd like to implement the second panel also as MVP.
Tasks to be performed:
- Drag a circle with the mouse
- The position of the circle should be stored in the model
- The view should only draw, what's in the model ( a circle at a specific position)
- The second MPV view should show the value of the x and y position of the circle in text form.
- At some point the user can click a save button, which will take the models data and stores it to a text file. On startup the position from the text file will be written to the model and the view refreshed.
Now here are my questions:
- I've read a lot of different solutions on how to implement the MVP pattern in general an specific with jgoodies. jgoodies seems to be perfect for standard gui components like text fields. As far as I understood, the viewer should only be passive. Thus the viewer visualizes the values hold in the model. Now, should the viewer call the presenter in a onDrag() method or should the peresenter call a viewer.getDragPane().addListener() method?
I assume in either implementation, the value in the model will be set. Who is telling the view to refresh, based on the new values in the model? With jgoodies the view is updated automatically, but how to do it without jgoodies? Should I have a method in the viewer class like, viewer.setData(model). I'm asking because I've read, that the view should know nothing about the model.
Now the second MVP (table with centerX, centerY as label) needs to be notified by someone. Who should this be? I've read that messagebusses are commonly used, but from my personal experience it's a bit "uncool" to debug messagebusses. Is there a best practice?