[8780cbec] | 1 | package com.algomagic.atn; |
---|
| 2 | |
---|
| 3 | import att.grappa.*; |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | public class NodeUpdate |
---|
| 7 | extends AbstractUpdate |
---|
| 8 | implements Update, VisualizationConstants |
---|
| 9 | { |
---|
| 10 | private String _name; |
---|
| 11 | private String _type; |
---|
| 12 | private String _cluster; |
---|
| 13 | |
---|
| 14 | private String _satisfied; |
---|
| 15 | private String _processed; |
---|
| 16 | |
---|
| 17 | private boolean _local; |
---|
| 18 | |
---|
| 19 | private NodeState _oldState; |
---|
| 20 | private boolean _newNode; |
---|
| 21 | |
---|
| 22 | public NodeUpdate( String name, |
---|
| 23 | String type, |
---|
| 24 | String cluster, |
---|
| 25 | String satisfied, |
---|
| 26 | String processed, |
---|
| 27 | int side, |
---|
| 28 | boolean local ) { |
---|
| 29 | _name = name; |
---|
| 30 | _type = type; |
---|
| 31 | _cluster = cluster; |
---|
| 32 | _satisfied = satisfied; |
---|
| 33 | _processed = processed; |
---|
| 34 | _side = side; |
---|
| 35 | _local = local; |
---|
| 36 | _newNode = false; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | public String toString( ) { |
---|
| 40 | return "NodeUpdate: " + _name + " " + _type + " " + _cluster + " " + _satisfied + " " + _processed; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | public boolean getLocal( ) { |
---|
| 45 | return _local; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | public int initialize( VisualizationPanel visPanel ) { |
---|
| 49 | Graph g = visPanel.getGraph( ); |
---|
| 50 | |
---|
| 51 | Node n = g.findNodeByName( _name ); |
---|
| 52 | boolean newNode; |
---|
| 53 | int changed; |
---|
| 54 | |
---|
| 55 | if( n == null ) { |
---|
| 56 | new Node( g, _name ); |
---|
| 57 | NodeState ns = new NodeState( _name, _type ); |
---|
| 58 | changed = ns.updateState( this ); |
---|
| 59 | |
---|
| 60 | newNode = visPanel.addNodeState( ns ); |
---|
| 61 | _newNode = true; |
---|
| 62 | return 3; |
---|
| 63 | |
---|
| 64 | } else { |
---|
| 65 | |
---|
| 66 | NodeState ns = visPanel.getNodeState( _name ); |
---|
| 67 | changed = ns.updateState( this ); |
---|
| 68 | |
---|
| 69 | return changed; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | public Element getElement( VisualizationPanel visPanel ) { |
---|
| 75 | Graph g = visPanel.getGraph( ); |
---|
| 76 | return g.findNodeByName( _name ); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | public boolean apply( VisualizationPanel visPanel ) { |
---|
| 80 | Graph g = visPanel.getGraph( ); |
---|
| 81 | Node n = g.findNodeByName( _name ); |
---|
| 82 | if( n != null ) { |
---|
| 83 | NodeState ns = visPanel.getNodeState( _name ); |
---|
| 84 | _oldState = new NodeState( ns ); |
---|
| 85 | |
---|
| 86 | ns.updateState( this ); |
---|
| 87 | visPanel.setNodeProperties( n, ns, _local, _newNode ); |
---|
| 88 | return true; |
---|
| 89 | } |
---|
| 90 | return false; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | public void undo( VisualizationPanel visPanel ) { |
---|
| 94 | if( _oldState == null ) { |
---|
| 95 | throw new RuntimeException( ); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | Graph g = visPanel.getGraph( ); |
---|
| 99 | Node n = g.findNodeByName( _name ); |
---|
| 100 | |
---|
| 101 | if( n == null ) { |
---|
| 102 | throw new RuntimeException( ); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | NodeState ns = visPanel.getNodeState( _name ); |
---|
| 106 | ns.setHidden( _oldState.getHidden( ) ); |
---|
| 107 | ns.setSatisfied( _oldState.getSatisfied( ) ); |
---|
| 108 | |
---|
| 109 | visPanel.setNodeProperties( n, _oldState, _local, _newNode ); |
---|
| 110 | |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | public String getName( ) { |
---|
| 114 | return _name; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | public String getSatisfied( ) { |
---|
| 118 | return _satisfied; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | public String getProcessed( ) { |
---|
| 122 | return _processed; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | public void setNew( ) { |
---|
| 126 | _newNode = true; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | } |
---|