ExtremalLayoutCalc.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package Algorithms.Animated.BK;
  2. import Algorithms.Animated.AlgorithmStage;
  3. import Model.LayeredGraphNode;
  4. /**
  5. * The stage where the for extremal layouts are computed.
  6. * @author kolja
  7. *
  8. */
  9. public class ExtremalLayoutCalc implements AlgorithmStage {
  10. public enum LayoutType{
  11. TOP_BOTTOM_LEFT,
  12. TOP_BOTTOM_RIGHT,
  13. BOTTOM_TOP_LEFT,
  14. BOTTOM_TOP_RIGHT
  15. }
  16. private enum LayoutState
  17. {
  18. BLOCK_CALCULATION,
  19. COMPACTION
  20. }
  21. private LayoutType typ;
  22. private BlockCalc bc;
  23. private Compaction cp;
  24. private LayoutState status;
  25. public ExtremalLayoutCalc( LayoutType typ, LayeredGraphNode graph )
  26. {
  27. status = LayoutState.BLOCK_CALCULATION;
  28. this.typ = typ;
  29. bc = new BlockCalc( graph );
  30. cp = new Compaction( graph );
  31. }
  32. @Override
  33. public StageStatus forwardStep() {
  34. if( status == LayoutState.BLOCK_CALCULATION )
  35. {
  36. if( bc.forwardStep() == StageStatus.FINISHED )
  37. {
  38. status = LayoutState.COMPACTION;
  39. }
  40. return StageStatus.UNFINISHED;
  41. }
  42. if( status == LayoutState.COMPACTION )
  43. return cp.forwardStep();
  44. return StageStatus.UNFINISHED;
  45. }
  46. @Override
  47. public StageStatus backwardStep() {
  48. if( status == LayoutState.BLOCK_CALCULATION )
  49. return bc.backwardStep();
  50. if( status == LayoutState.COMPACTION )
  51. {
  52. if( cp.backwardStep() == StageStatus.FINISHED )
  53. status = LayoutState.BLOCK_CALCULATION;
  54. }
  55. return StageStatus.UNFINISHED;
  56. }
  57. }