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