First knowledge of jgraph

Source: Internet
Author: User
First knowledge of jgraph

Collation

When I was writing a project for my teacher, I urgently needed a Java-based graphical component. I found jgraph in my first search. The overall feeling is quite easy to use, and it is a set of tools that can cope with a variety of graphic purposes. Although I am not very satisfied with some of the programming styles. But it is good to do it! Thanks to the powerful tools provided by the jgraph community.
What I like most is that jgraph is only paying half the price for academic applications that require jgraph layout pro. This shows the importance of academic research outside China and the need for learning in China.

Introduction to jgraph

Jgraph has a high degree of interactivity and automation. It is a set of custom components. It is mainly used in some applications that need to represent the graph structure, such as flowcharts, UML, traffic lines, and networks.
The jgraph version is 5.8.0.0 at the time of writing this article. You can find the jgraph homepage at the link.
Jgraph mainly includes the following products:

Jgraph-the Java open source graph drawing component (with open source)
Jgraph layout pro-the Java Graph Layout Solution
Jgraphpad pro dimo-editor framework
Mxgraph thin client-jgraph in a browser!

Let's just learn. Of course we only use jgraph. Jgraph layout pro is a software for layout graphs. It looks cool to see the demo. Jgraphed pro now has a Web Start demonstration, which seems to be used for jgraph demonstration. On Solaris, I also saw jgraphed pro, which is a set of graphic editing software for the giant ox. Mxgraph thin client is a thin client software that uses JavaScript and SVG in the browser of the XML communication protocol.
Jgraph operations on graphs include: Graph Display, graph interaction, graph layout, and graph analysis.

The basic swing components of jgraph are as follows:

Org. jgraph basic jgraph class
Org. jgraph. event graph event model
Org. jgraph. Graph graph structure and Node
Org. jgraph. plaf graph UI delegate component
Common tools for org. jgraph. util

In addition, similar to jgraph, eclipse GEF can be used for plotting.

Jgraph Model

A figure -- main structure of the jgraph class:
Jgraph extends jcomponent {
Org. jgraph. graph. graphmodel model; (defaultgraphmodel)
Org. jgraph. plaf. graphui UI; (basicgraphui)
Org. jgraph. graph. graphlayoutcache cache;
}

In addition to the swing MVC structure, jgraph references the model and ui, and maintains a strange application graphlayoutcache. Graphlayoutcache can be seen as an extension of the model. It ensures the status and appearance of each node in the graph. Because of the complexity of graphs, A graphlayoutcache can be used to deal with these complex problems.
You can use a series of Set methods to configure jgraph, and there are many useful functions to switch.

The logical structure of the graph -- graphmodel class:
Meeting the MVC requirements, graphmodel stores all the objects in the graph, and its default implementation defaultgraphmodel can meet general requirements.
Graphmodel contains three basic operations: insert (), edit (), remove (). These operations will achieve the same effect as graphlayoutcache, but slightly different from graphlayoutcache, there are many parameters, which at first glance is more troublesome. In fact, all graphmodel requires is the logical structure of the node, and it does not care about the details of the node. Therefore, you can use graphmodel when initializing an image. Do not use its method to modify the details. This is neither convenient nor necessary.
In addition, graphmodel provides many get methods to conveniently retrieve corresponding nodes.

Cells

Jgraph has three units (cells): vertex, edge, and port.
Vertex can carry objects because jgraph is only responsible for representation and is not really responsible for data operations. Therefore, a messenger is needed between the image and the data, which is vertex, which can be objects such as text and graphics.
Port is a relatively unfamiliar Unit. It is not designed in graph algorithms, but it is very useful in graphic representation. Like its name, it is a port on vertex, which can be connected to other vertex through the port, and the port in jgraph can also be used to change the Edge Shape and so on.
Edge is a little different from the edge in graph algorithms. edge can only be connected to port rather than vertex. In this way, edge is more flexible and richer with more port units.

Default unit -- defaultcell:
It is the parent class of defaultedge and defaultport, and a subclass of defaultmutabletreenode. Its position can be equivalent to vertex. A defaultcell can carry a userobject. Each defaultcell has an attributemap, which is responsible for its attributes (color, size, and so on ). You can use a set method to modify attributemap.

Edge and port units-edge and Port:
Besides inheriting defaultcell, edge and port, there are also some unique methods.
Edge has the getsource () and gettarget () methods to obtain the objects at both ends of the edge (generally port ). Also, a routing class defines some routing methods.
The main task of port is to carry the edge, so there are some methods to obtain the edge. In addition, the port defines the method to obtain the anchor (for example, a vertex contains a port.

Cell processing:
Each cell includes Cell Object, cell Renderer, cell editor, and cell handle. Renderer is responsible for cell representation, including shape and so on. Editor is used to modify the cell. When you double-click the cell, the editor is called to edit the cell. The above are similar to jtable and jtree.
Handle is not included in the swing component, and its task is to process the cell size and movement. You can override the paint () method to specify the cell size and position changes caused by dragging the mouse.

For the attribute control of these units, you can take a closer look at the set method of graphconstants class. Basically, all attributes are modified using the set method of this class.

Summary

  • You can use graphconstants to set most attributes (I personally don't like this method)
  • A cell object can be set to view, Renderer, editor, and handler.
  • To customize a personalized cell, you need to inherit defaultcell and add new attributes and methods to implement them. Remember to modify attributemap, which will be helpful and reference userobject.
  • In addition, cells can only call the insert, delete, and modify methods, but cannot call the view.

Link

Jgraph:
Http://www.jgraph.com/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.