Переглянути джерело

replace tab characters with whitespace

Eren Yilmaz 6 роки тому
батько
коміт
180d4816fc

+ 6 - 6
src/animation/Action.java

@@ -9,10 +9,10 @@ package animation;
  *
  */
 public enum Action {
-	FORWARD,
-	FORWARD_OVER,
-	FORWARD_OUT,
-	BACKWARD,
-	BACKWARD_OVER,
-	BACKWARD_OUT
+    FORWARD,
+    FORWARD_OVER,
+    FORWARD_OUT,
+    BACKWARD,
+    BACKWARD_OVER,
+    BACKWARD_OUT
 }

+ 18 - 18
src/animation/AlgorithmStage.java

@@ -17,22 +17,22 @@ public interface AlgorithmStage {
      * @author kolja
      *
      */
-	public static enum StageStatus
-	{
-		UNFINISHED,
-		BREAKPOINT,
-		FINISHED
-	}
-	
-	/**
-	 * perform one atomic step of the algorithm
-	 * @return whether the whole stage is finished.
+    public static enum StageStatus
+    {
+        UNFINISHED,
+        BREAKPOINT,
+        FINISHED
+    }
+
+    /**
+     * perform one atomic step of the algorithm
+     * @return whether the whole stage is finished.
      * For example if all steps are reverted, then {@code FINISHED} is returned.
-	 */
-	public StageStatus forwardStep();
-	
-	public StageStatus forwardStepOver();
-	
+     */
+    public StageStatus forwardStep();
+
+    public StageStatus forwardStepOver();
+
     public StageStatus forwardStepOut();
     
     /**
@@ -40,11 +40,11 @@ public interface AlgorithmStage {
      * @return whether the whole stage is finished in backwards direction. 
      * For example if all steps are reverted, then {@code FINISHED} is returned.
      */
-	public StageStatus backwardStep();
-	
+    public StageStatus backwardStep();
+
     public StageStatus backwardStepOver();
     
     public StageStatus backwardStepOut();
-	
+
     public PseudoCodeNode createPseudocodeTree( JTree tree );
 }

+ 38 - 38
src/animation/AnimatedAlgorithm.java

@@ -11,19 +11,19 @@ import graph.LayeredGraphNode;
 
 public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage {
 
-	protected AnimationController ac;
-	protected LayeredGraphNode graph;
-	private JFrame view;
-	
-	public AnimatedAlgorithm( AnimationController controller, LayeredGraphNode graph, JFrame view )
-	{
-		this.ac = controller;
-		this.graph = graph;
-		this.view = view;
-	}
-	
-	private void update()
-	{
+    protected AnimationController ac;
+    protected LayeredGraphNode graph;
+    private JFrame view;
+
+    public AnimatedAlgorithm( AnimationController controller, LayeredGraphNode graph, JFrame view )
+    {
+        this.ac = controller;
+        this.graph = graph;
+        this.view = view;
+    }
+
+    private void update()
+    {
         SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                 view.repaint();
@@ -33,20 +33,20 @@ public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage
                 }
             }
         });
-	}
-	
-	@Override
-	public void run()
-	{
-		while( true ) // if this loop would end we could not undo steps any more
-		{
-			try {
-				switch( ac.getNextAction() )
-				{
-				case FORWARD:
-					forwardStep();
-					update();
-					break;
+    }
+
+    @Override
+    public void run()
+    {
+        while( true ) // if this loop would end we could not undo steps any more
+        {
+            try {
+                switch( ac.getNextAction() )
+                {
+                case FORWARD:
+                    forwardStep();
+                    update();
+                    break;
                 case FORWARD_OUT:
                     forwardStepOut();
                     graph.unselectGraph();
@@ -57,10 +57,10 @@ public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage
                     graph.unselectGraph();
                     update();
                     break;
-				case BACKWARD:
-					backwardStep();
+                case BACKWARD:
+                    backwardStep();
                     update();
-					break;
+                    break;
                 case BACKWARD_OUT:
                     backwardStepOut();
                     graph.unselectGraph();
@@ -73,14 +73,14 @@ public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage
                     break;
                 default:
                     break;
-				}
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-				return;
-			}
-			
-		}
-	}
+                }
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+                return;
+            }
+
+        }
+    }
     /**
      * creates a node in the pseudo code tree
      */

+ 60 - 60
src/animation/AnimationController.java

@@ -1,64 +1,64 @@
 package animation;
 
 public class AnimationController {
-	
-	private Action next;
-	private boolean continuous;
-	private long lastTime;
-	private long timeBetween;
-	
-	public AnimationController()
-	{
-		next = null;
-		continuous = false;
-		lastTime = 0;
-		timeBetween = 0;
-	}
-	
-	public Action getNextAction() throws InterruptedException
-	{
-		long old = lastTime;
-		Action ret = null;
-		synchronized( this ) {
-			while( next == null )
-				wait();
-			lastTime = System.currentTimeMillis();
-			ret = next;
-		}
-		if( !continuous )
-			next = null;
-		else
-		{
-			if( lastTime - old < timeBetween )
-			{
-				Thread.sleep( timeBetween - ( lastTime - old ) );
-				System.out.println( "sleep: " + ( timeBetween - ( lastTime - old ) ) );
-				lastTime = System.currentTimeMillis();
-			}
-		}
-		return ret;
-	}
-	
-	public void setContinuous( boolean c )
-	{
-		this.continuous = c;
-	}
-	
-	public void setTimeBetween( long between )
-	{
-		timeBetween = between;
-	}
-	
-	public void setNextAction( Action a )
-	{
-		next = a;
-		synchronized( this ) {
-			notify();
-		}
-	}
-	
-	public boolean isContinuous()
-	{
-		return continuous;
-	}
+
+    private Action next;
+    private boolean continuous;
+    private long lastTime;
+    private long timeBetween;
+
+    public AnimationController()
+    {
+        next = null;
+        continuous = false;
+        lastTime = 0;
+        timeBetween = 0;
+    }
+
+    public Action getNextAction() throws InterruptedException
+    {
+        long old = lastTime;
+        Action ret = null;
+        synchronized( this ) {
+            while( next == null )
+                wait();
+            lastTime = System.currentTimeMillis();
+            ret = next;
+        }
+        if( !continuous )
+            next = null;
+        else
+        {
+            if( lastTime - old < timeBetween )
+            {
+                Thread.sleep( timeBetween - ( lastTime - old ) );
+                System.out.println( "sleep: " + ( timeBetween - ( lastTime - old ) ) );
+                lastTime = System.currentTimeMillis();
+            }
+        }
+        return ret;
+    }
+
+    public void setContinuous( boolean c )
+    {
+        this.continuous = c;
+    }
+
+    public void setTimeBetween( long between )
+    {
+        timeBetween = between;
+    }
+
+    public void setNextAction( Action a )
+    {
+        next = a;
+        synchronized( this ) {
+            notify();
+        }
+    }
+
+    public boolean isContinuous()
+    {
+        return continuous;
+    }
 }

+ 1 - 1
src/animation/BackwardAction.java

@@ -10,5 +10,5 @@ public interface BackwardAction {
     /**
      * Undo another action.
      */
-	public void reverse();
+    public void reverse();
 }

+ 48 - 48
src/bk/BKNodePlacement.java

