package com.algomagic.atn; import att.grappa.*; import java.util.*; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; public class Test extends JFrame { private GrappaPanel _grappaPanel; private Graph _graph; private Subgraph[] _subgraphs; public Test( ) { addWindowListener( new WindowAdapter( ) { public void windowClosing( WindowEvent we ) { Window w = we.getWindow( ); w.setVisible( false ); w.dispose( ); System.exit( 0 ); } }); _graph = new Graph( "Trust Negotiation Graph: " ); _grappaPanel = new GrappaPanel( _graph ); _grappaPanel.setScaleToFit( false ); JScrollPane jsp = new JScrollPane( ); jsp.getViewport( ).setScrollMode( JViewport.BACKINGSTORE_SCROLL_MODE ); jsp.getViewport( ).setBackground( Color.white ); jsp.setViewportView( _grappaPanel ); Container contentPane = getContentPane( ); contentPane.setLayout( new BorderLayout( ) ); contentPane.add( jsp, BorderLayout.CENTER ); setSize( 500, 500 ); _subgraphs = new Subgraph[2]; _subgraphs[0] = new Subgraph( _graph, "cluster 0" ); _subgraphs[1] = new Subgraph( _graph, "cluster 1" ); Node n1 = new Node( _subgraphs[0], "node1" ); Node n2 = new Node( _subgraphs[0], "node2" ); Node n3 = new Node( _subgraphs[1], "node3" ); Node n4 = new Node( _subgraphs[1], "node4" ); Node n5 = new Node( _subgraphs[1], "node5" ); // _subgraphs[0].addNode( n1 ); // _subgraphs[0].addNode( n2 ); // _subgraphs[1].addNode( n3 ); // _subgraphs[1].addNode( n4 ); Edge e = new Edge( _subgraphs[0], n1, n2 ); Edge e2 = new Edge( _subgraphs[0], n2, n3 ); new Edge( _subgraphs[1], n3, n4 ); new Edge( _subgraphs[1], n3, n5 ); new Edge( _subgraphs[1], n5, n4 ); // _subgraphs[0].addEdge( e1 ); // _graph.addEdge( e2 ); // _subgraphs[1].addEdge( e3 ); e.setAttribute( "style", "bold,solid,filled" ); e2.setAttribute( "style", "solid" ); formatGraph( _graph ); // _graph.setAttribute( "style", "invis" ); Subgraph sg = _graph.findSubgraphByName( "cluster 0" ); sg.setAttribute( "color", "red" ); sg.setAttribute( "style", "dotted" ); sg.setAttribute( "label", "this is a cluster" ); Node n = _graph.findNodeByName( "node1" ); n.setAttribute( "style", "filled" ); n.setAttribute( "color", "green" ); n.setAttribute( "bgcolor", "blue" ); n.setAttribute( "fillcolor", "red" ); n = _graph.findNodeByName( "node2" ); n.setAttribute( "style", "solid" ); n.setAttribute( "color", "black" ); sg = _graph.findSubgraphByName( "cluster 1" ); sg.setAttribute( "style", "dotted" ); sg.setAttribute( "fillcolor", "white" ); sg.setAttribute( "color", "white" ); sg.setAttribute( "bgcolor", "white" ); show( ); } public static void main( String[] args ) { Test t = new Test( ); } private void formatGraph( Graph g ) { try { Process formater = Runtime.getRuntime( ).exec( "dot" ); GrappaSupport.filterGraph( g, formater ); formater.destroy( ); g.repaint( ); } catch( Exception e ) { e.printStackTrace( ); } } }