BlockCalc.java 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package bk;
  2. import javax.swing.JTree;
  3. import animation.AlgorithmStage;
  4. import animation.AnimatedAlgorithm;
  5. import animation.CodeLine;
  6. import animation.ControlFlow;
  7. import animation.Memory;
  8. import animation.PseudoCodeNode;
  9. import graph.LayeredGraphNode;
  10. import lib.TextLayoutHelper;
  11. /**
  12. * The stage of the BK node placement algorithm where the blocks are computed.
  13. * @author kolja
  14. *
  15. */
  16. public class BlockCalc implements AlgorithmStage {
  17. private LayeredGraphNode graph;
  18. private AnimatedAlgorithm alg;
  19. public BlockCalc( LayeredGraphNode graph, AnimatedAlgorithm alg )
  20. {
  21. this.graph = graph;
  22. this.alg = alg;
  23. }
  24. @Override
  25. public PseudoCodeNode createPseudocodeTree( JTree tree ) {
  26. String[] vars = { "graph", "L", "v", "r", "neighbors" };
  27. PseudoCodeNode root = new PseudoCodeNode( TextLayoutHelper.setupPseudoCode( "calculateBlockGraph( graph )", vars ), tree, new CodeLine() {
  28. private LayeredGraphNode param;
  29. @Override
  30. public ControlFlow runForward(Memory m) {
  31. param = m.<LayeredGraphNode>read( "param1", true );
  32. m.declare( "graph", param, false );
  33. m.declare( "Layers", param.getContainedLayers(), false );
  34. return new ControlFlow( ControlFlow.STEP_INTO );
  35. }
  36. }, alg);
  37. return root;
  38. }
  39. @Override
  40. public String getDebugString()
  41. {
  42. return "";
  43. }
  44. }