浏览代码

Debug info eingebaut

Kolja Strohm 6 年之前
父节点
当前提交
65d23d957f

+ 2 - 0
src/animation/AlgorithmStage.java

@@ -47,4 +47,6 @@ public interface AlgorithmStage {
     public StageStatus backwardStepOut();
 
     public PseudoCodeNode createPseudocodeTree( JTree tree );
+    
+    public String getDebugString();
 }

+ 7 - 1
src/animation/PseudoCodeNode.java

@@ -79,11 +79,17 @@ public class PseudoCodeNode extends DefaultMutableTreeNode {
     {
         if( selected && breakPoint )
             controller.setContinuous( false );
+        this.selected = selected;
         if( selected )
+        {
+            tree.collapsePath( new TreePath( this.getPath() ) );
             tree.expandPath( new TreePath( this.getPath() ) );
+        }
         else
+        {
+            tree.expandPath( new TreePath( this.getPath() ) );
             tree.collapsePath( new TreePath( this.getPath() ) );
-        this.selected = selected;
+        }
         return !breakPoint || !selected;
     }
     

+ 23 - 0
src/bk/BKNodePlacement.java

@@ -139,6 +139,29 @@ public class BKNodePlacement extends AnimatedAlgorithm {
         else
             return backward( "backwardStepOut" );
     }
+
+    @Override
+    public String getDebugString()
+    {
+        if( !inside )
+            return "";
+        switch( state )
+        {
+        case CONFLICTS:
+            return combine.getDebugString();
+        case LAYOUT1:
+            return layouts[ 0 ].getDebugString();
+        case LAYOUT2:
+            return layouts[ 1 ].getDebugString();
+        case LAYOUT3:
+            return layouts[ 2 ].getDebugString();
+        case LAYOUT4:
+            return layouts[ 3 ].getDebugString();
+        case COMBINE:
+            return combine.getDebugString();
+        }
+        return "";
+    }
     
     private StageStatus forward( String fName )
     {

+ 6 - 0
src/bk/BlockCalc.java

@@ -418,4 +418,10 @@ public class BlockCalc implements AlgorithmStage {
             return StageStatus.UNFINISHED;
         }
     }
+    
+    @Override
+    public String getDebugString()
+    {
+        return "";
+    }
 }

+ 21 - 8
src/bk/Combine.java

@@ -11,6 +11,7 @@ import animation.BackwardAction;
 import animation.PseudoCodeNode;
 import bk.ExtremalLayoutCalc.LayoutType;
 import graph.LayeredGraphNode;