@@ -17,24 +17,24 @@ import graph.LayeredGraphNode;
  */
 public class BKNodePlacement extends AnimatedAlgorithm {
 
-	/*
-	 * Private data structures to store the process of the algorithm
-	 */
-	
-	private enum State
-	{
-		CONFLICTS,
-		LAYOUT1,
-		LAYOUT2,
-		LAYOUT3,
-		LAYOUT4,
-		COMBINE
-	}
-	
-	private ConflictDetection conftion;
-	private State state;
-	private ExtremalLayoutCalc layouts[];
-	private Combine combine;
+    /*
+     * Private data structures to store the process of the algorithm
+     */
+
+    private enum State
+    {
+        CONFLICTS,
+        LAYOUT1,
+        LAYOUT2,
+        LAYOUT3,
+        LAYOUT4,
+        COMBINE
+    }
+
+    private ConflictDetection conftion;
+    private State state;
+    private ExtremalLayoutCalc layouts[];
+    private Combine combine;
     private PseudoCodeNode conflictsNode; 
     private PseudoCodeNode layout1Node;
     private PseudoCodeNode layout2Node;
@@ -42,35 +42,35 @@ public class BKNodePlacement extends AnimatedAlgorithm {
     private PseudoCodeNode layout4Node;
     private PseudoCodeNode combineNode;
     private boolean inside;
-	
-	public BKNodePlacement(AnimationController controller, LayeredGraphNode graph, JFrame view) {
-		super(controller, graph, view);
-		state = State.CONFLICTS;
-		conftion = new ConflictDetection( graph );
-		layouts = new ExtremalLayoutCalc[ 4 ];
-		layouts[ 0 ] = new ExtremalLayoutCalc( ExtremalLayoutCalc.LayoutType.TOP_BOTTOM_LEFT, graph );
-		layouts[ 1 ] = new ExtremalLayoutCalc( ExtremalLayoutCalc.LayoutType.TOP_BOTTOM_RIGHT, graph );
-		layouts[ 2 ] = new ExtremalLayoutCalc( ExtremalLayoutCalc.LayoutType.BOTTOM_TOP_LEFT, graph );
-		layouts[ 3 ] = new ExtremalLayoutCalc( ExtremalLayoutCalc.LayoutType.BOTTOM_TOP_RIGHT, graph );
-		combine = new Combine( graph );
-		inside = false;
-	}
 
-	@Override
-	public StageStatus forwardStep() {
-		return forward( "forwardStep" );
-	}
+    public BKNodePlacement(AnimationController controller, LayeredGraphNode graph, JFrame view) {
+        super(controller, graph, view);
+        state = State.CONFLICTS;
+        conftion = new ConflictDetection( graph );
+        layouts = new ExtremalLayoutCalc[ 4 ];
+        layouts[ 0 ] = new ExtremalLayoutCalc( ExtremalLayoutCalc.LayoutType.TOP_BOTTOM_LEFT, graph );
+        layouts[ 1 ] = new ExtremalLayoutCalc( ExtremalLayoutCalc.LayoutType.TOP_BOTTOM_RIGHT, graph );
+        layouts[ 2 ] = new ExtremalLayoutCalc( ExtremalLayoutCalc.LayoutType.BOTTOM_TOP_LEFT, graph );
+        layouts[ 3 ] = new ExtremalLayoutCalc( ExtremalLayoutCalc.LayoutType.BOTTOM_TOP_RIGHT, graph );
+        combine = new Combine( graph );
+        inside = false;
+    }
+
+    @Override
+    public StageStatus forwardStep() {
+        return forward( "forwardStep" );
+    }
 
-	@Override
-	public StageStatus backwardStep() {
-	    return backward( "backwardStep" );
-	}
-	
-	@Override
-	public PseudoCodeNode createPseudocodeTree( JTree tree )
-	{
-	    PseudoCodeNode root = new PseudoCodeNode( "BK Node Placement Algorithm", tree );
-	    root.setSelected( true );
+    @Override
+    public StageStatus backwardStep() {
+        return backward( "backwardStep" );
+    }
+
+    @Override
+    public PseudoCodeNode createPseudocodeTree( JTree tree )
+    {
+        PseudoCodeNode root = new PseudoCodeNode( "BK Node Placement Algorithm", tree );
+        root.setSelected( true );
         conflictsNode = conftion.createPseudocodeTree( tree );
         layout1Node = layouts[ 0 ].createPseudocodeTree( tree );
         layout2Node = layouts[ 1 ].createPseudocodeTree( tree );
@@ -84,7 +84,7 @@ public class BKNodePlacement extends AnimatedAlgorithm {
         root.add( layout4Node );
         root.add( combineNode );
         return root;
-	}
+    }
 
     @Override
     public StageStatus forwardStepOver() {
@@ -147,8 +147,8 @@ public class BKNodePlacement extends AnimatedAlgorithm {
             switch( state )
             {
             case CONFLICTS:
-            	if( !conflictsNode.isSelected() )
-            		breakpoint |= !conflictsNode.setSelected( true );
+                if( !conflictsNode.isSelected() )
+                    breakpoint |= !conflictsNode.setSelected( true );
                 switch( (StageStatus)(ConflictDetection.class.getMethod( fName ).invoke( conftion ) ) )
                 {
                 case FINISHED:

+ 326 - 326
src/bk/BlockCalc.java

@@ -20,70 +20,70 @@ import graph.LayeredGraphNode;
  */
 public class BlockCalc implements AlgorithmStage {
 
-	private int layerIndex;
-	private int nodeIndex;
-	private int r;
-	private LayeredGraphNode graph;
-	private ArrayList< ArrayList< PseudoCodeNode > > subgraphNodes;
-	private ArrayList< ArrayList< ExtremalLayoutCalc > > subgraphAlgs;
-	private ArrayList< BackwardAction > backwards; // TODO: evtl richtigen "Stack" benutzen
-	private LayoutType layout;
-	private PseudoCodeNode loopNode;
-	private boolean inside;
-	int step;
-	
-	public BlockCalc( LayeredGraphNode graph, LayoutType layout )
-	{
-	    this.layout = layout;
-		step = 0;
-		this.graph = graph;
-		layerIndex = 0;
-		nodeIndex = 0;
-		r = 0;
-		subgraphNodes = new ArrayList<>();
-		subgraphAlgs = new ArrayList<>();
-		for( ArrayList<LayeredGraphNode> l : graph.getContainedLayers() )
-		{
-			ArrayList< PseudoCodeNode > nodes = new ArrayList<>();
-			ArrayList< ExtremalLayoutCalc > algs = new ArrayList<>();
-			for( int i = 0; i < l.size(); i++ )
-			{
-				nodes.add( null );
-				algs.add( null );
-			}
-			subgraphAlgs.add( algs );
-			subgraphNodes.add( nodes );
-		}
-		inside = false;
-		backwards = new ArrayList<>();
-	}
-	
-	private int calcLayerIndex()
-	{
+    private int layerIndex;
+    private int nodeIndex;
+    private int r;
+    private LayeredGraphNode graph;
+    private ArrayList< ArrayList< PseudoCodeNode > > subgraphNodes;
+    private ArrayList< ArrayList< ExtremalLayoutCalc > > subgraphAlgs;
+    private ArrayList< BackwardAction > backwards; // TODO: evtl richtigen "Stack" benutzen
+    private LayoutType layout;
+    private PseudoCodeNode loopNode;
+    private boolean inside;
+    int step;
+
+    public BlockCalc( LayeredGraphNode graph, LayoutType layout )
+    {
+        this.layout = layout;
+        step = 0;
+        this.graph = graph;
+        layerIndex = 0;
+        nodeIndex = 0;
+        r = 0;
+        subgraphNodes = new ArrayList<>();
+        subgraphAlgs = new ArrayList<>();
+        for( ArrayList<LayeredGraphNode> l : graph.getContainedLayers() )
+        {
+            ArrayList< PseudoCodeNode > nodes = new ArrayList<>();
+            ArrayList< ExtremalLayoutCalc > algs = new ArrayList<>();
+            for( int i = 0; i < l.size(); i++ )
+            {
+                nodes.add( null );
+                algs.add( null );
+            }
+            subgraphAlgs.add( algs );
+            subgraphNodes.add( nodes );
+        }
+        inside = false;
+        backwards = new ArrayList<>();
+    }
+
+    private int calcLayerIndex()
+    {
         if( layout == LayoutType.TOP_BOTTOM_LEFT || layout == LayoutType.TOP_BOTTOM_RIGHT )
-	        return layerIndex;
+            return layerIndex;
         if( layout == LayoutType.BOTTOM_TOP_LEFT || layout == LayoutType.BOTTOM_TOP_RIGHT )
-	        return graph.getContainedLayers().size() - layerIndex - 1;
-	    return -1;
-	}
-	
-	private int calcBeforeLayerIndex()
-	{
+            return graph.getContainedLayers().size() - layerIndex - 1;
+        return -1;
+    }
+
+    private int calcBeforeLayerIndex()
+    {
         if( layout == LayoutType.TOP_BOTTOM_LEFT || layout == LayoutType.TOP_BOTTOM_RIGHT )
             return layerIndex - 1;
         if( layout == LayoutType.BOTTOM_TOP_LEFT || layout == LayoutType.BOTTOM_TOP_RIGHT )
             return graph.getContainedLayers().size() - layerIndex;
         return -1;
-	}
-	
-	private int calcNodeIndex( int index )
-	{
+    }
+
+    private int calcNodeIndex( int index )
+    {
         if( layout == LayoutType.TOP_BOTTOM_LEFT || layout == LayoutType.BOTTOM_TOP_LEFT )
             return index;
         if( layout == LayoutType.TOP_BOTTOM_RIGHT || layout == LayoutType.BOTTOM_TOP_RIGHT )
             return graph.getContainedLayers().get( calcLayerIndex() ).size() - index - 1;
         return index;
-	}
+    }
     
     private int calcBeforeLayerNodeIndex( int index )
     {
@@ -93,51 +93,51 @@ public class BlockCalc implements AlgorithmStage {
             return graph.getContainedLayers().get( calcBeforeLayerIndex() ).size() - index - 1;
         return index;
     }
-	
-	@Override
-	public StageStatus forwardStep() {
-		LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) );
-		current.setSelected( layout );
-		if( current.getContainedNodes().size() > 0 )
-		{
-			inside = true;
-			boolean breakpoint = false;
-			if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
-				breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
-			switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).forwardStep() )
-			{
+
+    @Override
+    public StageStatus forwardStep() {
+        LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) );
+        current.setSelected( layout );
+        if( current.getContainedNodes().size() > 0 )
+        {
+            inside = true;
+            boolean breakpoint = false;
+            if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
+                breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
+            switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).forwardStep() )
+            {
             case BREAKPOINT:
                 return StageStatus.BREAKPOINT;
-			case UNFINISHED:
-				if( breakpoint )
-					return StageStatus.BREAKPOINT;
-				return StageStatus.UNFINISHED;
-			case FINISHED:
-				inside = false;
-				subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
-				break;
-			}
-		}
-		ArrayList< LayeredGraphEdge > incommingEdges = null;
+            case UNFINISHED:
+                if( breakpoint )
+                    return StageStatus.BREAKPOINT;
+                return StageStatus.UNFINISHED;
+            case FINISHED:
+                inside = false;
+                subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
+                break;
+            }
+        }
+        ArrayList< LayeredGraphEdge > incommingEdges = null;
         if( layout == LayoutType.TOP_BOTTOM_LEFT || layout == LayoutType.TOP_BOTTOM_RIGHT )
             incommingEdges = current.getSortedIncomingEdges();
         if( layout == LayoutType.BOTTOM_TOP_LEFT || layout == LayoutType.BOTTOM_TOP_RIGHT )
             incommingEdges = current.getSortedOutgoingEdges();
         if( layout == LayoutType.TOP_BOTTOM_RIGHT || layout == LayoutType.BOTTOM_TOP_RIGHT )
         Collections.reverse( incommingEdges );
-		if( incommingEdges.size() == 0 )
-		{
-			backwards.add( 0, () -> {
-				System.out.println( "Performing Empty Backwards Step..." );
-			});
-			return calcNextState();
-		}
-		int[] ms = {(incommingEdges.size() + 1) / 2, (int)( (incommingEdges.size() + 1) / 2.0 + 0.5 )};
-		boolean backwardsAdded = false;
-		for( int m : ms )
-		{
-		    if( current.getAlign( layout ) == current )
-		    {
+        if( incommingEdges.size() == 0 )
+        {
+            backwards.add( 0, () -> {
+                System.out.println( "Performing Empty Backwards Step..." );
+            });
+            return calcNextState();
+        }
+        int[] ms = {(incommingEdges.size() + 1) / 2, (int)( (incommingEdges.size() + 1) / 2.0 + 0.5 )};
+        boolean backwardsAdded = false;
+        for( int m : ms )
+        {
+            if( current.getAlign( layout ) == current )
+            {
                 LayeredGraphNode u = null;
                 if( layout == LayoutType.TOP_BOTTOM_LEFT || layout == LayoutType.TOP_BOTTOM_RIGHT )
                     u = incommingEdges.get( m - 1 ).getSources().get( 0 );
@@ -145,277 +145,277 @@ public class BlockCalc implements AlgorithmStage {
                     u = incommingEdges.get( m - 1 ).getTargets().get( 0 );
                 ArrayList<LayeredGraphEdge> conflicts = incommingEdges.get( m - 1 ).calcEdgeCrossings();
                 
-		        if( !incommingEdges.get( m - 1 ).isConflicted( layout ) && r < calcBeforeLayerNodeIndex( graph.getContainedLayers().get( calcBeforeLayerIndex() ).indexOf( u ) ) + 1 )
-		        {
-		        	System.out.println( "" );
-		        	ArrayList< Boolean > oldConflicts = new ArrayList<>();
-		        	for( LayeredGraphEdge e : conflicts )
-		        	{
-		        		oldConflicts.add( e.isConflicted( layout ) );
-		        		e.setConflicted( true, layout );
-		        	}
-		            LayeredGraphNode oldAlignU = u.getAlign( layout );
-		            Color oldColorCurrent = current.getColor( layout );
-		            LayeredGraphNode oldRootCurrent = current.getRoot( layout );
-		            LayeredGraphNode oldAlignCurrent = current.getAlign( layout );
-		            int oldR = r;
-		            u.setAlign( current, layout );
-		            current.setColor( u.getRoot( layout ).getColor( layout ), layout );
-		            current.setRoot( u.getRoot( layout ), layout );
-		            current.setAlign( current.getRoot( layout ), layout );
-		            r = calcBeforeLayerNodeIndex( graph.getContainedLayers().get( calcBeforeLayerIndex() ).indexOf( u ) ) + 1;
-		            int oldStep = step++;
-		            final LayeredGraphNode uf = u;
-		            backwards.add( 0, () -> {
-		                System.out.println( "Stepping Backwards... (Step " + oldStep + ")" );
-			        	for( int i = 0; i < conflicts.size(); i++ )
-			        		conflicts.get( i ).setConflicted( oldConflicts.get( i ), layout );
-			        	uf.setAlign( oldAlignU, layout );
-		                current.setColor( oldColorCurrent, layout );
-		                current.setRoot( oldRootCurrent, layout );
-		                current.setAlign( oldAlignCurrent, layout );
-		                r = oldR;
-		            });
-		            backwardsAdded = true;
-		        }
-		    }
-		}
-		if( !backwardsAdded )
-		{
-    		backwards.add( 0, () -> {
+                if( !incommingEdges.get( m - 1 ).isConflicted( layout ) && r < calcBeforeLayerNodeIndex( graph.getContainedLayers().get( calcBeforeLayerIndex() ).indexOf( u ) ) + 1 )
+                {
+                    System.out.println( "" );
+                    ArrayList< Boolean > oldConflicts = new ArrayList<>();
+                    for( LayeredGraphEdge e : conflicts )
+                    {
+                        oldConflicts.add( e.isConflicted( layout ) );
+                        e.setConflicted( true, layout );
+                    }
+                    LayeredGraphNode oldAlignU = u.getAlign( layout );
+                    Color oldColorCurrent = current.getColor( layout );
+                    LayeredGraphNode oldRootCurrent = current.getRoot( layout );
+                    LayeredGraphNode oldAlignCurrent = current.getAlign( layout );
+                    int oldR = r;
+                    u.setAlign( current, layout );
+                    current.setColor( u.getRoot( layout ).getColor( layout ), layout );
+                    current.setRoot( u.getRoot( layout ), layout );
+                    current.setAlign( current.getRoot( layout ), layout );
+                    r = calcBeforeLayerNodeIndex( graph.getContainedLayers().get( calcBeforeLayerIndex() ).indexOf( u ) ) + 1;
+                    int oldStep = step++;
+                    final LayeredGraphNode uf = u;
+                    backwards.add( 0, () -> {
+                        System.out.println( "Stepping Backwards... (Step " + oldStep + ")" );
+                        for( int i = 0; i < conflicts.size(); i++ )
+                            conflicts.get( i ).setConflicted( oldConflicts.get( i ), layout );
+                        uf.setAlign( oldAlignU, layout );
+                        current.setColor( oldColorCurrent, layout );
+                        current.setRoot( oldRootCurrent, layout );
+                        current.setAlign( oldAlignCurrent, layout );
+                        r = oldR;
+                    });
+                    backwardsAdded = true;
+                }
+            }
+        }
+        if( !backwardsAdded )
+        {
+            backwards.add( 0, () -> {
                 System.out.println( "Performing Empty Backwards Step..." );
-    		});
-		}
-		//current.update();
-		return calcNextState();
-	}
-	
-	private StageStatus calcNextState()
-	{
+            });
+        }
+        //current.update();
+        return calcNextState();
+    }
+
+    private StageStatus calcNextState()
+    {
         boolean breakpoint = !loopNode.setSelected( true );
-		if( layerIndex >= graph.getContainedLayers().size() - 1 )
-		{
-			if( nodeIndex >= graph.getContainedLayers().get( calcLayerIndex() ).size() -1 )
-			{
+        if( layerIndex >= graph.getContainedLayers().size() - 1 )
+        {
+            if( nodeIndex >= graph.getContainedLayers().get( calcLayerIndex() ).size() -1 )
+            {
                 loopNode.setSelected( false );
-				return StageStatus.FINISHED;
-			}
-		}
-		nodeIndex++;
-		if( nodeIndex >= graph.getContainedLayers().get( calcLayerIndex() ).size() )
-		{
-			layerIndex++;
-			nodeIndex = 0;
-			int oldR = r;
-			r = 0;
-			backwards.add(0, ()->{
-			   this.r = oldR;
-			});
-		}
-		if( breakpoint )
-		    return StageStatus.BREAKPOINT;
-		return StageStatus.UNFINISHED;
-	}
+                return StageStatus.FINISHED;
+            }
+        }
+        nodeIndex++;
+        if( nodeIndex >= graph.getContainedLayers().get( calcLayerIndex() ).size() )
+        {
+            layerIndex++;
+            nodeIndex = 0;
+            int oldR = r;
+            r = 0;
+            backwards.add(0, ()->{
+               this.r = oldR;
+            });
+        }
+        if( breakpoint )
+            return StageStatus.BREAKPOINT;
+        return StageStatus.UNFINISHED;
+    }
+
+    @Override
+    public StageStatus backwardStep() {
+        if( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ) != null )
+        {
+            inside = true;
+            boolean breakpoint = false;
+            if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
+                breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
+            switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).backwardStep() )
+            {
+            case BREAKPOINT:
+                return StageStatus.BREAKPOINT;
+            case UNFINISHED:
+                LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( nodeIndex );
+                current.setSelected( layout );
+                if( breakpoint )
+                    return StageStatus.BREAKPOINT;
+                return StageStatus.UNFINISHED;
+            case FINISHED:
+                inside = false;
+                subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
+                break;
+            }
+        }
+        StageStatus status = calcBeforeState();
+        if( status == StageStatus.FINISHED )
+            return status;
+        LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) );
+        current.setSelected( layout );
+        //current.update();
+        if( !backwards.isEmpty() )
+        {
+            backwards.get( 0 ).reverse();
+            backwards.remove( 0 );
+        }
+        return status;
+    }
 
