JGRAPH FAQ (Continued 2)

zhaozj2021-02-16  51

JGRAPH FAQ (Continued 2)

Translation: nxyc_twz@163.com

core

Is JGRAPH to be serialized?

Yes, nor. JGRAPH and its classes support short-term serialization without supporting long-term serialization (using XMLencoder). However, in most cases, the short-term serialization is sufficient to graphic mode. Clarification: new API separation mode and view. If a single serialization model, visual properties (such as size, location, color, etc.) cannot be saved! By overloading the graphmodel.isattributestore () method, JGRAPH can be set to store visual properties into the model. Typically, JGRAPH (short period) serialization should not use storage files, and do not recommend serialization of long-term GraphModel. Note: The file format depends on the application and is not included in the core API of JGRAPH. The JGRAPH component supports XML through Swing's long-term serialization, but now only a short period serialization is achieved. The file format used in JGraphPad is vector (such as an array of object arrays) including a serialized model unit, and the connection between these units, such as the corresponding view, CellView,. (Note: Using the Vector Description Parameter Insert Unit to GraphModel) You can refer to Implementation in class com.jgraph.pad.gpgraph: getArchiveAbleState () and setarchiveableState () methods.

How to achieve drag / put?

JGRAPH is fully adapted to two Java versions (Java 1.3 and Java 1.4). Java 1.3 DND supports Transferables, DropTargetListeners and DragsourceListeners, which are illustrated in the Java API specification. (Java 1.4 version uses JComponent's TransferHandler.) Dragging, is part of Java, not JGraph, JGRAPH is completely compatible with swing drag, put. Therefore, I suggest you check the details of the Java document. For example, you can refer to the Java Guide: http://java.sun.com/docs/books/tutorial/dnd/Java 1.3 version of a good drag, the presentation example can be referred to: http://www.javaworld.com/ JavaWorld / JW-03-1999 / JW-03-Dragndrop.html Java 1.4 version of JGRAPH Using Swing New Properties TransferHandler:

Public class myTransferhandler Extends TransferHandler {

Public Boolean ImportData (JComponent Comp, Transferable T) {

Point P = getInsertionLocation ();

Object cell = graph.getCellForLocation (p.x, p.y);

CellView View = graph.getmapping (Cell);

View InstanceOf Graphdrophandler

Return (graphdrophandler) View .handle (p, t);

Else

Return Super.Importdata (Comp, T);

}

}

Graph.setTransferHandler (New MyTransferHandler ());

How to open an editing dialog?

Use JGRAPH.STARTEDITIATCELL (Object) to start editing units. To program a change tag, you can use the Value property: map change = graphconstants.createmap ();

GraphConstants.SetValue (Change, "Hello World!");

Map Nest = new hashtable ();

Nest.Put (Cell, Change);

Model.ed (Nest, NULL, NULL, NULL);

How to reflect the zoom in the event handle?

JGraph provides two ways: fromScreen method, used to transfer mouse events to the model; Toscreen method, used to transfer models to the scaled screen. Name habits of these methods are based on actual conditions, such as the units on the screen and its visual description, need to transmit "from the screen" to the unit, and vice versa ("to the screen"). Typically, the following methods are commonly used:

Public void mousepressed (mouseevent e) {

Point Point = graph.fromscreen (new point (E.GETPOINT ()));

Cell = graph.getnextViewat (Null, Point.x, Point.y);

}

Note: The getFirstCELLAT and GetNextCellat methods do not need to scale their parameters.

User objects can be set to a string after editing?

JGRAPH provides interface DEFAULTGRAPHCELL.VALUECHANGEHANDLER for this issue. If your customized user object implements the interface, it will not be rewritten when edited. At the same time, DefaultGraphcell calls the ValueChanged method with the new parameter value of the user object (new value is a string), and looks forward to return the original value (using the same mechanism to achieve the modified undo function). The return value can be any object that the ValueChanged method can process.

Does the debug output contain only empty strings?

When using the code such as System.out.Println (Cell), you should remember that the method defaultgraphcells toString is pointed to a user object that might be empty string. This method inherits from Swing DefaultTreenode.

How to test the surrounding limit?

Use the defaultgraphmodel.contains method.

How to shrink / expand / hide unit?

GraphLayoutCache must be "topical". You can use the following code to create local graphLayoutCache:

JGRAPH graph = new jgraph ();

GraphLayoutcache Cache = New GraphLayoutcache (graph, graph.getmodel (), false, true);

Graph.setgraphLayoutcache (cache);

The following code successfully implements the display and hidden vertices and their parent nodes:

Object [] Cells = getSelectionCells ();

if (Cells! = NULL) {// If the unit is selected

LinkedList Children = new linkedlist ();

For (int i = 0; i

For (int J = 0; j

Children.Add (Model.getChild (Cells [i], j);

}

Object [] Childs = Children.toArray (); graph.getgraphLayoutcache (). Setvisible (childs, cells);

Graph.setSelectioncells (GetSelectionCells ());

}

This method has many modifications, so we will keep it so that you can implement it in your application. (Note: In this operation, the edge of the parent node will automatically hide).

(to be continued……)

转载请注明原文地址:https://www.9cbs.com/read-26391.html

New Post(0)