Ver código fonte

fixed an null pointer exception for unnamed nodes

Kolja Strohm 6 anos atrás
pai
commit
c96eebbe42

+ 5 - 5
src/bk/BKNodePlacement.java

@@ -153,11 +153,11 @@ public class BKNodePlacement extends AnimatedAlgorithm {
                 }
                 for( LayeredGraphNode n : graph.getContainedNodes() )
                 {
-                    info += "|" + TextLayoutHelper.strToLen( n.getName(), 6 ) +
+                    info += "|" + TextLayoutHelper.strToLen( n.toString(), 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.getSink( type ).toString(), 6 ) +
+                            "|" + TextLayoutHelper.strToLen( n.getRoot( type ).toString(), 6 ) +
+                            "|" + TextLayoutHelper.strToLen( n.getAlign( type ).toString(), 7 ) +
                             "|" + TextLayoutHelper.strToLen( n.getX( type ) + "", 5 ) +
                             "|" + TextLayoutHelper.strToLen( !n.isXUndefined( type ) + "", 8 ) + "|\n";
                 }
@@ -182,7 +182,7 @@ public class BKNodePlacement extends AnimatedAlgorithm {
                 LayeredGraphNode graph = m.read( "graph", MemoryType.COMPLETE_STACK );
                 for( LayeredGraphNode n : graph.getContainedNodes() )
                 {
-                    info += "|" + TextLayoutHelper.strToLen( n.getName(), 6 ) +
+                    info += "|" + TextLayoutHelper.strToLen( n.toString(), 6 ) +
                             "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.TOP_BOTTOM_LEFT ) + "", 6 ) +
                             "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.TOP_BOTTOM_RIGHT ) + "", 6 ) +
                             "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.BOTTOM_TOP_LEFT ) + "", 6 ) +

+ 4 - 4
src/bk/ConflictDetection.java

@@ -76,10 +76,10 @@ public class ConflictDetection {
             k0 = "" + m.<Integer>read( "k0", MemoryType.LOCAL );
         if( m.isSomewhereDefined( "k1", MemoryType.LOCAL ) )
             k1 = "" + m.<Integer>read( "k1", MemoryType.LOCAL );
-        if( m.isSomewhereDefined( "v", MemoryType.LOCAL ) && m.<LayeredGraphEdge>read( "v", MemoryType.LOCAL ).getSources().get( 0 ).getName() != null )
-            v = "" + m.<LayeredGraphEdge>read( "v", MemoryType.LOCAL ).getSources().get( 0 ).getName();
-        if( m.isSomewhereDefined( "n", MemoryType.LOCAL ) && m.<LayeredGraphNode>read( "n", MemoryType.LOCAL ).getName() != null )
-            n = "" + m.<LayeredGraphNode>read( "n", MemoryType.LOCAL ).getName();
+        if( m.isSomewhereDefined( "v", MemoryType.LOCAL ) && m.<LayeredGraphEdge>read( "v", MemoryType.LOCAL ).getSources().get( 0 ).toString() != null )
+            v = "" + m.<LayeredGraphEdge>read( "v", MemoryType.LOCAL ).getSources().get( 0 ).toString();
+        if( m.isSomewhereDefined( "n", MemoryType.LOCAL ) && m.<LayeredGraphNode>read( "n", MemoryType.LOCAL ).toString() != null )
+            n = "" + m.<LayeredGraphNode>read( "n", MemoryType.LOCAL ).toString();
         info += "|" + TextLayoutHelper.strToLen( i, 4 ) + 
                 "|" + TextLayoutHelper.strToLen( l, 4 ) + 
                 "|" + TextLayoutHelper.strToLen( l1, 4 ) + 

+ 0 - 7
src/graph/LayeredGraphNode.java

@@ -135,13 +135,6 @@ public interface LayeredGraphNode {
    */
   public void setName(String name);
 
-  /**
-   * get the name of this node
-   * 
-   * @return the name
-   */
-  public String getName();
-
   /**
    * set the display color of this node in the given layout
    * or in all layouts if the argument is null.

+ 1 - 6
src/graph/LayeredNode.java

@@ -463,11 +463,6 @@ public class LayeredNode implements LayeredGraphNode {
         name = n;
     }
 
-    @Override
-    public String getName() {
-        return name;
-    }
-
     @Override
     public ElkNode getOriginalNode() {
         return original;
@@ -898,7 +893,7 @@ public class LayeredNode implements LayeredGraphNode {
     @Override
     public LayeredGraphNode findNodeByName(String name) {
         for (LayeredGraphNode n : nodes) {
-            if (n.getName() != null && name != null && n.getName().equals(name))
+            if (name != null && n.toString().equals(name))
                 return n;
         }
         return null;

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

@@ -63,7 +63,7 @@ public class Writer {
             edges.put( parseEdge( e ) );
         }
         node.put( "edges", edges );
-        node.put( "name", graph.getName() );
+        node.put( "name", graph.toString() );
         if( graph.isDummyNode() )
             node.put( "dummy", "true" );
         return node;
@@ -72,8 +72,8 @@ public class Writer {
     private JSONObject parseEdge( LayeredGraphEdge e ) throws JSONException
     {
         JSONObject edge = new JSONObject();
-        edge.put( "source", e.getSources().get( 0 ).getName() );
-        edge.put( "target", e.getTargets().get( 0 ).getName() );
+        edge.put( "source", e.getSources().get( 0 ).toString() );
+        edge.put( "target", e.getTargets().get( 0 ).toString() );
         return edge;
     }
 }

+ 1 - 1
src/main/Main.java

@@ -17,7 +17,7 @@ public class Main {
      * @param args the command line arguments, currently not in use
      */
     public static void main(String[] args) {
-        Reader r = new Reader( "logo.json" );
+        Reader r = new Reader( "papergraph_in_two_nodes.json" );
         LayeredGraphNode graph = r.readInputGraph();
         SimpleNodePlacement.placeNodes( graph );
         new MainView( graph );

+ 16 - 16
src/view/MainView.java

@@ -97,32 +97,32 @@ public class MainView {
         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 += "|" + TextLayoutHelper.strToLen( n.getName(), 6 ) + 
+            info += "|" + TextLayoutHelper.strToLen( n.toString(), 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.getSink( LayoutType.TOP_BOTTOM_LEFT ).toString(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getRoot( LayoutType.TOP_BOTTOM_LEFT ).toString(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getAlign( LayoutType.TOP_BOTTOM_LEFT ).toString(), 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.toString(), 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.getSink( LayoutType.TOP_BOTTOM_RIGHT ).toString(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getRoot( LayoutType.TOP_BOTTOM_RIGHT ).toString(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getAlign( LayoutType.TOP_BOTTOM_RIGHT ).toString(), 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.toString(), 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.getSink( LayoutType.BOTTOM_TOP_LEFT ).toString(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getRoot( LayoutType.BOTTOM_TOP_LEFT ).toString(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getAlign( LayoutType.BOTTOM_TOP_LEFT ).toString(), 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.toString(), 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.getSink( LayoutType.BOTTOM_TOP_RIGHT ).toString(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getRoot( LayoutType.BOTTOM_TOP_RIGHT ).toString(), 6 ) + 
+                    "|" + TextLayoutHelper.strToLen( n.getAlign( LayoutType.BOTTOM_TOP_RIGHT ).toString(), 7 ) + 
                     "|" + TextLayoutHelper.strToLen( n.getX( LayoutType.BOTTOM_TOP_RIGHT ) + "", 5 ) + 
                     "|" + TextLayoutHelper.strToLen( !n.isXUndefined( LayoutType.BOTTOM_TOP_RIGHT ) + "", 8 ) + "|\n";
         }

+ 0 - 2
src/view/PseudoCodeLines.java

@@ -33,8 +33,6 @@ public class PseudoCodeLines extends JComponent implements MouseListener{
    
     //pixel padding on left and right
     private static final int HORIZONTAL_PADDING = 1;
-    //pixel padding on left and right
-    private static final int VERTICAL_PADDING = 3;
     
     private static ImageIcon currentLine = new ImageIcon( PseudoCodeNode.class.getResource( "/img/current_line.png" ) );