Index: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/BoxesLayoutEngine.cs
===================================================================
--- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/BoxesLayoutEngine.cs	(revision 10545)
+++ trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/BoxesLayoutEngine.cs	(revision 10561)
@@ -131,4 +131,8 @@
     }
 
+    public IEnumerable<T> GetContentNodes() {
+      return nodeMap.Keys;
+    }
+
     public IEnumerable<VisualTreeNode<T>> GetVisualNodes() {
       return nodeMap.Values;
Index: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ILayoutEngine.cs
===================================================================
--- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ILayoutEngine.cs	(revision 10545)
+++ trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ILayoutEngine.cs	(revision 10561)
@@ -22,4 +22,5 @@
     Func<T, int> GetDepth { get; set; }
 
+    IEnumerable<T> GetContentNodes();
     IEnumerable<VisualTreeNode<T>> GetVisualNodes();
     Dictionary<T, PointF> GetCoordinates();
Index: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs
===================================================================
--- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs	(revision 10545)
+++ trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs	(revision 10561)
@@ -63,4 +63,8 @@
         Expand(node);
       }
+    }
+
+    public IEnumerable<T> GetContentNodes() {
+      return nodeMap.Keys;
     }
 
@@ -191,4 +195,7 @@
         // reset layout-related parameters 
         layoutNode.Reset();
+        // reset the width and height since they might have been affected by scaling
+        layoutNode.Width = NodeWidth;
+        layoutNode.Height = NodeHeight;
       }
     }
Index: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarAllowedChildSymbolsControl.cs
===================================================================
--- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarAllowedChildSymbolsControl.cs	(revision 10545)
+++ trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarAllowedChildSymbolsControl.cs	(revision 10561)
@@ -105,5 +105,4 @@
 
       var tree = new SymbolicExpressionTree(new SymbolicExpressionTreeNode(Symbol));
-      symbolicExpressionTreeChart.SuspendRepaint = true;
       if (Grammar.GetMaximumSubtreeCount(Symbol) > 0) {
         for (int i = 0; i < Grammar.GetMaximumSubtreeCount(Symbol); i++) {
@@ -118,5 +117,5 @@
       }
       symbolicExpressionTreeChart.Tree = tree;
-
+      symbolicExpressionTreeChart.SuspendRepaint = true;
       foreach (var subtreeNode in tree.Root.Subtrees) {
         foreach (var allowedChildNode in subtreeNode.Subtrees) {
@@ -144,5 +143,4 @@
         }
       }
-
       symbolicExpressionTreeChart.SuspendRepaint = false;
       UpdateSelectedSymbolicExpressionTreeNodes();
@@ -155,5 +153,5 @@
         else visualNode.FillColor = Color.LightSteelBlue;
       }
-      symbolicExpressionTreeChart.Repaint();
+      symbolicExpressionTreeChart.RepaintNodes();
     }
 
Index: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
===================================================================
--- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs	(revision 10545)
+++ trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs	(revision 10561)
@@ -58,4 +58,13 @@
     }
 
+    private ILayoutEngine<ISymbolicExpressionTreeNode> TreeLayoutEngine {
+      get { return layoutEngine; }
+      set {
+        layoutEngine = value;
+        InitializeLayout();
+        Repaint();
+      }
+    }
+
     public SymbolicExpressionTreeChart(ISymbolicExpressionTree tree)
       : this() {
@@ -128,7 +137,16 @@
       if (this.Width <= 1 || this.Height <= 1)
         this.image = new Bitmap(1, 1);
-      else
+      else {
         this.image = new Bitmap(Width, Height);
+      }
       this.Repaint();
+    }
+
+    public event EventHandler Repainted;//expose this event to notify the parent control that the tree was repainted
+    protected virtual void OnRepaint(object sender, EventArgs e) {
+      var repainted = Repainted;
+      if (repainted != null) {
+        repainted(sender, e);
+      }
     }
 
@@ -137,4 +155,5 @@
         this.GenerateImage();
         this.Refresh();
+        OnRepaint(this, EventArgs.Empty);
       }
     }
@@ -147,4 +166,9 @@
           foreach (var visualNode in visualTreeNodes.Values) {
             DrawTreeNode(graphics, visualNode);
+            if (visualNode.Content.SubtreeCount > 0) {
+              foreach (var visualSubtree in visualNode.Content.Subtrees.Select(s => visualTreeNodes[s])) {
+                DrawLine(graphics, visualNode, visualSubtree);
+              }
+            }
           }
         }
