Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: How do I update a View when a Model's Collection is added to?
    primarykey
    data
    text
    <p>So I'm working on rewriting a program for a professor, and I have some questions related to the Model-View-Controller pattern. The program is called GraphViewer and is used to design and view graphs (as in Graph Theory, not Statistics). So far I have planned the structure thus:</p> <ul> <li>Models <ul> <li>VertexModel - Has id, location, color, and a collection of edges it is coincident to</li> <li>EdgeModel - Has the two vertices it spans, weight, color, and a couple other things</li> <li>GraphModel - Primarily, but not just, a collection of vertices and a collection of edges</li> </ul></li> <li>Views <ul> <li>VertexView - Paints its vertex, and has its own properties</li> <li>EdgeView - Paints its edge, and also has some of its own properties</li> <li>GraphView - Basically a JPanel that has a collection of vertex and edge views, when it gets a paint command, it also iterates through each collection of views and issues a paint command to them</li> </ul></li> <li>Controllers <ul> <li>GraphController - Takes care of interpreting user gestures for adding vertices, edges, etc. and updates the model.</li> </ul></li> </ul> <p>Now the first question I have is related to this plan: Should each model have a view--even though only the graphmodel is a JComponent? Now part of me says yes--because each vertex and edge might be drawn differently. But another part of me screams no to the kind-of parallel-list structure of a graphview having collections of views that correspond to models in the collections of the graphview's graphmodel (boy that's complicated). And somehow, I have to work in that the whole graphview must repaint if a vertex or edge model changes. I suppose the answer to this is also related to whether each model gets a controller. (Am I just approaching this wrong?)</p> <p>Somewhat tied to the answer of the first question is my second: how will I know to notify the graphview if a vertexmodel is added to the graphmodel's collection? If a whole new collection is set, it'll notify the view when it enters the setEdges() method. But what if I have to write getEdges().add(...)? Now the graphview needs to be notified of an update, but setEdges was never called...</p> <p>Thanks a bunch, as you can tell I'm kinda new to design patterns!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload