Chapter 6. Displaying and Editing Graphs

Table of Contents

Model-View-Controller Paradigm
Graph Structure Enhancements
Class Graph2D
Advanced Topics
Bringing Graph Elements to Life: The Realizer Concept
Binding Realizers
General Features
Node Realizers
Edge Realizers
Realizer-Related Features
Label Support
Related Classes
Selection State
Writing Customized Realizers
Subclassing and Overriding
Providing Interface Implementations
Swing User Interface Components as Node Realizers
Rendering
Editor Functionality
Tutorial Demo Code
View Implementations
Class Graph2DView
Class Overview
Related Classes and Interfaces
User Interaction
Mouse-Driven Actions
Keyboard-Driven Actions
Label Editor
Node-Related Editing Capabilities
ViewMode Workings
Class EditMode
Class NavigationMode
Class CellEditorMode
Class MagnifierViewMode
Class AutoDragViewMode
Related Classes and Interfaces
Customizing an EditMode
Events and Listeners
Graphical Property Changes
Selection State Changes
Multiple Views on a Common Model Graph
Concept
Class ModelViewManager
Printing a Graph's Visual Representation
Scaling and Clipping
Title Bar and Footer Support
Printing Preview
Creating a Dedicated Printing View
Tutorial Demo Code
Animations for Graph Elements
Animation Framework
Tutorial Demo Code
Advanced Application Logic
Undo/Redo
Clipboard
Layout Morphing

This chapter shows how to render a graph in a so-called "view." It presents the classes that are responsible for the visual representation of graph elements and explains their contribution to the "look and feel" of an application. Furthermore, it shows how user interaction with both graph elements and the view containing a graph is handled.

Model-View-Controller Paradigm

Package y.view bundles the yFiles classes that provide user interface (UI) functionality. UI functionality comprises two main aspects, namely the representation of a graph structure to the user and the interaction of a user with the graph structure.

The classes from package y.view reflect the Model-View-Controller (MVC) paradigm, i.e., conceptually they can be divided into three types, each having specific responsibilities:

  • Model classes: hold data specific to the application
  • View classes: present information to the user
  • Controller classes: tie the model to the view

In terms of MVC then, class Graph2D together with classes NodeRealizer and EdgeRealizer make up the model which holds the data and its state. Class Graph2DView defines the view which presents the information to the user. Finally, class ViewMode and its descendants tie together model and view.

The respective parts of MVC are further described in the following sections:

Figure 6.1, “Model-View-Controller paradigm in package y.view” depicts the interdependencies of the three parts. The view (a Graph2DView instance) renders the model (an object of type Graph2D); it also propagates user interface events to the controller (class ViewMode and its descendants). According to these events, the controller then changes state on either view or model.

Figure 6.1. Model-View-Controller paradigm in package y.view

Model-View-Controller paradigm in package y.view.