Ver Fonte

Merge branch 'master' of https://koljastrohm-games.com:3000/GraphDrawer/NodeShuffler

Kolja Strohm há 5 anos atrás
pai
commit
ad4d94a2b6

+ 9 - 0
src/view/PseudoCodeLines.java

@@ -70,6 +70,7 @@ public class PseudoCodeLines extends JComponent implements MouseListener{
                 dimension = scroller.getViewport().getView().getPreferredSize();
             }           
         }
+        // update width
         if ( width > super.getPreferredSize().width || width < super.getPreferredSize().width){
             setPreferredSize(new Dimension(width + 2*HORIZONTAL_PADDING, dimension.height));
             revalidate();
@@ -119,18 +120,26 @@ public class PseudoCodeLines extends JComponent implements MouseListener{
         super.paintComponent(g);
         Graphics2D g2d = (Graphics2D)g;
         g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        
+        // background
         g.setColor(RenderHelper.BACKGROUND_COLOR);
         g2d.fillRect(0, 0, getWidth(), getHeight());
+        
+        // foreground
         g.setColor(RenderHelper.FOREGROUND_COLOR);
         for ( int i = 0; i < tree.getRowCount(); i++ ){
             PseudoCodeNode node = (PseudoCodeNode)tree.getPathForRow( i ).getLastPathComponent();
+            // line numbers
             int number = getLineNumber( node );
             Rectangle rect = tree.getRowBounds( i );
             String text = String.valueOf( number );
             int yPosition = rect.y + rect.height / 2 + 4;
+            // highlight current node
             if( node.isSelected() )
                 g.drawImage( currentLine.getImage(), HORIZONTAL_PADDING, rect.y + rect.height / 2 - 10, 20, 20, null );
             g2d.drawString( text, HORIZONTAL_PADDING * 2 + 20, yPosition );
+            
+            // breakpoint symbol
             if( node.hasBreakPoint() )
             {
                 Color c = g.getColor();

+ 7 - 0
src/view/PseudoCodeRenderer.java

@@ -65,13 +65,19 @@ public class PseudoCodeRenderer extends DefaultTreeCellRenderer {
         this.setOpenIcon( null );
         this.setLeafIcon( null );
         super.getTreeCellRendererComponent(tree, value, arg2, arg3, arg4, arg5, arg6);
+        
+        // breakpoints in special color
         specialColor = null;
         if(node.isSelected()) {
             specialColor = new Color(0x2d6099);
         } else if (node.hasBreakPoint()) {
             specialColor = RenderHelper.BREAKPOINT_COLOR;
         }
+        
+        // the text in the code line
         setText((String)node.getUserObject());
+        
+        // the tooltip showing variable values
         toolTip = "<html>";
         for( String var : TextLayoutHelper.getVariables( (String)node.getUserObject() ) )
         {
@@ -92,6 +98,7 @@ public class PseudoCodeRenderer extends DefaultTreeCellRenderer {
         else
             toolTip = toolTip.substring( 0, toolTip.length() - 4 );
         toolTip += "</html>";
+        
         return this;
     }
 

+ 19 - 1
src/view/RandomGraphDialog.java

@@ -48,6 +48,8 @@ public class RandomGraphDialog extends JDialog {
         GridBagConstraints c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 0;
+        
+        // P(subgraph exists)
         add( new JLabel( "P(subgraph exists)"), c );
         c = new GridBagConstraints();
         c.gridx = 1;
@@ -73,6 +75,8 @@ public class RandomGraphDialog extends JDialog {
             }
         });
         add( pSubgraph, c );
+        
+        // P(edge exists)
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 1;
@@ -101,6 +105,8 @@ public class RandomGraphDialog extends JDialog {
             }
         });
         add( pEdge, c );
+        
+        // P(min. num. layers)
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 2;
@@ -133,6 +139,8 @@ public class RandomGraphDialog extends JDialog {
             }
         });
         add( minLayers, c );
+        
+        // P(max. num. layers)
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 3;
@@ -163,6 +171,8 @@ public class RandomGraphDialog extends JDialog {
             }
         });
         add( maxLayers, c );
+
+        // P(min. num. nodes)
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 4;
@@ -196,6 +206,8 @@ public class RandomGraphDialog extends JDialog {
             }
         });
         add( minNodes, c );
+        
+        // max. num. nodes
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 5;
@@ -227,6 +239,8 @@ public class RandomGraphDialog extends JDialog {
             }
         });
         add( maxNodes, c );
+        
+        // max. hier. depth
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 6;
@@ -256,6 +270,8 @@ public class RandomGraphDialog extends JDialog {
             }
         });
         add( maxDepth, c );
+        
+        // "generate" button
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 7;
@@ -273,6 +289,7 @@ public class RandomGraphDialog extends JDialog {
                 int maxNodeI = Integer.parseInt( maxNodes.getText() );
                 int maxDepthI = Integer.parseInt( maxDepth.getText() );
                 boolean ok = true;
+                // check parameters
                 if( pSubGraphD < 0 || pSubGraphD > 1 )
                 {
                     pSubgraph.setBackground( Color.RED );
@@ -309,7 +326,8 @@ public class RandomGraphDialog extends JDialog {
                     ok = false;
                 }
                 if( ok )
-                {                            
+                {             
+                    // generate the graph
                     RandomGraphGenerator r = new RandomGraphGenerator( pSubGraphD, pEdgeD, minLayerI, maxLayerI, minNodeI, maxNodeI, maxDepthI );
                     try {
                         LayeredGraphNode graph = r.createRandomNode( null, 0, true );

+ 2 - 1
src/view/RenderHelper.java

@@ -26,14 +26,15 @@ public class RenderHelper {
      * @return the shape
      */
     public static Shape createArrowShape(Point fromPt, Point toPt) {
+        // create the shape of the arrow
         Polygon arrowPolygon = new Polygon();
         arrowPolygon.addPoint(-3,6);
         arrowPolygon.addPoint(3,0);
         arrowPolygon.addPoint(-3,-6);
         arrowPolygon.addPoint(-3,6);
 
+        // rotate and translate the shape
         double rotate = Math.atan2( ( toPt.y - fromPt.y ) , ( toPt.x - fromPt.x ) );
-
         AffineTransform transform = new AffineTransform();
         transform.translate(toPt.x, toPt.y);
         transform.rotate(rotate);