Bläddra i källkod

Fehler in Conflict Detection behoben

Kolja Strohm 7 år sedan
förälder
incheckning
42dd36881a

+ 12 - 2
src/Algorithms/Animated/BK/Combine.java

@@ -1,7 +1,12 @@
 package Algorithms.Animated.BK;
 
+import java.awt.Color;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+
 import Algorithms.Animated.AlgorithmStage;
 import Model.LayeredGraphNode;
+import View.MainView;
 
 /**
  * The stage of the combination of the four extremal layouts.
@@ -10,14 +15,19 @@ import Model.LayeredGraphNode;
  */
 public class Combine implements AlgorithmStage {
 
+	LayeredGraphNode graph;
+	
 	public Combine( LayeredGraphNode graph )
 	{
-		
+		this.graph = graph;
 	}
 	
 	@Override
 	public StageStatus forwardStep() {
-		// TODO Auto-generated method stub
+		MainView.frame.setSize( MainView.frame.getWidth() + 1, MainView.frame.getHeight() );
+		MainView.frame.setSize( MainView.frame.getWidth() - 1, MainView.frame.getHeight() );
+		
+		graph.setColor( Color.BLACK, null );
 		return null;
 	}
 

+ 2 - 0
src/Algorithms/Animated/BK/ConflictDetection.java

@@ -27,6 +27,8 @@ public class ConflictDetection implements AlgorithmStage {
     public StageStatus forwardStep() {
     	int oldI = i;
     	int oldL1 = l1;
+    	if( i + 1 >= graph.getContainedLayers().size() - 1 )
+    		return StageStatus.FINISHED;
     	LayeredGraphNode curr = graph.getContainedLayers().get( i + 1 ).get( l1 );
     	curr.setSelected( null );
     	ArrayList< LayeredGraphEdge > edges = curr.getIncomingEdges();

+ 1 - 1
src/Main.java

@@ -13,7 +13,7 @@ import View.MainView;
 public class Main {
 
 	public static void main(String[] args) {
-		Reader r = new Reader( "papergraph.json" );
+		Reader r = new Reader( "test3.json" );
 		LayeredGraphNode graph = r.readInputGraph();
 	    //RandomGraphGenerator r = new RandomGraphGenerator( 0.1, 0.2, 5,5, 5, 5, 1 );
 	    //LayeredGraphNode graph = r.createRandomNode( null, 0 );

+ 25 - 7
src/View/MainView.java

@@ -50,7 +50,7 @@ public class MainView {
 	public MainView( LayeredGraphNode graph )
 	{
 		controller = new AnimationController();
-		controller.setTimeBetween( 10 );
+		controller.setTimeBetween( 1 );
 		frame = new JFrame();
         frame.setSize( Math.min( (int)graph.getWidth( LayoutType.TOP_BOTTOM_LEFT ) * 2 + 200, 1700 ), Math.min( (int)graph.getHeight( LayoutType.TOP_BOTTOM_LEFT ) * 2 + 200, 900 ) );
 		frame.setLocation( 100, 100 );
@@ -131,13 +131,18 @@ public class MainView {
 		
 		JLayeredPane layne = new JLayeredPane();
 		JPanel pl = new JPanel();
-		pl.setLayout(new GridLayout( 2, 2, 500, 500 ) );
+		GridLayout grout = new GridLayout( 2, 2, 10, 10 );
+		pl.setLayout( grout );
 		pl.setLocation( 0, 0 );
 		pl.setSize( frame.getSize() );
-		pl.add(createNodeView( graph, LayoutType.TOP_BOTTOM_LEFT ));
-		pl.add(createNodeView( graph, LayoutType.TOP_BOTTOM_RIGHT ));
-		pl.add(createNodeView( graph, LayoutType.BOTTOM_TOP_LEFT ));
-		pl.add(createNodeView( graph, LayoutType.BOTTOM_TOP_RIGHT ));
+		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 );
@@ -150,7 +155,20 @@ public class MainView {
 		{  
 	        public void componentResized(ComponentEvent evt) {
 	    		pl.setSize( layne.getSize() );
-	    		combined.setLocation( layne.getWidth() / 2 - combined.getWidth() / 2, layne.getHeight() / 2 - combined.getHeight() / 2 );
+	    		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 );
+	    		frame.validate();
+	    		frame.repaint();
 	        }
 		});
 		new BKNodePlacement( controller, graph );

+ 2 - 0
src/View/NodeView.java

@@ -45,6 +45,8 @@ public class NodeView extends JPanel {
     @Override
     public void paint( Graphics g )
     {
+    	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 );