The NodeView
displays the data of the NodeModel
in a specific way. This can be done either by using Java components such as javax.swing.JTable
or javax.swing.JTree
or by drawing the data using the java.awt.Graphics
object. In the latter case a javax.swing.JPanel
can be used and the paintComponent(Graphics)
method must be overridden. There are four sites in the NodeView to place your code:
NodeView constructor:
- constructor
- modelChanged
- onOpen
- onClose
- The constructor is called whenever the view is opened. This is the best place to initialize the fields, data structures, and components you need. When everything is initialized and the preferences are set, call the
setComponent(Component)
. Only one component can be set with this method, thus, if you have several components you have the make a composite by your own and set this composite. It is good practice to call this method only once and then in the constructor. Note: you can leave the view open, when resetting the node or even change the input of the node, i.e. all operations related to the data of the model cannot be placed in the contructor. Hence, themodelChanged
method informs the view about changes in the underlyingNodeModel
. It is possible to open several views for a singleNodeModel
, though. Local functionality, such as selection, has to be administered in theNodeView
. Corresponding data structures can be initialized in theNodeView
's constructor.Example #1:
protected ValueCounterNodeView(final NodeModel nodeModel) { super(nodeModel); m_panel = new YourSpecializedPanel(); setComponent(m_panel); }