-	@Override
-	public StageStatus backwardStep() {
-		if( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ) != null )
-		{
-			inside = true;
-			boolean breakpoint = false;
-			if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
-				breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
-			switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).backwardStep() )
-			{
-			case BREAKPOINT:
-				return StageStatus.BREAKPOINT;
-			case UNFINISHED:
-				LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( nodeIndex );
-				current.setSelected( layout );
-				if( breakpoint )
-					return StageStatus.BREAKPOINT;
-				return StageStatus.UNFINISHED;
-			case FINISHED:
-				inside = false;
-				subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
-				break;
-			}
-		}
-		StageStatus status = calcBeforeState();
-		if( status == StageStatus.FINISHED )
-			return status;
-		LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) );
-		current.setSelected( layout );
-		//current.update();
-		if( !backwards.isEmpty() )
-		{
-			backwards.get( 0 ).reverse();
-			backwards.remove( 0 );
-		}
-		return status;
-	}
-	
-	private StageStatus calcBeforeState()
-	{
-	    boolean breakpoint = !loopNode.setSelected( true );
-		if( layerIndex == 0 )
-		{
-			if( nodeIndex == 0 )
-			{
-		        loopNode.setSelected( false );
-				return StageStatus.FINISHED;
-			}	
-		}
-		nodeIndex--;
-		if( nodeIndex < 0 )
-		{
-			layerIndex--;
-	        backwards.get( 0 ).reverse();
-	        backwards.remove( 0 );
-			nodeIndex = graph.getContainedLayers().get( calcLayerIndex() ).size() - 1;
-		}
+    private StageStatus calcBeforeState()
+    {
+        boolean breakpoint = !loopNode.setSelected( true );
+        if( layerIndex == 0 )
+        {
+            if( nodeIndex == 0 )
+            {
+                loopNode.setSelected( false );
+                return StageStatus.FINISHED;
+            }
+        }
+        nodeIndex--;
+        if( nodeIndex < 0 )
+        {
+            layerIndex--;
+            backwards.get( 0 ).reverse();
+            backwards.remove( 0 );
+            nodeIndex = graph.getContainedLayers().get( calcLayerIndex() ).size() - 1;
+        }
         if( breakpoint )
             return StageStatus.BREAKPOINT;
-		return StageStatus.UNFINISHED;
-	}
+        return StageStatus.UNFINISHED;
+    }
 
     @Override
     public PseudoCodeNode createPseudocodeTree( JTree tree ) {
         PseudoCodeNode root = new PseudoCodeNode( "Vertical alignment", tree );
         loopNode = new PseudoCodeNode( "Loop through all nodes...", tree );
         do {
-    		LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) );
-    		if( current.getContainedNodes().size() > 0 )
-    		{
-			    ExtremalLayoutCalc extcalc = new ExtremalLayoutCalc( layout, current );
-			    PseudoCodeNode subNode = extcalc.createPseudocodeTree( loopNode.getTree() );
-			    loopNode.add( subNode );
-				subgraphAlgs.get( calcLayerIndex() ).set( calcNodeIndex( nodeIndex ), extcalc );
-				subgraphNodes.get( calcLayerIndex() ).set( calcNodeIndex( nodeIndex ), subNode );
-        	}
+            LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) );
+            if( current.getContainedNodes().size() > 0 )
+            {
+                ExtremalLayoutCalc extcalc = new ExtremalLayoutCalc( layout, current );
+                PseudoCodeNode subNode = extcalc.createPseudocodeTree( loopNode.getTree() );
+                loopNode.add( subNode );
+                subgraphAlgs.get( calcLayerIndex() ).set( calcNodeIndex( nodeIndex ), extcalc );
+                subgraphNodes.get( calcLayerIndex() ).set( calcNodeIndex( nodeIndex ), subNode );
+            }
         } while( calcNextState() != StageStatus.FINISHED );
-		layerIndex = 0;
-		nodeIndex = 0;
-		backwards.clear();
+        layerIndex = 0;
+        nodeIndex = 0;
+        backwards.clear();
         root.add( loopNode );
         return root;
     }
 
     @Override
     public StageStatus forwardStepOver() {
-    	if( !inside )
-    		return forwardStep();
-    	else
-    	{
-    		boolean breakpoint = false;
-			if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
-				breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
-			switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).forwardStepOver() )
-			{
+        if( !inside )
+            return forwardStep();
+        else
+        {
+            boolean breakpoint = false;
+            if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
+                breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
+            switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).forwardStepOver() )
+            {
             case BREAKPOINT:
                 return StageStatus.BREAKPOINT;
-			case UNFINISHED:
-				if( breakpoint )
-					return StageStatus.BREAKPOINT;
-				return StageStatus.UNFINISHED;
-			case FINISHED:
-				inside = false;
-				subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
-				break;
-			}
-			return StageStatus.UNFINISHED;
-    	}
+            case UNFINISHED:
+                if( breakpoint )
+                    return StageStatus.BREAKPOINT;
+                return StageStatus.UNFINISHED;
+            case FINISHED:
+                inside = false;
+                subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
+                break;
+            }
+            return StageStatus.UNFINISHED;
+        }
     }
 
     @Override
     public StageStatus forwardStepOut() {
-    	if( !inside )
-    	{
-	        StageStatus status = StageStatus.UNFINISHED;
-	        while( status == StageStatus.UNFINISHED )
-	            status = forwardStep();
-	        return status;
-    	}
-    	else
-    	{
-    		boolean breakpoint = false;
-			if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
-				breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
-			switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).forwardStepOut() )
-			{
+        if( !inside )
+        {
+            StageStatus status = StageStatus.UNFINISHED;
+            while( status == StageStatus.UNFINISHED )
+                status = forwardStep();
+            return status;
+        }
+        else
+        {
+            boolean breakpoint = false;
+            if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
+                breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
+            switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).forwardStepOut() )
+            {
             case BREAKPOINT:
                 return StageStatus.BREAKPOINT;
-			case UNFINISHED:
-				if( breakpoint )
-					return StageStatus.BREAKPOINT;
-				return StageStatus.UNFINISHED;
-			case FINISHED:
-				inside = false;
-				subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
-				break;
-			}
-			return StageStatus.UNFINISHED;
-    	}
+            case UNFINISHED:
+                if( breakpoint )
+                    return StageStatus.BREAKPOINT;
+                return StageStatus.UNFINISHED;
+            case FINISHED:
+                inside = false;
+                subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
+                break;
+            }
+            return StageStatus.UNFINISHED;
+        }
     }
 
     @Override
     public StageStatus backwardStepOver() {
-    	if( !inside )
-    		return backwardStep();
-    	else
-    	{
-    		boolean breakpoint = false;
-			if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
-				breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
-			switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).backwardStepOver() )
-			{
-			case BREAKPOINT:
-				return StageStatus.BREAKPOINT;
-			case UNFINISHED:
-				LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( nodeIndex );
-				current.setSelected( layout );
-				if( breakpoint )
-					return StageStatus.BREAKPOINT;
-				return StageStatus.UNFINISHED;
-			case FINISHED:
-				inside = false;
-				subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
-				break;
-			}
-			return StageStatus.UNFINISHED;
-    	}
+        if( !inside )
+            return backwardStep();
+        else
+        {
+            boolean breakpoint = false;
+            if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
+                breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
+            switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).backwardStepOver() )
+            {
+            case BREAKPOINT:
+                return StageStatus.BREAKPOINT;
+            case UNFINISHED:
+                LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( nodeIndex );
+                current.setSelected( layout );
+                if( breakpoint )
+                    return StageStatus.BREAKPOINT;
+                return StageStatus.UNFINISHED;
+            case FINISHED:
+                inside = false;
+                subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
+                break;
+            }
+            return StageStatus.UNFINISHED;
+        }
     }
 
     @Override
     public StageStatus backwardStepOut() {
-    	if( !inside )
-    	{
-	        StageStatus status = StageStatus.UNFINISHED;
-	        while( status == StageStatus.UNFINISHED )
-	            status = backwardStep();
-	        return status;
-    	}
-    	else
-    	{
-    		boolean breakpoint = false;
-			if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
-				breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
-			switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).backwardStepOut() )
-			{
-			case BREAKPOINT:
-				return StageStatus.BREAKPOINT;
-			case UNFINISHED:
-				LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( nodeIndex );
-				current.setSelected( layout );
-				if( breakpoint )
-					return StageStatus.BREAKPOINT;
-				return StageStatus.UNFINISHED;
-			case FINISHED:
-				inside = false;
-				subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
-				break;
-			}
-			return StageStatus.UNFINISHED;
-    	}
+        if( !inside )
+        {
+            StageStatus status = StageStatus.UNFINISHED;
+            while( status == StageStatus.UNFINISHED )
+                status = backwardStep();
+            return status;
+        }
+        else
+        {
+            boolean breakpoint = false;
+            if( !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).isSelected() )
+                breakpoint |= !subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( true );
+            switch( subgraphAlgs.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).backwardStepOut() )
+            {
+            case BREAKPOINT:
+                return StageStatus.BREAKPOINT;
+            case UNFINISHED:
+                LayeredGraphNode current = graph.getContainedLayers().get( calcLayerIndex() ).get( nodeIndex );
+                current.setSelected( layout );
+                if( breakpoint )
+                    return StageStatus.BREAKPOINT;
+                return StageStatus.UNFINISHED;
+            case FINISHED:
+                inside = false;
+                subgraphNodes.get( calcLayerIndex() ).get( calcNodeIndex( nodeIndex ) ).setSelected( false );
+                break;
+            }
+            return StageStatus.UNFINISHED;
+        }
     }
 }

+ 130 - 130
src/bk/Combine.java

