Jgraph development experience

Source: Internet
Author: User
Subaccount

Originally, swing or AWT was rarely used, but recently the company had to create a custom workflow interface, so it finally got what it wanted. I know that, if everything starts from the bottom layer, I am afraid that time and energy are not allowed, and some ready-made workflow products cannot meet the needs of the company's specific industry workflows, so I had to find an open-source middleware and modify it. In this way, I gradually got to know jgraph ......
About jgraph, open-open is introduced as follows: jgraph, a graphical component developed purely in Java, supports drag, drop, zoom, merge, and other operations. It can be integrated into any swing application.
On jgraph's website, we can see that it is divided into free, pro, and layout pro versions. As the majority of "hard-working people", of course, the free version is preferred ~~

Drawing Mechanism of jgraph

Referring to the example and source code of jgraph, we found that:

Jgraph defines elements as one cell. Each cell can be a vertex (vertex), edge (edge), or node (port. Vertices can have adjacent vertices. They are connected by edges. The two endpoints connected by edges are called the target and source. Each target or source is a node. A node is a child of a vertex. Each cell can have its own children.
The appearance of each cell is defined by the corresponding attribute. The attribute sequence refers to a series of key-value pairs, which are organized in the form of map. For example:

// Define the appearance of Edge
Map map = new hashtable ();
Graphconstants. setlineend (MAP, graphconstants. arrow_classic );
Graphconstants. setendfill (MAP, true );
Graphconstants. setlabelalongedge (MAP, true );
Getattributes (). applymap (MAP );

The "canvas" (similar to jgraph) can also have its own appearance attributes. For example:

// Define the canvas attributes
Setbackground (color. Decode ("# c0c0c0 "));
Seteditable (false );
Setcloneable (false );
Setinvokesstopcellediting (true );
Setjumptodefaultport (true );
Setportsvisible (false );
Setgridenabled (false );
Setgridvisible (false );
Setgridmode (jgraph. cross_grid_mode );
Setgridcolor (color. Decode ("#808080 "));
Setgridsize (10 );

Jgraph Extension

Jgraph only provides a simple graphic rendering function that does not contain actual data. Therefore, if you want to add your own data, you may have to consider extending jgraph.
The vertex class is org. jgraph. graph. defaultgraphcell.
The Edge Class is org. jgraph. graph. defaultedge.
The class corresponding to the node (port) is org. jgraph. graph. defaultport.
All we need to do is inherit the corresponding classes and put our own data objects in them. Of course, you can also change the appearance attributes. However, if you are also interested in drawing events (which should be useful in), pay attention to Org. jgraph. graph. basicmarqueehandler and org. jgraph. graph. graphundomanager. Basicmarqueehandler processes events such as clicking the mouse on the canvas, adding connections, and merging. graphundomanager revokes and replies to events.
If you perform this operation carefully, you may find that the event of moving by the edge endpoint is not handled by graphundomanager. At this time, you need to pay attention to another class: Org. jgraph. graph. edgeview. edgehandle is an internal class. If necessary, rewrite a class to inherit it. In this way, most of the required events are under control.
Hey ~~~~

Summary

In fact, there is nothing to summarize. writing this article is also hesitant to enable the keyboard three more times. It was originally intended to be written last month. Until now, I think it's just a simple application. It's all basic skills. There's no "advanced" or "new". It seems there's nothing to write about.
I read a post on blogjava today, and I was deeply touched by the following sentence: "It's better to get bored with the old classic technology all day long ", I have been confused for a long time! Starting from basic skills, I am not a master, but I am very familiar with it ......

Postscript

If you are interested in similar projects, please give us some advice and study and discuss them together.

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.