Uses 591K of libraries. Click here for Pure Java version (209L/2K/6K).
1 | !7 |
2 | |
3 | lib 1007175 // mxGraph |
4 | |
5 | import com.mxgraph.model.mxCell; |
6 | import com.mxgraph.util.mxPoint; |
7 | import com.mxgraph.view.mxGraph; |
8 | |
9 | p { Frame.main(args); } |
10 | |
11 | /** |
12 | * The frame example uses the graph model API to programmatically create |
13 | * a graph image to be used as a background of a JComponent. |
14 | */ |
15 | static class Frame extends JFrame |
16 | { |
17 | |
18 | /** |
19 | * |
20 | */ |
21 | private static final long serialVersionUID = -578683911307318455L; |
22 | |
23 | /** |
24 | * |
25 | */ |
26 | private GraphControl graphControl; |
27 | |
28 | /** |
29 | * |
30 | */ |
31 | public Frame() |
32 | { |
33 | super("mxGraph"); |
34 | |
35 | // Creates graph with model |
36 | mxGraph graph = new mxGraph(); |
37 | Object parent = graph.getDefaultParent(); |
38 | |
39 | graph.getModel().beginUpdate(); |
40 | try |
41 | { |
42 | |
43 | Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80, |
44 | 30); |
45 | mxCell v2 = (mxCell) graph.insertVertex(parent, null, "World!", |
46 | 240, 150, 80, 30); |
47 | Object e1 = graph.insertEdge(parent, null, "e1", v1, v2); |
48 | |
49 | mxCell v3 = (mxCell) graph.insertVertex(e1, null, "v3", -0.5, 0, |
50 | 40, 40, "shape=triangle"); |
51 | v3.getGeometry().setRelative(true); |
52 | v3.getGeometry().setOffset(new mxPoint(-20, -20)); |
53 | } |
54 | finally |
55 | { |
56 | graph.getModel().endUpdate(); |
57 | } |
58 | |
59 | // Creates a control in a scrollpane |
60 | graphControl = new GraphControl(graph); |
61 | JScrollPane scrollPane = new JScrollPane(graphControl); |
62 | scrollPane.setAutoscrolls(true); |
63 | |
64 | // Puts the control into the frame |
65 | getContentPane().setLayout(new BorderLayout()); |
66 | getContentPane().add(scrollPane, BorderLayout.CENTER); |
67 | setSize(new Dimension(320, 200)); |
68 | } |
69 | |
70 | /** |
71 | * |
72 | */ |
73 | public static void main(String[] args) |
74 | { |
75 | Frame frame = new Frame(); |
76 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
77 | frame.setVisible(true); |
78 | } |
79 | } |
80 | |
81 | |
82 | import com.mxgraph.util.mxCellRenderer; |
83 | import com.mxgraph.util.mxEvent; |
84 | import com.mxgraph.util.mxEventObject; |
85 | import com.mxgraph.util.mxEventSource.mxIEventListener; |
86 | |
87 | static class GraphControl extends JComponent { |
88 | |
89 | /** |
90 | * |
91 | */ |
92 | private static final long serialVersionUID = -7470544285363165479L; |
93 | |
94 | mxGraph graph; |
95 | |
96 | Icon buffer; |
97 | |
98 | public GraphControl(mxGraph graph) |
99 | { |
100 | this.graph = graph; |
101 | this.graph.getModel().addListener(mxEvent.CHANGE, |
102 | new mxIEventListener() |
103 | { |
104 | public void invoke(Object source, mxEventObject evt) |
105 | { |
106 | GraphControl.this.graphModelChanged(); |
107 | } |
108 | }); |
109 | } |
110 | |
111 | public mxGraph getGraph() |
112 | { |
113 | return graph; |
114 | } |
115 | |
116 | public void paint(Graphics g) |
117 | { |
118 | super.paint(g); |
119 | paintBuffer(g); |
120 | |
121 | } |
122 | |
123 | void paintBuffer(Graphics g) |
124 | { |
125 | Icon icon = getBuffer(); |
126 | icon.paintIcon(this, g, 0, 0); |
127 | } |
128 | |
129 | public Icon getBuffer() |
130 | { |
131 | if (buffer == null) |
132 | { |
133 | updateBuffer(); |
134 | } |
135 | return buffer; |
136 | } |
137 | |
138 | protected void updateBuffer() |
139 | { |
140 | buffer = createBuffer(); |
141 | int width = buffer.getIconWidth() + 1; |
142 | int height = buffer.getIconHeight() + 1; |
143 | Dimension d = new Dimension(width, height); |
144 | |
145 | if (!getPreferredSize().equals(d)) |
146 | { |
147 | setPreferredSize(d); |
148 | revalidate(); |
149 | } |
150 | } |
151 | |
152 | protected Icon createBuffer() |
153 | { |
154 | return new ImageIcon(mxCellRenderer.createBufferedImage(graph, null, |
155 | graph.getView().getScale(), null, true, null)); |
156 | } |
157 | |
158 | protected void clearBuffer() |
159 | { |
160 | buffer = null; |
161 | } |
162 | |
163 | public void refreshBuffer() |
164 | { |
165 | clearBuffer(); |
166 | repaint(); |
167 | } |
168 | |
169 | protected void graphModelChanged() |
170 | { |
171 | refreshBuffer(); |
172 | } |
173 | |
174 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1007176 |
Snippet name: | Test mxGraph [WORKS, but code is too long] |
Eternal ID of this version: | #1007176/5 |
Text MD5: | 66622623297da32b716fce9cb5e64860 |
Transpilation MD5: | 41b534b444fb167f8a88f960a5487707 |
Author: | stefan |
Category: | javax / imaging |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-03-10 15:19:55 |
Source code size: | 3420 bytes / 174 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 497 / 576 |
Version history: | 4 change(s) |
Referenced in: | [show references] |