[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Diva: a graph library for Java
From: |
Marcus G. Daniels |
Subject: |
Diva: a graph library for Java |
Date: |
Tue, 26 Oct 1999 15:42:59 -0600 (MDT) |
Those of you that have struggled to use the Swarm graph library or
tkobjc canvas features for representing, visualizing, or manipulating
graphs may be interested in `Diva' (Dynamic Interactive Visualization).
Diva is a large but modular Java package that can be used with the
Java layer of Swarm. One of its components is a nice graph
visualization and editing package, with optional auto-layout features.
Diva even saves graphs as XML.
http://www-cad.eecs.berkeley.edu/diva
Below is a fairly minimal graph display program. (The demo programs
distributed with Diva are much neater.)
Note this requires Sun JDK 1.2; Kaffe doesn't have enough Swing
features implemented.
To run it, point the Java runtime at the Diva jar file.
In Bourne shell, like so:
$ CLASSPATH=.:$HOME/diva.jar:$CLASSPATH
$ export CLASSPATH
$ /usr/java1.2/bin/javac TestGraph.java # put the program below in this file
$ /usr/java1.2/bin/java TestGraph
import diva.canvas.*;
import diva.graph.*;
import diva.graph.layout.*;
import diva.graph.model.*;
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
import diva.canvas.connector.ConnectorTarget;
import diva.canvas.connector.PerimeterSite;
import diva.canvas.connector.Connector;
import diva.canvas.connector.StraightConnector;
import diva.canvas.connector.ArcConnector;
public class TestGraph {
public static void main(String argv[]) {
new TestGraph ();
}
private GraphPane _gp1;
private GraphModel _model;
private TestGraph () {
JFrame fr = new JFrame ("myFrame");
_model = new GraphModel();
JGraph gr1 = new JGraph(_model);
_gp1 = (GraphPane)gr1.getCanvasPane();
BasicGraphController gc1 =
(BasicGraphController)_gp1.getGraphController();
GraphView gv1 = _gp1.getGraphView();
gv1.setIncrLayout(new RandomIncrLayout(gv1));
fr.getContentPane().add("Center", gr1);
BasicNodeRenderer bnr = new BasicNodeRenderer();
bnr.setNodeShape(makePoly(5, 20));
bnr.setNodeFill(Color.green);
fr.setSize(600, 400);
fr.setVisible(true);
Node _a = _model.createNode("a");
Node _b = _model.createNode("b");
Node _c = _model.createNode("c");
_model.addNode(_a);
_model.addNode(_b);
_model.addNode(_c);
_model.createEdge("ab", _a, _b);
_model.createEdge("ac", _a, _c);
}
private Shape makePoly(int num, double r) {
GeneralPath p = new GeneralPath();
p.moveTo((float)r,0);
for(int i = 1; i < num; i++) {
double theta = i*Math.PI*2.0/num;
double x = r*Math.cos(theta);
double y = r*Math.sin(theta);
p.lineTo((float)x, (float)y);
}
p.closePath();
return p;
}
}
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Diva: a graph library for Java,
Marcus G. Daniels <=