Beispiel #1
0
        public static ILabelStyle CreateLabelStyle(this IGraph graph, ILabelOwner owner)
        {
            if (owner is INode)
            {
                return(graph.NodeDefaults.Labels.GetStyleInstance(owner));
            }
            if (owner is IEdge)
            {
                return(graph.EdgeDefaults.Labels.GetStyleInstance(owner));
            }
            var port = owner as IPort;

            if (port != null)
            {
                if (port.Owner is INode)
                {
                    return(graph.NodeDefaults.Ports.Labels.GetStyleInstance(owner));
                }
                if (port.Owner is IEdge)
                {
                    return(graph.EdgeDefaults.Ports.Labels.GetStyleInstance(owner));
                }
            }
            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Updates the labels of a given owner.
        /// </summary>
        /// <param name="graph">The graph the owner belongs to.</param>
        /// <param name="labelDefaults">The defaults to create the labels with.</param>
        /// <param name="item">The owner of the label.</param>
        /// <param name="labelData">The data to create the labels from.</param>
        private static void UpdateLabels(IGraph graph, ILabelDefaults labelDefaults, ILabelOwner item, object labelData)
        {
            var labels = item.Labels;

            if (labelData == null)
            {
                while (labels.Count > 0)
                {
                    graph.Remove(labels[labels.Count - 1]);
                }
            }
            else if (labels.Count == 0)
            {
                var layoutParameter = labelDefaults.GetLayoutParameterInstance(item);
                var labelStyle      = labelDefaults.GetStyleInstance(item);
                graph.AddLabel(item, labelData.ToString(), layoutParameter, labelStyle, null, labelData);
            }
            else if (labels.Count > 0)
            {
                var label = labels[0];
                if (label.Text != labelData.ToString())
                {
                    graph.SetLabelText(label, labelData.ToString());
                }
                if (label.Tag != labelData)
                {
                    label.Tag = labelData;
                }
            }
        }
 public MyEditLabelHelper(ILabelOwner owner, ILabel label, ILabelModelParameter firstLabelParam, ILabelStyle firstLabelStyle)
 {
     this.owner           = owner;
     this.label           = label;
     this.firstLabelParam = firstLabelParam;
     this.firstLabelStyle = firstLabelStyle;
     TextBoxBackground    = Color.LightGray;
     TextBoxForeground    = Color.DarkSlateGray;
 }
Beispiel #4
0
 /// <summary>
 /// Builds the options for the first label of the node instance.
 /// </summary>
 /// <param name="context">The context to use for building.</param>
 /// <param name="subject">The current node instance.</param>
 protected virtual void BuildLabelOptions(IOptionBuilderContext context, ILabelOwner subject)
 {
     if (subject.Labels.Count > 0)
     {
         context = context.CreateChildContext(DefaultNodePropertyMapBuilder.LabelPropertyName);
         ILabel label = subject.Labels[0];
         if (label != null)
         {
             IOptionBuilder builder = GetLabelOptionBuilder(context, label);
             if (builder != null)
             {
                 builder.AddItems(context, typeof(ILabel), label);
             }
         }
     }
 }
        /// <summary>
        /// Calls <see cref="ISnapLineProvider.AddSnapLines"/> of the wrapped provider and adds custom <see cref="OrthogonalSnapLine"/>s
        /// for the <paramref name="item"/>.
        /// </summary>
        /// <param name="context">The context which holds the settings for the snap lines. </param>
        /// <param name="args">The argument to use for adding snap lines.</param>
        /// <param name="item">The item to add snaplines for.</param>
        public void AddSnapLines(GraphSnapContext context, CollectGraphSnapLinesEventArgs args, IModelItem item)
        {
            wrapped.AddSnapLines(context, args, item);

            // add snaplines for orthogonal labels
            ILabelOwner labelOwner = item as ILabelOwner;

            if (labelOwner != null)
            {
                foreach (ILabel label in labelOwner.Labels)
                {
                    var    layout = label.GetLayout();
                    double upX    = Math.Round(layout.UpX, 6); // round UpX to it's first 6 digits
                    if (upX == 0 || upX == 1 || upX == -1)     // check if it's orthogonal
                    // label is orthogonal
                    {
                        RectD bounds = layout.GetBounds();

                        // add snaplines to the top, bottom, left and right border of the label
                        PointD topCenter = bounds.TopLeft + new PointD(layout.Width / 2, 0);
                        var    snapLine  = new OrthogonalSnapLine(SnapLineOrientation.Horizontal, SnapLineSnapTypes.Bottom,
                                                                  SnapLine.SnapLineFixedLineKey, topCenter, bounds.MinX - 10, bounds.MaxX + 10, label, 100);
                        args.AddAdditionalSnapLine(snapLine);

                        PointD bottomCenter = bounds.BottomLeft + new PointD(layout.Width / 2, 0);
                        snapLine = new OrthogonalSnapLine(SnapLineOrientation.Horizontal, SnapLineSnapTypes.Top,
                                                          SnapLine.SnapLineFixedLineKey, bottomCenter, bounds.MinX - 10, bounds.MaxX + 10, label, 100);
                        args.AddAdditionalSnapLine(snapLine);

                        PointD leftCenter = bounds.TopLeft + new PointD(0, layout.Height / 2);
                        snapLine = new OrthogonalSnapLine(SnapLineOrientation.Vertical, SnapLineSnapTypes.Right,
                                                          SnapLine.SnapLineFixedLineKey, leftCenter, bounds.MinY - 10, bounds.MaxY + 10, label, 100);
                        args.AddAdditionalSnapLine(snapLine);

                        PointD rightCenter = bounds.TopRight + new PointD(0, layout.Height / 2);
                        snapLine = new OrthogonalSnapLine(SnapLineOrientation.Vertical, SnapLineSnapTypes.Left,
                                                          SnapLine.SnapLineFixedLineKey, rightCenter, bounds.MinY - 10, bounds.MaxY + 10, label, 100);
                        args.AddAdditionalSnapLine(snapLine);
                    }
                }
            }
        }
Beispiel #6
0
 protected override ILabelModelParameter GetLabelParameter(IInputModeContext context, ILabelOwner owner)
 {
     if (style.TableNodeStyle.TableRenderingOrder == TableRenderingOrder.ColumnsFirst)
     {
         return(PoolHeaderLabelModel.North);
     }
     else
     {
         return(PoolHeaderLabelModel.West);
     }
 }
 /// <summary>
 /// Provides the label model parameter for newly created labels.
 /// </summary>
 /// <remarks>
 /// This implementation returns the special parameter for the first label if there are no labels yet, and the base label
 /// model parameter otherwise.
 /// </remarks>
 protected override ILabelModelParameter GetLabelParameter(IInputModeContext context, ILabelOwner owner)
 {
     return(owner.Labels.Count == 0 ? firstLabelParam : base.GetLabelParameter(context, owner));
 }
 /// <summary>
 /// Provides the label style for newly created labels.
 /// </summary>
 /// <remarks>
 /// This implementation return the special style for the first if there are no labels yet, and the base style otherwise.
 /// </remarks>
 protected override ILabelStyle GetLabelStyle(IInputModeContext context, ILabelOwner owner)
 {
     return(owner.Labels.Count == 0 ? firstLabelStyle : base.GetLabelStyle(context, owner));
 }
Beispiel #9
0
 public static ILabel AddLabel(this IGraph graph, ILabelOwner owner, ILabelModelParameter parameter, string text, object tag = null)
 {
     return(graph.AddLabel(owner, text, parameter, null, null, tag));
 }
Beispiel #10
0
 public static ILabel AddLabel(this IGraph graph, ILabelOwner owner, ILabelModelParameter parameter, ILabelStyle style, string text, SizeD preferredSize, object tag = null)
 {
     return(graph.AddLabel(owner, text, parameter, style, preferredSize, tag));
 }