Jgraph Introduction and Usage Tips

Source: Internet
Author: User

It has been very rare to have access to swing or AWT, just recently the company has to do a workflow customization interface, so finally get the wish. I know, if all from the bottom of the words, I am afraid time, energy is not allowed, and some of the workflow products can not meet the needs of the company specific industry workflow, so have to find an open source middleware to modify. In this way, slowly understand the jgraph ...

On the Jgraph,open-open is this introduction: Jgraph, pure Java development of graphical components, support drag, drop, zoom, merge and other operations. It can be incorporated into any swing application.

In Jgraph's website can be seen, it is divided into free, Pro and Layout Pro version, as the vast number of "labor people", of course, the preferred free version, hehe ~ ~

The drawing mechanism of jgraph

Referring to the Jgraph's example and source code, we found that:

Jgraph defines an entity as a cell, and each cell can be one of a vertex (Vertex), Edge (edge), or node (Port). Vertices can have contiguous vertices, they are connected by edges, and the two endpoints of an edge join are called targets and sources, and each target or source is a node. node is the vertex of the child. Every cell can have its own children.

The appearance of each cell is defined by the corresponding attribute sequence, which refers to a series of key-value pairs, which are organized in the form of a map, for example:

Define the appearance of the Edge

Map map = new Hashtable ();

Graphconstants.setlineend (map, Graphconstants.arrow_classic);

Graphconstants.setendfill (map, true);

Graphconstants.setlabelalongedge (map, true);

GetAttributes (). Applymap (map);

and the "Canvas" (class Jgraph, you might want to understand it) can also have their own appearance attributes. For example:

Defining the properties of a canvas

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);

Extension of the Jgraph

Jgraph just provide a simple graphics rendering function, does not contain actual data, so to find a way to "add" their data into the only line, which I am afraid to consider the expansion of the jgraph.

Vertex (Vertex) corresponds to a class of Org.jgraph.graph.DefaultGraphCell

The corresponding class of Edge (Edge) is Org.jgraph.graph.DefaultEdge

Node (Port) corresponds to a class of Org.jgraph.graph.DefaultPort

All we have to do is simply inherit the corresponding class and put our own data objects into it. Of course, you can also change the corresponding appearance properties. But if you are interested in drawing events (oh, ten should be useful), Also pay attention to Org.jgraph.graph.BasicMarqueeHandler and Org.jgraph.graph.GraphUndoManager these two classes. The basicmarqueehandler includes the process of clicking the mouse on the canvas, increasing the connection, merging, and so on, while Graphundomanager the supervisor to undo and reply to the event.

If you do this carefully, you may find that the event that you click on the end of The Edge (edge) to move is not handled by Graphundomanager. This is the time to pay attention to a class: Org.jgraph.graph.EdgeView.EdgeHandle, this is an internal class, if necessary, rewrite a class to inherit it. In this way, most of the events that need to be done are in their own hands.

Summarize

In fact, there is no good summary, write this article is hesitant to open the keyboard, originally prepared to write in the last month. has been dragged until now, because I think it is just a simple application, are all basic skills, there is no "advanced" "new", as if there is nothing to write.

Today in Blogjava read a post, feeling quite deep, one of the words "the whole day eloquent new technology, better to be the classic old technique drunk in the heart", a language to solve puzzles me a long time of a puzzle! From the basic skills, not a master, only hand-cooked and ...

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.