Jelajahi Sumber

layouting problems fixed

Kolja Strohm 7 tahun lalu
induk
melakukan
229986f076

+ 32 - 8
src/animation/AnimatedAlgorithm.java

@@ -1,17 +1,37 @@
 package animation;
 
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+
+import javax.swing.JFrame;
+import javax.swing.SwingUtilities;
+
 import graph.LayeredGraphNode;
-import view.MainView;
 
 public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage {
 
 	protected AnimationController ac;
 	protected LayeredGraphNode graph;
+	private JFrame view;
 	
-	public AnimatedAlgorithm( AnimationController controller, LayeredGraphNode graph )
+	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();
+                for( ComponentListener l : view.getComponentListeners() )
+                {
+                    l.componentResized( new ComponentEvent(view, 0) );
+                }
+            }
+        });
 	}
 	
 	@Override
@@ -24,27 +44,31 @@ public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage
 				{
 				case FORWARD:
 					forwardStep();
-                    MainView.frame.repaint();
+					update();
 					break;
                 case FORWARD_OUT:
                     forwardStepOut();
-                    MainView.frame.repaint();
+                    graph.unselectGraph();
+                    update();
                     break;
                 case FORWARD_OVER:
                     forwardStepOver();
-                    MainView.frame.repaint();
+                    graph.unselectGraph();
+                    update();
                     break;
 				case BACKWARD:
 					backwardStep();
-                    MainView.frame.repaint();
+                    update();
 					break;
                 case BACKWARD_OUT:
                     backwardStepOut();
-                    MainView.frame.repaint();
+                    graph.unselectGraph();
+                    update();
                     break;
                 case BACKWARD_OVER:
                     backwardStepOver();
-                    MainView.frame.repaint();
+                    graph.unselectGraph();
+                    update();
                     break;
                 default:
                     break;

+ 4 - 2
src/bk/BKNodePlacement.java

@@ -2,6 +2,8 @@ package bk;
 
 import java.lang.reflect.InvocationTargetException;
 
+import javax.swing.JFrame;
+
 import animation.AlgorithmStage;
 import animation.AnimatedAlgorithm;
 import animation.AnimationController;
@@ -41,8 +43,8 @@ public class BKNodePlacement extends AnimatedAlgorithm {
     private PseudoCodeNode combineNode;
     private boolean inside;
 	
-	public BKNodePlacement(AnimationController controller, LayeredGraphNode graph) {
-		super(controller, graph);
+	public BKNodePlacement(AnimationController controller, LayeredGraphNode graph, JFrame view) {
+		super(controller, graph, view);
 		state = State.CONFLICTS;
 		conftion = new ConflictDetection( graph );
 		layouts = new ExtremalLayoutCalc[ 4 ];

+ 4 - 4
src/bk/Combine.java

@@ -80,16 +80,16 @@ public class Combine implements AlgorithmStage {
 			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() );
+			//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 );
                 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() );
+				//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 );

+ 1 - 1
src/bk/Compaction.java

@@ -63,7 +63,7 @@ public class Compaction implements AlgorithmStage{
 		for( LayeredGraphNode n : graph.getContainedNodes() )
 			max = Math.max( max, n.getWidth( layout ) );
 		//return max + 25;
-		return max;
+		return max + 5;
 	}
 	
 	private LayeredGraphNode getNodeFromIndex( int index )

+ 1 - 1
src/graph/LayeredGraphNode.java

@@ -36,11 +36,11 @@ public interface LayeredGraphNode {
     public String getName();
     public void setColor( Color c, LayoutType layout );
     public Color getColor( LayoutType layout );
-    public void update();
     public void setSelected( LayoutType layoutType );
     public boolean isSelected( LayoutType layout );
     public void setDummyNode( boolean dummy );
     public boolean isDummyNode();
+    public void unselectGraph();
     
     /**
      * Setzt den Index des Layers, zu dem der Knoten geh�ren soll

+ 14 - 14
src/graph/LayeredNode.java

@@ -3,13 +3,10 @@ package graph;
 import java.awt.Color;
 import java.util.ArrayList;
 
-import javax.swing.SwingUtilities;
-
 import org.eclipse.elk.graph.ElkEdge;
 import org.eclipse.elk.graph.ElkNode;
 
 import bk.ExtremalLayoutCalc.LayoutType;
-import view.MainView;
 
 /**
  * Die Implementation eines Knotens in einem Layered Graph.
@@ -263,16 +260,6 @@ public class LayeredNode implements LayeredGraphNode {
         return null;
     }
 
-    @Override
-    public void update()
-    {
-    	SwingUtilities.invokeLater(new Runnable() {
-		    public void run() {
-		        MainView.frame.repaint();
-		    }
-		});
-    }
-
     @Override
     public void setSelected( LayoutType layout )
     {
@@ -294,7 +281,20 @@ public class LayeredNode implements LayeredGraphNode {
             this.layouts[ 3 ].selected = true;
         if( layout == LayoutType.COMBINED )
         	combined.selected = true;
-    	update();
+    }
+    
+    @Override
+    public void unselectGraph()
+    {
+        for( LayeredGraphNode n : nodes)
+        {
+            n.unselectGraph();
+        }
+        this.layouts[ 0 ].selected = false;
+        this.layouts[ 1 ].selected = false;
+        this.layouts[ 2 ].selected = false;
+        this.layouts[ 3 ].selected = false;
+        combined.selected = false;
     }
 
     @Override

+ 7 - 5
src/view/MainView.java

@@ -45,7 +45,7 @@ public class MainView {
      * The 'frame' of the main window.
      * The reason why there can only be one instance of this class.
      */
-    public static JFrame frame;
+    private JFrame frame;
 	private AnimationController controller;
     private JButton stepForward;
     private JButton stepForwardInto;
@@ -137,7 +137,8 @@ public class MainView {
 	    this.graph = graph;
         controller = new AnimationController();
         controller.setTimeBetween( 50 );
-        BKNodePlacement algorithm = new BKNodePlacement( controller, graph );
+        frame = new JFrame();
+        BKNodePlacement algorithm = new BKNodePlacement( controller, graph, frame );
         
         // Create Menu GUI
 	    stepForward = new NiceButton( "stepForward" );
@@ -307,7 +308,6 @@ public class MainView {
         JScrollPane treeView = new JScrollPane( pseudoTree );
         treeView.setBounds( 10,  110,  380, 380 );
         
-		frame = new JFrame(); // this may write to a static field because there should be only one instance of this class.
         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 );
 		frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
@@ -408,8 +408,10 @@ public class MainView {
 	    		}
 	    		combined.setSize( layne.getWidth() / 3, layne.getHeight() / 3 );
 	    		combined.setLocation( layne.getWidth() / 3, layne.getHeight() / 3 );
-	    		frame.validate();
-	    		frame.repaint();
+	    		
+	    		layne.remove( pl );
+	            layne.add( pl, 1 );
+	            frame.repaint();
 	        }
 		});
         algorithm.start();

+ 0 - 2
src/view/NodeView.java

@@ -57,8 +57,6 @@ public class NodeView extends JPanel {
         }
         for( Component c : getComponents() )
         {
-            if( c.getLocation().x < 0 )
-                System.out.println( "x: " + c.getLocation().x + " y: " + c.getLocation().y );
             c.paint( g.create( 
                     c.getLocation().x + 25 - (int)minX, 
                     c.getLocation().y + 25,