Debian Codegraph @

docs/visualizations.html

raw
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <!--
4 /* ==========================================
5 * JGraphT : a free Java graph-theory library
6 * ==========================================
7 *
8 * Project Info: http://jgrapht.sourceforge.net/
9 * Project Lead: Barak Naveh (http://sourceforge.net/users/barak_naveh)
10 *
11 * (C) Copyright 2003, by Barak Naveh and Contributors.
12 *
13 * This library is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU Lesser General Public License as published by
15 * the Free Software Foundation; either version 2.1 of the License, or
16 * (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
21 * License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public License
24 * along with this library; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
26 */
27 /* ~~~~~~~~~~~~~~~~~~~
28 * visualizations.html
29 * ~~~~~~~~~~~~~~~~~~~
30 * (C) Copyright 2003, by Barak Naveh and Contributors.
31 *
32 * Original Author: Barak Naveh
33 * Contributor(s): -
34 *
35 * $Id: visualizations.html 677 2009-03-13 22:40:26Z perfecthash $
36 *
37 * Changes
38 * ~~~~~~~
39 * 03-Aug-2003 : Initial revision (BN);
40 *
41 */
42 -->
43
44 <head>
45 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
46 <meta name="Author" content="Barak Naveh">
47 <meta name="keywords" content="JGraphT, Java graph library, graph theory, free, java, LGPL, open-source">
48 <title>JGraphT visualization using JGraph</title>
49 </head>
50 <body>
51 <h1><font color="#cc3399">J</font>Graph<font color="#ffcc00">T</font>&nbsp;Visualizations<br>
52 <font size="5">via JGraph</font></h1>
53
54
55 <br>
56
57 <h2>THIS PAGE IS OUT OF DATE</h2>
58
59 Modern web browsers don't support applets directly, and <a href="https://github.com/jgrapht/jgrapht/issues/522">JGraphT is dropping support for JGraph and replacing it with JGraphX</a>. If you'd like to help with making this page work again, <a href="https://github.com/jgrapht/jgrapht/issues/523">here is the relevant github issue</a>.
60
61 <h2>Demo Applet</h2>
62
63
64 <p>The following applet shows how a JGraphT graph can be visualized using
65 <a href="http://www.jgraph.com/">JGraph</a>. Try to play and drag
66 around the vertices and edges to get the feel of it.</p>
67
68
69 <p><font color="#7AA1E6" size="2">Note: Java 1.3 or above must be installed for
70 this applet to work correctly.</font></p>
71
72 <br/>
73
74
75 <table align="center" border="1" bordercolor="#7AA1E6" style="border-collapse: collapse" >
76 <tr><td>
77 <applet width="550" height="330"
78 code="org._3pq.jgrapht.demo.JGraphAdapterDemo.class"
79 archive="./jgrapht-0.5.2.jar">
80 <param name="bgcolor" value="#ffffff">
81
82 Java 2 Standard Edition v 1.3 or above is required for this applet.<br/>
83 Download it from <a href="http://java.sun.com">http://java.sun.com</a>.
84 </applet>
85 </td></tr>
86 </table>
87 <DIV style="TEXT-ALIGN: center">a JGraphT graph visualized using JGraph.</DIV>
88
89 <p>&nbsp;</p>
90
91
92 <h2>How it Works</h2>
93
94 <p>It's very simple: the JGraphT library comes with an
95 adapter that makes JGraphT graphs compatible with JGraph. To visualize a JGraphT
96 graph you just need to initialize JGraph via that adapter. </p>
97
98 <p>Example code:</p>
99
100 <p>
101 <pre><i><font color="#b22222"> // create a JGraphT graph</font></i>
102 ListenableGraph g = <B><FONT color=#a020f0>new</FONT></B> ListenableDirectedGraph( DefaultEdge.class );
103
104 <i><font color="#b22222">// create a visualization using JGraph, via the adapter</font></i>
105 JGraph jgraph = <b><font color="#a020f0">new</font></b> JGraph( <b><font color="#a020f0">new</font></b> JGraphModelAdapter( g ) );
106 </pre>
107 </p>
108
109
110 <p>Is that all?!&nbsp; Yes, that's all. Any modification now made to the graph <code>g</code> will
111 automatically be reflected by the JGraph component.</p>
112
113
114
115
116
117 <p>&nbsp;</p>
118
119
120
121
122
123 <h2>Source Code of the Applet</h2>
124
125
126
127 <p>The full source code of this demo is listed below and is also included in the
128 JGraphT distribution (<a href="http://sourceforge.net/project/showfiles.php?group_id=86459">download now</a>).<br>
129 &nbsp;</p>
130
131
132
133 <div align="center">
134 <center>
135
136
137
138 <table border="1" bordercolor="#7AA1E6" bgcolor="white" cellpadding="20" style="border-collapse: collapse" cellspacing="0">
139 <tr>
140 <td align="left">
141
142 <PRE><B><FONT color=#a020f0>package</FONT></B> org.jgrapht.demo;
143
144 <B><FONT color=#a020f0>import</FONT></B> java.awt.Color;
145 <B><FONT color=#a020f0>import</FONT></B> java.awt.Dimension;
146 <B><FONT color=#a020f0>import</FONT></B> java.awt.Rectangle;
147
148 <B><FONT color=#a020f0>import</FONT></B> java.util.HashMap;
149 <B><FONT color=#a020f0>import</FONT></B> java.util.Map;
150
151 <B><FONT color=#a020f0>import</FONT></B> javax.swing.JApplet;
152 <B><FONT color=#a020f0>import</FONT></B> javax.swing.JFrame;
153
154 <B><FONT color=#a020f0>import</FONT></B> org.jgraph.JGraph;
155 <B><FONT color=#a020f0>import</FONT></B> org.jgraph.graph.DefaultGraphCell;
156 <B><FONT color=#a020f0>import</FONT></B> org.jgraph.graph.GraphConstants;
157
158 <B><FONT color=#a020f0>import</FONT></B> org.jgrapht.ListenableGraph;
159 <B><FONT color=#a020f0>import</FONT></B> org.jgrapht.ext.JGraphModelAdapter;
160 <B><FONT color=#a020f0>import</FONT></B> org.jgrapht.graph.ListenableDirectedGraph;
161 <B><FONT color=#a020f0>import</FONT></B> org.jgrapht.graph.DefaultEdge;
162
163 <I><FONT color=#b22222>/**
164 * A demo applet that shows how to use JGraph to visualize JGraphT graphs.
165 *
166 * @author Barak Naveh
167 *
168 * @since Aug 3, 2003
169 */</FONT></I>
170 <B><FONT color=#a020f0>public</FONT></B> <B><FONT color=#a020f0>class</FONT></B> JGraphAdapterDemo <B><FONT color=#a020f0>extends</FONT></B> JApplet {
171 <B><FONT color=#a020f0>private</FONT></B> <B><FONT color=#a020f0>static</FONT></B> <B><FONT color=#a020f0>final</FONT></B> Color DEFAULT_BG_COLOR = Color.decode( <B><FONT color=#bc8f8f>"#FAFBFF"</FONT></B> );
172 <B><FONT color=#a020f0>private</FONT></B> <B><FONT color=#a020f0>static</FONT></B> <B><FONT color=#a020f0>final</FONT></B> Dimension DEFAULT_SIZE = <B><FONT color=#a020f0>new</FONT></B> Dimension( 530, 320 );
173
174 <I><FONT color=#b22222>//
175 </FONT></I> <B><FONT color=#a020f0>private</FONT></B> JGraphModelAdapter m_jgAdapter;
176
177 <I><FONT color=#b22222>/**
178 * @see java.applet.Applet#init().
179 */</FONT></I>
180 <B><FONT color=#a020f0>public</FONT></B> <B><FONT color=#a020f0>void</FONT></B> init( ) {
181 <I><FONT color=#b22222>// create a JGraphT graph
182 </FONT></I> ListenableGraph g = <B><FONT color=#a020f0>new</FONT></B> ListenableDirectedGraph( DefaultEdge.class );
183
184 <I><FONT color=#b22222>// create a visualization using JGraph, via an adapter
185 </FONT></I> m_jgAdapter = <B><FONT color=#a020f0>new</FONT></B> JGraphModelAdapter( g );
186
187 JGraph jgraph = <B><FONT color=#a020f0>new</FONT></B> JGraph( m_jgAdapter );
188
189 adjustDisplaySettings( jgraph );
190 getContentPane( ).add( jgraph );
191 resize( DEFAULT_SIZE );
192
193 <I><FONT color=#b22222>// add some sample data (graph manipulated via JGraphT)
194 </FONT></I> g.addVertex( <B><FONT color=#bc8f8f>"v1"</FONT></B> );
195 g.addVertex( <B><FONT color=#bc8f8f>"v2"</FONT></B> );
196 g.addVertex( <B><FONT color=#bc8f8f>"v3"</FONT></B> );
197 g.addVertex( <B><FONT color=#bc8f8f>"v4"</FONT></B> );
198
199 g.addEdge( <B><FONT color=#bc8f8f>"v1"</FONT></B>, <B><FONT color=#bc8f8f>"v2"</FONT></B> );
200 g.addEdge( <B><FONT color=#bc8f8f>"v2"</FONT></B>, <B><FONT color=#bc8f8f>"v3"</FONT></B> );
201 g.addEdge( <B><FONT color=#bc8f8f>"v3"</FONT></B>, <B><FONT color=#bc8f8f>"v1"</FONT></B> );
202 g.addEdge( <B><FONT color=#bc8f8f>"v4"</FONT></B>, <B><FONT color=#bc8f8f>"v3"</FONT></B> );
203
204 <I><FONT color=#b22222>// position vertices nicely within JGraph component
205 </FONT></I> positionVertexAt( <B><FONT color=#bc8f8f>"v1"</FONT></B>, 130, 40 );
206 positionVertexAt( <B><FONT color=#bc8f8f>"v2"</FONT></B>, 60, 200 );
207 positionVertexAt( <B><FONT color=#bc8f8f>"v3"</FONT></B>, 310, 230 );
208 positionVertexAt( <B><FONT color=#bc8f8f>"v4"</FONT></B>, 380, 70 );
209
210 <I><FONT color=#b22222>// that's all there is to it!...
211 </FONT></I> }
212
213
214 <B><FONT color=#a020f0>private</FONT></B> <B><FONT color=#a020f0>void</FONT></B> adjustDisplaySettings( JGraph jg ) {
215 jg.setPreferredSize( DEFAULT_SIZE );
216
217 Color c = DEFAULT_BG_COLOR;
218 String colorStr = <B><FONT color=#a020f0>null</FONT></B>;
219
220 <B><FONT color=#a020f0>try</FONT></B> {
221 colorStr = getParameter( <B><FONT color=#bc8f8f>"bgcolor"</FONT></B> );
222 }
223 <B><FONT color=#a020f0>catch</FONT></B>( Exception e ) {}
224
225 <B><FONT color=#a020f0>if</FONT></B>( colorStr != <B><FONT color=#a020f0>null</FONT></B> ) {
226 c = Color.decode( colorStr );
227 }
228
229 jg.setBackground( c );
230 }
231
232
233 <B><FONT color=#a020f0>private</FONT></B> <B><FONT color=#a020f0>void</FONT></B> positionVertexAt( Object vertex, <B><FONT color=#a020f0>int</FONT></B> x, <B><FONT color=#a020f0>int</FONT></B> y ) {
234 DefaultGraphCell cell = m_jgAdapter.getVertexCell( vertex );
235 Map attr = cell.getAttributes( );
236 Rectangle b = GraphConstants.getBounds( attr );
237
238 GraphConstants.setBounds( attr, <B><FONT color=#a020f0>new</FONT></B> Rectangle( x, y, b.width, b.height ) );
239
240 Map cellAttr = <B><FONT color=#a020f0>new</FONT></B> HashMap( );
241 cellAttr.put( cell, attr );
242 m_jgAdapter.edit( cellAttr, null, null, null, null );
243 }
244 }</PRE>
245
246 </td>
247 </tr>
248 </table>
249
250
251
252 </center>
253 </div>
254
255
256
257 <p>&nbsp;</p>
258
259 <hr noshade size="2" style="background-color:#7AA1E6;color:#7AA1E6;border-width: thin none none;">
260 <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%">
261 <tr>
262 <td width="10%"align="left"><a href="http://validator.w3.org/check/referer"><img
263 src="http://www.w3.org/Icons/valid-html401" border="0"
264 alt="Valid HTML 4.01!" height="31" width="88"/></a></td>
265
266 <td width="80%"align="center"><small>
267 &copy; Copyright 2003, by Barak Naveh and Contributors. All rights reserved.</small></td>
268
269 <td width="10%" align="right">
270 <a href="http://sourceforge.net/projects/jgrapht"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=86459&type=12" width="120" height="30" border="0" alt="Get JGraphT at SourceForge.net. Fast, secure and Free Open Source software downloads" /></a>
271 </td>
272 </tr>
273 </table>
274 <br/>
275
276
277
278 </body>
279 </html>