1 | package com.algomagic.atn; |
---|
2 | |
---|
3 | import att.grappa.*; |
---|
4 | import java.util.*; |
---|
5 | |
---|
6 | import java.awt.*; |
---|
7 | import java.awt.event.*; |
---|
8 | import java.awt.geom.*; |
---|
9 | |
---|
10 | import javax.swing.*; |
---|
11 | import javax.swing.border.*; |
---|
12 | import javax.swing.event.*; |
---|
13 | |
---|
14 | |
---|
15 | public class VisualizationPanel |
---|
16 | extends JPanel |
---|
17 | implements Observer, VisualizationConstants { |
---|
18 | |
---|
19 | private int _side; |
---|
20 | private Properties _properties; |
---|
21 | |
---|
22 | private GrappaPanel _grappaPanel; |
---|
23 | private Graph _graph; |
---|
24 | |
---|
25 | private JPanel _complete; |
---|
26 | private JPanel _graphPanel; |
---|
27 | private CredentialPanel _credentialPanel; |
---|
28 | |
---|
29 | private ImageIcon _collapse; |
---|
30 | private ImageIcon _expand; |
---|
31 | |
---|
32 | private HashMap _nodeStates; |
---|
33 | private Subgraph _currentCluster; |
---|
34 | |
---|
35 | private boolean _local; |
---|
36 | private java.util.List _bolded; |
---|
37 | private HashMap _remoteClusters; |
---|
38 | private HashMap _remoteEvidence; |
---|
39 | |
---|
40 | private HashMap _localClusters; |
---|
41 | |
---|
42 | private String _shadowColor; |
---|
43 | private int _currentIndex; |
---|
44 | |
---|
45 | private BatchGraphUpdate _batchUpdate; |
---|
46 | private boolean _ignoreProcessing; |
---|
47 | private HashSet _boldedNodes; |
---|
48 | private boolean _basicProps; |
---|
49 | |
---|
50 | private String _name; |
---|
51 | |
---|
52 | public void setName( String name ) { |
---|
53 | _name = name; |
---|
54 | PanelHelper.setBorder( _graphPanel, "Trust Target Graph: " + name ); |
---|
55 | // _graph.setAttribute( TIP_ATTR, "Trust Target Graph: " + name ); |
---|
56 | // _graph.setAttribute( TIP_ATTR, null ); |
---|
57 | |
---|
58 | _grappaPanel.setToolTipText( null ); |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | class CredentialPanel extends JPanel { |
---|
63 | JTabbedPane _tabs; |
---|
64 | JList _local; |
---|
65 | JList _remote; |
---|
66 | JList _policy; |
---|
67 | |
---|
68 | DefaultListModel _localCreds; |
---|
69 | DefaultListModel _remoteCreds; |
---|
70 | DefaultListModel _policyCreds; |
---|
71 | |
---|
72 | boolean _autoRaise; |
---|
73 | |
---|
74 | public CredentialPanel( ) { |
---|
75 | super( ); |
---|
76 | |
---|
77 | _autoRaise = true; |
---|
78 | |
---|
79 | _tabs = new JTabbedPane( ); |
---|
80 | |
---|
81 | _localCreds = new DefaultListModel( ); |
---|
82 | _remoteCreds = new DefaultListModel( ); |
---|
83 | _policyCreds = new DefaultListModel( ); |
---|
84 | |
---|
85 | |
---|
86 | _local = new JList( _localCreds ); |
---|
87 | _remote = new JList( _remoteCreds ); |
---|
88 | _policy = new JList( _policyCreds ); |
---|
89 | |
---|
90 | |
---|
91 | _tabs.addTab( "Local Credentials", new JScrollPane( _local ) ); |
---|
92 | _tabs.addTab( "Remote Credentials", new JScrollPane( _remote ) ); |
---|
93 | _tabs.addTab( "Policies", new JScrollPane( _policy ) ); |
---|
94 | |
---|
95 | |
---|
96 | setLayout( new BorderLayout( ) ); |
---|
97 | add( _tabs, BorderLayout.CENTER ); |
---|
98 | |
---|
99 | PanelHelper.setBorder( this, "Credentials" ); |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | public void clearSelection( ) { |
---|
104 | _local.clearSelection( ); |
---|
105 | _remote.clearSelection( ); |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | public void setAutoRaise( boolean state ) { |
---|
110 | _autoRaise = state; |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | public void setRaised( int tab ) { |
---|
115 | clearSelection( ); |
---|
116 | |
---|
117 | if( _autoRaise ) { |
---|
118 | // System.out.println( "side: " + _side + " tab: " + tab ); |
---|
119 | |
---|
120 | _tabs.setSelectedIndex( tab ); |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | |
---|
125 | public void setRaised( boolean local ) { |
---|
126 | clearSelection( ); |
---|
127 | |
---|
128 | if( _autoRaise ) { |
---|
129 | if( local ) { |
---|
130 | _tabs.setSelectedIndex( 0 ); |
---|
131 | } else { |
---|
132 | _tabs.setSelectedIndex( 1 ); |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | public void addCredentials( Collection evidence, int tab ) { |
---|
139 | clearSelection( ); |
---|
140 | DefaultListModel m; |
---|
141 | |
---|
142 | if( tab == 0 ) { |
---|
143 | m = _localCreds; |
---|
144 | } else if( tab == 1 ) { |
---|
145 | m = _remoteCreds; |
---|
146 | } else { |
---|
147 | m = _policyCreds; |
---|
148 | } |
---|
149 | |
---|
150 | for( Iterator i = evidence.iterator( ); i.hasNext( ); ) { |
---|
151 | Object o = i.next( ); |
---|
152 | |
---|
153 | if( !m.contains( o ) ) { |
---|
154 | m.addElement( o ); |
---|
155 | } |
---|
156 | // m.addElement( i.next( ) ); |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | |
---|
161 | public void removeCredentials( Collection evidence, int tab ) { |
---|
162 | clearSelection( ); |
---|
163 | DefaultListModel m; |
---|
164 | |
---|
165 | if( tab == 0 ) { |
---|
166 | m = _localCreds; |
---|
167 | } else if( tab == 1 ) { |
---|
168 | m = _remoteCreds; |
---|
169 | } else { |
---|
170 | m = _policyCreds; |
---|
171 | } |
---|
172 | |
---|
173 | for( Iterator i = evidence.iterator( ); i.hasNext( ); ) { |
---|
174 | Object o = i.next( ); |
---|
175 | |
---|
176 | if( m.contains( o ) ) { |
---|
177 | m.removeElement( o ); |
---|
178 | } |
---|
179 | // m.addElement( i.next( ) ); |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | |
---|
184 | public void addCredentials( Collection evidence, boolean local ) { |
---|
185 | clearSelection( ); |
---|
186 | DefaultListModel m; |
---|
187 | |
---|
188 | if( local ) { |
---|
189 | m = _localCreds; |
---|
190 | } else { |
---|
191 | m = _remoteCreds; |
---|
192 | } |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | for( Iterator i = evidence.iterator( ); i.hasNext( ); ) { |
---|
198 | Object o = i.next( ); |
---|
199 | |
---|
200 | if( !m.contains( o ) ) { |
---|
201 | m.addElement( o ); |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | } |
---|
206 | |
---|
207 | |
---|
208 | public void removeCredentials( Collection evidence, boolean local ) { |
---|
209 | clearSelection( ); |
---|
210 | DefaultListModel m; |
---|
211 | |
---|
212 | if( local ) { |
---|
213 | m = _localCreds; |
---|
214 | } else { |
---|
215 | m = _remoteCreds; |
---|
216 | } |
---|
217 | |
---|
218 | |
---|
219 | |
---|
220 | |
---|
221 | for( Iterator i = evidence.iterator( ); i.hasNext( ); ) { |
---|
222 | Object o = i.next( ); |
---|
223 | |
---|
224 | if( m.contains( o ) ) { |
---|
225 | m.removeElement( o ); |
---|
226 | } |
---|
227 | } |
---|
228 | |
---|
229 | } |
---|
230 | |
---|
231 | public void highlightCredentials( Collection evidence, int tab ) { |
---|
232 | |
---|
233 | DefaultListModel m; |
---|
234 | JList l; |
---|
235 | |
---|
236 | if( tab == 0 ) { |
---|
237 | m = _localCreds; |
---|
238 | l = _local; |
---|
239 | } else { |
---|
240 | m = _remoteCreds; |
---|
241 | l = _remote; |
---|
242 | } |
---|
243 | |
---|
244 | |
---|
245 | clearSelection( ); |
---|
246 | |
---|
247 | int[] indices = new int[evidence.size( )]; |
---|
248 | int count = 0; |
---|
249 | for( Iterator i = evidence.iterator( ); i.hasNext( ); ) { |
---|
250 | indices[count] = m.indexOf( i.next( ) ); |
---|
251 | count++; |
---|
252 | } |
---|
253 | |
---|
254 | l.setSelectedIndices( indices ); |
---|
255 | } |
---|
256 | |
---|
257 | |
---|
258 | public void highlightCredentials( Collection evidence, boolean local ) { |
---|
259 | DefaultListModel m; |
---|
260 | JList l; |
---|
261 | |
---|
262 | if( local ) { |
---|
263 | m = _localCreds; |
---|
264 | l = _local; |
---|
265 | } else { |
---|
266 | m = _remoteCreds; |
---|
267 | l = _remote; |
---|
268 | } |
---|
269 | |
---|
270 | |
---|
271 | clearSelection( ); |
---|
272 | |
---|
273 | int[] indices = new int[evidence.size( )]; |
---|
274 | int count = 0; |
---|
275 | for( Iterator i = evidence.iterator( ); i.hasNext( ); ) { |
---|
276 | indices[count] = m.indexOf( i.next( ) ); |
---|
277 | count++; |
---|
278 | } |
---|
279 | |
---|
280 | l.setSelectedIndices( indices ); |
---|
281 | |
---|
282 | } |
---|
283 | |
---|
284 | public void removeRemoteCreds( ) { |
---|
285 | // System.out.println( "removing remote creds" ); |
---|
286 | |
---|
287 | _remoteCreds.clear( ); |
---|
288 | } |
---|
289 | |
---|
290 | } |
---|
291 | |
---|
292 | |
---|
293 | public void setAutoRaise( boolean state ) { |
---|
294 | _credentialPanel.setAutoRaise( state ); |
---|
295 | } |
---|
296 | |
---|
297 | public void clearSelection( ) { |
---|
298 | _credentialPanel.clearSelection( ); |
---|
299 | } |
---|
300 | |
---|
301 | |
---|
302 | public void setRaised( boolean local ) { |
---|
303 | _credentialPanel.setRaised( local ); |
---|
304 | } |
---|
305 | |
---|
306 | public void setRaised( int tab ) { |
---|
307 | _credentialPanel.setRaised( tab ); |
---|
308 | } |
---|
309 | |
---|
310 | |
---|
311 | public void addCredentials( Collection evidence, boolean local ) { |
---|
312 | if( evidence != null ) { |
---|
313 | _credentialPanel.addCredentials( evidence, local ); |
---|
314 | } |
---|
315 | } |
---|
316 | |
---|
317 | public void removeCredentials( Collection evidence, boolean local ) { |
---|
318 | if( evidence != null ) { |
---|
319 | _credentialPanel.removeCredentials( evidence, local ); |
---|
320 | } |
---|
321 | } |
---|
322 | |
---|
323 | |
---|
324 | public void highlightCredentials( Collection evidence, boolean local ) { |
---|
325 | if( evidence != null ) { |
---|
326 | _credentialPanel.highlightCredentials( evidence, local ); |
---|
327 | } |
---|
328 | } |
---|
329 | |
---|
330 | public void addCredentials( Collection evidence, int tab ) { |
---|
331 | if( evidence != null ) { |
---|
332 | _credentialPanel.addCredentials( evidence, tab ); |
---|
333 | } |
---|
334 | } |
---|
335 | |
---|
336 | public void removeCredentials( Collection evidence, int tab ) { |
---|
337 | if( evidence != null ) { |
---|
338 | _credentialPanel.removeCredentials( evidence, tab ); |
---|
339 | } |
---|
340 | } |
---|
341 | |
---|
342 | public void highlightCredentials( Collection evidence, int tab ) { |
---|
343 | if( evidence != null ) { |
---|
344 | _credentialPanel.highlightCredentials( evidence, tab ); |
---|
345 | } |
---|
346 | } |
---|
347 | |
---|
348 | |
---|
349 | public VisualizationPanel( int side, Properties properties ) { |
---|
350 | super( ); |
---|
351 | |
---|
352 | _side = side; |
---|
353 | _properties = properties; |
---|
354 | _currentCluster = null; |
---|
355 | _local = true; |
---|
356 | _basicProps = false; |
---|
357 | |
---|
358 | _nodeStates = new HashMap( ); |
---|
359 | _bolded = new ArrayList( ); |
---|
360 | _remoteClusters = new HashMap( ); |
---|
361 | _remoteEvidence = new HashMap( ); |
---|
362 | _localClusters = new HashMap( ); |
---|
363 | _batchUpdate = new BatchGraphUpdate( ); |
---|
364 | _boldedNodes = new HashSet( ); |
---|
365 | |
---|
366 | |
---|
367 | _ignoreProcessing = (new Boolean( _properties.getProperty( IGNOREPROC_PROP, IGNOREPROC_DEFAULT ) )).booleanValue( ); |
---|
368 | // System.out.println( _properties.getProperty( IGNOREPROC_PROP, IGNOREPROC_DEFAULT ) ); |
---|
369 | // System.out.println( _ignoreProcessing ); |
---|
370 | |
---|
371 | |
---|
372 | _shadowColor = _properties.getProperty( SHADOW_PROP, SHADOW_DEFAULT ); |
---|
373 | |
---|
374 | |
---|
375 | Class clazz = this.getClass( ); |
---|
376 | _collapse = new ImageIcon( clazz.getResource( "/resources/collapse.gif" ), "collapse" ); |
---|
377 | _expand = new ImageIcon( clazz.getResource( "/resources/expand.gif" ), "expand" ); |
---|
378 | |
---|
379 | |
---|
380 | JPanel hiderPanel = new JPanel( ); |
---|
381 | hiderPanel.setLayout( new BoxLayout( hiderPanel, BoxLayout.X_AXIS ) ); |
---|
382 | |
---|
383 | JButton hider = new JButton( _collapse ); |
---|
384 | hider.setMaximumSize( new Dimension( 2000, 10 ) ); |
---|
385 | hider.setPreferredSize( new Dimension( 2000, 10 ) ); |
---|
386 | hider.setMinimumSize( new Dimension( 0, 10 ) ); |
---|
387 | |
---|
388 | hider.addActionListener( new ActionListener( ) { |
---|
389 | boolean removed = false; |
---|
390 | |
---|
391 | public void actionPerformed( ActionEvent e ) { |
---|
392 | JButton button = (JButton)e.getSource( ); |
---|
393 | |
---|
394 | if( ! removed ) { |
---|
395 | _complete.remove( _credentialPanel ); |
---|
396 | button.setIcon( _expand ); |
---|
397 | removed = true; |
---|
398 | } else { |
---|
399 | _complete.add( _credentialPanel, 2 ); |
---|
400 | button.setIcon( _collapse ); |
---|
401 | removed = false; |
---|
402 | } |
---|
403 | |
---|
404 | validate( ); |
---|
405 | repaint( ); |
---|
406 | } |
---|
407 | |
---|
408 | } ); |
---|
409 | |
---|
410 | hiderPanel.add( hider ); |
---|
411 | |
---|
412 | _graph = new Graph( "Trust Target Graph: " + _side ); |
---|
413 | |
---|
414 | _grappaPanel = new GrappaPanel( _graph ); |
---|
415 | _grappaPanel.setScaleToFit( false ); |
---|
416 | |
---|
417 | // JScrollPane jsp = new JScrollPane( ); |
---|
418 | // jsp.getViewport( ).setScrollMode( JViewport.BACKINGSTORE_SCROLL_MODE ); |
---|
419 | // jsp.getViewport( ).setBackground( Color.white ); |
---|
420 | // jsp.setViewportView( _grappaPanel ); |
---|
421 | |
---|
422 | JScrollPane jsp = new JScrollPane( _grappaPanel ); |
---|
423 | // jsp.getViewport( ).setScrollMode( JViewport.BACKINGSTORE_SCROLL_MODE ); |
---|
424 | jsp.getViewport( ).setBackground( Color.white ); |
---|
425 | // jsp.setViewportView( _grappaPanel ); |
---|
426 | |
---|
427 | |
---|
428 | _graphPanel = new JPanel( new BorderLayout( ) ); |
---|
429 | PanelHelper.setBorder( _graphPanel, "Trust Target Graph" ); |
---|
430 | _graphPanel.add( jsp, BorderLayout.CENTER ); |
---|
431 | |
---|
432 | |
---|
433 | _credentialPanel = new CredentialPanel( ); |
---|
434 | _credentialPanel.setMaximumSize( new Dimension( 2000, 150 ) ); |
---|
435 | _credentialPanel.setPreferredSize( new Dimension( 2000, 150 ) ); |
---|
436 | _credentialPanel.setMinimumSize( new Dimension( 0, 150 ) ); |
---|
437 | |
---|
438 | _complete = new JPanel( ); |
---|
439 | _complete.setLayout( new BoxLayout( _complete, BoxLayout.Y_AXIS ) ); |
---|
440 | |
---|
441 | _complete.add( _graphPanel ); |
---|
442 | _complete.add( hiderPanel ); |
---|
443 | _complete.add( _credentialPanel ); |
---|
444 | |
---|
445 | |
---|
446 | _grappaPanel.addGrappaListener( new TipAdapter( ) ); |
---|
447 | |
---|
448 | |
---|
449 | setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) ); |
---|
450 | add( _complete ); |
---|
451 | |
---|
452 | } |
---|
453 | |
---|
454 | |
---|
455 | |
---|
456 | |
---|
457 | |
---|
458 | public boolean addNodeState( NodeState ns ) { |
---|
459 | if( _nodeStates.containsKey( ns.getName( ) ) ) { |
---|
460 | return false; |
---|
461 | } |
---|
462 | |
---|
463 | _nodeStates.put( ns.getName( ), ns ); |
---|
464 | |
---|
465 | return true; |
---|
466 | } |
---|
467 | |
---|
468 | public NodeState getNodeState( String name ) { |
---|
469 | return (NodeState)_nodeStates.get( name ); |
---|
470 | } |
---|
471 | |
---|
472 | |
---|
473 | |
---|
474 | public void reset( java.util.List updates ) { |
---|
475 | _basicProps = true; |
---|
476 | |
---|
477 | for( ListIterator i = updates.listIterator( ); i.hasNext( ); ) { |
---|
478 | Update u = (Update)i.next( ); |
---|
479 | |
---|
480 | if( u.getSide( ) == _side ) { |
---|
481 | u.apply( this ); |
---|
482 | } |
---|
483 | } |
---|
484 | |
---|
485 | _basicProps = false; |
---|
486 | hideGraph( _graph ); |
---|
487 | |
---|
488 | } |
---|
489 | |
---|
490 | |
---|
491 | public java.util.List initialize( java.util.List updates ) { |
---|
492 | java.util.List filteredUpdates = new ArrayList( ); |
---|
493 | |
---|
494 | for( ListIterator i = updates.listIterator( ); i.hasNext( ); ) { |
---|
495 | Update u = (Update)i.next( ); |
---|
496 | if( u.getSide( ) == _side ) { |
---|
497 | int changed = u.initialize( this ); |
---|
498 | |
---|
499 | // if changed == 1, processing state changed |
---|
500 | // changed == 2, satisfaction state changed |
---|
501 | // changed == 3, processing and satisfaction changed |
---|
502 | // changed == 0, no change |
---|
503 | |
---|
504 | |
---|
505 | if( changed == 3 || |
---|
506 | (!_ignoreProcessing && changed >= 1 ) || |
---|
507 | (_ignoreProcessing && changed >= 2 ) ) { |
---|
508 | |
---|
509 | filteredUpdates.add( u ); |
---|
510 | } |
---|
511 | } else { |
---|
512 | filteredUpdates.add( u ); |
---|
513 | } |
---|
514 | } |
---|
515 | |
---|
516 | |
---|
517 | boolean isRemoteCluster = false; |
---|
518 | int clusterNumber = -1; |
---|
519 | HashSet remoteCluster = null; |
---|
520 | Collection remoteEvidence = null; |
---|
521 | |
---|
522 | |
---|
523 | for( ListIterator i = filteredUpdates.listIterator( ); i.hasNext( ); ) { |
---|
524 | Update u = (Update)i.next( ); |
---|
525 | if( u.getSide( ) == _side ) { |
---|
526 | // if( u instanceof NodeUpdate ) { |
---|
527 | // System.out.println( u ); |
---|
528 | // } |
---|
529 | |
---|
530 | u.apply( this ); |
---|
531 | |
---|
532 | if( u instanceof ClusterUpdate ) { |
---|
533 | ClusterUpdate cu = (ClusterUpdate)u; |
---|
534 | if( !cu.getLocal( ) ) { |
---|
535 | if( cu.getStart( ) ) { |
---|
536 | isRemoteCluster = true; |
---|
537 | clusterNumber = cu.getCluster( ); |
---|
538 | remoteCluster = new HashSet( ); |
---|
539 | remoteEvidence = new ArrayList( ); |
---|
540 | } else { |
---|
541 | isRemoteCluster = false; |
---|
542 | _remoteClusters.put( new Integer( clusterNumber ), remoteCluster ); |
---|
543 | _remoteEvidence.put( new Integer( clusterNumber ), remoteEvidence ); |
---|
544 | } |
---|
545 | } |
---|
546 | } else if( isRemoteCluster ) { |
---|
547 | remoteCluster.add( u ); |
---|
548 | if( u instanceof EdgeUpdate ) { |
---|
549 | Collection c = ((EdgeUpdate)u).getEvidence( ); |
---|
550 | remoteEvidence.addAll( c ); |
---|
551 | } |
---|
552 | } |
---|
553 | |
---|
554 | } |
---|
555 | } |
---|
556 | |
---|
557 | |
---|
558 | formatGraph( _graph ); |
---|
559 | hideGraph( _graph ); |
---|
560 | _credentialPanel.removeRemoteCreds( ); |
---|
561 | |
---|
562 | |
---|
563 | String scaleStr = _properties.getProperty( SCALE_PROP, SCALE_DEFAULT ); |
---|
564 | double scale = Double.parseDouble( scaleStr ); |
---|
565 | |
---|
566 | _grappaPanel.multiplyScaleFactor( scale ); |
---|
567 | |
---|
568 | _graph.resync( ); |
---|
569 | _graph.repaint( ); |
---|
570 | |
---|
571 | |
---|
572 | return filteredUpdates; |
---|
573 | } |
---|
574 | |
---|
575 | |
---|
576 | |
---|
577 | public PanelUpdate apply( Update u ) { |
---|
578 | _batchUpdate = new BatchGraphUpdate( ); |
---|
579 | |
---|
580 | if( u.getSide( ) != _side ) { |
---|
581 | throw new RuntimeException( ); |
---|
582 | } |
---|
583 | |
---|
584 | |
---|
585 | u.apply( this ); |
---|
586 | |
---|
587 | boolean raise = false; |
---|
588 | int tab = -1; |
---|
589 | |
---|
590 | boolean add = false; |
---|
591 | boolean hl = true; |
---|
592 | |
---|
593 | Collection c = null; |
---|
594 | |
---|
595 | if( u instanceof ClusterUpdate ) { |
---|
596 | ClusterUpdate cu = (ClusterUpdate)u; |
---|
597 | if( !cu.getStart( ) && cu.getLocal( ) ) { |
---|
598 | unSetBolded( !cu.getUndo( ), cu.getCluster( ) ); |
---|
599 | } else if( cu.getStart( ) && !cu.getLocal( ) ) { |
---|
600 | setShadowed( !cu.getUndo( ), cu.getCluster( ) ); |
---|
601 | c = (Collection) _remoteEvidence.get( new Integer( cu.getCluster( ) ) ); |
---|
602 | add = true; |
---|
603 | hl = false; |
---|
604 | } |
---|
605 | } |
---|
606 | |
---|
607 | |
---|
608 | if( u.getLocal( ) ) { |
---|
609 | tab = 0; |
---|
610 | raise = true; |
---|
611 | } else { |
---|
612 | tab = 1; |
---|
613 | raise = true; |
---|
614 | } |
---|
615 | |
---|
616 | |
---|
617 | if( u instanceof EdgeUpdate ) { |
---|
618 | EdgeUpdate eu = (EdgeUpdate)u; |
---|
619 | c = eu.getEvidence( ); |
---|
620 | |
---|
621 | if( eu.getType( ).equals( CONTROL_EDGE ) ) { |
---|
622 | if( u.getLocal( ) ) { |
---|
623 | tab = 2; |
---|
624 | raise = true; |
---|
625 | } |
---|
626 | } |
---|
627 | } |
---|
628 | |
---|
629 | |
---|
630 | |
---|
631 | return new PanelUpdate( _batchUpdate, _side, tab, c, raise, add, hl ); |
---|
632 | } |
---|
633 | |
---|
634 | |
---|
635 | public void update( Observable o, Object arg ) { |
---|
636 | clearSelection( ); |
---|
637 | |
---|
638 | if( arg instanceof PanelUpdate ) { |
---|
639 | |
---|
640 | PanelUpdate u = (PanelUpdate)arg; |
---|
641 | if( u.getSide( ) != _side ) { |
---|
642 | return; |
---|
643 | } |
---|
644 | |
---|
645 | |
---|
646 | // if( u instanceof ClusterUpdate ) { |
---|
647 | // ClusterUpdate cu = (ClusterUpdate)u; |
---|
648 | // if( !cu.getStart( ) && cu.getLocal( ) ) { |
---|
649 | // unSetBolded( !cu.getUndo( ), cu.getCluster( ) ); |
---|
650 | // } else if( cu.getStart( ) && !cu.getLocal( ) ) { |
---|
651 | // setShadowed( !cu.getUndo( ), cu.getCluster( ) ); |
---|
652 | // } |
---|
653 | // } |
---|
654 | |
---|
655 | u.apply( this ); |
---|
656 | |
---|
657 | _graph.resync( ); |
---|
658 | _graph.repaint( ); |
---|
659 | |
---|
660 | |
---|
661 | // if( u.getUndo( ) ) { |
---|
662 | // // System.out.println( "UNDO" ); |
---|
663 | // u.undo( this ); |
---|
664 | // } else { |
---|
665 | // u.apply( this ); |
---|
666 | // } |
---|
667 | |
---|
668 | // _graph.resync( ); |
---|
669 | // _graph.repaint( ); |
---|
670 | |
---|
671 | } else if( arg instanceof String ) { |
---|
672 | |
---|
673 | String s = (String)arg; |
---|
674 | if( s.equals( "CLEAR" ) ) { |
---|
675 | // System.out.println( "CLEAR" ); |
---|
676 | |
---|
677 | hideGraph( _graph ); |
---|
678 | // _credentialPanel.removeRemoteCreds( ); |
---|
679 | } |
---|
680 | } |
---|
681 | } |
---|
682 | |
---|
683 | |
---|
684 | public Graph getGraph( ) { |
---|
685 | return _graph; |
---|
686 | } |
---|
687 | |
---|
688 | public Subgraph getCurrentCluster( ) { |
---|
689 | return _currentCluster; |
---|
690 | } |
---|
691 | |
---|
692 | public void setCurrentCluster( Subgraph sg ) { |
---|
693 | _currentCluster = sg; |
---|
694 | } |
---|
695 | |
---|
696 | |
---|
697 | |
---|
698 | |
---|
699 | |
---|
700 | private void setShadowed( boolean shadow, int clusterNum ) { |
---|
701 | HashSet cluster = (HashSet)_remoteClusters.get( new Integer( clusterNum ) ); |
---|
702 | |
---|
703 | for( Iterator i = cluster.iterator( ); i.hasNext( ); ) { |
---|
704 | Update u = (Update)i.next( ); |
---|
705 | |
---|
706 | if( u instanceof NodeUpdate ) { |
---|
707 | NodeUpdate nu = (NodeUpdate)u; |
---|
708 | |
---|
709 | NodeState ns = getNodeState( nu.getName( ) ); |
---|
710 | if( ns.getHidden( ) == false ) { |
---|
711 | continue; |
---|
712 | } |
---|
713 | |
---|
714 | } |
---|
715 | |
---|
716 | Element e = u.getElement( this ); |
---|
717 | |
---|
718 | if( shadow ) { |
---|
719 | setShadow( e ); |
---|
720 | } else { |
---|
721 | setInvis( e ); |
---|
722 | } |
---|
723 | |
---|
724 | if( u instanceof EdgeUpdate ) { |
---|
725 | EdgeUpdate eu = (EdgeUpdate)u; |
---|
726 | |
---|
727 | NodeState ns = getNodeState( eu.getChildName( ) ); |
---|
728 | if( ns.getHidden( ) == false ) { |
---|
729 | continue; |
---|
730 | } |
---|
731 | |
---|
732 | e = eu.getChild( this ); |
---|
733 | |
---|
734 | if( shadow ) { |
---|
735 | setShadow( e ); |
---|
736 | } else { |
---|
737 | setInvis( e ); |
---|
738 | } |
---|
739 | |
---|
740 | } |
---|
741 | |
---|
742 | |
---|
743 | } |
---|
744 | |
---|
745 | |
---|
746 | } |
---|
747 | |
---|
748 | |
---|
749 | |
---|
750 | public void setShadow( Element e ) { |
---|
751 | setAttribute( e, "color", _shadowColor ); |
---|
752 | setAttribute( e, "style", "solid" ); |
---|
753 | setAttribute( e, "fontcolor", _shadowColor ); |
---|
754 | } |
---|
755 | |
---|
756 | |
---|
757 | private void unSetBolded( boolean unbold, int cluster ) { |
---|
758 | _boldedNodes = new HashSet( ); |
---|
759 | |
---|
760 | if( !unbold ) { |
---|
761 | _local = true; |
---|
762 | _bolded = (java.util.List)_localClusters.get( new Integer( cluster ) ); |
---|
763 | } |
---|
764 | |
---|
765 | if( unbold ) { |
---|
766 | for( Iterator i = _bolded.iterator( ); i.hasNext( ); ) { |
---|
767 | |
---|
768 | ElementAtt e = (ElementAtt)i.next( ); |
---|
769 | e.apply( ); |
---|
770 | } |
---|
771 | } else { |
---|
772 | |
---|
773 | for( int i=_bolded.size()-1; i>=0;i-- ) { |
---|
774 | ElementAtt e = (ElementAtt)_bolded.get(i); |
---|
775 | e.undo( ); |
---|
776 | } |
---|
777 | } |
---|
778 | |
---|
779 | if( !unbold ) { |
---|
780 | _local = false; |
---|
781 | } else { |
---|
782 | _localClusters.put( new Integer( cluster ), _bolded ); |
---|
783 | _bolded = new ArrayList( ); |
---|
784 | } |
---|
785 | |
---|
786 | } |
---|
787 | |
---|
788 | |
---|
789 | private class ElementAtt { |
---|
790 | private Element _e; |
---|
791 | private String _att; |
---|
792 | private String _value; |
---|
793 | private Object _undoValue; |
---|
794 | |
---|
795 | public ElementAtt( Element e, String att, String value, String undoValue ) { |
---|
796 | _e = e; |
---|
797 | _att = att; |
---|
798 | _value = value; |
---|
799 | _undoValue = undoValue; |
---|
800 | } |
---|
801 | |
---|
802 | public void apply( ) { |
---|
803 | _undoValue = setAttribute( _e, _att, _value ); |
---|
804 | } |
---|
805 | |
---|
806 | public void undo( ) { |
---|
807 | _e.setAttribute( _att, _undoValue ); |
---|
808 | } |
---|
809 | |
---|
810 | |
---|
811 | } |
---|
812 | |
---|
813 | |
---|
814 | |
---|
815 | |
---|
816 | |
---|
817 | private Object setAttribute( Element e, String attr, Object value ) { |
---|
818 | Object previousValue = e.setAttribute( attr, value ); |
---|
819 | if( _batchUpdate != null ) { |
---|
820 | _batchUpdate.add( new ElementAttribute( e, attr, value, previousValue ) ); |
---|
821 | } |
---|
822 | |
---|
823 | return previousValue; |
---|
824 | } |
---|
825 | |
---|
826 | |
---|
827 | |
---|
828 | private void setNodeProps( Node n, String prefix, boolean setBold ) { |
---|
829 | |
---|
830 | for( int i=0; i < NODE_ATTRS.length; i++ ) { |
---|
831 | String strValue = _properties.getProperty( prefix + NODE_ATTRS_PROP[i] ); |
---|
832 | if( strValue == null ) { |
---|
833 | continue; |
---|
834 | } |
---|
835 | |
---|
836 | |
---|
837 | if( NODE_ATTRS_INT[i] ) { |
---|
838 | setAttribute( n, NODE_ATTRS[i], new Integer( strValue ) ); |
---|
839 | } else { |
---|
840 | |
---|
841 | if( NODE_ATTRS[i].equals( FONTSTYLE_ATTR ) && ( setBold || _boldedNodes.contains( n ) ) ) { |
---|
842 | _bolded.add( new ElementAtt( n, FONTSTYLE_ATTR, strValue,"bold" ) ); |
---|
843 | strValue = "bold"; |
---|
844 | } |
---|
845 | |
---|
846 | setAttribute( n, NODE_ATTRS[i], strValue ); |
---|
847 | |
---|
848 | } |
---|
849 | } |
---|
850 | } |
---|
851 | |
---|
852 | |
---|
853 | |
---|
854 | private void setEdgeProps( Edge e, String prefix, boolean local ) { |
---|
855 | for( int i=0; i < EDGE_ATTRS.length; i++ ) { |
---|
856 | String strValue = _properties.getProperty( prefix + EDGE_ATTRS_PROP[i] ); |
---|
857 | String undoValue = _properties.getProperty( prefix + EDGE_ATTRS_PROP[i] + ".bold" ); |
---|
858 | |
---|
859 | String change = strValue; |
---|
860 | |
---|
861 | |
---|
862 | if( strValue == null ) { |
---|
863 | continue; |
---|
864 | } |
---|
865 | |
---|
866 | if( local ) { |
---|
867 | if( undoValue != null ) { |
---|
868 | _bolded.add( new ElementAtt( e, EDGE_ATTRS[i], strValue, undoValue ) ); |
---|
869 | change = undoValue; |
---|
870 | } |
---|
871 | |
---|
872 | } |
---|
873 | |
---|
874 | setAttribute( e, EDGE_ATTRS[i], change ); |
---|
875 | } |
---|
876 | } |
---|
877 | |
---|
878 | |
---|
879 | public void setNodeProperties( Node n, NodeState ns, boolean local, boolean newNode ) { |
---|
880 | if( ns.getHidden( ) ) { |
---|
881 | |
---|
882 | if( _local == false ) { |
---|
883 | setShadow( n ); |
---|
884 | } else { |
---|
885 | setInvis( n ); |
---|
886 | } |
---|
887 | return; |
---|
888 | } |
---|
889 | |
---|
890 | if( ns.getBolded( ) == false && ( local && newNode ) ) { |
---|
891 | ns.setBolded( true ); |
---|
892 | } |
---|
893 | |
---|
894 | if( local&&newNode ) { |
---|
895 | _boldedNodes.add( n ); |
---|
896 | } |
---|
897 | |
---|
898 | setNodeProperties( n, ns.getType( ), ns.getSatisfied( ), ns.getProcessed( ), local&&newNode ); |
---|
899 | } |
---|
900 | |
---|
901 | |
---|
902 | private void setNodeProperties( Node n, String type, String satisfaction, String process, boolean setBold ) { |
---|
903 | setNodeProps( n, DEFAULT_NODE, setBold ); |
---|
904 | setNodeProps( n, SYSTEM_PREFIX + "node." + type + ".", setBold ); |
---|
905 | |
---|
906 | if( _basicProps ) { |
---|
907 | return; |
---|
908 | } |
---|
909 | |
---|
910 | |
---|
911 | setNodeProps( n, SYSTEM_PREFIX + "node.satisfied." + satisfaction + ".", setBold ); |
---|
912 | |
---|
913 | if( !_ignoreProcessing ) { |
---|
914 | setNodeProps( n, SYSTEM_PREFIX + "node.processed." + process + ".", setBold ); |
---|
915 | } |
---|
916 | } |
---|
917 | |
---|
918 | public void setEdgeProperties( Edge e, String type, boolean local ) { |
---|
919 | setEdgeProps( e, DEFAULT_EDGE, local ); |
---|
920 | setEdgeProps( e, SYSTEM_PREFIX + "edge." + type + ".", local ); |
---|
921 | } |
---|
922 | |
---|
923 | |
---|
924 | private void formatGraph( Graph g ) { |
---|
925 | try { |
---|
926 | Process formater = Runtime.getRuntime( ).exec( "dot" ); |
---|
927 | GrappaSupport.filterGraph( g, formater ); |
---|
928 | formater.destroy( ); |
---|
929 | |
---|
930 | g.repaint( ); |
---|
931 | } catch( Exception e ) { |
---|
932 | e.printStackTrace( ); |
---|
933 | } |
---|
934 | } |
---|
935 | |
---|
936 | |
---|
937 | public void hideGraph( ) { |
---|
938 | |
---|
939 | hideSubgraph( _graph ); |
---|
940 | _graph.resync( ); |
---|
941 | _graph.repaint( ); |
---|
942 | _credentialPanel.removeRemoteCreds( ); |
---|
943 | } |
---|
944 | |
---|
945 | |
---|
946 | public void updateGraph( ) { |
---|
947 | _graph.resync( ); |
---|
948 | _graph.repaint( ); |
---|
949 | } |
---|
950 | |
---|
951 | |
---|
952 | public void hideGraph( Graph g) { |
---|
953 | _credentialPanel.removeRemoteCreds( ); |
---|
954 | |
---|
955 | hideSubgraph( g ); |
---|
956 | |
---|
957 | for( Iterator i = _nodeStates.values( ).iterator( ); i.hasNext( ); ) { |
---|
958 | NodeState ns = (NodeState) i.next( ); |
---|
959 | ns.clearState( ); |
---|
960 | } |
---|
961 | |
---|
962 | g.resync( ); |
---|
963 | g.repaint( ); |
---|
964 | |
---|
965 | } |
---|
966 | |
---|
967 | private void hideSubgraph( Subgraph sg ) { |
---|
968 | // System.out.println( "HIDING GRAPH" ); |
---|
969 | |
---|
970 | Enumeration nodes = sg.nodeElements( ); |
---|
971 | Enumeration edges = sg.edgeElements( ); |
---|
972 | |
---|
973 | while( nodes.hasMoreElements( ) ) { |
---|
974 | Node n = (Node) nodes.nextElement( ); |
---|
975 | setInvis( n ); |
---|
976 | } |
---|
977 | |
---|
978 | while( edges.hasMoreElements( ) ) { |
---|
979 | Edge e = (Edge) edges.nextElement( ); |
---|
980 | setInvis( e ); |
---|
981 | } |
---|
982 | } |
---|
983 | |
---|
984 | |
---|
985 | public void setInvis( Element e ) { |
---|
986 | e.setAttribute( FONTSTYLE_ATTR, "normal" ); |
---|
987 | e.setAttribute( STYLE_ATTR, "invis" ); |
---|
988 | } |
---|
989 | |
---|
990 | public void setLocal( boolean local ) { |
---|
991 | _local = local; |
---|
992 | } |
---|
993 | |
---|
994 | public boolean getLocal( ) { |
---|
995 | return _local; |
---|
996 | } |
---|
997 | |
---|
998 | |
---|
999 | |
---|
1000 | } |
---|