Download Jar. Uses 2086K of libraries. Click here for Pure Java version (5618L/40K).
1 | !7 |
2 | |
3 | import java.awt.geom.*; |
4 | |
5 | lib 1007171 |
6 | |
7 | import org.jgraph.JGraph; |
8 | import org.jgraph.graph.DefaultGraphCell; |
9 | import org.jgraph.graph.GraphConstants; |
10 | |
11 | import org.jgrapht.ListenableGraph; |
12 | import org.jgrapht.ext.JGraphModelAdapter; |
13 | import org.jgrapht.graph.ListenableDirectedGraph; |
14 | import org.jgrapht.graph.DefaultEdge; |
15 | |
16 | /** |
17 | * A demo that shows how to use JGraph to visualize JGraphT graphs. |
18 | * |
19 | * @author Barak Naveh / adapted by Stefan Reich |
20 | */ |
21 | |
22 | static final Color DEFAULT_BG_COLOR = Color.decode( "#FAFBFF" ); |
23 | static final Dimension DEFAULT_SIZE = new Dimension( 530, 320 ); |
24 | |
25 | static JGraphModelAdapter m_jgAdapter; |
26 | |
27 | p-awt { |
28 | // create a JGraphT graph |
29 | ListenableGraph g = new ListenableDirectedGraph( DefaultEdge.class ); |
30 | |
31 | // create a visualization using JGraph, via an adapter |
32 | m_jgAdapter = new JGraphModelAdapter( g ); |
33 | |
34 | JGraph jgraph = new JGraph( m_jgAdapter ); |
35 | |
36 | adjustDisplaySettings( jgraph ); |
37 | frameInnerSize(showFrame(jgraph), DEFAULT_SIZE); |
38 | |
39 | // add some sample data (graph manipulated via JGraphT) |
40 | g.addVertex( "v1" ); |
41 | g.addVertex( "v2" ); |
42 | g.addVertex( "v3" ); |
43 | g.addVertex( "v4" ); |
44 | |
45 | g.addEdge( "v1", "v2" ); |
46 | g.addEdge( "v2", "v3" ); |
47 | g.addEdge( "v3", "v1" ); |
48 | g.addEdge( "v4", "v3" ); |
49 | |
50 | // position vertices nicely within JGraph component |
51 | positionVertexAt( "v1", 130, 40 ); |
52 | positionVertexAt( "v2", 60, 200 ); |
53 | positionVertexAt( "v3", 310, 230 ); |
54 | positionVertexAt( "v4", 380, 70 ); |
55 | |
56 | // that's all there is to it!... |
57 | } |
58 | |
59 | static void adjustDisplaySettings( JGraph jg ) { |
60 | jg.setPreferredSize(DEFAULT_SIZE); |
61 | jg.setBackground(DEFAULT_BG_COLOR); |
62 | } |
63 | |
64 | static void positionVertexAt( Object vertex, int x, int y ) { |
65 | DefaultGraphCell cell = m_jgAdapter.getVertexCell( vertex ); |
66 | Map attr = cell.getAttributes( ); |
67 | Rectangle2D b = GraphConstants.getBounds( attr ); |
68 | |
69 | GraphConstants.setBounds( attr, new Rectangle2D.Double( x, y, b.getWidth(), b.getHeight() ) ); |
70 | |
71 | Map cellAttr = lithashmap(cell, attr); |
72 | m_jgAdapter.edit( cellAttr, null, null, null); |
73 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1007170 |
Snippet name: | JGraphT Graphical Demo [OK] |
Eternal ID of this version: | #1007170/14 |
Text MD5: | 4737a666ed7f5e80e75277c50643a838 |
Transpilation MD5: | 711121503e276c9e035f26499ef8d258 |
Author: | stefan |
Category: | javax / imaging |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-12-20 14:34:39 |
Source code size: | 2101 bytes / 73 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 563 / 1176 |
Version history: | 13 change(s) |
Referenced in: | [show references] |