source: fedd/abac-src/atnvis/src/ATNVisualizer.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: 36.0 KB
Line 
1package com.algomagic.atn.vis;
2import att.grappa.*;
3
4import java.util.*;
5import java.io.*;
6
7import java.awt.*;
8import java.awt.event.*;
9import java.awt.geom.*;
10import javax.swing.*;
11import javax.swing.border.*;
12import javax.swing.event.*;
13
14
15public class ATNVisualizer extends JFrame
16    implements ATNVisualizerConstants, GrappaConstants {
17
18    private Properties _properties;
19    private SidePanel[] _sides;
20
21    private Collection _updates;
22
23    private ControlPanel _controls;
24    private ProgressPanel _progressPanel;
25    private PlayBackManager _playBackManager;
26
27
28    public ATNVisualizer( String log1, String log2 ) {
29        loadProperties( );
30
31        initATNVisualizer( log1, log2 );
32        parseUpdates( log1, log2 );
33
34        _playBackManager = new PlayBackManager( );
35        _controls.addObserver( _playBackManager );
36        _playBackManager.addObserver( _progressPanel );
37
38
39        show( );
40    }
41
42
43    private void initATNVisualizer( String log1, String log2 ) {
44
45        addWindowListener( new WindowAdapter( ) {
46                public void windowClosing( WindowEvent we ) {
47                    Window w = we.getWindow( );
48                    w.setVisible( false );
49                    w.dispose( );
50                    System.exit( 0 );
51                }
52            });
53
54
55        _sides = new SidePanel[2];
56
57
58
59        _sides[LEFT_SIDE] = new SidePanel( LEFT_SIDE );
60        _sides[RIGHT_SIDE] = null;
61
62        JPanel main = new JPanel( );
63        main.setLayout( new BoxLayout( main, BoxLayout.X_AXIS ) );
64        main.add( _sides[LEFT_SIDE] );
65
66
67        if( log2 != null ) {
68            _sides[RIGHT_SIDE] = new SidePanel( RIGHT_SIDE );
69            main.add( Box.createHorizontalStrut( 10 ) );
70            main.add( _sides[RIGHT_SIDE] );
71        }
72
73
74        JPanel bottom = new JPanel( );
75
76        bottom.setLayout( new BoxLayout( bottom, BoxLayout.X_AXIS ) );
77        bottom.add( _controls = new ControlPanel( ) );
78        bottom.add( _progressPanel = new ProgressPanel( ) );
79       
80
81        Container contentPane = getContentPane( );
82        contentPane.setLayout( new BoxLayout( contentPane, BoxLayout.Y_AXIS ) );
83        contentPane.add( main );
84        contentPane.add( bottom );
85
86
87        setTitle( _properties.getProperty( WINDOW_TITLE_PROP, WINDOW_TITLE_DEFAULT ) );
88        setSize( Integer.parseInt( _properties.getProperty( WINDOW_WIDTH_PROP, WINDOW_WIDTH_DEFAULT ) ),
89                 Integer.parseInt( _properties.getProperty( WINDOW_HEIGHT_PROP, WINDOW_HEIGHT_DEFAULT ) ) );
90
91        show( );
92    }
93
94
95    private void parseUpdates( String log1, String log2 ) {
96        _updates = new ArrayList( );
97
98        _updates.add( new NodeUpdate( _sides[LEFT_SIDE], 
99                                      "MedSup: MedSup.discount <- Alice",
100                                      STANDARD_TARGET, 
101                                      NOT_SATISFIED,
102                                      OPPONENT_PROC ) );
103
104        _updates.add( new NodeUpdate( _sides[LEFT_SIDE], 
105                                      "MedSup: ReliefNet.provisioner <- Alice",
106                                      STANDARD_TARGET,
107                                      NOT_SATISFIED,
108                                      VERIFIER_PROC ) );
109
110        _updates.add( new EdgeUpdate( _sides[LEFT_SIDE], 
111                                      "MedSup: MedSup.discount <- Alice", "MedSup: ReliefNet.provisioner <- Alice",
112                                      IMPLICATION_EDGE ) );
113
114        _updates.add( new NodeUpdate( _sides[LEFT_SIDE], 
115                                      "MedSup: MedSup.discount <- Alice",
116                                      STANDARD_TARGET, 
117                                      NOT_SATISFIED,
118                                      VERIFIER_PROC ) );
119
120
121
122        if( _sides[RIGHT_SIDE] != null ) {
123
124            _updates.add( new MessageBeginUpdate( _sides[RIGHT_SIDE], "<Message>\n<NodeOp type=\"root\">\n<TrustTarget>\n       <Verifier>MedSup</Verifier>\n   <Target>MedSup.discount</Target>\n      <Subject>Alice</Subject>\n</TrustTarget>\n<ProcessingState>OpponentProcessed</ProcessingState>\n</NodeOp>\n<EdgeOp type=\"implication\" newChild=\"true\">\n<Parent>\n<TrustTarget>\n   <Verifier>MedSup</Verifier>\n   <Target>MedSup.discount</Target>\n      <Subject>Alice</Subject>\n</TrustTarget>\n</Parent>\n<Child>\n<TrustTarget>\n   <Verifier>MedSup</Verifier>\n   <Target>ReliefNet.provisioner</Target>\n        <Subject>Alice</Subject>\n</TrustTarget>\n</Child>\n<ProcessingState>Verifier Processed</ProcessingState>\n<Credential  definedRole=\"MedSup.discount\" subject=\"ReliefNet.provisioner\"/>\n</Evidence>\n</EdgeOp>\n<NodeOp>\n<TrustTarget>\n  <Verifier>MedSup</Verifier>\n   <Target>MedSup.discount</Target>\n      <Subject>Alice</Subject>\n</TrustTarget>\n<ProcessingState>Verifier Processed</ProcessingState>\n</NodeOp>\n</Message>" ) );
125
126
127            // 2
128            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE], 
129                                          "MedSup: MedSup.discount <- Alice",
130                                          STANDARD_TARGET, 
131                                          NOT_SATISFIED,
132                                          OPPONENT_PROC ) );
133
134           
135            // 3
136            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE], 
137                                          "MedSup: ReliefNet.provisioner <- Alice",
138                                          STANDARD_TARGET,
139                                          NOT_SATISFIED,
140                                          VERIFIER_PROC ) );
141
142            _updates.add( new EdgeUpdate( _sides[RIGHT_SIDE], 
143                                          "MedSup: MedSup.discount <- Alice", 
144                                          "MedSup: ReliefNet.provisioner <- Alice",
145                                          IMPLICATION_EDGE ) );
146
147           
148            // 4
149            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE], 
150                                          "MedSup: MedSup.discount <- Alice",
151                                          STANDARD_TARGET, 
152                                          NOT_SATISFIED,
153                                          VERIFIER_PROC ) );
154           
155
156            _updates.add( new MessageEndUpdate( _sides[RIGHT_SIDE] ) );
157                         
158
159           
160            // 6
161            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE],
162                                          "MedSup: MedixFund.purchasingA <- Alice",
163                                          STANDARD_TARGET,
164                                          NOT_SATISFIED,
165                                          VERIFIER_PROC ) );
166
167            _updates.add( new EdgeUpdate( _sides[RIGHT_SIDE], 
168                                          "MedSup: ReliefNet.provisioner <- Alice", 
169                                          "MedSup: MedixFund.purchasingA <- Alice" ) );
170
171
172           
173            // 7
174            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE], 
175                                          "MedSup: ReliefNet.provisioner <- Alice",
176                                          STANDARD_TARGET,
177                                          NOT_SATISFIED,
178                                          OPPONENT_PROC ) );
179
180
181            // 8
182            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE], 
183                                          "Alice: MedixFund.cPartner <- MedSup",
184                                          STANDARD_TARGET,
185                                          NOT_SATISFIED,
186                                          OPPONENT_PROC ) );
187
188            _updates.add( new EdgeUpdate( _sides[RIGHT_SIDE], 
189                                          "MedSup: MedixFund.purchasingA <- Alice", 
190                                          "Alice: MedixFund.cPartner <- MedSup" ) );
191
192
193
194            // 9
195            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE], 
196                                          "Alice: ReliefNet.member <- MedSup",
197                                          STANDARD_TARGET,
198                                          NOT_SATISFIED,
199                                          VERIFIER_PROC ) );
200
201            _updates.add( new EdgeUpdate( _sides[RIGHT_SIDE], 
202                                          "Alice: MedixFund.cPartner <- MedSup", 
203                                          "Alice: ReliefNet.member <- MedSup" ) );
204
205
206            // 10
207            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE], 
208                                          "Alice: MedixFund.cPartner <- MedSup",
209                                          STANDARD_TARGET,
210                                          NOT_SATISFIED,
211                                          VERIFIER_PROC ) );
212
213
214
215        }
216
217        _updates.add( new MessageBeginUpdate( _sides[LEFT_SIDE],
218                                              "<Message>\n<EdgeOp type=\"implication\" newChild=\"true\">\n<Parent>\n<TrustTarget>\n    <Verifier>MedSup</Verifier>\n   <Target>ReliefNet.provisioner</Target>\n        <Subject>Alice</Subject>\n</TrustTarget>\n</Parent>\n<Child>\n<TrustTarget>\n   <Verifier>MedSup</Verifier>\n   <Target>MedixFund.purchasingA</Target>\n        <Subject>Alice</Subject>\n</TrustTarget>\n</Child>\n<ProcessingState>Verifier Processed</ProcessingState>\n<Evidence count=\"1\">\n<Credential  definedRole=\"ReliefNet.provisioner\" subject=\"MedixFund.purchasingA\"/>\n</Evidence>\n</EdgeOp>\n<NodeOp>\n<TrustTarget>\n    <Verifier>MedSup</Verifier>\n   <Target>ReliefNet.provisioner</Target>\n        <Subject>Alice</Subject>\n</TrustTarget>\n<ProcessingState>OpponentProcessed</ProcessingState>\n</NodeOp>\n<EdgeOp type=\"control\" newChild=\"true\">\n<Parent>\n<TrustTarget>\n       <Verifier>MedSup</Verifier>\n   <Target>MedixFund.purchasingA</Target>\n        <Subject>Alice</Subject>\n</TrustTarget>\n</Parent>\n<Child>\n<TrustTarget>\n   <Verifier>Alice</Verifier>\n    <Target>MedixFund.cPartner</Target>\n   <Subject>MedSup</Subject>\n</TrustTarget>\n</Child>\n<ProcessingState>OpponentProcessed</ProcessingState>\n</EdgeOp>\n<EdgeOp type=\"implication\" newChild=\"true\">\n<Parent>\n<TrustTarget>\n        <Verifier>Alice</Verifier>\n    <Target>MedixFund.cPartner</Target>\n   <Subject>MedSup</Subject>\n</TrustTarget>\n</Parent>\n<Child>\n<TrustTarget>\n  <Verifier>Alice</Verifier>\n    <Target>ReliefNet.member</Target>\n     <Subject>MedSup</Subject>\n</TrustTarget>\n</Child>\n<ProcessingState>Verifier Processed</ProcessingState>\n<Evidence count=\"1\">\n<Credential  definedRole=\"MedixFund.cPartner\" subject=\"ReliefNet.member\"/>\n</Evidence>\n</EdgeOp>\n<NodeOp>\n<TrustTarget>\n   <Verifier>Alice</Verifier>\n    <Target>MedixFund.cPartner</Target>\n   <Subject>MedSup</Subject>\n</TrustTarget>\n<ProcessingState>Verifier Processed</ProcessingState>\n</NodeOp>\n</Message>" ) );
219
220
221        _updates.add( new NodeUpdate( _sides[LEFT_SIDE],
222                                      "MedSup: MedixFund.purchasingA <- Alice",
223                                      STANDARD_TARGET,
224                                      NOT_SATISFIED,
225                                      VERIFIER_PROC ) );
226
227        _updates.add( new EdgeUpdate( _sides[LEFT_SIDE], "MedSup: ReliefNet.provisioner <- Alice", "MedSup: MedixFund.purchasingA <- Alice" ) );
228
229
230        // 7
231        _updates.add( new NodeUpdate( _sides[LEFT_SIDE], 
232                                      "MedSup: ReliefNet.provisioner <- Alice",
233                                      STANDARD_TARGET,
234                                      NOT_SATISFIED,
235                                      OPPONENT_PROC ) );
236
237
238        // 8
239        _updates.add( new NodeUpdate( _sides[LEFT_SIDE], 
240                                      "Alice: MedixFund.cPartner <- MedSup",
241                                      STANDARD_TARGET,
242                                      NOT_SATISFIED,
243                                      OPPONENT_PROC ) );
244
245        _updates.add( new EdgeUpdate( _sides[LEFT_SIDE], 
246                                      "MedSup: MedixFund.purchasingA <- Alice", 
247                                      "Alice: MedixFund.cPartner <- MedSup" ) );
248
249
250        // 9
251        _updates.add( new NodeUpdate( _sides[LEFT_SIDE], 
252                                      "Alice: ReliefNet.member <- MedSup",
253                                      STANDARD_TARGET,
254                                      NOT_SATISFIED,
255                                      VERIFIER_PROC ) );
256
257        _updates.add( new EdgeUpdate( _sides[LEFT_SIDE], 
258                                      "Alice: MedixFund.cPartner <- MedSup", 
259                                      "Alice: ReliefNet.member <- MedSup" ) );
260
261
262        // 10
263        _updates.add( new NodeUpdate( _sides[LEFT_SIDE], 
264                                      "Alice: MedixFund.cPartner <- MedSup",
265                                      STANDARD_TARGET,
266                                      NOT_SATISFIED,
267                                      VERIFIER_PROC ) );
268
269
270        _updates.add( new MessageEndUpdate( _sides[LEFT_SIDE] ) );
271
272
273        // 12
274
275        _updates.add( new NodeUpdate( _sides[LEFT_SIDE], 
276                                      "Alice: MedSup <- MedSup",
277                                      STANDARD_TARGET,
278                                      SATISFIED,
279                                      FULLY_PROC ) );
280
281        _updates.add( new EdgeUpdate( _sides[LEFT_SIDE], 
282                                      "Alice: ReliefNet.member <- MedSup",
283                                      "Alice: MedSup <- MedSup" ) );
284
285
286        // 13
287        _updates.add( new NodeUpdate( _sides[LEFT_SIDE], 
288                                      "Alice: ReliefNet.member <- MedSup",
289                                      STANDARD_TARGET,
290                                      SATISFIED,
291                                      VERIFIER_PROC ) );
292
293
294        // 14
295        _updates.add( new NodeUpdate( _sides[LEFT_SIDE], 
296                                      "Alice: MedixFund.cPartner <- MedSup",
297                                      STANDARD_TARGET,
298                                      SATISFIED,
299                                      FULLY_PROC ) );
300
301        // 15
302        _updates.add( new NodeUpdate( _sides[LEFT_SIDE], 
303                                      "Alice: ReliefNet.member <- MedSup",
304                                      STANDARD_TARGET,
305                                      SATISFIED,
306                                      OPPONENT_PROC ) );
307       
308       
309
310        if( _sides[RIGHT_SIDE] != null ) {
311
312            _updates.add( new MessageBeginUpdate( _sides[RIGHT_SIDE],
313                                                  "<Message>\n<EdgeOp type=\"implication\" newChild=\"true\">\n<Parent>\n<TrustTarget>\n        <Verifier>Alice</Verifier>\n    <Target>ReliefNet.member</Target>\n     <Subject>MedSup</Subject>\n</TrustTarget>\n</Parent>\n<Child>\n<TrustTarget>\n  <Verifier>Alice</Verifier>\n    <Target>MedSup</Target>\n       <Subject>MedSup</Subject>\n</TrustTarget>\n</Child>\n<ProcessingState>Fully Processed</ProcessingState>\n<Evidence count=\"1\">\n<Credential  definedRole=\"ReliefNet.member\" subject=\"MedSup\"/>\n</Evidence>\n</EdgeOp>\n<NodeOp>\n<TrustTarget>\n  <Verifier>Alice</Verifier>\n    <Target>ReliefNet.member</Target>\n     <Subject>MedSup</Subject>\n</TrustTarget>\n<ProcessingState>OpponentProcessed</ProcessingState>\n</NodeOp>\n</Message>" ) );
314
315
316            // 13
317
318            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE], 
319                                          "Alice: MedSup <- MedSup",
320                                          STANDARD_TARGET,
321                                          SATISFIED,
322                                          FULLY_PROC ) );
323
324            _updates.add( new EdgeUpdate( _sides[RIGHT_SIDE], 
325                                          "Alice: ReliefNet.member <- MedSup",
326                                          "Alice: MedSup <- MedSup" ) );
327
328
329            // 14
330            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE], 
331                                          "Alice: ReliefNet.member <- MedSup",
332                                          STANDARD_TARGET,
333                                          SATISFIED,
334                                          VERIFIER_PROC ) );
335
336
337            // 15
338            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE], 
339                                          "Alice: MedixFund.cPartner <- MedSup",
340                                          STANDARD_TARGET,
341                                          SATISFIED,
342                                          FULLY_PROC ) );
343
344            // 16
345            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE], 
346                                          "Alice: ReliefNet.member <- MedSup",
347                                          STANDARD_TARGET,
348                                          SATISFIED,
349                                          OPPONENT_PROC ) );
350       
351
352
353            _updates.add( new MessageEndUpdate( _sides[RIGHT_SIDE] ) );
354
355           
356            // 18
357
358            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE], 
359                                          "MedSup: Alice <- Alice",
360                                          STANDARD_TARGET,
361                                          SATISFIED,
362                                          FULLY_PROC ) );
363
364            _updates.add( new EdgeUpdate( _sides[RIGHT_SIDE], 
365                                          "MedSup: MedixFund.purchasingA <- Alice", 
366                                          "MedSup: Alice <- Alice" ) );
367
368
369
370            // 19
371            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE],
372                                          "MedSup: MedixFund.purchasingA <- Alice",
373                                          STANDARD_TARGET,
374                                          SATISFIED,
375                                          VERIFIER_PROC ) );
376
377
378            // 20
379            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE], 
380                                          "MedSup: ReliefNet.provisioner <- Alice",
381                                          STANDARD_TARGET,
382                                          SATISFIED,
383                                          FULLY_PROC ) );
384
385       
386            // 21
387            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE], 
388                                          "MedSup: MedSup.discount <- Alice",
389                                          STANDARD_TARGET, 
390                                          SATISFIED,
391                                          FULLY_PROC ) );
392       
393
394            // 22
395            _updates.add( new NodeUpdate( _sides[RIGHT_SIDE],
396                                          "MedSup: MedixFund.purchasingA <- Alice",
397                                          STANDARD_TARGET,
398                                          SATISFIED,
399                                          OPPONENT_PROC ) );
400
401
402
403        }
404
405
406        _updates.add( new MessageBeginUpdate( _sides[LEFT_SIDE],
407                                              "<Message>\n<EdgeOp type=\"implication\" newChild=\"true\">\n<Parent>\n<TrustTarget>\n    <Verifier>MedSup</Verifier>\n   <Target>MedixFund.purchasingA</Target>\n        <Subject>Alice</Subject>\n</TrustTarget>\n</Parent>\n<Child>\n<TrustTarget>\n   <Verifier>MedSup</Verifier>\n   <Target>Alice</Target>\n        <Subject>Alice</Subject>\n</TrustTarget>\n</Child>\n<ProcessingState>Fully Processed</ProcessingState>\n</EdgeOp>\n<NodeOp>\n<TrustTarget>\n    <Verifier>MedSup</Verifier>\n   <Target>MedixFund.purchasingA</Target>\n        <Subject>Alice</Subject>\n</TrustTarget>\n<ProcessingState>OpponentProcessed</ProcessingState>\n</NodeOp>\n</Message>") );
408
409
410
411
412        // 18
413
414        _updates.add( new NodeUpdate( _sides[LEFT_SIDE], 
415                                      "MedSup: Alice <- Alice",
416                                      STANDARD_TARGET,
417                                      SATISFIED,
418                                      FULLY_PROC ) );
419
420        _updates.add( new EdgeUpdate( _sides[LEFT_SIDE], 
421                                      "MedSup: MedixFund.purchasingA <- Alice", 
422                                      "MedSup: Alice <- Alice" ) );
423
424
425
426        // 19
427        _updates.add( new NodeUpdate( _sides[LEFT_SIDE],
428                                      "MedSup: MedixFund.purchasingA <- Alice",
429                                      STANDARD_TARGET,
430                                      SATISFIED,
431                                      VERIFIER_PROC ) );
432
433
434        // 20
435        _updates.add( new NodeUpdate( _sides[LEFT_SIDE], 
436                                      "MedSup: ReliefNet.provisioner <- Alice",
437                                      STANDARD_TARGET,
438                                      SATISFIED,
439                                      FULLY_PROC ) );
440
441       
442        // 21
443        _updates.add( new NodeUpdate( _sides[LEFT_SIDE], 
444                                      "MedSup: MedSup.discount <- Alice",
445                                      STANDARD_TARGET, 
446                                      SATISFIED,
447                                      FULLY_PROC ) );
448       
449
450        // 22
451        _updates.add( new NodeUpdate( _sides[LEFT_SIDE],
452                                      "MedSup: MedixFund.purchasingA <- Alice",
453                                      STANDARD_TARGET,
454                                      SATISFIED,
455                                      OPPONENT_PROC ) );
456
457        _updates.add( new MessageEndUpdate( _sides[LEFT_SIDE] ) );
458
459
460
461        formatGraph( _sides[LEFT_SIDE].getGraph( ) );
462
463        if( _sides[RIGHT_SIDE] != null ) {
464            formatGraph( _sides[RIGHT_SIDE].getGraph( ) );
465        }
466
467    }
468
469
470    private void hideGraph( Graph g ) {
471        Enumeration nodes = g.nodeElements( );
472        Enumeration edges = g.edgeElements( );
473
474        while( nodes.hasMoreElements( ) ) {
475            Node n = (Node) nodes.nextElement( );
476            setInvis( n );
477        }
478
479        while( edges.hasMoreElements( ) ) {
480            Edge e = (Edge) edges.nextElement( );
481            setInvis( e );
482        }
483
484        g.resync( );
485        g.repaint( );
486
487    }
488
489
490    private void formatGraph( Graph g ) {
491        try {
492            Process formater = Runtime.getRuntime( ).exec( "dot" );
493            GrappaSupport.filterGraph( g, formater );
494            formater.destroy( );
495           
496            g.repaint( );
497        } catch( Exception e ) {
498            e.printStackTrace( );
499        }
500    }
501
502
503   
504    private void setNodeProps( Node n, String prefix ) {
505
506        for( int i=0; i < NODE_ATTRS.length; i++ ) {
507            String strValue = _properties.getProperty( prefix + NODE_ATTRS_PROP[i] );
508            if( strValue == null ) {
509                continue;
510            }
511
512            System.out.print( prefix + NODE_ATTRS_PROP[i] );
513            System.out.println( ":" + strValue );
514
515//          if( NODE_ATTRS_PROP[i].equals( "peripheries" ) ) {
516//              n.setDefaultAttribute( NODE_ATTRS[i], new Integer( strValue ) );
517//              continue;
518//          }
519           
520
521            if( NODE_ATTRS_INT[i] ) {
522                Attribute a = new Attribute( NODE, NODE_ATTRS[i], new Integer( strValue ) );
523                n.setAttribute( a );
524//              n.setAttribute( NODE_ATTRS[i], new Integer( strValue ) );
525            } else {
526                Attribute a = new Attribute( NODE, NODE_ATTRS[i], strValue );
527                n.setAttribute( a );
528//              n.setAttribute( NODE_ATTRS[i], strValue );
529            }
530        }
531    }
532
533    private void setEdgeProps( Edge e, String prefix ) {
534        for( int i=0; i < EDGE_ATTRS.length; i++ ) {
535            String strValue = _properties.getProperty( prefix + EDGE_ATTRS_PROP[i] );
536
537            if( strValue == null ) {
538                continue;
539            }
540           
541            if( EDGE_ATTRS_INT[i] ) {
542                e.setAttribute( EDGE_ATTRS[i], new Integer( strValue ) );
543            } else {
544                e.setAttribute( EDGE_ATTRS[i], strValue );
545            }
546        }
547    }
548
549
550
551
552    private void setNodeProperties( Node n, String type, String satisfaction, String process ) {
553        setNodeProps( n, DEFAULT_NODE );
554        setNodeProps( n, SYSTEM_PREFIX + "node." + type + "." );
555        setNodeProps( n, SYSTEM_PREFIX + "node.processed." + process + "." );
556        setNodeProps( n, SYSTEM_PREFIX + "node.satisfied." + satisfaction + "." );
557    }
558
559    private void setEdgeProperties( Edge e, String type ) {
560        setEdgeProps( e, DEFAULT_EDGE );
561        setEdgeProps( e, SYSTEM_PREFIX + "edge." + type + "." );
562    }
563
564
565
566
567    private void setSolid( Element e ) {
568        e.setAttribute( FONTSTYLE_ATTR, "normal" );
569        e.setAttribute( STYLE_ATTR, "filled" );
570        e.setAttribute( COLOR_ATTR, ".5,.5,.5" );
571       
572        if( e instanceof Node ) {
573            e.setDefaultAttribute( PERIPHERIES_ATTR, new Integer( 2 ) );
574        }
575    }
576
577    private void setBold( Element e ) {
578        e.setAttribute( FONTSTYLE_ATTR, "bold" );
579        e.setAttribute( STYLE_ATTR, "bold" );
580    }
581
582    private void setInvis( Element e ) {
583        e.setAttribute( FONTSTYLE_ATTR, "normal" );
584        e.setAttribute( STYLE_ATTR, "invis" );
585    }
586
587
588    private void loadProperties( ) {
589        String propsFileName = System.getProperty( CONFIG_FILE_PROP, CONFIG_FILE_DEFAULT );
590        File file = new File( propsFileName );
591
592        _properties = new Properties( );
593
594        if( file.exists( ) ) {
595            try {
596                _properties.load( new FileInputStream( file ) );
597            } catch( Exception e ) { }
598        }
599
600    }
601
602
603    private class SidePanel extends JPanel {
604        GrappaPanel _grappaPanel;
605        Graph _graph;
606
607        JPanel _listPanel;
608        MessagePanel _messagePanel;
609        JPanel _graphPanel;
610
611        JPanel _tallPanel;
612        JPanel _thinPanel;
613       
614        JPanel _top;
615        JPanel _complete;
616
617        int _side;
618
619        public Graph getGraph( ) {
620            return _graph;
621        }
622
623
624        public SidePanel( int side ) {
625            super( );
626            Class clazz = this.getClass( );
627
628
629            _side = side;
630
631            _tallPanel = new JPanel( );
632            _tallPanel.setLayout( new BoxLayout( _tallPanel, BoxLayout.Y_AXIS ) );
633
634            JButton tall = new JButton( );
635            tall.setMaximumSize( new Dimension( 10, 2000 ) );
636            tall.setPreferredSize( new Dimension( 10, 2000 ) );
637            tall.setMinimumSize( new Dimension( 10, 0 ) );
638
639            tall.addActionListener( new ActionListener( ) {
640                    boolean removed = false;
641                   
642                    public void actionPerformed( ActionEvent e ) {
643                        if( ! removed ) {
644                            _top.remove( _listPanel );
645                            removed = true;
646                        } else {
647                            if( _side == LEFT_SIDE ) {
648                                _top.add( _listPanel, 0 );
649                            } else {
650                                _top.add( _listPanel, 2 );
651                            }
652
653                            removed = false;
654                        }
655                       
656                        validate( );
657                        repaint( );
658
659                    }
660
661                } );
662
663
664            _tallPanel.add( tall );
665
666
667            _thinPanel = new JPanel( );
668            _thinPanel.setLayout( new BoxLayout( _thinPanel, BoxLayout.X_AXIS ) );
669
670            JButton thin = new JButton( );
671            thin.setMaximumSize( new Dimension( 2000, 10 ) );
672            thin.setPreferredSize( new Dimension( 2000, 10 ) );
673            thin.setMinimumSize( new Dimension( 0, 10 ) );
674
675            thin.addActionListener( new ActionListener( ) {
676                    boolean removed = false;
677                   
678                    public void actionPerformed( ActionEvent e ) {
679                        if( ! removed ) {
680                            _complete.remove( _messagePanel );
681                            removed = true;
682                        } else {
683                            _complete.add( _messagePanel, 2 );
684                            removed = false;
685                        }
686
687                        validate( );
688                        repaint( );
689                    }
690
691                } );
692
693
694            _thinPanel.add( thin );
695
696            _listPanel = new ListPanel( );
697
698            _messagePanel = new MessagePanel( );
699
700            _graphPanel = new JPanel( new BorderLayout( ) );
701
702            setPanelBorder( _graphPanel, "Trust Negotiation Graph" );
703
704            _listPanel.setMaximumSize( new Dimension( 150, 2000 ) );
705            _listPanel.setPreferredSize( new Dimension( 150, 2000 ) );
706            _listPanel.setMinimumSize( new Dimension( 150, 0 ) );
707
708            _messagePanel.setMaximumSize( new Dimension( 2000, 150 ) );
709            _messagePanel.setPreferredSize( new Dimension( 2000, 150 ) );
710            _messagePanel.setMinimumSize( new Dimension( 0, 150 ) );
711
712
713            _top = new JPanel( );
714            _top.setLayout( new BoxLayout( _top, BoxLayout.X_AXIS ) );
715           
716
717            if( _side == LEFT_SIDE ) {
718                _top.add( _listPanel );
719                _top.add( _tallPanel );
720                _top.add( _graphPanel );
721            } else {
722                _top.add( _graphPanel );
723                _top.add( _tallPanel );
724                _top.add( _listPanel );
725            }
726
727
728            _complete = new JPanel( );
729            _complete.setLayout( new BoxLayout( _complete, BoxLayout.Y_AXIS ) );
730
731            _complete.add( _top );
732            _complete.add( _thinPanel );
733            _complete.add( _messagePanel );
734
735            _graph = new Graph( "Trust Negotiation Graph: " + _side );
736            _grappaPanel = new GrappaPanel( _graph );
737            _grappaPanel.setScaleToFit( false );
738
739            JScrollPane jsp = new JScrollPane( );
740            jsp.getViewport( ).setScrollMode( JViewport.BACKINGSTORE_SCROLL_MODE );
741            jsp.getViewport( ).setBackground( Color.white );
742            jsp.setViewportView( _grappaPanel );
743       
744            _graphPanel.add( jsp, BorderLayout.CENTER );
745
746            setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) );
747            add( _complete );
748
749        }
750
751        public void setMessage( String message ) {
752            _messagePanel.setMessage( message );
753        }
754
755    }
756
757
758    private class ControlPanel extends JPanel implements ActionListener {
759        JButton play, pause, stepForward, stepBack, rewind, fastForward, stop;
760        InternalObservable _observable;
761
762        public ControlPanel( ) {
763            super( );
764           
765            _observable = new InternalObservable( );
766            Class clazz = this.getClass( );
767
768            play = new JButton( new ImageIcon( clazz.getResource( "/resources/Play24.gif" ), "play" ) );
769            play.setActionCommand( "play" );
770            play.addActionListener( this );
771            play.setEnabled( true );
772
773            pause = new JButton( new ImageIcon( clazz.getResource( "/resources/Pause24.gif" ), "pause" ) );
774            pause.setActionCommand( "pause" );
775            pause.addActionListener( this );
776            pause.setEnabled( false );
777
778
779            stepForward = new JButton( new ImageIcon( clazz.getResource( "/resources/StepForward24.gif" ), "step forward" ) );
780            stepForward.setActionCommand( "stepf" );
781            stepForward.addActionListener( this );
782            stepForward.setEnabled( true );
783
784            stepBack = new JButton( new ImageIcon( clazz.getResource( "/resources/StepBack24.gif" ), "step back" ) );
785            stepBack.setActionCommand( "stepb" );
786            stepBack.addActionListener( this );
787            stepBack.setEnabled( true );
788
789            rewind = new JButton( new ImageIcon( clazz.getResource( "/resources/Rewind24.gif" ), "rewind" ) );
790            rewind.setActionCommand( "rewind" );
791            rewind.addActionListener( this );
792            rewind.setEnabled( true );
793
794            fastForward = new JButton( new ImageIcon( clazz.getResource( "/resources/FastForward24.gif" ), "fast forward" ) );
795            fastForward.setActionCommand( "ff" );
796            fastForward.addActionListener( this );
797            fastForward.setEnabled( true );
798
799//          stop = new JButton( new ImageIcon( clazz.getResource( "/resources/Stop24.gif" ), "stop" ) );
800//          stop.setActionCommand( "stop" );
801//          stop.addActionListener( this );
802
803
804            setStyle( play );
805            setStyle( pause );
806            setStyle( stepForward );
807            setStyle( stepBack );
808            setStyle( rewind );
809            setStyle( fastForward );
810//          setStyle( stop );
811
812            setLayout( new BoxLayout( this, BoxLayout.X_AXIS ) );
813            add( rewind );
814            add( stepBack );
815            add( play );
816            add( pause );
817//          add( stop );
818            add( stepForward );
819            add( fastForward );
820
821            JCheckBox loop = new JCheckBox( "loop", (new Boolean( _properties.getProperty( LOOP_PROP, LOOP_DEFAULT ) )).booleanValue( ) );
822            loop.addItemListener( new ItemListener( ) {
823                    public void itemStateChanged( ItemEvent e ) {
824                        int s = e.getStateChange( );
825                        Boolean state = Boolean.TRUE;
826
827                        if( s == ItemEvent.DESELECTED ) {
828                            state = Boolean.FALSE;
829                        }
830                       
831                        _observable.notify( state );
832
833                    }
834
835                } );
836
837
838            add( Box.createHorizontalStrut( 10 ) );
839            add( loop );
840
841            JSpinner spinner = new JSpinner( new SpinnerNumberModel( Integer.parseInt( _properties.getProperty( DELAY_PROP, DELAY_DEFAULT ) ), 
842                                                                     0, 
843                                                                     5000, 
844                                                                     100 ) );
845
846            JLabel spinnerLabel = new JLabel( "delay (msec)" );
847
848            spinner.addChangeListener( new ChangeListener( ) {
849                    public void stateChanged( ChangeEvent e ) {
850                        _observable.notify( e.getSource( ) );
851                    }
852                } );
853
854
855            add( spinner );
856            add( Box.createHorizontalStrut( 5 ) );
857            add( spinnerLabel );
858
859            setPanelBorder( this, "Controls" );
860        }
861
862
863        public void addObserver( Observer o ) {
864            _observable.addObserver( o );
865        }
866
867
868        private void setStyle( JButton b ) {
869            b.setMinimumSize( new Dimension( 24, 24 ) );
870            b.setMaximumSize( new Dimension( 24, 24 ) );
871            b.setPreferredSize( new Dimension( 24, 24 ) );
872           
873            b.setBorderPainted( false );
874        }
875
876        public void actionPerformed( ActionEvent e ) {
877            String cmd = e.getActionCommand( );
878            if( cmd.equals( "play" ) ) {
879                stepForward.setEnabled( false );
880                stepBack.setEnabled( false );
881                rewind.setEnabled( false );
882                fastForward.setEnabled( false );
883                play.setEnabled( false );
884                pause.setEnabled( true );
885            }
886
887            else if( cmd.equals( "pause" ) ) {
888                stepForward.setEnabled( true );
889                stepBack.setEnabled( true );
890                rewind.setEnabled( true );
891                fastForward.setEnabled( true );
892                play.setEnabled( true );
893                pause.setEnabled( false );
894            }
895
896
897
898
899
900            _observable.notify( e.getActionCommand( ) );
901        }
902
903
904        private class InternalObservable extends Observable {
905            public void notify( Object arg ) {
906                setChanged( );
907                notifyObservers( arg );
908            }
909
910           
911        }
912
913    }
914
915
916    private class ListPanel extends JPanel implements Observer {
917        public ListPanel( ) {
918            super( );
919
920            JList oCreds = new JList( );
921            JScrollPane oCredsJSP = new JScrollPane( oCreds );
922            setPanelBorder( oCredsJSP, "Opponent Creds." );
923
924            JList vCreds = new JList( );
925            JScrollPane vCredsJSP = new JScrollPane( vCreds );
926            setPanelBorder( vCredsJSP, "Verifier Creds." );
927
928            JList acPolicy = new JList( );
929            JScrollPane acPolicyJSP = new JScrollPane( acPolicy );
930            setPanelBorder( acPolicyJSP, "AC Policies" );
931
932            JList ackPolicy = new JList( );
933            JScrollPane ackPolicyJSP = new JScrollPane( ackPolicy );
934            setPanelBorder( ackPolicyJSP, "Ack Policies" );
935
936
937            setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) );
938
939            JList list = new JList( );
940            JScrollPane jsp = new JScrollPane( list );
941           
942            add( oCredsJSP );
943            add( vCredsJSP );
944            add( acPolicyJSP );
945            add( ackPolicyJSP );
946
947
948        }
949
950
951        public void update( Observable o, Object arg ) {
952
953
954        }
955
956    }
957
958
959    private class MessagePanel extends JPanel {
960        JTextArea _message;
961
962        public MessagePanel( ) {
963            super( );
964            setLayout( new BorderLayout( ) );
965
966            _message = new JTextArea( );
967            JScrollPane jsp = new JScrollPane( _message );
968
969            add( jsp, BorderLayout.CENTER );
970
971            setPanelBorder( this, "Message" );
972
973        }
974
975        public void setMessage( String message ) {
976            _message.setText( message );
977        }
978
979
980    }
981
982   
983    private class ProgressPanel extends JPanel implements Observer {
984        JProgressBar _progress;
985
986        public ProgressPanel( ) {
987            super( );
988            setLayout( new BorderLayout( ) );
989
990//          _progress = new JProgressBar( 0, _updates.size( ) );
991            _progress = new JProgressBar( 0, 1 );
992            _progress.setValue( 0 );
993            _progress.setStringPainted( true );
994
995
996            add( _progress, BorderLayout.CENTER );
997
998            setPanelBorder( this, "Negotiation Progress" );
999        }
1000
1001
1002        public void setMax( int n ) {
1003            _progress.setMaximum( n );
1004        }
1005
1006        public void update( Observable o, Object arg ) {
1007            _progress.setValue( ((Integer)arg).intValue( ) );
1008
1009        }
1010
1011
1012    }
1013
1014
1015    private void setPanelBorder( JComponent comp, String label ) {
1016        Border empty = BorderFactory.createEmptyBorder( 0, 0, 0, 0 );
1017        Border etched = BorderFactory.createEtchedBorder( );
1018       
1019        TitledBorder title = BorderFactory.createTitledBorder( etched, label );
1020        title.setTitleJustification( TitledBorder.RIGHT );
1021
1022        Border compound = BorderFactory.createCompoundBorder( title, empty );
1023        comp.setBorder( compound );
1024    }
1025
1026
1027    private class PlayBackManager extends Observable implements Observer {
1028        private int _delay = Integer.parseInt( _properties.getProperty( DELAY_PROP, DELAY_DEFAULT ) );
1029        private boolean _loop = (new Boolean( _properties.getProperty( LOOP_PROP, LOOP_DEFAULT ) )).booleanValue( );
1030        private Update[] _updateArray = (Update[]) _updates.toArray( new Update[0] );
1031        private int _index = 0;
1032        private boolean _clear = true;
1033
1034
1035        private boolean _playing = false;
1036
1037
1038        public PlayBackManager( ) {
1039            _progressPanel.setMax( _updateArray.length );
1040        }
1041
1042        public void update( Observable o, Object arg ) {
1043            if( arg instanceof String ) {
1044                String cmd = (String)arg;
1045
1046                if( cmd.equals( "play" ) ) {
1047                    _playing = true;
1048                    new Thread( new PlayThread( ) ).start( );
1049                } else if( cmd.equals( "pause" ) ) {
1050                    _playing = false;
1051                } else if( cmd.equals( "stepf" ) ) {
1052                    stepf( );
1053                } else if( cmd.equals( "ff" ) ) {
1054                    ff( );
1055                } else if( cmd.equals( "rewind" ) ) {
1056                    rewind( );
1057                }
1058
1059            } else if( arg instanceof JSpinner ) {
1060                SpinnerNumberModel snm = (SpinnerNumberModel)((JSpinner)arg).getModel( );
1061                _delay = snm.getNumber( ).intValue( );
1062            } else if (arg instanceof Boolean ) {
1063                _loop = ((Boolean)arg).booleanValue( );
1064            }
1065        }
1066
1067
1068        private synchronized void stepf( ) {
1069            if( _index == 0 && _clear == false ) {
1070                clearAll( );
1071                _clear = true;
1072
1073                setChanged( );
1074                notifyObservers( new Integer( _index ) );
1075
1076                return;
1077            }
1078
1079            _clear = false;
1080
1081
1082            _updateArray[_index].execute( );
1083            _index++;
1084
1085            setChanged( );
1086            notifyObservers( new Integer( _index ) );
1087
1088           
1089            if( _index == _updateArray.length ) {
1090                _index = 0;
1091                if( _playing == true && _loop == false ) {
1092                    _playing = false;
1093                }
1094            }
1095
1096
1097        }
1098
1099        private synchronized void stepb( ) {
1100            setChanged( );
1101            notifyObservers( new Integer( _index ) );
1102        }
1103       
1104        private synchronized void ff( ) {
1105            for( int i = _index; i < _updateArray.length; i++ ) {
1106                _updateArray[i].execute( );
1107            }
1108
1109            _index = 0;
1110
1111            setChanged( );
1112            notifyObservers( new Integer( _index ) );
1113
1114        }
1115
1116
1117        private synchronized void rewind( ) {
1118            clearAll( );
1119            _index = 0;
1120
1121            setChanged( );
1122            notifyObservers( new Integer( _index ) );
1123        }
1124
1125
1126        private class PlayThread implements Runnable {
1127            public void run( ) {
1128                while( _playing ) {
1129                    try {
1130                        stepf( );
1131                        Thread.currentThread( ).sleep( _delay );
1132                    } catch( InterruptedException ie ) {
1133                        throw new RuntimeException( ie );
1134                    }
1135                }
1136               
1137            }
1138        }
1139
1140
1141    }
1142
1143
1144    protected abstract class  Update {
1145        public abstract void execute( );
1146        public abstract void fixRef( );
1147    }
1148
1149
1150    private class TestUpdate extends Update {
1151        private int _i;
1152
1153        public TestUpdate( int i ) {
1154            _i = i;
1155        }
1156
1157        public void execute( ) {
1158            System.out.println( _i );
1159        }
1160       
1161        public void fixRef( ) {
1162
1163        }
1164
1165    }
1166
1167    private class MessageBeginUpdate extends Update {
1168        SidePanel _sp;
1169        String _message;
1170
1171        public MessageBeginUpdate( SidePanel sp, String message ) {
1172            _sp = sp;
1173            _message = message;
1174        }
1175
1176
1177        public void execute( ) {
1178            _sp.setMessage( _message );
1179        }
1180       
1181        public void fixRef( ) {
1182
1183        }
1184       
1185    }
1186   
1187    private class MessageEndUpdate extends Update {
1188        SidePanel _sp;
1189
1190        public MessageEndUpdate( SidePanel sp ) {
1191            _sp = sp;
1192        }
1193
1194
1195        public void execute( ) {
1196            _sp.setMessage( "" );
1197        }
1198       
1199        public void fixRef( ) {
1200
1201        }
1202    }
1203   
1204       
1205
1206
1207
1208
1209
1210
1211    private class NodeUpdate extends Update {
1212        SidePanel _sp;
1213        String _name;
1214        Node _n;
1215
1216        String _type;
1217        String _satisfactionState;
1218        String _processingState;
1219
1220        public NodeUpdate( SidePanel sp, String name ) {
1221            _sp = sp;
1222            _name = name;
1223
1224            Graph g = _sp.getGraph( );
1225
1226            _n = g.findNodeByName( name );
1227            if( _n == null ) {
1228                _n = new Node( g, name );
1229                setInvis( _n );
1230                g.addNode( _n );
1231            }
1232
1233        }
1234
1235        public NodeUpdate( SidePanel sp, 
1236                           String name, 
1237                           String type,
1238                           String satisfactionState, 
1239                           String processingState ) {
1240            this( sp, name );
1241
1242            _type = type;
1243
1244
1245            _satisfactionState = satisfactionState;
1246            _processingState = processingState;
1247
1248
1249        }
1250
1251        public void fixRef( ) {
1252            _n = _sp.getGraph( ).findNodeByName( _name );
1253        }
1254
1255
1256        public void execute( ) {
1257            fixRef( );
1258
1259            setNodeProperties( _n, _type, _satisfactionState, _processingState );
1260
1261            Graph g = _sp.getGraph( );
1262
1263            g.resync( );
1264            g.repaint( );
1265        }
1266    }
1267
1268   
1269    private class EdgeUpdate extends Update {
1270        SidePanel _sp;
1271        String _headNodeName;
1272        String _tailNodeName;
1273        Edge _e;
1274
1275        String _type;
1276
1277
1278        public EdgeUpdate( SidePanel sp, 
1279                           String headNodeName, 
1280                           String tailNodeName, 
1281                           String type ) {
1282            this( sp, headNodeName, tailNodeName );
1283            _type = type;
1284        }
1285
1286
1287
1288        public EdgeUpdate( SidePanel sp, String headNodeName, String tailNodeName ) {
1289            _sp = sp;
1290            _headNodeName = headNodeName;
1291            _tailNodeName = tailNodeName;
1292
1293            Graph g = _sp.getGraph( );
1294            Node head = g.findNodeByName( _headNodeName );
1295            Node tail = g.findNodeByName( _tailNodeName );
1296
1297
1298            _e = getEdgeBetween( g, head, tail );
1299
1300            if( _e == null ) {
1301                _e = new Edge( g, head, tail );
1302                setInvis( _e );
1303                g.addEdge( _e );
1304            }
1305
1306        }
1307
1308
1309        public void fixRef( ) {
1310            Graph g = _sp.getGraph( );
1311            Node head = g.findNodeByName( _headNodeName );
1312            Node tail = g.findNodeByName( _tailNodeName );
1313
1314
1315            _e = getEdgeBetween( g, head, tail );
1316        }
1317
1318        public void execute( ) {
1319            fixRef( );
1320            setEdgeProperties( _e, _type );
1321
1322            Graph g = _sp.getGraph( );
1323
1324            g.resync( );
1325            g.repaint( );
1326        }
1327    }
1328
1329
1330    private void clearAll( ) {
1331        for( int i = 0; i < _sides.length; i++ ) {
1332            if( _sides[i] != null ) {
1333                hideGraph( _sides[i].getGraph( ) );
1334            }
1335        }
1336
1337       
1338    }
1339
1340    private Graph loadGraph( String dotFile ) {
1341        Parser parser = null;
1342        try {
1343            parser = new Parser( new FileInputStream( dotFile ) );
1344            parser.parse( );
1345        } catch( Exception e ) {
1346            e.printStackTrace( );
1347            System.exit( 1 );
1348        }
1349
1350        return parser.getGraph( );
1351    }
1352
1353
1354
1355    public static void main( String[] args ) {
1356        ATNVisualizer atnVis = null;
1357
1358        if( args.length == 1 ) {
1359            atnVis = new ATNVisualizer( args[0], null );
1360        } else if ( args.length == 2 ) {
1361            atnVis = new ATNVisualizer( args[0], args[1] );
1362        } else {
1363            System.err.println( "usage: ATNVisualizer <log file> [<log file>]" );
1364            System.exit( 1 );
1365        }
1366
1367    }
1368
1369
1370
1371    private void printGraph( Graph g ) {
1372        Enumeration nodes = g.nodeElements( );
1373        Enumeration edges = g.edgeElements( );
1374
1375        while( nodes.hasMoreElements( ) ) {
1376            System.out.println( "----------------------------------------------------------------------" );
1377
1378            Node n = (Node) nodes.nextElement( );
1379            n.printAllAttributes = true;
1380
1381            System.out.println( n.getName( ) );
1382
1383            Enumeration e = n.getAttributePairs( );
1384            while( e.hasMoreElements( ) ) {
1385                System.out.println( e.nextElement( ) );
1386            }
1387
1388        }
1389
1390        while( edges.hasMoreElements( ) ) {
1391            System.out.println( "----------------------------------------------------------------------" );
1392
1393            Edge e = (Edge) edges.nextElement( );
1394            e.printAllAttributes = true;
1395
1396            System.out.println( e.getName( ) );
1397
1398            Enumeration en = e.getAttributePairs( );
1399            while( en.hasMoreElements( ) ) {
1400                System.out.println( en.nextElement( ) );
1401            }
1402        }
1403
1404        System.out.println( "======================================================================" );
1405
1406        g.printSubgraph( new PrintWriter( System.err, true ) );
1407    }
1408
1409
1410    private Edge getEdgeBetween( Graph g, Node head, Node tail ) {
1411        Enumeration edges = g.edgeElements( );
1412        while( edges.hasMoreElements( ) ) {
1413            Edge e = (Edge) edges.nextElement( );
1414            Node t = e.getHead( );
1415            Node h = e.getTail( );
1416           
1417            if( h.getName( ).equals( head.getName( ) ) && t.getName( ).equals( tail.getName( ) ) ) {
1418                return e;
1419            }
1420        }
1421
1422        return null;
1423    }
1424
1425
1426}
Note: See TracBrowser for help on using the repository browser.