source: fedd/abac-src/atnvis/src/Test.java @ 8780cbec

axis_examplecompt_changesinfo-opsversion-1.30version-2.00version-3.01version-3.02
Last change on this file since 8780cbec was 8780cbec, checked in by Jay Jacobs <Jay.Jacobs@…>, 15 years ago

ABAC sources from Cobham

  • Property mode set to 100644
File size: 3.1 KB
Line 
1package com.algomagic.atn;
2
3import att.grappa.*;
4import java.util.*;
5
6import java.awt.*;
7import java.awt.event.*;
8import java.awt.geom.*;
9
10import javax.swing.*;
11import javax.swing.border.*;
12import javax.swing.event.*;
13
14
15
16public class Test 
17    extends JFrame
18{
19
20    private GrappaPanel _grappaPanel;
21    private Graph _graph;
22    private Subgraph[] _subgraphs;
23
24
25
26    public Test( ) {
27
28        addWindowListener( new WindowAdapter( ) {
29                public void windowClosing( WindowEvent we ) {
30                    Window w = we.getWindow( );
31                    w.setVisible( false );
32                    w.dispose( );
33                    System.exit( 0 );
34                }
35            });
36
37
38        _graph = new Graph( "Trust Negotiation Graph: " );
39        _grappaPanel = new GrappaPanel( _graph );
40        _grappaPanel.setScaleToFit( false );
41       
42        JScrollPane jsp = new JScrollPane( );
43        jsp.getViewport( ).setScrollMode( JViewport.BACKINGSTORE_SCROLL_MODE );
44        jsp.getViewport( ).setBackground( Color.white );
45        jsp.setViewportView( _grappaPanel );
46
47
48        Container contentPane = getContentPane( );
49        contentPane.setLayout( new BorderLayout( ) );
50        contentPane.add( jsp, BorderLayout.CENTER );
51        setSize( 500, 500 );
52
53
54        _subgraphs = new Subgraph[2];
55        _subgraphs[0] = new Subgraph( _graph, "cluster 0" );
56        _subgraphs[1] = new Subgraph( _graph, "cluster 1" );
57
58
59        Node n1 = new Node( _subgraphs[0], "node1" );
60        Node n2 = new Node( _subgraphs[0], "node2" );
61        Node n3 = new Node( _subgraphs[1], "node3" );
62        Node n4 = new Node( _subgraphs[1], "node4" );
63        Node n5 = new Node( _subgraphs[1], "node5" );
64       
65
66//      _subgraphs[0].addNode( n1 );
67//      _subgraphs[0].addNode( n2 );
68//      _subgraphs[1].addNode( n3 );
69//      _subgraphs[1].addNode( n4 );
70
71
72        Edge e = new Edge( _subgraphs[0], n1, n2 );
73        Edge e2 = new Edge( _subgraphs[0], n2, n3 );
74        new Edge( _subgraphs[1], n3, n4 );
75        new Edge( _subgraphs[1], n3, n5 );
76        new Edge( _subgraphs[1], n5, n4 );
77       
78
79//      _subgraphs[0].addEdge( e1 );
80//      _graph.addEdge( e2 );
81//      _subgraphs[1].addEdge( e3 );
82
83
84        e.setAttribute( "style", "bold,solid,filled" );
85        e2.setAttribute( "style", "solid" );
86
87        formatGraph( _graph );
88
89//      _graph.setAttribute( "style", "invis" );
90
91
92        Subgraph sg = _graph.findSubgraphByName( "cluster 0" );
93        sg.setAttribute( "color", "red" );
94        sg.setAttribute( "style", "dotted" );
95        sg.setAttribute( "label", "this is a cluster" );
96
97
98        Node n = _graph.findNodeByName( "node1" );
99        n.setAttribute( "style", "filled" );
100        n.setAttribute( "color", "green" );
101        n.setAttribute( "bgcolor", "blue" );
102        n.setAttribute( "fillcolor", "red" );
103
104        n = _graph.findNodeByName( "node2" );
105        n.setAttribute( "style", "solid" );
106        n.setAttribute( "color", "black" );
107
108
109        sg = _graph.findSubgraphByName( "cluster 1" );
110        sg.setAttribute( "style", "dotted" );
111        sg.setAttribute( "fillcolor", "white" );
112        sg.setAttribute( "color", "white" );
113        sg.setAttribute( "bgcolor", "white" );
114
115
116
117
118
119        show( );
120    }
121
122
123    public static void main( String[] args ) {
124        Test t = new Test( );
125    }
126
127
128    private void formatGraph( Graph g ) {
129        try {
130            Process formater = Runtime.getRuntime( ).exec( "dot" );
131            GrappaSupport.filterGraph( g, formater );
132            formater.destroy( );
133           
134            g.repaint( );
135        } catch( Exception e ) {
136            e.printStackTrace( );
137        }
138    }
139
140
141}
Note: See TracBrowser for help on using the repository browser.