1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package bk;
- import javax.swing.JFrame;
- import javax.swing.JTree;
- import animation.AnimatedAlgorithm;
- import animation.AnimationController;
- import animation.CodeLine;
- import animation.ControlFlow;
- import animation.Memory;
- import animation.PseudoCodeNode;
- import animation.PseudoCodeProcessor;
- import animation.Memory.MemoryType;
- import codelines.FunctionCall;
- import codelines.FunctionDefinition;
- import graph.LayeredGraphNode;
- import lib.TextLayoutHelper;
- /**
- * The main stage of the BK node placement algorithm.
- * @author kolja
- *
- */
- public class BKNodePlacement extends AnimatedAlgorithm {
- public enum State
- {
- CONFLICTS,
- LAYOUT1,
- LAYOUT2,
- LAYOUT3,
- LAYOUT4,
- COMBINE
- }
-
- private State state;
-
- public BKNodePlacement(AnimationController controller, LayeredGraphNode graph, JFrame view) {
- super(controller, graph, view);
- state = State.CONFLICTS;
- }
-
- public State getAlgorithmState()
- {
- return state;
- }
-
- public void setAlgorithmState( State s )
- {
- state = s;
- }
- @Override
- public PseudoCodeNode createPseudocodeTree( JTree tree )
- {
- String[] vars = { "graph" };
- PseudoCodeNode mainFunction = new PseudoCodeNode( TextLayoutHelper.setupPseudoCode("function bkNodePlacement( graph )", vars ), tree, new FunctionDefinition( new String[]{"graph"} ) );
- root = new PseudoCodeNode( TextLayoutHelper.setupPseudoCodeStage("-- BK Node Placement Algorithm --" ), tree, new CodeLine() {
- @Override
- public ControlFlow runForward(Memory m) {
- m.declare( "param1", graph, MemoryType.GLOBAL );
- if( m.isDefined( "Called", MemoryType.GLOBAL ) )
- {
- actions.push( (Memory mem) -> {
- m.undeclare( "param1", MemoryType.GLOBAL );
- } );
- return new ControlFlow( ControlFlow.STEP_OVER );
- }
- m.declare( "Called", true, MemoryType.GLOBAL );
- actions.push( (Memory mem) -> {
- m.undeclare( "param1", MemoryType.GLOBAL );
- m.undeclare( "Called", MemoryType.GLOBAL );
- } );
- return new ControlFlow( mainFunction );
- }
-
- } );
- root.setSelected( true );
-
- PseudoCodeNode conflictDetectionFunction = new ConflictDetection( this ).createPseudocodeTree( tree );
- PseudoCodeNode node1 = new PseudoCodeNode( TextLayoutHelper.setupPseudoCode( "call detectConflicts( graph )", vars ), tree, new FunctionCall( conflictDetectionFunction, new String[]{ "graph" } ) );
- root.add( mainFunction );
- mainFunction.add( node1 );
- root.add( conflictDetectionFunction );
- processor = new PseudoCodeProcessor( root );
- return root;
- }
- }
|