private void PaintLine(Graphics g, SnapshotIcon icon, SnapshotIcon child, bool highlight) { if (child.Index == -1) { return; } try { Rectangle leftItemBounds = icon.GetBounds(ItemBoundsPortion.Entire); Rectangle rightItemBounds = child.GetBounds(ItemBoundsPortion.Entire); leftItemBounds.Size = icon.DefaultSize; rightItemBounds.Size = child.DefaultSize; int left = leftItemBounds.Right + 6; int right = rightItemBounds.Left; int mid = (left + right) / 2; Point start = new Point(left, (leftItemBounds.Bottom + leftItemBounds.Top) / 2); Point end = new Point(right, (rightItemBounds.Top + rightItemBounds.Bottom) / 2); Point curveStart = start; curveStart.Offset(straightLineLength, 0); Point curveEnd = end; curveEnd.Offset(-straightLineLength, 0); Point control1 = new Point(mid + straightLineLength, start.Y); Point control2 = new Point(mid - straightLineLength, end.Y); Color lineColor = LinkLineColor; float lineWidth = LinkLineWidth; if (highlight) { lineColor = Color.ForestGreen; lineWidth = 2.5f; } using (Pen p = new Pen(lineColor, lineWidth)) { p.SetLineCap(LineCap.Round, LineCap.Custom, DashCap.Flat); p.CustomEndCap = linkLineArrow; g.SmoothingMode = SmoothingMode.AntiAlias; GraphicsPath path = new GraphicsPath(); path.AddLine(start, curveStart); path.AddBezier(curveStart, control1, control2, curveEnd); path.AddLine(curveEnd, end); g.DrawPath(p, path); } } catch (Exception) { //Debugger.Break(); } }
public SnapshotIcon(string name, string createTime, SnapshotIcon parent, SnapshotTreeView treeView, int imageIndex) : base(name.Ellipsise(35)) { this._name = name.Ellipsise(35); this._creationTime = createTime; this.parent = parent; this.treeView = treeView; this.UseItemStyleForSubItems = false; this.ToolTipText = String.Format("{0} {1}", name, createTime); this.ImageIndex = imageIndex; if (imageIndex == SnapshotIcon.VMImageIndex) { spinningTimer.Tick += new EventHandler(timer_Tick); spinningTimer.Interval = 150; } }
internal ListViewItem AddSnapshot(SnapshotIcon snapshot) { if (snapshot == null) { throw new ArgumentNullException("snapshot"); } if (snapshot.Parent != null) { snapshot.Parent.AddChild(snapshot); snapshot.Parent.Invalidate(); } else if (root != null) { throw new InvalidOperationException("Adding a new root!"); } else { root = snapshot; } if (snapshot.ImageIndex == SnapshotIcon.VMImageIndex) { //Sort all the parents of the VM to make the path to the VM the first one. SnapshotIcon current = snapshot; while (current.Parent != null) { if (current.Parent.Children.Count > 1) { int indexCurrent = current.Parent.Children.IndexOf(current); SnapshotIcon temp = current.Parent.Children[0]; current.Parent.Children[0] = current; current.Parent.Children[indexCurrent] = temp; } current.IsInVMBranch = true; current = current.Parent; } } ListViewItem item = Items.Add(snapshot); if (Items.Count == 1) { Items.Add(whiteIcon); } return(item); }
internal void ChangeVMToSpinning(bool p, string message) { _spinningMessage = message; foreach (var item in Items) { SnapshotIcon snapshotIcon = item as SnapshotIcon; if (snapshotIcon != null && (snapshotIcon.ImageIndex == SnapshotIcon.VMImageIndex || snapshotIcon.ImageIndex > SnapshotIcon.UnknownImage)) { if (string.IsNullOrEmpty(message)) { snapshotIcon.ChangeSpinningIcon(p, _spinningMessage); } else { snapshotIcon.ChangeSpinningIcon(p, _spinningMessage); } return; } } }
internal void RemoveSnapshot(SnapshotIcon snapshot) { if (snapshot != null && snapshot.Parent != null) { IList <SnapshotIcon> siblings = snapshot.Parent.Children; int pos = siblings.IndexOf(snapshot); siblings.Remove(snapshot); // add our children in our place foreach (SnapshotIcon child in snapshot.Children) { siblings.Insert(pos++, child); child.Parent = snapshot.Parent; } snapshot.Parent.Invalidate(); snapshot.Parent = null; } else { root = null; } }
private void PositionSnapshots(SnapshotIcon icon, int x, int y) { try { Size iconSize = icon.DefaultSize; Point newPoint = new Point(x, y + icon.CentreHeight - iconSize.Height / 2); icon.Position = new Point(newPoint.X + origin.X, newPoint.Y + origin.Y); x += iconSize.Width + HGap; for (int i = 0; i < icon.Children.Count; i++) { SnapshotIcon child = icon.Children[i]; PositionSnapshots(child, x, y); y += child.SubtreeHeight; } } catch (Exception) { // Debugger.Break(); } }
private void DrawDate(DrawListViewItemEventArgs e, SnapshotIcon icon, bool background) { StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; //Time int timeX = e.Bounds.X; int timeY = e.Bounds.Y + e.Bounds.Height; Size proposedSizeName = new Size(e.Bounds.Width, Int32.MaxValue); Size timeSize = TextRenderer.MeasureText(e.Graphics, icon.LabelCreationTime, new Font(this.Font.FontFamily, this.Font.Size - 1), proposedSizeName, TextFormatFlags.WordBreak); timeSize = new Size(e.Bounds.Width, timeSize.Height); Rectangle timeRect = new Rectangle(new Point(timeX, timeY), timeSize); if (background) { e.Graphics.FillRectangle(Brushes.GreenYellow, timeRect); } e.Graphics.DrawString(icon.LabelCreationTime, new Font(this.Font.FontFamily, this.Font.Size - 1), Brushes.Black, timeRect, stringFormat); }
private void SnapshotTreeView_DrawItem(object sender, DrawListViewItemEventArgs e) { if (this.Parent != null) { e.DrawDefault = true; SnapshotIcon icon = e.Item as SnapshotIcon; if (icon == null) { return; } DrawDate(e, icon, false); if (icon.Parent != null) { PaintLine(e.Graphics, icon.Parent, icon, icon.IsInVMBranch); } for (int i = 0; i < icon.Children.Count; i++) { SnapshotIcon child = icon.Children[i]; PaintLine(e.Graphics, icon, child, child.IsInVMBranch); } } }
internal ListViewItem AddSnapshot(SnapshotIcon snapshot) { if (snapshot == null) throw new ArgumentNullException("snapshot"); if (snapshot.Parent != null) { snapshot.Parent.AddChild(snapshot); snapshot.Parent.Invalidate(); } else if (root != null) { throw new InvalidOperationException("Adding a new root!"); } else { root = snapshot; } if (snapshot.ImageIndex == SnapshotIcon.VMImageIndex) { //Sort all the parents of the VM to make the path to the VM the first one. SnapshotIcon current = snapshot; while (current.Parent != null) { if (current.Parent.Children.Count > 1) { int indexCurrent = current.Parent.Children.IndexOf(current); SnapshotIcon temp = current.Parent.Children[0]; current.Parent.Children[0] = current; current.Parent.Children[indexCurrent] = temp; } current.IsInVMBranch = true; current = current.Parent; } } ListViewItem item = Items.Add(snapshot); if (Items.Count == 1) Items.Add(whiteIcon); return item; }
private void RefreshTreeView(IList<VM> roots) { if (TreeView.Parent == null) return; TreeView.SuspendLayout(); TreeView.BeginUpdate(); TreeView.Clear(); Debug.WriteLine("Start refreshing Tree"); SnapshotIcon rootIcon = null; rootIcon = new SnapshotIcon(VM.Name, Messages.BASE, null, TreeView, SnapshotIcon.Template); TreeView.AddSnapshot(rootIcon); //Set VM VM vmParent = VM.Connection.Resolve<VM>(VM.parent); if (vmParent == null || !vmParent.is_a_snapshot) { SnapshotIcon vmIcon = new SnapshotIcon(Messages.NOW, "", rootIcon, TreeView, SnapshotIcon.VMImageIndex); TreeView.AddSnapshot(vmIcon); } foreach (VM root in roots) { if (!(root.is_snapshot_from_vmpp && !toolStripMenuItemScheduledSnapshots.Checked)) { int icon; if (root.is_snapshot_from_vmpp) icon = root.power_state == vm_power_state.Suspended ? SnapshotIcon.ScheduledDiskMemorySnapshot : SnapshotIcon.ScheduledDiskSnapshot; else icon = root.power_state == vm_power_state.Suspended ? SnapshotIcon.DiskAndMemorySnapshot : SnapshotIcon.DiskSnapshot; DateTime time = root.snapshot_time.ToLocalTime() + root.Connection.ServerTimeOffset; SnapshotIcon currentIcon = new SnapshotIcon(root.name_label, HelpersGUI.DateTimeToString(time, Messages.DATEFORMAT_DMY_HMS, true), rootIcon, TreeView, icon); TreeView.AddSnapshot(currentIcon); currentIcon.Tag = root; BuildTree(root, currentIcon); } else BuildTree(root, rootIcon); } if (TreeView.Items.Count < 4) TreeView.Clear(); TreeView.EndUpdate(); TreeView.ResumeLayout(); TreeView.PerformLayout(); }
internal void AddChild(SnapshotIcon icon) { children.Add(icon); Invalidate(); }
private void PaintLine(Graphics g, SnapshotIcon icon, SnapshotIcon child, bool highlight) { if (child.Index == -1) return; try { Rectangle leftItemBounds = icon.GetBounds(ItemBoundsPortion.Entire); Rectangle rightItemBounds = child.GetBounds(ItemBoundsPortion.Entire); leftItemBounds.Size = icon.DefaultSize; rightItemBounds.Size = child.DefaultSize; int left = leftItemBounds.Right + 6; int right = rightItemBounds.Left; int mid = (left + right) / 2; Point start = new Point(left, (leftItemBounds.Bottom + leftItemBounds.Top) / 2); Point end = new Point(right, (rightItemBounds.Top + rightItemBounds.Bottom) / 2); Point curveStart = start; curveStart.Offset(straightLineLength, 0); Point curveEnd = end; curveEnd.Offset(-straightLineLength, 0); Point control1 = new Point(mid + straightLineLength, start.Y); Point control2 = new Point(mid - straightLineLength, end.Y); Color lineColor = LinkLineColor; float lineWidth = LinkLineWidth; if (highlight) { lineColor = Color.ForestGreen; lineWidth = 2.5f; } using (Pen p = new Pen(lineColor, lineWidth)) { p.SetLineCap(LineCap.Round, LineCap.Custom, DashCap.Flat); p.CustomEndCap = linkLineArrow; g.SmoothingMode = SmoothingMode.AntiAlias; GraphicsPath path = new GraphicsPath(); path.AddLine(start, curveStart); path.AddBezier(curveStart, control1, control2, curveEnd); path.AddLine(curveEnd, end); g.DrawPath(p, path); } } catch (Exception) { //Debugger.Break(); } }
internal void RemoveSnapshot(SnapshotIcon snapshot) { if (snapshot != null && snapshot.Parent != null) { IList<SnapshotIcon> siblings = snapshot.Parent.Children; int pos = siblings.IndexOf(snapshot); siblings.Remove(snapshot); // add our children in our place foreach (SnapshotIcon child in snapshot.Children) { siblings.Insert(pos++, child); child.Parent = snapshot.Parent; } snapshot.Parent.Invalidate(); snapshot.Parent = null; } else { root = null; } }
private void BuildTree(VM currentNode, SnapshotIcon currentIcon) { //Set VM if (VM.Connection.Resolve<VM>(VM.parent) == currentNode) { SnapshotIcon vmIcon = new SnapshotIcon(Messages.NOW, "", currentIcon, TreeView, SnapshotIcon.VMImageIndex); TreeView.AddSnapshot(vmIcon); } //Do childs foreach (XenRef<VM> child in currentNode.children) { if (VM.snapshots.Contains(child)) { VM childSnapshot = VM.Connection.Resolve<VM>(child); if (!(childSnapshot.is_snapshot_from_vmpp && !toolStripMenuItemScheduledSnapshots.Checked)) { int icon; if (childSnapshot.is_snapshot_from_vmpp) icon = childSnapshot.power_state == vm_power_state.Suspended ? SnapshotIcon.ScheduledDiskMemorySnapshot : SnapshotIcon.ScheduledDiskSnapshot; else icon = childSnapshot.power_state == vm_power_state.Suspended ? SnapshotIcon.DiskAndMemorySnapshot : SnapshotIcon.DiskSnapshot; DateTime time = childSnapshot.snapshot_time.ToLocalTime() + childSnapshot.Connection.ServerTimeOffset; SnapshotIcon childIcon = new SnapshotIcon(childSnapshot.name_label, HelpersGUI.DateTimeToString(time, Messages.DATEFORMAT_DMY_HMS, true), currentIcon, TreeView, icon); TreeView.AddSnapshot(childIcon); childIcon.Tag = childSnapshot; BuildTree(childSnapshot, childIcon); } else BuildTree(childSnapshot, currentIcon); } } }