@@ -19,152 +19,152 @@ import graph.LayeredGraphNode;
  */
 public class Combine implements AlgorithmStage {
 
-	LayeredGraphNode graph;
-	
-	private enum State
-	{
-		ALIGN,
-		SET_COORDINATES
-	}
-	
-	private State state;
-	private int btlOffset;
-	private int btrOffset;
-	private int tblOffset;
-	private int tbrOffset;
-	private int vIndex;
-	private ArrayList< BackwardAction > actions;
+    LayeredGraphNode graph;
+
+    private enum State
+    {
+        ALIGN,
+        SET_COORDINATES
+    }
+
+    private State state;
+    private int btlOffset;
+    private int btrOffset;
+    private int tblOffset;
+    private int tbrOffset;
+    private int vIndex;
+    private ArrayList< BackwardAction > actions;
     private PseudoCodeNode alignNode;
     private PseudoCodeNode setNode;
     private PseudoCodeNode loopNode;
     private boolean inside;
     private boolean breakPoint;
-	
-	public Combine( LayeredGraphNode graph )
-	{
-		this.graph = graph;
-		state = State.ALIGN;
-		vIndex = 0;
-		actions = new ArrayList<>();
-		inside = false;
-	}
-	
-	@Override
-	public StageStatus forwardStep() {
-		breakPoint = false;
-		if( state == State.ALIGN )
-		{
-		    inside = false;
-		    if( !alignNode.isSelected() )
-		    	breakPoint |= !alignNode.setSelected( true );
-			int tblw = (int)graph.getWidth( LayoutType.TOP_BOTTOM_LEFT );
-			int tbrw = (int)graph.getWidth( LayoutType.TOP_BOTTOM_RIGHT );
-			int btlw = (int)graph.getWidth( LayoutType.BOTTOM_TOP_LEFT );
-			int btrw = (int)graph.getWidth( LayoutType.BOTTOM_TOP_RIGHT );
-			LayoutType minLayout = LayoutType.TOP_BOTTOM_LEFT;
-			int minWidth = tblw;
-			if( tbrw < minWidth )
-			{
-				minWidth = tbrw;
-				minLayout = LayoutType.TOP_BOTTOM_RIGHT;
-			}
-			if( btlw < minWidth )
-			{
-				minWidth = btlw;
-				minLayout = LayoutType.BOTTOM_TOP_LEFT;
-			}
-			if( btrw < minWidth )
-			{
-				minWidth = btrw;
-				minLayout = LayoutType.BOTTOM_TOP_RIGHT;
-			}
-			int minX = calcMinX( minLayout );
-			btlOffset = minX - calcMinX( LayoutType.BOTTOM_TOP_LEFT );
-			tblOffset = minX - calcMinX( LayoutType.TOP_BOTTOM_LEFT );
-			btrOffset = minWidth - btrw;
-			tbrOffset = minWidth - tbrw;
-			graph.setColor( Color.BLACK, null );
-			//MainView.frame.setSize( MainView.frame.getWidth() + 1, MainView.frame.getHeight() );
-			//MainView.frame.setSize( MainView.frame.getWidth() - 1, MainView.frame.getHeight() );
-			actions.add( 0, () -> {
+
+    public Combine( LayeredGraphNode graph )
+    {
+        this.graph = graph;
+        state = State.ALIGN;
+        vIndex = 0;
+        actions = new ArrayList<>();
+        inside = false;
+    }
+
+    @Override
+    public StageStatus forwardStep() {
+        breakPoint = false;
+        if( state == State.ALIGN )
+        {
+            inside = false;
+            if( !alignNode.isSelected() )
+                breakPoint |= !alignNode.setSelected( true );
+            int tblw = (int)graph.getWidth( LayoutType.TOP_BOTTOM_LEFT );
+            int tbrw = (int)graph.getWidth( LayoutType.TOP_BOTTOM_RIGHT );
+            int btlw = (int)graph.getWidth( LayoutType.BOTTOM_TOP_LEFT );
+            int btrw = (int)graph.getWidth( LayoutType.BOTTOM_TOP_RIGHT );
+            LayoutType minLayout = LayoutType.TOP_BOTTOM_LEFT;
+            int minWidth = tblw;
+            if( tbrw < minWidth )
+            {
+                minWidth = tbrw;
+                minLayout = LayoutType.TOP_BOTTOM_RIGHT;
+            }
+            if( btlw < minWidth )
+            {
+                minWidth = btlw;
+                minLayout = LayoutType.BOTTOM_TOP_LEFT;
+            }
+            if( btrw < minWidth )
+            {
+                minWidth = btrw;
+                minLayout = LayoutType.BOTTOM_TOP_RIGHT;
+            }
+            int minX = calcMinX( minLayout );
+            btlOffset = minX - calcMinX( LayoutType.BOTTOM_TOP_LEFT );
+            tblOffset = minX - calcMinX( LayoutType.TOP_BOTTOM_LEFT );
+            btrOffset = minWidth - btrw;
+            tbrOffset = minWidth - tbrw;
+            graph.setColor( Color.BLACK, null );
+            //MainView.frame.setSize( MainView.frame.getWidth() + 1, MainView.frame.getHeight() );
+            //MainView.frame.setSize( MainView.frame.getWidth() - 1, MainView.frame.getHeight() );
+            actions.add( 0, () -> {
                 inside = false;
                 setNode.setSelected( false );
                 breakPoint = false;
-    		    if( !alignNode.isSelected() )
-    		    	breakPoint |= !alignNode.setSelected( true );
-				state = State.ALIGN;
-				graph.setColor( null, null );
-				//MainView.frame.setSize( MainView.frame.getWidth() + 1, MainView.frame.getHeight() );
-				//MainView.frame.setSize( MainView.frame.getWidth() - 1, MainView.frame.getHeight() );
-			});
-			state = State.SET_COORDINATES;
+                if( !alignNode.isSelected() )
+                    breakPoint |= !alignNode.setSelected( true );
+                state = State.ALIGN;
+                graph.setColor( null, null );
+                //MainView.frame.setSize( MainView.frame.getWidth() + 1, MainView.frame.getHeight() );
+                //MainView.frame.setSize( MainView.frame.getWidth() - 1, MainView.frame.getHeight() );
+            });
+            state = State.SET_COORDINATES;
             alignNode.setSelected( false );
-		    if( !setNode.isSelected() )
-		    	breakPoint |= !setNode.setSelected( true );
+            if( !setNode.isSelected() )
+                breakPoint |= !setNode.setSelected( true );
             breakPoint |= !loopNode.setSelected( true );
-		}
-		else
-		{
+        }
+        else
+        {
             breakPoint = !loopNode.setSelected( true );
-			if( vIndex >= graph.getContainedNodes().size() )
-			{
-	            inside = false; 
-			    setNode.setSelected( false );
-			    loopNode.setSelected( false );
-				return StageStatus.FINISHED;
-			}
-			else
-	            inside = true;
-			LayeredGraphNode current = graph.getContainedNodes().get( vIndex );
-			current.setSelected( null );
-			ArrayList< Integer > positions = new ArrayList<>();
-			positions.add( (int)current.getX( LayoutType.TOP_BOTTOM_LEFT ) + tblOffset );
-			positions.add( (int)current.getX( LayoutType.TOP_BOTTOM_RIGHT ) + tbrOffset );
-			positions.add( (int)current.getX( LayoutType.BOTTOM_TOP_LEFT ) + btlOffset );
-			positions.add( (int)current.getX( LayoutType.BOTTOM_TOP_RIGHT ) + btrOffset );
-			Collections.sort( positions );
-			int oldX = (int)current.getX( LayoutType.COMBINED );
-			current.setX( (positions.get( 1 ) + positions.get( 2 )) / 2, true, LayoutType.COMBINED );
-			actions.add( 0, () -> {
+            if( vIndex >= graph.getContainedNodes().size() )
+            {
+                inside = false;
+                setNode.setSelected( false );
+                loopNode.setSelected( false );
+                return StageStatus.FINISHED;
+            }
+            else
+                inside = true;
+            LayeredGraphNode current = graph.getContainedNodes().get( vIndex );
+            current.setSelected( null );
+            ArrayList< Integer > positions = new ArrayList<>();
+            positions.add( (int)current.getX( LayoutType.TOP_BOTTOM_LEFT ) + tblOffset );
+            positions.add( (int)current.getX( LayoutType.TOP_BOTTOM_RIGHT ) + tbrOffset );
+            positions.add( (int)current.getX( LayoutType.BOTTOM_TOP_LEFT ) + btlOffset );
+            positions.add( (int)current.getX( LayoutType.BOTTOM_TOP_RIGHT ) + btrOffset );
+            Collections.sort( positions );
+            int oldX = (int)current.getX( LayoutType.COMBINED );
+            current.setX( (positions.get( 1 ) + positions.get( 2 )) / 2, true, LayoutType.COMBINED );
+            actions.add( 0, () -> {
                 inside = true;
                 breakPoint = false;
-    		    if( !setNode.isSelected() )
-    		    	breakPoint |= !setNode.setSelected( true );
-    		    breakPoint |= !loopNode.setSelected( true );
-				vIndex--;
-				current.setX( oldX, true, LayoutType.COMBINED );
-				current.setSelected( null );
-			});
-			vIndex++;
-		}
-		if( breakPoint )
-		    return StageStatus.BREAKPOINT;
-		return StageStatus.UNFINISHED;
-	}
-	
-	private int calcMinX(  LayoutType layout )
-	{
-		int minX = 0;
-		if( graph.getContainedNodes().size() > 0 )
-			minX = (int)graph.getContainedNodes().get( 0 ).getX( layout );
-		for( LayeredGraphNode n : graph.getContainedNodes() )
-			minX = Math.min( minX, (int)n.getX( layout ) );
-		return minX;
-	}
-
-	@Override
-	public StageStatus backwardStep() {
-		if( actions.size() == 0 )
-		{
+                if( !setNode.isSelected() )
+                    breakPoint |= !setNode.setSelected( true );
+                breakPoint |= !loopNode.setSelected( true );
+                vIndex--;
+                current.setX( oldX, true, LayoutType.COMBINED );
+                current.setSelected( null );
+            });
+            vIndex++;
+        }
+        if( breakPoint )
+            return StageStatus.BREAKPOINT;
+        return StageStatus.UNFINISHED;
+    }
+
+    private int calcMinX(  LayoutType layout )
+    {
+        int minX = 0;
+        if( graph.getContainedNodes().size() > 0 )
+            minX = (int)graph.getContainedNodes().get( 0 ).getX( layout );
+        for( LayeredGraphNode n : graph.getContainedNodes() )
+            minX = Math.min( minX, (int)n.getX( layout ) );
+        return minX;
+    }
+
+    @Override
+    public StageStatus backwardStep() {
+        if( actions.size() == 0 )
+        {
             inside = false;
-			return StageStatus.FINISHED;
-		}
-		actions.get( 0 ).reverse();
-		actions.remove( 0 );
+            return StageStatus.FINISHED;
+        }
+        actions.get( 0 ).reverse();
+        actions.remove( 0 );
         if( breakPoint )
             return StageStatus.BREAKPOINT;
-		return StageStatus.UNFINISHED;
-	}
+        return StageStatus.UNFINISHED;
+    }
 
     @Override
     public PseudoCodeNode createPseudocodeTree( JTree tree ) {

+ 310 - 310
src/bk/Compaction.java

@@ -17,242 +17,242 @@ import graph.LayeredGraphNode;
  */
 public class Compaction implements AlgorithmStage{
 
-	private enum CompactionState
-	{
-		PLACE_BLOCKS,
-		APPLY_SHIFT
-	}
-	
-	private class StackFrame
-	{
-		public LayeredGraphNode v;
-		public LayeredGraphNode u;
-		public LayeredGraphNode w;
-	}
-	
-	private CompactionState state;
-	private LayeredGraphNode graph;
-	private int vIndex;
-	
-	private ArrayList< StackFrame > stack; // TODO: evtl richtigen "Stack" benutzen
-	private ArrayList< BackwardAction > actions; // TODO: evtl richtigen "Stack" benutzen
-	private LayoutType layout;
-	private PseudoCodeNode placeNode;
+    private enum CompactionState
+    {
+        PLACE_BLOCKS,
+        APPLY_SHIFT
+    }
+
+    private class StackFrame
+    {
+        public LayeredGraphNode v;
+        public LayeredGraphNode u;
+        public LayeredGraphNode w;
+    }
+
+    private CompactionState state;
+    private LayeredGraphNode graph;
+    private int vIndex;
+
+    private ArrayList< StackFrame > stack; // TODO: evtl richtigen "Stack" benutzen
+    private ArrayList< BackwardAction > actions; // TODO: evtl richtigen "Stack" benutzen
+    private LayoutType layout;
+    private PseudoCodeNode placeNode;
     private PseudoCodeNode placeLoopNode;
     private PseudoCodeNode applyNode;
     private PseudoCodeNode applyLoopNode;
     private boolean breakPoint;
     private boolean inside;
-	
-	
-	public Compaction( LayeredGraphNode graph, LayoutType layout )
-	{
-	    this.layout = layout;
-		this.graph = graph;
-		state = CompactionState.PLACE_BLOCKS;
-		stack = new ArrayList<>(); // der call-stack des rekursiven algorithmus
-		vIndex = 0;
-		actions = new ArrayList<>();
-		inside = false;
-	}
-	
-	/**
-	 * calculates the minimum spacing needed between two left borders of nodes.
-	 * @return the spacing
-	 */
-	public double calcSpacing()
-	{
-		double max = 0;
-		for( LayeredGraphNode n : graph.getContainedNodes() )
-			max = Math.max( max, n.getWidth( layout ) );
-		//return max + 25;
-		return max + 5;
-	}
-	
-	private LayeredGraphNode getNodeFromIndex( int index )
-	{
-	    for( ArrayList< LayeredGraphNode > l : graph.getContainedLayers() )
-	    {
-	        if( index >= l.size() )
-	            index -= l.size();
-	        else
-	            return l.get( index );
-	    }
-	    return null;
-	}
-	
-	@Override
-	public StageStatus forwardStep() {
-		breakPoint = false;
-		int acSize = actions.size();
-		if( state == CompactionState.PLACE_BLOCKS ) // blöcke platzieren
-		{
-		    inside = true;
-		    if( !placeNode.isSelected() )
-		    	breakPoint = !placeNode.setSelected( true );
-		    breakPoint |= !placeLoopNode.setSelected( true );
-			if( stack.size() == 0 ) // äußere schleife, placeblocks bisher nicht aufgerufen
-			{
-				ArrayList< LayeredGraphNode > nodes = graph.getContainedNodes();
-				boolean found = false; // knoten mit v = root[v] gefunden?
-				int oldVIndex = vIndex; // nötig für "undo"
-				
-				// suche knoten mit v = root[v] und undefiniertem x-Wert
-				for( ; vIndex < nodes.size(); vIndex++ )
-				{
-					if( getNodeFromIndex( vIndex ).isXUndefined( layout ) && getNodeFromIndex( vIndex ) == getNodeFromIndex( vIndex ).getRoot( layout ) )
-					{
-	                    found = true;
-						break;
-					}
-				}
-				
-				// kein knoten gefunden
-				if( !found )
-				{
-				    // wechsele in die phase des Blöckeshiftens
-		            placeNode.setSelected( false );
-		            placeLoopNode.setSelected( false );
-				    if( !applyNode.isSelected() )
-				    	breakPoint |= !applyNode.setSelected( true );
-		            breakPoint |= !applyLoopNode.setSelected( true );
-					state = CompactionState.APPLY_SHIFT;
-					inside = false;
-					vIndex = 0;
-					actions.add( 0, ()-> {
-	                    applyNode.setSelected( false );
-	                    applyLoopNode.setSelected( false );
-	                    breakPoint = false;
-					    if( !placeNode.isSelected() )
-					    	breakPoint |= !placeNode.setSelected( true );
-	                    breakPoint |= !placeLoopNode.setSelected( true );
-						vIndex = oldVIndex;
-						inside = false;
-						state = CompactionState.PLACE_BLOCKS;
-					} );
-				}
-				else // Knoten gefunden
-				{
-					StackFrame f = new StackFrame(); // enthält lokale variablen
-					f.v = getNodeFromIndex( vIndex );
-					double oldX = f.v.getX( layout ); // nötig für "undo"
-					f.v.setX( 0, true, layout );
-					f.w = f.v;
+
+
+    public Compaction( LayeredGraphNode graph, LayoutType layout )
+    {
+        this.layout = layout;
+        this.graph = graph;
+        state = CompactionState.PLACE_BLOCKS;
+        stack = new ArrayList<>(); // der call-stack des rekursiven algorithmus
+        vIndex = 0;
+        actions = new ArrayList<>();
+        inside = false;
+    }
+
+    /**
+     * calculates the minimum spacing needed between two left borders of nodes.
+     * @return the spacing
+     */
+    public double calcSpacing()
+    {
+        double max = 0;
+        for( LayeredGraphNode n : graph.getContainedNodes() )
+            max = Math.max( max, n.getWidth( layout ) );
+        //return max + 25;
+        return max + 5;
+    }
+
+    private LayeredGraphNode getNodeFromIndex( int index )
+    {
+        for( ArrayList< LayeredGraphNode > l : graph.getContainedLayers() )
+        {
+            if( index >= l.size() )
+                index -= l.size();
+            else
+                return l.get( index );
+        }
+        return null;
+    }
+
+    @Override
+    public StageStatus forwardStep() {
+        breakPoint = false;
+        int acSize = actions.size();
+        if( state == CompactionState.PLACE_BLOCKS ) // blöcke platzieren
+        {
+            inside = true;
+            if( !placeNode.isSelected() )
+                breakPoint = !placeNode.setSelected( true );
+            breakPoint |= !placeLoopNode.setSelected( true );
+            if( stack.size() == 0 ) // äußere schleife, placeblocks bisher nicht aufgerufen
+            {
+                ArrayList< LayeredGraphNode > nodes = graph.getContainedNodes();
+                boolean found = false; // knoten mit v = root[v] gefunden?
+                int oldVIndex = vIndex; // nötig für "undo"
+
+                // suche knoten mit v = root[v] und undefiniertem x-Wert
+                for( ; vIndex < nodes.size(); vIndex++ )
+                {
+                    if( getNodeFromIndex( vIndex ).isXUndefined( layout ) && getNodeFromIndex( vIndex ) == getNodeFromIndex( vIndex ).getRoot( layout ) )
+                    {
+                        found = true;
+                        break;
+                    }
+                }
+
+                // kein knoten gefunden
+                if( !found )
+                {
+                    // wechsele in die phase des Blöckeshiftens
+                    placeNode.setSelected( false );
+                    placeLoopNode.setSelected( false );
+                    if( !applyNode.isSelected() )
+                        breakPoint |= !applyNode.setSelected( true );
+                    breakPoint |= !applyLoopNode.setSelected( true );
+                    state = CompactionState.APPLY_SHIFT;
+                    inside = false;
+                    vIndex = 0;
+                    actions.add( 0, ()-> {
+                        applyNode.setSelected( false );
+                        applyLoopNode.setSelected( false );
+                        breakPoint = false;
+                        if( !placeNode.isSelected() )
+                            breakPoint |= !placeNode.setSelected( true );
+                        breakPoint |= !placeLoopNode.setSelected( true );
+                        vIndex = oldVIndex;
+                        inside = false;
+                        state = CompactionState.PLACE_BLOCKS;
+                    } );
+                }
+                else // Knoten gefunden
+                {
+                    StackFrame f = new StackFrame(); // enthält lokale variablen
+                    f.v = getNodeFromIndex( vIndex );
+                    double oldX = f.v.getX( layout ); // nötig für "undo"
+                    f.v.setX( 0, true, layout );
+                    f.w = f.v;
                     f.w.setSelected( layout ); // zeige knoten als aktiven knoten an
                     System.out.println( "call place_block( " + f.v + " )" );
-					stack.add( 0, f );
-					
-					// die "undo"-action
-					actions.add( 0, ()-> {
-	                    breakPoint = false;
-					    if( !placeNode.isSelected() )
-					    	breakPoint |= !placeNode.setSelected( true );
+                    stack.add( 0, f );
+
+                    // die "undo"-action
+                    actions.add( 0, ()-> {
+                        breakPoint = false;
+                        if( !placeNode.isSelected() )
+                            breakPoint |= !placeNode.setSelected( true );
                         breakPoint |= !placeLoopNode.setSelected( true );
-					    inside = true;
-						stack.get( 0 ).v.setX( oldX, false, layout );
-						stack.get( 0 ).v.setSelected( layout );
-						stack.remove( 0 );
-						vIndex = oldVIndex;
-						state = CompactionState.PLACE_BLOCKS;
-					});
-				}
-			}
-			else // zurzeit innerhalb einer placeblock methode
-			{
-				StackFrame sf = stack.get( 0 );
-				if( sf.u == null ) // zu beginn der placeblock methode
-				{
+                        inside = true;
+                        stack.get( 0 ).v.setX( oldX, false, layout );
+                        stack.get( 0 ).v.setSelected( layout );
+                        stack.remove( 0 );
+                        vIndex = oldVIndex;
+                        state = CompactionState.PLACE_BLOCKS;
+                    });
+                }
+            }
+            else // zurzeit innerhalb einer placeblock methode
+            {
+                StackFrame sf = stack.get( 0 );
+                if( sf.u == null ) // zu beginn der placeblock methode
+                {
                     int posW = graph.getContainedLayers().get( sf.w.getLayer() ).indexOf( sf.w );
-					if( (posW >= 1 && (layout == LayoutType.BOTTOM_TOP_LEFT || layout == LayoutType.TOP_BOTTOM_LEFT)) || (posW < graph.getContainedLayers().get( sf.w.getLayer() ).size() - 1 && (layout == LayoutType.BOTTOM_TOP_RIGHT || layout == LayoutType.TOP_BOTTOM_RIGHT)) ) // if pos[w] > 1"
-					{
-					    int offset = -1;
-					    if( layout == LayoutType.BOTTOM_TOP_RIGHT || layout == LayoutType.TOP_BOTTOM_RIGHT )
-					        offset = 1;
+                    if( (posW >= 1 && (layout == LayoutType.BOTTOM_TOP_LEFT || layout == LayoutType.TOP_BOTTOM_LEFT)) || (posW < graph.getContainedLayers().get( sf.w.getLayer() ).size() - 1 && (layout == LayoutType.BOTTOM_TOP_RIGHT || layout == LayoutType.TOP_BOTTOM_RIGHT)) ) // if pos[w] > 1"
+                    {
+                        int offset = -1;
+                        if( layout == LayoutType.BOTTOM_TOP_RIGHT || layout == LayoutType.TOP_BOTTOM_RIGHT )
+                            offset = 1;
                         sf.u = graph.getContainedLayers().get( sf.w.getLayer() ).get( posW + offset ).getRoot( layout );
-						
-						if( sf.u.isXUndefined( layout ) ) // nötig placeblock aufzurufen?
-						{// ja
-							StackFrame nsf = new StackFrame(); // enthält lokale variablen
-							nsf.v = sf.u;
-							double oldX = nsf.v.getX( layout ); // nötig für "undo"
-							nsf.v.setX( 0, true, layout );
-							nsf.w = nsf.v;
+
+                        if( sf.u.isXUndefined( layout ) ) // nötig placeblock aufzurufen?
+                        {// ja
+                            StackFrame nsf = new StackFrame(); // enthält lokale variablen
+                            nsf.v = sf.u;
+                            double oldX = nsf.v.getX( layout ); // nötig für "undo"
+                            nsf.v.setX( 0, true, layout );
+                            nsf.w = nsf.v;
                             nsf.w.setSelected( layout ); // zeige knoten als aktiven knoten an
-		                    System.out.println( "call place_block( " + nsf.v + " )" );
-							stack.add( 0, nsf );
-		                    
-		                    // die "undo"-action
-							actions.add( 0, ()-> {
-			                    breakPoint = false;
-							    if( !placeNode.isSelected() )
-							    	breakPoint |= !placeNode.setSelected( true );
-		                        breakPoint |= !placeLoopNode.setSelected( true );
-							    inside = true;
-								stack.get( 0 ).v.setX( oldX, false, layout );
-								stack.get( 0 ).v.setSelected( layout );
-								stack.remove( 0 );
-								stack.get( 0 ).u = null;
-							});
-						}
-						else // nein
-						{
-						    // tue nix
-							sf.w.setSelected( layout );
-							actions.add( 0, ()-> {
-			                    breakPoint = false;
-							    if( !placeNode.isSelected() )
-							    	breakPoint |= !placeNode.setSelected( true );
-		                        breakPoint |= !placeLoopNode.setSelected( true );
+                            System.out.println( "call place_block( " + nsf.v + " )" );
+                            stack.add( 0, nsf );
+
+                            // die "undo"-action
+                            actions.add( 0, ()-> {
+                                breakPoint = false;
+                                if( !placeNode.isSelected() )
+                                    breakPoint |= !placeNode.setSelected( true );
+                                breakPoint |= !placeLoopNode.setSelected( true );
+                                inside = true;
+                                stack.get( 0 ).v.setX( oldX, false, layout );
+                                stack.get( 0 ).v.setSelected( layout );
+                                stack.remove( 0 );
+                                stack.get( 0 ).u = null;
+                            });
+                        }
+                        else // nein
+                        {
+                            // tue nix
+                            sf.w.setSelected( layout );
+                            actions.add( 0, ()-> {
+                                breakPoint = false;
+                                if( !placeNode.isSelected() )
+                                    breakPoint |= !placeNode.setSelected( true );
+                                breakPoint |= !placeLoopNode.setSelected( true );
                                 inside = true;
-								stack.get( 0 ).u = null;
-							});
-						}
-					}
-					else 
-					{ // w = align[w]
-						LayeredGraphNode oldW = sf.w;
-						sf.w = sf.w.getAlign( layout );
-						sf.w.setSelected( layout );
-						if( sf.w == sf.v ) // schleifenabbruchbedingung
-						{ //abbrechen, placeblock beendet
+                                stack.get( 0 ).u = null;
+                            });
+                        }
+                    }
+                    else
+                    { // w = align[w]
+                        LayeredGraphNode oldW = sf.w;
+                        sf.w = sf.w.getAlign( layout );
+                        sf.w.setSelected( layout );
+                        if( sf.w == sf.v ) // schleifenabbruchbedingung
+                        { //abbrechen, placeblock beendet
                             System.out.println( "return place_block( " + sf.v + " )" );
-							stack.remove( 0 );
-							actions.add( 0, ()-> {
-			                    breakPoint = false;
-							    if( !placeNode.isSelected() )
-							    	breakPoint |= !placeNode.setSelected( true );
-		                        breakPoint |= !placeLoopNode.setSelected( true );
+                            stack.remove( 0 );
+                            actions.add( 0, ()-> {
+                                breakPoint = false;
+                                if( !placeNode.isSelected() )
+                                    breakPoint |= !placeNode.setSelected( true );
+                                breakPoint |= !placeLoopNode.setSelected( true );
                                 inside = true;
-								stack.add( 0, sf );
-								sf.w = oldW;
+                                stack.add( 0, sf );
+                                sf.w = oldW;
                                 sf.w.setSelected( layout );
-							});
-						}
-						else
-						{ //nur "undo aktion" hinzufügen
-							actions.add( 0, ()-> {
-			                    breakPoint = false;
-							    if( !placeNode.isSelected() )
-							    	breakPoint |= !placeNode.setSelected( true );
-		                        breakPoint |= !placeLoopNode.setSelected( true );
+                            });
+                        }
+                        else
+                        { //nur "undo aktion" hinzufügen
+                            actions.add( 0, ()-> {
+                                breakPoint = false;
+                                if( !placeNode.isSelected() )
+                                    breakPoint |= !placeNode.setSelected( true );
+                                breakPoint |= !placeLoopNode.setSelected( true );
                                 inside = true;
-								sf.w = oldW;
-								sf.w.setSelected( layout );
-							});
-						}
-					}	
-				}
-				else // ein "placeBlock(u)" aufruf hat gerade returned
-				{
-				    // alte Werte merken für undo
-					LayeredGraphNode oldSink = sf.v.getSink( layout );	
-					LayeredGraphNode sinkOfU = sf.u.getSink( layout );
-					double oldShift = sinkOfU.getShift( layout );
-					double oldX = sf.v.getX( layout );
-					boolean oldDef = !sf.v.isXUndefined( layout );
-					
-					// v für visualisierung markieren
-					sf.w.setSelected( layout );
+                                sf.w = oldW;
+                                sf.w.setSelected( layout );
+                            });
+                        }
+                    }
+                }
+                else // ein "placeBlock(u)" aufruf hat gerade returned
+                {
+                    // alte Werte merken für undo
+                    LayeredGraphNode oldSink = sf.v.getSink( layout );
+                    LayeredGraphNode sinkOfU = sf.u.getSink( layout );
+                    double oldShift = sinkOfU.getShift( layout );
+                    double oldX = sf.v.getX( layout );
+                    boolean oldDef = !sf.v.isXUndefined( layout );
+
+                    // v für visualisierung markieren
+                    sf.w.setSelected( layout );
                     
                     if( sf.v.getSink( layout ) == sf.v ) // sink[v] = v?
                         sf.v.setSink( sf.u.getSink( layout ), layout ); // sink[v] := sink[u]
@@ -260,121 +260,121 @@ public class Compaction implements AlgorithmStage{
                     if( layout == LayoutType.BOTTOM_TOP_RIGHT || layout == LayoutType.TOP_BOTTOM_RIGHT )
                         multiplyer = -1;
                     
-					if( sf.v.getSink( layout ) != sf.u.getSink( layout ) ) // sink[v] != sink [u]?
-						sf.u.getSink( layout ).setShift( // shift[sink[u]] =
-						  Math.min( sf.u.getSink( layout ).getShift( layout ),  // min(shift[sink[u]]
-						          multiplyer * (Math.abs(sf.v.getX( layout )) - Math.abs(sf.u.getX( layout )) - calcSpacing()) ), layout ); // y_v - y_u - s
-					else
-					    // y_v = max {y_v, y_u + s}
-						sf.v.setX( multiplyer * Math.max( Math.abs( sf.v.getX( layout ) ), Math.abs( sf.u.getX( layout ) ) + calcSpacing() ), true, layout );
-					
+                    if( sf.v.getSink( layout ) != sf.u.getSink( layout ) ) // sink[v] != sink [u]?
+                        sf.u.getSink( layout ).setShift( // shift[sink[u]] =
+                          Math.min( sf.u.getSink( layout ).getShift( layout ),  // min(shift[sink[u]]
+                                  multiplyer * (Math.abs(sf.v.getX( layout )) - Math.abs(sf.u.getX( layout )) - calcSpacing()) ), layout ); // y_v - y_u - s
+                    else
+                        // y_v = max {y_v, y_u + s}
+                        sf.v.setX( multiplyer * Math.max( Math.abs( sf.v.getX( layout ) ), Math.abs( sf.u.getX( layout ) ) + calcSpacing() ), true, layout );
+
 
                     // alte Werte merken für undo
-					LayeredGraphNode oldW = sf.w;
+                    LayeredGraphNode oldW = sf.w;
                     LayeredGraphNode oldU = sf.u;
                     
-					sf.w = sf.w.getAlign( layout ); // w = align[w]
-					sf.u = null; // u wird nächsten schleifendurchlauf neu gesetzt
-					
-					if( sf.w == sf.v ) // schleifenabbruchbedingung
-					{ //abbrechen, placeblock beendet  
-					    System.out.println( "return place_block( " + sf.v + " )" );
-						stack.remove( 0 );
-						actions.add( 0, ()-> {
-		                    breakPoint = false;
-						    if( !placeNode.isSelected() )
-						    	breakPoint |= !placeNode.setSelected( true );
-	                        breakPoint |= !placeLoopNode.setSelected( true );
+                    sf.w = sf.w.getAlign( layout ); // w = align[w]
+                    sf.u = null; // u wird nächsten schleifendurchlauf neu gesetzt
+
+                    if( sf.w == sf.v ) // schleifenabbruchbedingung
+                    { //abbrechen, placeblock beendet
+                        System.out.println( "return place_block( " + sf.v + " )" );
+                        stack.remove( 0 );
+                        actions.add( 0, ()-> {
+                            breakPoint = false;
+                            if( !placeNode.isSelected() )
+                                breakPoint |= !placeNode.setSelected( true );
+                            breakPoint |= !placeLoopNode.setSelected( true );
                             inside = true;
-							stack.add( 0, sf );
-							stack.get( 0 ).v.setSink(  oldSink, layout );
-							sinkOfU.setShift( oldShift, layout );
-							sf.u = oldU;
-							sf.v.setX( oldX, oldDef, layout );
-							sf.w = oldW;
+                            stack.add( 0, sf );
+                            stack.get( 0 ).v.setSink(  oldSink, layout );
+                            sinkOfU.setShift( oldShift, layout );
+                            sf.u = oldU;
+                            sf.v.setX( oldX, oldDef, layout );
+                            sf.w = oldW;
                             sf.w.setSelected( layout );
-						});
-					}
-					else
-					{ //nur "undo aktion" hinzufügen
-						actions.add( 0, ()-> {
-		                    breakPoint = false;
-						    if( !placeNode.isSelected() )
-						    	breakPoint |= !placeNode.setSelected( true );
-	                        breakPoint |= !placeLoopNode.setSelected( true );
+                        });
+                    }
+                    else
+                    { //nur "undo aktion" hinzufügen
+                        actions.add( 0, ()-> {
+                            breakPoint = false;
+                            if( !placeNode.isSelected() )
+                                breakPoint |= !placeNode.setSelected( true );
+                            breakPoint |= !placeLoopNode.setSelected( true );
                             inside = true;
-							stack.get( 0 ).v.setSink(  oldSink, layout );
-							sinkOfU.setShift( oldShift, layout );
-							sf.u = oldU;
-							sf.v.setX( oldX, oldDef, layout );
-							sf.w = oldW;
+                            stack.get( 0 ).v.setSink(  oldSink, layout );
+                            sinkOfU.setShift( oldShift, layout );
+                            sf.u = oldU;
+                            sf.v.setX( oldX, oldDef, layout );
+                            sf.w = oldW;
                             sf.w.setSelected( layout );
-						});
-					}
-				}
-			}
-		}
-		else if( state == CompactionState.APPLY_SHIFT )// "Compute absolute coordinates"
-		{
+                        });
+                    }
+                }
+            }
+        }
+        else if( state == CompactionState.APPLY_SHIFT )// "Compute absolute coordinates"
+        {
             inside = true;
-		    if( !applyNode.isSelected() )
-		    	breakPoint |= !applyNode.setSelected( true );
+            if( !applyNode.isSelected() )
+                breakPoint |= !applyNode.setSelected( true );
             breakPoint |= !applyLoopNode.setSelected( true );
-		    if( vIndex >= graph.getContainedNodes().size() )
-		    {
+            if( vIndex >= graph.getContainedNodes().size() )
+            {
                 inside = false;
                 applyNode.setSelected( false );
                 applyLoopNode.setSelected( false );
                 return StageStatus.FINISHED;
-		    }
-			LayeredGraphNode v = graph.getContainedNodes().get( vIndex );
-			double oldX = v.getX( layout );
-			boolean oldDef = !v.isXUndefined( layout );
-			
-			v.setSelected( layout );
-			v.setX( v.getRoot( layout ).getX( layout ), true, layout ); // y_v = y_root[v]
-			if( v == v.getRoot( layout ) && v.getSink( layout ).getShift( layout ) < Double.POSITIVE_INFINITY )
-				v.setX( v.getX( layout ) + v.getSink( layout ).getShift( layout ), true, layout );
-			actions.add( 0, ()-> {
+            }
+            LayeredGraphNode v = graph.getContainedNodes().get( vIndex );
+            double oldX = v.getX( layout );
+            boolean oldDef = !v.isXUndefined( layout );
+
+            v.setSelected( layout );
+            v.setX( v.getRoot( layout ).getX( layout ), true, layout ); // y_v = y_root[v]
+            if( v == v.getRoot( layout ) && v.getSink( layout ).getShift( layout ) < Double.POSITIVE_INFINITY )
+                v.setX( v.getX( layout ) + v.getSink( layout ).getShift( layout ), true, layout );
+            actions.add( 0, ()-> {
                 inside = true;
                 breakPoint = false;
-			    if( !applyNode.isSelected() )
-			    	breakPoint |= !applyNode.setSelected( true );
+                if( !applyNode.isSelected() )
+                    breakPoint |= !applyNode.setSelected( true );
                 breakPoint |= !applyLoopNode.setSelected( true );
-				v.setX( oldX, oldDef, layout );
-				v.setSelected( layout );
-				vIndex--;
-			} );
-			vIndex++;
-			if( vIndex >= graph.getContainedNodes().size() )
-			{
+                v.setX( oldX, oldDef, layout );
+                v.setSelected( layout );
+                vIndex--;
+            } );
+            vIndex++;
+            if( vIndex >= graph.getContainedNodes().size() )
+            {
                 applyNode.setSelected( false );
                 applyLoopNode.setSelected( false );
-				return StageStatus.FINISHED;
-			}
-		}
-		if( actions.size() != acSize + 1 )
-			System.out.println( "ERROR" );
-		if( breakPoint )
-		    return StageStatus.BREAKPOINT;
-		return StageStatus.UNFINISHED;
-	}
+                return StageStatus.FINISHED;
+            }
+        }
+        if( actions.size() != acSize + 1 )
+            System.out.println( "ERROR" );
+        if( breakPoint )
+            return StageStatus.BREAKPOINT;
+        return StageStatus.UNFINISHED;
+    }
 
-	@Override
-	public StageStatus backwardStep() {
-		if( actions.size() == 0 )
-		{
+    @Override
+    public StageStatus backwardStep() {
+        if( actions.size() == 0 )
+        {
             inside = false;
             placeNode.setSelected( false );
             placeLoopNode.setSelected( false );
-			return StageStatus.FINISHED;
-		}
-		actions.get( 0 ).reverse();
-		actions.remove( 0 );
+            return StageStatus.FINISHED;
+        }
+        actions.get( 0 ).reverse();
+        actions.remove( 0 );
         if( breakPoint )
             return StageStatus.BREAKPOINT;
-		return StageStatus.UNFINISHED;
-	}
+        return StageStatus.UNFINISHED;
+    }
 
     @Override
     public PseudoCodeNode createPseudocodeTree( JTree tree ) {

+ 44 - 44
src/bk/ConflictDetection.java

@@ -29,61 +29,61 @@ public class ConflictDetection implements AlgorithmStage {
     
     @Override
     public StageStatus forwardStep() {
-    	int oldI = i;
-    	int oldL1 = l1;
-    	((PseudoCodeNode)markNode.getParent()).setSelected( true );
-    	boolean breakPoint = !markNode.setSelected( true );
-    	if( i + 1 >= graph.getContainedLayers().size() - 1 )
-    	{
+        int oldI = i;
+        int oldL1 = l1;
+        ((PseudoCodeNode)markNode.getParent()).setSelected( true );
+        boolean breakPoint = !markNode.setSelected( true );
+        if( i + 1 >= graph.getContainedLayers().size() - 1 )
+        {
             ((PseudoCodeNode)markNode.getParent()).setSelected( false );
             markNode.setSelected( false );
-    		return StageStatus.FINISHED;
-    	}
-    	LayeredGraphNode curr = graph.getContainedLayers().get( i + 1 ).get( l1 );
-    	curr.setSelected( null );
-    	ArrayList< LayeredGraphEdge > edges = curr.getIncomingEdges();
-    	LayeredGraphEdge dummyEdge = null;
-    	for( LayeredGraphEdge e : edges )
-    	{
-    		if( e.isDummyEdge() )
-    		{
-    			dummyEdge = e;
-    			break;
-    		}
-    	}
-    	ArrayList< LayeredGraphEdge > conflicts = new ArrayList<>();
+            return StageStatus.FINISHED;
+        }
+        LayeredGraphNode curr = graph.getContainedLayers().get( i + 1 ).get( l1 );
+        curr.setSelected( null );
+        ArrayList< LayeredGraphEdge > edges = curr.getIncomingEdges();
+        LayeredGraphEdge dummyEdge = null;
+        for( LayeredGraphEdge e : edges )
+        {
+            if( e.isDummyEdge() )
+            {
+                dummyEdge = e;
+                break;
+            }
+        }
+        ArrayList< LayeredGraphEdge > conflicts = new ArrayList<>();
         if( dummyEdge != null )
         {
-    		for( LayeredGraphEdge e : edges )
-    		{
-    			if( e.isDummyEdge() )
-    			{
-    				ArrayList< LayeredGraphEdge > conf = e.calcEdgeCrossings();
-    				for( LayeredGraphEdge ce : conf )
-    				{
-    					if( !ce.isDummyEdge() )
-    						conflicts.add( ce );
-    				}
-    			}
-    		}
+            for( LayeredGraphEdge e : edges )
+            {
+                if( e.isDummyEdge() )
+                {
+                    ArrayList< LayeredGraphEdge > conf = e.calcEdgeCrossings();
+                    for( LayeredGraphEdge ce : conf )
+                    {
+                        if( !ce.isDummyEdge() )
+                            conflicts.add( ce );
+                    }
+                }
+            }
         }
         for( LayeredGraphEdge c : conflicts )
-        	c.setConflicted( true, null );
-    	StageStatus status =  calcNextStatus();
-    	actions.add( 0, ()->{
-    		i = oldI;
-    		l1 = oldL1;
+            c.setConflicted( true, null );
+        StageStatus status =  calcNextStatus();
+        actions.add( 0, ()->{
+            i = oldI;
+            l1 = oldL1;
             if( i + 1 < graph.getContainedLayers().size() - 1 && l1 > 0 )
             {
                 LayeredGraphNode layde = graph.getContainedLayers().get( i + 1 ).get( l1 - 1 );
                 layde.setSelected( null );
             }
             for( LayeredGraphEdge c : conflicts )
-            	c.setConflicted( false, null );
-    	});
-    	if( status != StageStatus.FINISHED && breakPoint )
-    	    return StageStatus.BREAKPOINT;
-    	return status;
+                c.setConflicted( false, null );
+        });
+        if( status != StageStatus.FINISHED && breakPoint )
+            return StageStatus.BREAKPOINT;
+        return status;
     }
     
     private StageStatus calcNextStatus()
@@ -113,7 +113,7 @@ public class ConflictDetection implements AlgorithmStage {
         {
             ((PseudoCodeNode)markNode.getParent()).setSelected( false );
             markNode.setSelected( false );
-        	return StageStatus.FINISHED;
+            return StageStatus.FINISHED;
         }
         actions.get( 0 ).reverse();
         actions.remove( 0 );

+ 50 - 50
src/bk/ExtremalLayoutCalc.java

@@ -15,48 +15,48 @@ import graph.LayeredGraphNode;
  */
 public class ExtremalLayoutCalc implements AlgorithmStage {
 
-	public enum LayoutType{
-		TOP_BOTTOM_LEFT,
-		TOP_BOTTOM_RIGHT,
-		BOTTOM_TOP_LEFT,
-		BOTTOM_TOP_RIGHT,
-		COMBINED
-	}
-	
-	private enum LayoutState
-	{
-		BLOCK_CALCULATION,
-		COMPACTION
-	}
-	
-	private PseudoCodeNode pseudoCode;
-	private BlockCalc bc;
-	private Compaction cp;
-	private LayoutState status;
-	private PseudoCodeNode bcNode;
-	private PseudoCodeNode cpNode;
-	private LayoutType type;
-	private boolean inside;
-	
-	
-	public ExtremalLayoutCalc( LayoutType typ, LayeredGraphNode graph )
-	{
-	    type = typ;
-		status = LayoutState.BLOCK_CALCULATION;
-		bc = new BlockCalc( graph, typ );
-		cp = new Compaction( graph, typ );
-		inside = false;
-	}
-	
-	@Override
-	public StageStatus forwardStep() {
-		return forward( "forwardStep" );
-	}
-
-	@Override
-	public StageStatus backwardStep() {
-		return backward( "backwardStep" );
-	}
+    public enum LayoutType{
+        TOP_BOTTOM_LEFT,
+        TOP_BOTTOM_RIGHT,
+        BOTTOM_TOP_LEFT,
+        BOTTOM_TOP_RIGHT,
+        COMBINED
+    }
+
+    private enum LayoutState
+    {
+        BLOCK_CALCULATION,
+        COMPACTION
+    }
+
+    private PseudoCodeNode pseudoCode;
+    private BlockCalc bc;
+    private Compaction cp;
+    private LayoutState status;
+    private PseudoCodeNode bcNode;
+    private PseudoCodeNode cpNode;
+    private LayoutType type;
+    private boolean inside;
+
+
+    public ExtremalLayoutCalc( LayoutType typ, LayeredGraphNode graph )
+    {
+        type = typ;
+        status = LayoutState.BLOCK_CALCULATION;
+        bc = new BlockCalc( graph, typ );
+        cp = new Compaction( graph, typ );
+        inside = false;
+    }
+
+    @Override
+    public StageStatus forwardStep() {
+        return forward( "forwardStep" );
+    }
+
+    @Override
+    public StageStatus backwardStep() {
+        return backward( "backwardStep" );
+    }
 
     @Override
     public PseudoCodeNode createPseudocodeTree( JTree tree ) {
@@ -135,8 +135,8 @@ public class ExtremalLayoutCalc implements AlgorithmStage {
         try {
             if( status == LayoutState.BLOCK_CALCULATION )
             {
-            	if( !bcNode.isSelected() )
-            		breakpoint |= !bcNode.setSelected( true );
+                if( !bcNode.isSelected() )
+                    breakpoint |= !bcNode.setSelected( true );
                 switch( (StageStatus)(BlockCalc.class.getMethod( fName ).invoke( bc ) ) )
                 {
                 case FINISHED:
@@ -154,8 +154,8 @@ public class ExtremalLayoutCalc implements AlgorithmStage {
             }
             else if( status == LayoutState.COMPACTION )
             {
-            	if( !cpNode.isSelected() )
-            	    breakpoint |= !cpNode.setSelected( true );
+                if( !cpNode.isSelected() )
+                    breakpoint |= !cpNode.setSelected( true );
                 switch( (StageStatus)(Compaction.class.getMethod( fName ).invoke( cp ) ) )
                 {
                 case FINISHED:
@@ -191,8 +191,8 @@ public class ExtremalLayoutCalc implements AlgorithmStage {
         try {
             if( status == LayoutState.BLOCK_CALCULATION )
             {
-            	if( !bcNode.isSelected() )
-            		breakpoint |= !bcNode.setSelected( true );
+                if( !bcNode.isSelected() )
+                    breakpoint |= !bcNode.setSelected( true );
                 switch( (StageStatus)(BlockCalc.class.getMethod( fName ).invoke( bc ) ) )
                 {
                 case FINISHED:
@@ -208,8 +208,8 @@ public class ExtremalLayoutCalc implements AlgorithmStage {
             }
             else if( status == LayoutState.COMPACTION )
             {
-            	if( !cpNode.isSelected() )
-            		breakpoint |= !cpNode.setSelected( true );
+                if( !cpNode.isSelected() )
+                    breakpoint |= !cpNode.setSelected( true );
                 switch( (StageStatus)(Compaction.class.getMethod( fName ).invoke( cp ) ) )
                 {
                 case FINISHED:

+ 1 - 1
src/graph/InitializeNodePositions.java

@@ -18,7 +18,7 @@ public class InitializeNodePositions {
      * @param graph the graph where the node positions are to be set.
      */
     public static void placeNodes( LayeredGraphNode graph ) {
-    	for( LayeredGraphNode n : graph.getContainedNodes() )
+        for( LayeredGraphNode n : graph.getContainedNodes() )
         {
             n.setColor( new Color((int)(Math.random() * 0x1000000)), null );
             placeNodes( n );

+ 19 - 19
src/graph/LayeredEdge.java

@@ -64,25 +64,25 @@ public class LayeredEdge implements LayeredGraphEdge {
     @Override
     public ArrayList<LayeredGraphEdge> calcEdgeCrossings()
     {
-    	ArrayList<LayeredGraphEdge> list = new ArrayList<>();
-    	ArrayList<LayeredGraphNode> l = graph.getContainedLayers().get( sources.get( 0 ).getLayer() );
-    	ArrayList<LayeredGraphNode> l2 = graph.getContainedLayers().get( targets.get( 0 ).getLayer() );
-    	int startIndex = l.indexOf( sources.get( 0 ) );
-    	int endIndex = l2.indexOf( targets.get( 0 ) );
-    	for( int i = 0; i < l.size(); i++ )
-    	{
-    		if( i == startIndex )
-    			continue;
-    		for( LayeredGraphEdge e : l.get( i ).getOutgoingEdges() )
-    		{
-    			int i2 = l2.indexOf( e.getTargets().get( 0 ) );
-    			if( i2 == endIndex )
-    				continue;
-    			if( i < startIndex && i2 > endIndex || i > startIndex && i2 < endIndex )
-    				list.add( e );
-    		}
-    	}
-    	return list;
+        ArrayList<LayeredGraphEdge> list = new ArrayList<>();
+        ArrayList<LayeredGraphNode> l = graph.getContainedLayers().get( sources.get( 0 ).getLayer() );
+        ArrayList<LayeredGraphNode> l2 = graph.getContainedLayers().get( targets.get( 0 ).getLayer() );
+        int startIndex = l.indexOf( sources.get( 0 ) );
+        int endIndex = l2.indexOf( targets.get( 0 ) );
+        for( int i = 0; i < l.size(); i++ )
+        {
+            if( i == startIndex )
+                continue;
+            for( LayeredGraphEdge e : l.get( i ).getOutgoingEdges() )
+            {
+                int i2 = l2.indexOf( e.getTargets().get( 0 ) );
+                if( i2 == endIndex )
+                    continue;
+                if( i < startIndex && i2 > endIndex || i > startIndex && i2 < endIndex )
+                    list.add( e );
+            }
+        }
+        return list;
     };
     
     @Override

+ 81 - 81
src/graph/io/Reader.java

@@ -20,47 +20,47 @@ import graph.LayeredNode;
  */
 public class Reader {
 
-	private String fileName;
-	
-	public Reader( String inputFileName )
-	{
-		fileName = inputFileName;
-	}
-	
-	/**
-	 * read the JSON file and return its contents as a {@link LayeredGraphNode}
-	 * @return the read {@link LayeredGraphNode}
-	 */
-	public LayeredGraphNode readInputGraph()
-	{
-		String file = "";
-		try {
-			BufferedReader r = new BufferedReader( new FileReader( fileName ) );
-			String tmp = null;
-			while( (tmp = r.readLine()) != null )
-				file += tmp;
-			r.close();
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-		try {
-			JSONObject json = new JSONObject( file );
-			return parseNode( json, null );
-		} catch (JSONException e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-	
-	private LayeredGraphNode parseNode( JSONObject node, LayeredGraphNode parent ) throws JSONException
-	{
-		LayeredGraphNode newNode = new LayeredNode( null, null );
-		if( parent != null )
-			newNode = parent.createNode( null );
-		if( node.has( "dummy" ) && node.getBoolean( "dummy" ) )
-		{
-			newNode.setDummyNode( true );
-		}
+    private String fileName;
+
+    public Reader( String inputFileName )
+    {
+        fileName = inputFileName;
+    }
+
+    /**
+     * read the JSON file and return its contents as a {@link LayeredGraphNode}
+     * @return the read {@link LayeredGraphNode}
+     */
+    public LayeredGraphNode readInputGraph()
+    {
+        String file = "";
+        try {
+            BufferedReader r = new BufferedReader( new FileReader( fileName ) );
+            String tmp = null;
+            while( (tmp = r.readLine()) != null )
+                file += tmp;
+            r.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        try {
+            JSONObject json = new JSONObject( file );
+            return parseNode( json, null );
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    private LayeredGraphNode parseNode( JSONObject node, LayeredGraphNode parent ) throws JSONException
+    {
+        LayeredGraphNode newNode = new LayeredNode( null, null );
+        if( parent != null )
+            newNode = parent.createNode( null );
+        if( node.has( "dummy" ) && node.getBoolean( "dummy" ) )
+        {
+            newNode.setDummyNode( true );
+        }
         if( node.has( "name" ) )
         {
             if( parent != null && parent.findNodeByName( node.getString( "name" ) ) != null )
@@ -75,49 +75,49 @@ public class Reader {
             newNode.setHeight( node.getInt( "height" ), null );
         else
             newNode.setHeight( 40, null );
-		if( node.has( "layers" ) )
-		{
-			JSONArray layers = node.getJSONArray( "layers" );
-			for( int i = 0; i < layers.length(); i++ )
-			{
-				for( LayeredGraphNode n : parseLayer( layers.getJSONArray( i ), newNode ) )
-					n.setLayer( i );
-			}
-		}
-		if( node.has( "edges" ) )
-		{
-			JSONArray edges = node.getJSONArray( "edges" );
-			for( int i = 0; i < edges.length(); i++ )
-			{
-				JSONObject edge = edges.getJSONObject( i );
-				newNode.addEdge( parseEdge( edge, newNode ) );
-			}
-		}
-		return newNode;
-	}
-	
-	private LayeredGraphEdge parseEdge( JSONObject edge, LayeredGraphNode parent ) throws JSONException
-	{
-		if( !edge.has( "source" ) || !edge.has( "target" ) )
-			throw new JSONException( edge + " is no valid Layered Graph Edge." );
-		if( parent.findNodeByName( edge.getString( "source" ) ) == null )
+        if( node.has( "layers" ) )
+        {
+            JSONArray layers = node.getJSONArray( "layers" );
+            for( int i = 0; i < layers.length(); i++ )
+            {
+                for( LayeredGraphNode n : parseLayer( layers.getJSONArray( i ), newNode ) )
+                    n.setLayer( i );
+            }
+        }
+        if( node.has( "edges" ) )
+        {
+            JSONArray edges = node.getJSONArray( "edges" );
+            for( int i = 0; i < edges.length(); i++ )
+            {
+                JSONObject edge = edges.getJSONObject( i );
+                newNode.addEdge( parseEdge( edge, newNode ) );
+            }
+        }
+        return newNode;
+    }
+
+    private LayeredGraphEdge parseEdge( JSONObject edge, LayeredGraphNode parent ) throws JSONException
+    {
+        if( !edge.has( "source" ) || !edge.has( "target" ) )
+            throw new JSONException( edge + " is no valid Layered Graph Edge." );
+        if( parent.findNodeByName( edge.getString( "source" ) ) == null )
             throw new JSONException( edge + " is no valid Layered Graph Edge." );
         if( parent.findNodeByName( edge.getString( "target" ) ) == null )
             throw new JSONException( edge + " is no valid Layered Graph Edge." );
         LayeredGraphEdge newEdge = parent.createSimpleEdge( null, parent.findNodeByName( edge.getString( "source" ) ), parent.findNodeByName( edge.getString( "target" ) ) );
         if( parent.findNodeByName( edge.getString( "source" ) ).isDummyNode() && parent.findNodeByName( edge.getString( "target" ) ).isDummyNode() )
-        	newEdge.setDummyEdge();
-		return newEdge;
-	}
-	
-	private ArrayList<LayeredGraphNode> parseLayer( JSONArray layer, LayeredGraphNode parent ) throws JSONException
-	{
-		ArrayList<LayeredGraphNode> nodes = new ArrayList<>();
-		for( int i = 0; i < layer.length(); i++ )
-		{
-			JSONObject node = layer.getJSONObject( i );
-			nodes.add( parseNode( node, parent ) );
-		}
-		return nodes;
-	}
+            newEdge.setDummyEdge();
+        return newEdge;
+    }
+
+    private ArrayList<LayeredGraphNode> parseLayer( JSONArray layer, LayeredGraphNode parent ) throws JSONException
+    {
+        ArrayList<LayeredGraphNode> nodes = new ArrayList<>();
+        for( int i = 0; i < layer.length(); i++ )
+        {
+            JSONObject node = layer.getJSONObject( i );
+            nodes.add( parseNode( node, parent ) );
+        }
+        return nodes;
+    }
 }

+ 1 - 1
src/graph/io/Writer.java

@@ -65,7 +65,7 @@ public class Writer {
         node.put( "edges", edges );
         node.put( "name", graph.getName() );
         if( graph.isDummyNode() )
-        	node.put( "dummy", "true" );
+            node.put( "dummy", "true" );
         return node;
     }
     

+ 6 - 6
src/main/Main.java

@@ -16,11 +16,11 @@ public class Main {
      * Will be run when the application is started.
      * @param args the command line arguments, currently not in use
      */
-	public static void main(String[] args) {
-		Reader r = new Reader( "logo.json" );
-		LayeredGraphNode graph = r.readInputGraph();
-		InitializeNodePositions.placeNodes( graph );
-		new MainView( graph );
-	}
+    public static void main(String[] args) {
+        Reader r = new Reader( "logo.json" );
+        LayeredGraphNode graph = r.readInputGraph();
+        InitializeNodePositions.placeNodes( graph );
+        new MainView( graph );
+    }
 
 }

+ 2 - 2
src/view/EdgeView.java

@@ -68,7 +68,7 @@ public class EdgeView extends JPanel {
     @Override
     public Dimension getPreferredSize()
     {
-    	return new Dimension( getWidth(), getHeight() );
+        return new Dimension( getWidth(), getHeight() );
     }
     
     @Override
@@ -90,7 +90,7 @@ public class EdgeView extends JPanel {
         //System.out.println( "Clipping: x:" + g.getClip().getBounds().getX() + " y:" + g.getClip().getBounds().getY() + " w:" + g.getClip().getBounds().getWidth() + " h:" + g.getClip().getBounds().getHeight() );
         g.setColor( Color.GREEN );
         if( model.isConflicted( layout ) )
-        	g.setColor( Color.RED );
+            g.setColor( Color.RED );
         ArrayList<Point> bps = model.getLinePoints( layout );
         for( int i = 1; i < bps.size(); i++ )
         {

+ 129 - 129
src/view/MainView.java

@@ -64,7 +64,7 @@ public class MainView {
      */
     private static int frameCounter = 0;
     private JFrame frame;
-	private AnimationController controller;
+    private AnimationController controller;
     private JButton stepForward;
     private JButton stepForwardInto;
     private JButton stepForwardOut;
@@ -82,24 +82,24 @@ public class MainView {
     private JTextField delay;
     public JTree pseudoTree;
     private LayeredGraphNode graph;
-	
-	private String strToLen( String s, int l )
-	{
-		while( s.length() < l )
-		{
-			s = " " + s + " ";
-		}
-		if( s.length() > l )
-			return s.substring( 0, l );
-		return s;
-	}
-	
-	private String debugInfo()
-	{
-	    String info = "Debug Information Table: \n";
-	    info += "_______________________________________________________________________________________________________________________________________________________________________________________________________________________\n";
-	    info += "|" + strToLen( "Top -> Bottom :> Left", 51 ) + "| |" + strToLen( "Top -> Bottom :> Right", 51 ) + "| |" + strToLen( "Bottom -> Top :> Left", 51 ) + "| |" + strToLen( "Bottom -> Top :> Right", 51 ) + "|\n";
-	    info += "|___________________________________________________| |___________________________________________________| |___________________________________________________| |___________________________________________________|\n";
+
+    private String strToLen( String s, int l )
+    {
+        while( s.length() < l )
+        {
+            s = " " + s + " ";
+        }
+        if( s.length() > l )
+            return s.substring( 0, l );
+        return s;
+    }
+
+    private String debugInfo()
+    {
+        String info = "Debug Information Table: \n";
+        info += "_______________________________________________________________________________________________________________________________________________________________________________________________________________________\n";
+        info += "|" + strToLen( "Top -> Bottom :> Left", 51 ) + "| |" + strToLen( "Top -> Bottom :> Right", 51 ) + "| |" + strToLen( "Bottom -> Top :> Left", 51 ) + "| |" + strToLen( "Bottom -> Top :> Right", 51 ) + "|\n";
+        info += "|___________________________________________________| |___________________________________________________| |___________________________________________________| |___________________________________________________|\n";
         info += "| Node | Shift | Sink | Root | Align |  x  |  xDef  | | Node | Shift | Sink | Root | Align |  x  |  xDef  | | Node | Shift | Sink | Root | Align |  x  |  xDef  | | Node | Shift | Sink | Root | Align |  x  |  xDef  |\n";
         for( LayeredGraphNode n : graph.getContainedNodes() )
         {
@@ -134,36 +134,36 @@ public class MainView {
         }
         info += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------";
         return info;
-	}
-	
-	private void showDebugInfo()
-	{
-	    JFrame debugFrame = new JFrame();
-	    JTextArea info = new JTextArea();
-	    info.setEditable( false );
-	    info.setFont( new Font( Font.MONOSPACED, Font.PLAIN, 11 ) );
-	    String infoS = debugInfo();
-	    info.setText( infoS );
-	    JScrollPane view = new JScrollPane( info );
+    }
+
+    private void showDebugInfo()
+    {
+        JFrame debugFrame = new JFrame();
+        JTextArea info = new JTextArea();
+        info.setEditable( false );
+        info.setFont( new Font( Font.MONOSPACED, Font.PLAIN, 11 ) );
+        String infoS = debugInfo();
+        info.setText( infoS );
+        JScrollPane view = new JScrollPane( info );
         debugFrame.add( view );
         debugFrame.setSize( frame.getWidth(), frame.getHeight() );
-	    debugFrame.setVisible( true );
-	    System.out.println( infoS );
-	}
-
-	public MainView( ElkNode graph )
-	{
-		this( LayeredNode.convertToLayeredGraph( graph ) );
-	}
-	
-	/**
-	 * Initialize the window and its contents.
-	 * @param graph the graph that is displayed in this window.
-	 */
-	public MainView( LayeredGraphNode graph )
-	{
-	    frameCounter++;
-	    this.graph = graph;
+        debugFrame.setVisible( true );
+        System.out.println( infoS );
+    }
+
+    public MainView( ElkNode graph )
+    {
+        this( LayeredNode.convertToLayeredGraph( graph ) );
+    }
+
+    /**
+     * Initialize the window and its contents.
+     * @param graph the graph that is displayed in this window.
+     */
+    public MainView( LayeredGraphNode graph )
+    {
+        frameCounter++;
+        this.graph = graph;
         controller = new AnimationController();
         controller.setTimeBetween( 50 );
         frame = new JFrame( "NodeShuffler" );
@@ -179,11 +179,11 @@ public class MainView {
         BKNodePlacement algorithm = new BKNodePlacement( controller, graph, frame );
         
         // Create Menu GUI
-	    stepForward = new NiceButton( "stepForward" );
-	    stepForward.setLocation( 10, 10 );
-	    stepForward.setMnemonic( KeyEvent.VK_DOWN );
-	    stepForward.setToolTipText( "Forward step over (alt + down arrow key)" );
-	    stepForward.addActionListener( new ActionListener() {
+        stepForward = new NiceButton( "stepForward" );
+        stepForward.setLocation( 10, 10 );
+        stepForward.setMnemonic( KeyEvent.VK_DOWN );
+        stepForward.setToolTipText( "Forward step over (alt + down arrow key)" );
+        stepForward.addActionListener( new ActionListener() {
 
             @Override
             public void actionPerformed(ActionEvent e) {
@@ -192,11 +192,11 @@ public class MainView {
             }
             
         });
-	    stepForwardInto = new NiceButton( "stepForwardInto" );
-	    stepForwardInto.setLocation( 60, 10 );
-	    stepForwardInto.setMnemonic( KeyEvent.VK_RIGHT );
-	    stepForwardInto.setToolTipText( "Forward step into (alt + right arrow key)" );
-	    stepForwardInto.addActionListener( new ActionListener() {
+        stepForwardInto = new NiceButton( "stepForwardInto" );
+        stepForwardInto.setLocation( 60, 10 );
+        stepForwardInto.setMnemonic( KeyEvent.VK_RIGHT );
+        stepForwardInto.setToolTipText( "Forward step into (alt + right arrow key)" );
+        stepForwardInto.addActionListener( new ActionListener() {
 
             @Override
             public void actionPerformed(ActionEvent e) {
@@ -704,34 +704,34 @@ public class MainView {
         treeView.setBounds( 10,  110,  380, 380 );
         
         frame.setSize( (int)graph.getWidth( LayoutType.TOP_BOTTOM_LEFT ) * 2 + 575, (int)graph.getHeight( LayoutType.TOP_BOTTOM_LEFT ) * 2 + 200 );
-		frame.setLocation( 100, 100 );
-		frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
-		frame.setVisible( true );
-		
-		JLayeredPane layne = new JLayeredPane();
-		JPanel pl = new JPanel();
-		GridLayout grout = new GridLayout( 2, 2, 10, 10 );
-		pl.setLayout( grout );
-		pl.setLocation( 0, 0 );
-		pl.setSize( frame.getSize() );
-		NodeView topLeft = createNodeView( graph, LayoutType.TOP_BOTTOM_LEFT );
-		NodeView topRight = createNodeView( graph, LayoutType.TOP_BOTTOM_RIGHT );
-		NodeView bottomLeft = createNodeView( graph, LayoutType.BOTTOM_TOP_LEFT );
-		NodeView bottomRight = createNodeView( graph, LayoutType.BOTTOM_TOP_RIGHT );
-		pl.add( topLeft );
-		pl.add( topRight );
-		pl.add( bottomLeft );
-		pl.add( bottomRight );
-		layne.add( pl, 1 );
-		NodeView combined = createNodeView( graph, LayoutType.COMBINED );
-		combined.setSize( 500, 500 );
-		layne.add( combined, 0 );
-		frame.add( layne );
-		JPanel menue = new JPanel();
-		menue.setLayout( null );
-		menue.setPreferredSize( new Dimension( 400, 500 ) );
-		menue.add( stepForward );
-		menue.add( stepForwardInto );
+        frame.setLocation( 100, 100 );
+        frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
+        frame.setVisible( true );
+
+        JLayeredPane layne = new JLayeredPane();
+        JPanel pl = new JPanel();
+        GridLayout grout = new GridLayout( 2, 2, 10, 10 );
+        pl.setLayout( grout );
+        pl.setLocation( 0, 0 );
+        pl.setSize( frame.getSize() );
+        NodeView topLeft = createNodeView( graph, LayoutType.TOP_BOTTOM_LEFT );
+        NodeView topRight = createNodeView( graph, LayoutType.TOP_BOTTOM_RIGHT );
+        NodeView bottomLeft = createNodeView( graph, LayoutType.BOTTOM_TOP_LEFT );
+        NodeView bottomRight = createNodeView( graph, LayoutType.BOTTOM_TOP_RIGHT );
+        pl.add( topLeft );
+        pl.add( topRight );
+        pl.add( bottomLeft );
+        pl.add( bottomRight );
+        layne.add( pl, 1 );
+        NodeView combined = createNodeView( graph, LayoutType.COMBINED );
+        combined.setSize( 500, 500 );
+        layne.add( combined, 0 );
+        frame.add( layne );
+        JPanel menue = new JPanel();
+        menue.setLayout( null );
+        menue.setPreferredSize( new Dimension( 400, 500 ) );
+        menue.add( stepForward );
+        menue.add( stepForwardInto );
         menue.add( stepForwardOut );
         menue.add( runForward );
         menue.add( pause );
@@ -746,56 +746,56 @@ public class MainView {
         menue.add( randomGraph );
         menue.add( save );
         menue.add( load );
-		frame.add( menue, BorderLayout.EAST );
-		frame.setSize( frame.getWidth() + 1, frame.getHeight() );
+        frame.add( menue, BorderLayout.EAST );
+        frame.setSize( frame.getWidth() + 1, frame.getHeight() );
         frame.setSize( frame.getWidth() - 1, frame.getHeight() );
-		frame.validate();
-		frame.repaint();
-		
-		frame.addComponentListener(new ComponentAdapter() 
-		{  
-	        public void componentResized(ComponentEvent evt) {
-	    		pl.setSize( layne.getSize() );
-	    		menue.setSize( menue.getWidth(), layne.getHeight() );
-	    		treeView.setSize( treeView.getWidth(), layne.getHeight() - 120 );
-	    		if( graph.getColor( LayoutType.COMBINED ) == null )
-	    		{
-		    		grout.setHgap( 10 );
-		    		grout.setVgap( 10 );
-	    		}
-	    		else
-	    		{
-	    			grout.setHgap( layne.getWidth() / 3 );
-	    			grout.setVgap( layne.getHeight() / 3 );
-	    		}
-	    		combined.setSize( layne.getWidth() / 3, layne.getHeight() / 3 );
-	    		combined.setLocation( layne.getWidth() / 3, layne.getHeight() / 3 );
-	    		
-	    		layne.remove( pl );
-	            layne.add( pl, 1 );
-	            frame.repaint();
-	        }
-		});
+        frame.validate();
+        frame.repaint();
+
+        frame.addComponentListener(new ComponentAdapter()
+        {
+            public void componentResized(ComponentEvent evt) {
+                pl.setSize( layne.getSize() );
+                menue.setSize( menue.getWidth(), layne.getHeight() );
+                treeView.setSize( treeView.getWidth(), layne.getHeight() - 120 );
+                if( graph.getColor( LayoutType.COMBINED ) == null )
+                {
+                    grout.setHgap( 10 );
+                    grout.setVgap( 10 );
+                }
+                else
+                {
+                    grout.setHgap( layne.getWidth() / 3 );
+                    grout.setVgap( layne.getHeight() / 3 );
+                }
+                combined.setSize( layne.getWidth() / 3, layne.getHeight() / 3 );
+                combined.setLocation( layne.getWidth() / 3, layne.getHeight() / 3 );
+
+                layne.remove( pl );
+                layne.add( pl, 1 );
+                frame.repaint();
+            }
+        });
         algorithm.start();
-	}
-	
-	private NodeView createNodeView( LayeredGraphNode gNode, LayoutType lt )
-	{
-		NodeView graphView = new NodeView( gNode, lt );
-		graphView.setLayout( null );
-		graphView.setOpaque( true );
-		for( LayeredGraphNode n : gNode.getContainedNodes() )
-		{
-		    NodeView nv = createNodeView( n, lt );
-		    nv.setBounds( nv.getX(), nv.getY(), nv.getWidth(), nv.getHeight() );
-			graphView.add( nv );
-		}
+    }
+
+    private NodeView createNodeView( LayeredGraphNode gNode, LayoutType lt )
+    {
+        NodeView graphView = new NodeView( gNode, lt );
+        graphView.setLayout( null );
+        graphView.setOpaque( true );
+        for( LayeredGraphNode n : gNode.getContainedNodes() )
+        {
+            NodeView nv = createNodeView( n, lt );
+            nv.setBounds( nv.getX(), nv.getY(), nv.getWidth(), nv.getHeight() );
+            graphView.add( nv );
+        }
         for( LayeredGraphEdge e : gNode.getContainedEdges() )
         {
             EdgeView ev = new EdgeView( e, lt );
             ev.setOpaque( true );
             graphView.add( ev );
         }
-		return graphView;
-	}
+        return graphView;
+    }
 }

+ 54 - 54
src/view/NodeView.java

@@ -20,33 +20,33 @@ import graph.LayeredGraphNode;
  *
  */
 public class NodeView extends JPanel {
-	private static final long serialVersionUID = 1L;
-	private LayeredGraphNode model;
-	private LayoutType layout;
-	
-	public NodeView( LayeredGraphNode model, LayoutType lt ) {
-		this.model = model;
-		layout = lt;
-		setSize( (int)model.getWidth( layout ), (int)model.getHeight( layout ) );
-	}
-	
-	@Override
-	public Point getLocation()
-	{
-	    return new Point( (int)model.getX( layout ), (int)model.getY( layout ) );
-	}
+    private static final long serialVersionUID = 1L;
+    private LayeredGraphNode model;
+    private LayoutType layout;
+
+    public NodeView( LayeredGraphNode model, LayoutType lt ) {
+        this.model = model;
+        layout = lt;
+        setSize( (int)model.getWidth( layout ), (int)model.getHeight( layout ) );
+    }
+
+    @Override
+    public Point getLocation()
+    {
+        return new Point( (int)model.getX( layout ), (int)model.getY( layout ) );
+    }
     
     @Override
     public Dimension getPreferredSize()
     {
-    	return new Dimension( (int)model.getWidth( layout ), (int)model.getHeight( layout ) );
+        return new Dimension( (int)model.getWidth( layout ), (int)model.getHeight( layout ) );
     }
     
     @Override
     public void paint( Graphics g )
     {
-    	if( layout == LayoutType.COMBINED && model.getColor( layout ) == null )
-    		return;
+        if( layout == LayoutType.COMBINED && model.getColor( layout ) == null )
+            return;
         double scale = Math.min( (double)super.getWidth() / (int)model.getWidth( layout ), (double)super.getHeight() / (int)model.getHeight( layout ));
         ((Graphics2D)g).scale( scale, scale );
         paintComponent( g );
@@ -65,40 +65,40 @@ public class NodeView extends JPanel {
         }
     }
 
-	@Override
-	public void paintComponent( Graphics g )
-	{
-		Graphics2D g2 = (Graphics2D)g;
-		g2.setColor( model.getColor( layout ) );
-		g2.setStroke(new BasicStroke(5));
-		if( model.getContainedNodes().size() == 0 )
-		{
-			if( model.getRoot( layout ) == model )
-				g2.fillOval( 0, 0, (int)model.getWidth( layout )-1, (int)model.getHeight( layout )-1 );
-			else
-				g2.fillRect( 0, 0, (int)model.getWidth( layout )-1, (int)model.getHeight( layout )-1 );
-		}
-		boolean selected = model.isSelected( layout );
-		if( selected )
-		{
-			g.setColor( Color.BLACK );
-			if( model.getContainedNodes().size() > 0 )
-			    g.setColor( Color.GRAY );
-			g.fillRect( 0, 0, (int)model.getWidth( layout )-1, (int)model.getHeight( layout )-1 );
-		}
-		Border linebor = BorderFactory.createLineBorder(model.getColor( layout ), 5);
-		if( model.getRoot( layout ) != model || model.getContainedNodes().size() != 0  )
-			linebor.paintBorder( this, g2, 0, 0, (int)model.getWidth( layout )-1, (int)model.getHeight( layout )-1 );
-		if( layout != LayoutType.COMBINED && model.getRoot( layout ).getSink( layout ).getColor( layout ) != model.getColor( layout ))
-		{
-    		g.setColor( model.getRoot( layout ).getSink( layout ).getColor( layout ) );
-    		if( model.getContainedNodes().size() == 0 )
-    		{
-    		    if( selected )
-    		        g.fillOval( (int)model.getWidth( layout ) / 2 - (int)model.getWidth( layout ) / 5, (int)model.getHeight( layout ) / 2 - (int)model.getHeight( layout ) / 5, (int)model.getWidth( layout ) / 5 * 2, (int)model.getHeight( layout ) / 5 * 2 );
-    		    else
-    		        g.fillOval( (int)model.getWidth( layout ) / 2 - (int)model.getWidth( layout ) / 3, (int)model.getHeight( layout ) / 2 - (int)model.getHeight( layout ) / 3, (int)model.getWidth( layout ) / 3 * 2, (int)model.getHeight( layout ) / 3 * 2 );
-    		}
-		}
-	}
+    @Override
+    public void paintComponent( Graphics g )
+    {
+        Graphics2D g2 = (Graphics2D)g;
+        g2.setColor( model.getColor( layout ) );
+        g2.setStroke(new BasicStroke(5));
+        if( model.getContainedNodes().size() == 0 )
+        {
+            if( model.getRoot( layout ) == model )
+                g2.fillOval( 0, 0, (int)model.getWidth( layout )-1, (int)model.getHeight( layout )-1 );
+            else
+                g2.fillRect( 0, 0, (int)model.getWidth( layout )-1, (int)model.getHeight( layout )-1 );
+        }
+        boolean selected = model.isSelected( layout );
+        if( selected )
+        {
+            g.setColor( Color.BLACK );
+            if( model.getContainedNodes().size() > 0 )
+                g.setColor( Color.GRAY );
+            g.fillRect( 0, 0, (int)model.getWidth( layout )-1, (int)model.getHeight( layout )-1 );
+        }
+        Border linebor = BorderFactory.createLineBorder(model.getColor( layout ), 5);
+        if( model.getRoot( layout ) != model || model.getContainedNodes().size() != 0  )
+            linebor.paintBorder( this, g2, 0, 0, (int)model.getWidth( layout )-1, (int)model.getHeight( layout )-1 );
+        if( layout != LayoutType.COMBINED && model.getRoot( layout ).getSink( layout ).getColor( layout ) != model.getColor( layout ))
+        {
+            g.setColor( model.getRoot( layout ).getSink( layout ).getColor( layout ) );
+            if( model.getContainedNodes().size() == 0 )
+            {
+                if( selected )
+                    g.fillOval( (int)model.getWidth( layout ) / 2 - (int)model.getWidth( layout ) / 5, (int)model.getHeight( layout ) / 2 - (int)model.getHeight( layout ) / 5, (int)model.getWidth( layout ) / 5 * 2, (int)model.getHeight( layout ) / 5 * 2 );
+                else
+                    g.fillOval( (int)model.getWidth( layout ) / 2 - (int)model.getWidth( layout ) / 3, (int)model.getHeight( layout ) / 2 - (int)model.getHeight( layout ) / 3, (int)model.getWidth( layout ) / 3 * 2, (int)model.getHeight( layout ) / 3 * 2 );
+            }
+        }
+    }
 }