public void SetCommentObject(StickyNote comment, object parent) { if (null != m_sticky) { // Remove event handler before changing this value m_sticky.PropertyChanged -= this.StickyNote_PropertyChanged; } if (null != m_basic) { m_basic.OnTextChanged -= this.BasicComment_OnTextChanged; } // IMPORTANT: Unsubscribe from parent control property changes (if applicable) if (null != m_parentObject) { if (m_parentObject is AbstractProcessUnit) { (m_parentObject as AbstractProcessUnit).PropertyChanged -= this.ParentPU_PropertyChanged; } else if (m_parentObject is AbstractStream) { (m_parentObject as AbstractStream).PropertyChanged -= this.ParentStream_PropertyChanged; } } // Store references m_basic = null; m_sticky = comment; m_parentObject = parent; AbstractStream parentStream = parent as AbstractStream; AbstractProcessUnit parentAPU = parent as AbstractProcessUnit; // Update the UI elements if the comment is not null if (null != m_sticky) { CommentTextBox.Text = m_sticky.Text; UserNameLabel.Content = m_sticky.UserName; // Subsribe to property changes m_sticky.PropertyChanged += this.StickyNote_PropertyChanged; // Allow editing but not deletion CommentTextBox.IsReadOnly = false; XLabel.Visibility = System.Windows.Visibility.Collapsed; // Show or hide the icon based on the parent if (null != parentStream) { // Get the right icon for this type of stream string iconSource = PFD.Streams.StreamControl.GetIconSource(parent.GetType()); BitmapImage bmp = new BitmapImage(); bmp.UriSource = new Uri(iconSource, UriKind.Relative); IconImage.SetValue(Image.SourceProperty, bmp); // Make sure the icon is visible IconImage.Visibility = System.Windows.Visibility.Visible; TitleBarGrid.ColumnDefinitions[0].Width = new GridLength(20.0); // Give the icon a tooltip that tells what this is a comment for ToolTipService.SetToolTip(IconImage, "Comment for stream #" + parentStream.Id); // Subscribe to property changes for the stream parentStream.PropertyChanged += new PropertyChangedEventHandler(ParentStream_PropertyChanged); } else if (null != parentAPU) { // Get the right icon for this type of process unit string iconSource = ProcessUnitControl.GetIconSource(parent.GetType()); BitmapImage bmp = new BitmapImage(); bmp.UriSource = new Uri(iconSource, UriKind.Relative); IconImage.SetValue(Image.SourceProperty, bmp); // Make sure the icon is visible IconImage.Visibility = System.Windows.Visibility.Visible; TitleBarGrid.ColumnDefinitions[0].Width = new GridLength(20.0); // Give the icon a tooltip that tells what this is a comment for ToolTipService.SetToolTip(IconImage, "Comment for " + (m_parentObject as AbstractProcessUnit).Label); // Subscribe to property changes for the process unit parentAPU.PropertyChanged += new PropertyChangedEventHandler(ParentPU_PropertyChanged); } else { // Make sure the icon is hidden IconImage.Visibility = System.Windows.Visibility.Collapsed; TitleBarGrid.ColumnDefinitions[0].Width = new GridLength(0.0); } } }
private void RebuildIcon() { //// If we have are a connected destination endpoint then we have to procedurally build //// an arrow-head polygon //if (EndpointType.StreamDestinationConnected == m_type) //{ // AbstractStream a = m_owner as AbstractStream; // // Get the points array for the arrow's vertices // Point[] pts = a.GetArrowVertices(); // double minX, minY, maxX, maxY; // minX = minY = double.MaxValue; // maxX = maxY = double.MinValue; // foreach (Point pt in pts) // { // minX = Math.Min(minX, pt.X); // minY = Math.Min(minY, pt.Y); // maxX = Math.Max(maxX, pt.X); // maxY = Math.Max(maxY, pt.Y); // } // // Set the width and height // Width = maxX - minX; // Height = maxY - minY; // // Adjust points to make them relative to this control's coordinate system // for (int i = 0; i < 3; i++) // { // ArrowIcon.Points[i] = new Point(pts[i].X - minX, pts[i].Y - minY); // } // // Want position such that: // // Left.X + (pts[0].X - minX) = pts[0].X // // Left.X = minX // // Similar thing for Y // SetValue(Canvas.LeftProperty, minX); // SetValue(Canvas.TopProperty, minY); // // Use the same fill as the stem // ArrowIcon.Fill = m_owner.Stem.Fill; // // Make sure it's visible and the icon is hidden // ArrowIcon.Visibility = System.Windows.Visibility.Visible; // IconImage.Visibility = System.Windows.Visibility.Collapsed; // // Tell the other endpoint to update since we have potentially just repositioned this one // OtherEndpoint.PU_LocationChanged(null, null); //} //else if (true) { BitmapImage bmp = new BitmapImage(); // We have an icon for each of these 3 types switch (m_type) { case EndpointType.StreamDestination: bmp.UriSource = new Uri("/UI/Icons/pu_sink.png", UriKind.Relative); Width = Height = 20; break; //case EndpointType.StreamSourceConnected: // bmp.UriSource = new Uri("/UI/Icons/StreamSourceConnection.png", UriKind.Relative); // Width = Height = 12; // break; case EndpointType.StreamSource: bmp.UriSource = new Uri("/UI/Icons/pu_source.png", UriKind.Relative); Width = Height = 20; break; default: // Should be impossible to get here (unless breaking changes are made to this code) throw new InvalidOperationException(); } // Set the icon image IconImage.SetValue(Image.SourceProperty, bmp); IconImage.Visibility = System.Windows.Visibility.Visible; // Make sure the arrow is hidden ArrowIcon.Visibility = System.Windows.Visibility.Collapsed; } }