forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrame.java
More file actions
82 lines (67 loc) · 1.75 KB
/
Frame.java
File metadata and controls
82 lines (67 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.mxgraph.examples;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import com.mxgraph.model.mxCell;
import com.mxgraph.util.mxPoint;
import com.mxgraph.view.mxGraph;
/**
* The frame example uses the graph model API to programmatically create
* a graph image to be used as a background of a JComponent.
*/
public class Frame extends JFrame
{
/**
*
*/
private static final long serialVersionUID = -578683911307318455L;
/**
*
*/
private GraphControl graphControl;
/**
*
*/
public Frame()
{
super("mxGraph");
// Creates graph with model
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try
{
Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80,
30);
mxCell v2 = (mxCell) graph.insertVertex(parent, null, "World!",
240, 150, 80, 30);
Object e1 = graph.insertEdge(parent, null, "e1", v1, v2);
mxCell v3 = (mxCell) graph.insertVertex(e1, null, "v3", -0.5, 0,
40, 40, "shape=triangle");
v3.getGeometry().setRelative(true);
v3.getGeometry().setOffset(new mxPoint(-20, -20));
}
finally
{
graph.getModel().endUpdate();
}
// Creates a control in a scrollpane
graphControl = new GraphControl(graph);
JScrollPane scrollPane = new JScrollPane(graphControl);
scrollPane.setAutoscrolls(true);
// Puts the control into the frame
getContentPane().setLayout(new BorderLayout());
getContentPane().add(scrollPane, BorderLayout.CENTER);
setSize(new Dimension(320, 200));
}
/**
*
*/
public static void main(String[] args)
{
Frame frame = new Frame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}