1. First, we add the desired edge to jCellsBeingAdded to indicate that the edge is being inserted internally. 2. Then we invoke the JGraph 'insert' operation. 3. The JGraph listener will detect the newly inserted edge. 4. It checks if the edge is contained in jCellsBeingAdded. 5. If yes, it just removes it and does nothing else. if no, it knows that the edge was inserted externally and performs the insertion. 6. Lastly, we remove the edge from the jCellsBeingAdded.
Step 6 is not always required but we do it anyway as a safeguard against the rare case where the edge to be added is already contained in the graph and thus NO event will be fired. If 6 is not done, a junk edge will remain in the jCellsBeingAdded set.
The other sets are used in a similar manner to the above. Apparently, All that complication could be eliminated if JGraph and JGraphT had both allowed operations that do not inform listeners...
Copyright © 2017. All rights reserved.