@@ -170,5 +194,5 @@
         graphics.Clear(backgroundColor);
         if (tree != null) {
-          DrawFunctionTree(tree, graphics, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
+          DrawFunctionTree(graphics, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
         }
       }
@@ -236,5 +260,4 @@
 
     private void SymbolicExpressionTreeChart_MouseMove(object sender, MouseEventArgs e) {
-
       VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);
       if (draggedSymbolicExpressionTree != null &&
@@ -262,8 +285,16 @@
     #endregion
 
+    #region initialize the layout
     private void InitializeLayout() {
-      var actualRoot = tree.Root.SubtreeCount == 1 ? tree.Root.GetSubtree(0) : tree.Root;
+      var actualRoot = tree.Root;
+      if (actualRoot.Symbol is ProgramRootSymbol && actualRoot.SubtreeCount == 1) {
+        actualRoot = tree.Root.GetSubtree(0);
+      }
       layoutEngine.Initialize(actualRoot, n => n.Subtrees, n => n.GetLength(), n => n.GetDepth());
       layoutEngine.CalculateLayout(this.Width, this.Height);
+      UpdateDictionaries();
+    }
+
+    private void UpdateDictionaries() {
       var visualNodes = layoutEngine.GetVisualNodes().ToList();
       //populate the visual nodes and visual connections dictionaries
@@ -276,7 +307,7 @@
       }
     }
-
+    #endregion
     #region methods for painting the symbolic expression tree
-    private void DrawFunctionTree(ISymbolicExpressionTree symbExprTree, Graphics graphics, int preferredWidth, int preferredHeight, int minHDistance, int minVDistance) {
+    private void DrawFunctionTree(Graphics graphics, int preferredWidth, int preferredHeight, int minHDistance, int minVDistance) {
       //we assume here that the layout has already been initialized when the symbolic expression tree was changed
       //recalculate layout according to new node widths and spacing
@@ -286,4 +317,5 @@
       layoutEngine.VerticalSpacing = minVDistance;
       layoutEngine.CalculateLayout(Width, Height);
+      UpdateDictionaries();//this will reset the visual nodes, therefore colors will be reset to default values
       var visualNodes = visualTreeNodes.Values;
       //draw nodes and connections
@@ -333,4 +365,15 @@
       }
     }
+
+    protected void DrawLine(Graphics graphics, VisualTreeNode<ISymbolicExpressionTreeNode> startNode, VisualTreeNode<ISymbolicExpressionTreeNode> endNode) {
+      var origin = new Point(startNode.X + startNode.Width / 2, startNode.Y + startNode.Height);
+      var target = new Point(endNode.X + endNode.Width / 2, endNode.Y);
+      graphics.Clip = new Region(new Rectangle(Math.Min(origin.X, target.X), origin.Y, Math.Max(origin.X, target.X), target.Y));
+      var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(startNode.Content, endNode.Content);
+      using (var linePen = new Pen(visualLine.LineColor)) {
+        linePen.DashStyle = visualLine.DashStyle;
+        graphics.DrawLine(linePen, origin, target);
+      }
+    }
     #endregion
     #region save image
@@ -348,5 +391,5 @@
       Image image = new Bitmap(Width, Height);
       using (Graphics g = Graphics.FromImage(image)) {
-        DrawFunctionTree(tree, g, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
+        DrawFunctionTree(g, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
       }
       image.Save(filename);
@@ -358,5 +401,5 @@
         using (Metafile file = new Metafile(filename, g.GetHdc())) {
           using (Graphics emfFile = Graphics.FromImage(file)) {
-            DrawFunctionTree(tree, emfFile, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
+            DrawFunctionTree(emfFile, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
           }
         }
@@ -377,5 +420,5 @@
 
     private void reingoldTilfordToolStripMenuItem_Click(object sender, EventArgs e) {
-      layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> {
+      TreeLayoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> {
         NodeWidth = preferredNodeWidth,
         NodeHeight = preferredNodeHeight,
@@ -383,10 +426,8 @@
         VerticalSpacing = minVerticalDistance
       };
-      InitializeLayout();
-      Repaint();
     }
 
     private void boxesToolStripMenuItem_Click(object sender, EventArgs e) {
-      layoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode> {
+      TreeLayoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode> {
         NodeWidth = preferredNodeWidth,
         NodeHeight = preferredNodeHeight,
@@ -394,6 +435,4 @@
         VerticalSpacing = minVerticalDistance
       };
-      InitializeLayout();
-      Repaint();
     }
   }
Index: trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.cs	(revision 10545)
+++ trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.cs	(revision 10561)
@@ -218,5 +218,5 @@
             if (tempNode.IterateNodesBreadth().Contains(node))
               throw new ArgumentException();// cannot cut/paste a node into itself
-            ModifyTree(Tree, tempNode.Parent, tempNode, null); //remove node from its original parent 	 	 
+            ModifyTree(Tree, tempNode.Parent, tempNode, null); //remove node from its original parent
             ModifyTree(Tree, node, null, tempNode); //insert it as a child to the new parent 
             break;