+import lib.TextLayoutHelper;
 
 /**
  * The stage of the combination of the four extremal layouts.
@@ -84,8 +85,6 @@ 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() );
             actions.add( 0, () -> {
                 inside = false;
                 setNode.setSelected( false );
@@ -94,8 +93,6 @@ public class Combine implements AlgorithmStage {
                     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 );
@@ -118,10 +115,10 @@ public class Combine implements AlgorithmStage {
             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 );
+            positions.add( (Integer)(int)current.getX( LayoutType.TOP_BOTTOM_LEFT ) + tblOffset );
+            positions.add( (Integer)(int)current.getX( LayoutType.TOP_BOTTOM_RIGHT ) + tbrOffset );
+            positions.add( (Integer)(int)current.getX( LayoutType.BOTTOM_TOP_LEFT ) + btlOffset );
+            positions.add( (Integer)(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 );
@@ -243,4 +240,20 @@ public class Combine implements AlgorithmStage {
             return stage;
         }
     }
+    
+    @Override
+    public String getDebugString()
+    {
+        String info = "| Node |  x  | x TL | x TR | x BL | x BR |\n";
+        for( LayeredGraphNode n : graph.getContainedNodes() )
+        {
+            info += "|" + TextLayoutHelper.strToLen( n.getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.COMBINED ) + "", 5 ) + 
+                    "|" + TextLayoutHelper.strToLen( ( n.getX( LayoutType.TOP_BOTTOM_LEFT ) + tblOffset ) + "", 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( ( n.getX( LayoutType.TOP_BOTTOM_RIGHT ) + tbrOffset ) + "", 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( ( n.getX( LayoutType.BOTTOM_TOP_LEFT ) + btlOffset ) + "", 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( ( n.getX( LayoutType.BOTTOM_TOP_RIGHT ) + btrOffset ) + "", 6 ) + "|\n";
+        }
+        return info;
+    }
 }

+ 6 - 0
src/bk/Compaction.java

@@ -455,4 +455,10 @@ public class Compaction implements AlgorithmStage{
             return stage;
         }
     }
+    
+    @Override
+    public String getDebugString()
+    {
+        return "";
+    }
 }

+ 8 - 0
src/bk/ConflictDetection.java

@@ -7,8 +7,10 @@ import javax.swing.JTree;
 import animation.AlgorithmStage;
 import animation.BackwardAction;
 import animation.PseudoCodeNode;
+import bk.ExtremalLayoutCalc.LayoutType;
 import graph.LayeredGraphEdge;
 import graph.LayeredGraphNode;
+import lib.TextLayoutHelper;
 
 public class ConflictDetection implements AlgorithmStage {
 
@@ -157,4 +159,10 @@ public class ConflictDetection implements AlgorithmStage {
             status = backwardStep();
         return status;
     }
+
+    @Override
+    public String getDebugString()
+    {
+        return "";
+    }
 }

+ 20 - 0
src/bk/ExtremalLayoutCalc.java

@@ -7,6 +7,7 @@ import javax.swing.JTree;
 import animation.AlgorithmStage;
 import animation.PseudoCodeNode;
 import graph.LayeredGraphNode;
+import lib.TextLayoutHelper;
 
 /**
  * The stage where the for extremal layouts are computed.
@@ -37,10 +38,12 @@ public class ExtremalLayoutCalc implements AlgorithmStage {
     private PseudoCodeNode cpNode;
     private LayoutType type;
     private boolean inside;
+    private LayeredGraphNode graph;
 
 
     public ExtremalLayoutCalc( LayoutType typ, LayeredGraphNode graph )
     {
+        this.graph = graph;
         type = typ;
         status = LayoutState.BLOCK_CALCULATION;
         bc = new BlockCalc( graph, typ );
@@ -128,6 +131,23 @@ public class ExtremalLayoutCalc implements AlgorithmStage {
         else
             return backward( "backwardStepOut" );
     }
+
+    @Override
+    public String getDebugString()
+    {
+        String info = "| Node | Shift | Sink | Root | Align |  x  |  xDef  |\n";
+        for( LayeredGraphNode n : graph.getContainedNodes() )
+        {
+            info += "|" + TextLayoutHelper.strToLen( n.getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getShift( type ) + "", 7 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getSink( type ).getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getRoot( type ).getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getAlign( type ).getName(), 7 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getX( type ) + "", 5 ) + 
+                    "|" + TextLayoutHelper.strToLen( !n.isXUndefined( type ) + "", 8 ) + "|\n";
+        }
+        return info;
+    }
     
     private StageStatus forward( String fName )
     {

+ 14 - 0
src/lib/TextLayoutHelper.java

@@ -0,0 +1,14 @@
+package lib;
+
+public class TextLayoutHelper {
+    public static String strToLen( String s, int l )
+    {
+        while( s.length() < l )
+        {
+            s = " " + s + " ";
+        }
+        if( s.length() > l )
+            return s.substring( 0, l );
+        return s;
+    }
+}

+ 42 - 41
src/view/MainView.java

@@ -50,6 +50,7 @@ import graph.RandomGraphGenerator;
 import graph.io.Reader;
 import graph.io.Writer;
 import lib.SweepCrossingMinimizer;
+import lib.TextLayoutHelper;
 
 /**
  * The main window of the application.
@@ -84,54 +85,43 @@ public class MainView {
     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 += "|" + TextLayoutHelper.strToLen( "Top -> Bottom :> Left", 51 ) + "| |" + TextLayoutHelper.strToLen( "Top -> Bottom :> Right", 51 ) + "| |" + TextLayoutHelper.strToLen( "Bottom -> Top :> Left", 51 ) + "| |" + TextLayoutHelper.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() )
         {
-            info += "|" + strToLen( n.getName(), 6 ) + 
-                    "|" + strToLen( n.getShift( LayoutType.TOP_BOTTOM_LEFT ) + "", 7 ) + 
-                    "|" + strToLen( n.getSink( LayoutType.TOP_BOTTOM_LEFT ).getName(), 6 ) + 
-                    "|" + strToLen( n.getRoot( LayoutType.TOP_BOTTOM_LEFT ).getName(), 6 ) + 
-                    "|" + strToLen( n.getAlign( LayoutType.TOP_BOTTOM_LEFT ).getName(), 7 ) + 
-                    "|" + strToLen( n.getX( LayoutType.TOP_BOTTOM_LEFT ) + "", 5 ) + 
-                    "|" + strToLen( !n.isXUndefined( LayoutType.TOP_BOTTOM_LEFT ) + "", 8 ) + "| " +
-                    "|" + strToLen( n.getName(), 6 ) + 
-                    "|" + strToLen( n.getShift( LayoutType.TOP_BOTTOM_RIGHT ) + "", 7 ) + 
-                    "|" + strToLen( n.getSink( LayoutType.TOP_BOTTOM_RIGHT ).getName(), 6 ) + 
-                    "|" + strToLen( n.getRoot( LayoutType.TOP_BOTTOM_RIGHT ).getName(), 6 ) + 
-                    "|" + strToLen( n.getAlign( LayoutType.TOP_BOTTOM_RIGHT ).getName(), 7 ) + 
-                    "|" + strToLen( n.getX( LayoutType.TOP_BOTTOM_RIGHT ) + "", 5 ) + 
-                    "|" + strToLen( !n.isXUndefined( LayoutType.TOP_BOTTOM_RIGHT ) + "", 8 ) + "| " +
-                    "|" + strToLen( n.getName(), 6 ) + 
-                    "|" + strToLen( n.getShift( LayoutType.BOTTOM_TOP_LEFT ) + "", 7 ) + 
-                    "|" + strToLen( n.getSink( LayoutType.BOTTOM_TOP_LEFT ).getName(), 6 ) + 
-                    "|" + strToLen( n.getRoot( LayoutType.BOTTOM_TOP_LEFT ).getName(), 6 ) + 
-                    "|" + strToLen( n.getAlign( LayoutType.BOTTOM_TOP_LEFT ).getName(), 7 ) + 
-                    "|" + strToLen( n.getX( LayoutType.BOTTOM_TOP_LEFT ) + "", 5 ) + 
-                    "|" + strToLen( !n.isXUndefined( LayoutType.BOTTOM_TOP_LEFT ) + "", 8 ) + "| " +
-                    "|" + strToLen( n.getName(), 6 ) + 
-                    "|" + strToLen( n.getShift( LayoutType.BOTTOM_TOP_RIGHT ) + "", 7 ) + 
-                    "|" + strToLen( n.getSink( LayoutType.BOTTOM_TOP_RIGHT ).getName(), 6 ) + 
-                    "|" + strToLen( n.getRoot( LayoutType.BOTTOM_TOP_RIGHT ).getName(), 6 ) + 
-                    "|" + strToLen( n.getAlign( LayoutType.BOTTOM_TOP_RIGHT ).getName(), 7 ) + 
-                    "|" + strToLen( n.getX( LayoutType.BOTTOM_TOP_RIGHT ) + "", 5 ) + 
-                    "|" + strToLen( !n.isXUndefined( LayoutType.BOTTOM_TOP_RIGHT ) + "", 8 ) + "|\n";
+            info += "|" + TextLayoutHelper.strToLen( n.getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getShift( LayoutType.TOP_BOTTOM_LEFT ) + "", 7 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getSink( LayoutType.TOP_BOTTOM_LEFT ).getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getRoot( LayoutType.TOP_BOTTOM_LEFT ).getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getAlign( LayoutType.TOP_BOTTOM_LEFT ).getName(), 7 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.TOP_BOTTOM_LEFT ) + "", 5 ) + 
+                    "|" + TextLayoutHelper.strToLen( !n.isXUndefined( LayoutType.TOP_BOTTOM_LEFT ) + "", 8 ) + "| " +
+                    "|" + TextLayoutHelper.strToLen( n.getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getShift( LayoutType.TOP_BOTTOM_RIGHT ) + "", 7 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getSink( LayoutType.TOP_BOTTOM_RIGHT ).getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getRoot( LayoutType.TOP_BOTTOM_RIGHT ).getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getAlign( LayoutType.TOP_BOTTOM_RIGHT ).getName(), 7 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.TOP_BOTTOM_RIGHT ) + "", 5 ) + 
+                    "|" + TextLayoutHelper.strToLen( !n.isXUndefined( LayoutType.TOP_BOTTOM_RIGHT ) + "", 8 ) + "| " +
+                    "|" + TextLayoutHelper.strToLen( n.getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getShift( LayoutType.BOTTOM_TOP_LEFT ) + "", 7 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getSink( LayoutType.BOTTOM_TOP_LEFT ).getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getRoot( LayoutType.BOTTOM_TOP_LEFT ).getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getAlign( LayoutType.BOTTOM_TOP_LEFT ).getName(), 7 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.BOTTOM_TOP_LEFT ) + "", 5 ) + 
+                    "|" + TextLayoutHelper.strToLen( !n.isXUndefined( LayoutType.BOTTOM_TOP_LEFT ) + "", 8 ) + "| " +
+                    "|" + TextLayoutHelper.strToLen( n.getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getShift( LayoutType.BOTTOM_TOP_RIGHT ) + "", 7 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getSink( LayoutType.BOTTOM_TOP_RIGHT ).getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getRoot( LayoutType.BOTTOM_TOP_RIGHT ).getName(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getAlign( LayoutType.BOTTOM_TOP_RIGHT ).getName(), 7 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.BOTTOM_TOP_RIGHT ) + "", 5 ) + 
+                    "|" + TextLayoutHelper.strToLen( !n.isXUndefined( LayoutType.BOTTOM_TOP_RIGHT ) + "", 8 ) + "|\n";
         }
         info += "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------";
         return info;
@@ -722,6 +712,14 @@ public class MainView {
         JScrollPane treeView = new JScrollPane( pseudoTree );
         treeView.setBounds( 10,  110,  380, 380 );
         
+        JTextArea debugText = new JTextArea();
+        debugText.setFont( new Font( "Monospaced", Font.PLAIN, 12 ) );
+        debugText.setEditable( false );
+        debugText.setBackground( RenderHelper.BACKGROUND_COLOR );
+        debugText.setForeground( RenderHelper.FOREGROUND_COLOR );
+        JScrollPane debugView = new JScrollPane( debugText );
+        debugView.setBounds( treeView.getX(), treeView.getY() + 500, treeView.getWidth(), 250 );
+        
         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 );
@@ -765,6 +763,7 @@ public class MainView {
         menue.add( randomGraph );
         menue.add( save );
         menue.add( load );
+        menue.add( debugView );
         frame.add( menue, BorderLayout.EAST );
         frame.setSize( frame.getWidth() + 1, frame.getHeight() );
         frame.setSize( frame.getWidth() - 1, frame.getHeight() );
@@ -776,7 +775,8 @@ public class MainView {
             public void componentResized(ComponentEvent evt) {
                 pl.setSize( layne.getSize() );
                 menue.setSize( menue.getWidth(), layne.getHeight() );
-                treeView.setSize( treeView.getWidth(), layne.getHeight() - 120 );
+                treeView.setSize( treeView.getWidth(), layne.getHeight() - 370 );
+                debugView.setBounds( treeView.getX(), treeView.getY() + treeView.getHeight() + 10, treeView.getWidth(), 240 );
                 if( graph.getColor( LayoutType.COMBINED ) == null )
                 {
                     grout.setHgap( 10 );
@@ -790,6 +790,7 @@ public class MainView {
                 combined.setSize( layne.getWidth() / 3, layne.getHeight() / 3 );
                 combined.setLocation( layne.getWidth() / 3, layne.getHeight() / 3 );
 
+                debugText.setText( algorithm.getDebugString() );
                 layne.remove( pl );
                 layne.add( pl, 1 );
                 frame.repaint();