public static object InitUmlInterfaceFocus(IFocus focus, object model) { var facade = MemopadApplication.Instance; //((StyledTextFocus) focus).IsEmacsEdit = facade.Settings.KeyScheme == KeySchemeKind.Emacs; var elem = (UmlClassifier)model; if (elem != null) { var stereotypeRun = new Run(UmlTextUtil.GetStereotypeText(elem, "interface")); var nameRun = new Run(elem.Name); var para = new Paragraph(stereotypeRun); var line = new LineSegment(); line.InsertAfter(nameRun); para.InsertAfter(line); para.HorizontalAlignment = HorizontalAlignment.Center; para.Padding = Insets.Empty; return(new StyledText(para) { Font = MemopadApplication.Instance.Settings.GetDefaultUmlFont(), VerticalAlignment = VerticalAlignment.Top, }); } else { return(new StyledText()); } }
public static object InitUmlOperationFocus(IFocus focus, object model) { var facade = MemopadApplication.Instance; //((StyledTextFocus) focus).IsEmacsEdit = facade.Settings.KeyScheme == KeySchemeKind.Emacs; focus.Figure.Padding = MemopadConsts.UmlFeaturePadding; var ope = model as UmlOperation; if (ope != null) { var visText = UmlTextUtil.GetVisibilityText(ope.Visibility); var visibility = string.IsNullOrEmpty(visText)? "-": visText; var paras = string.IsNullOrEmpty(ope.Parameters)? "": ope.Parameters; var typeName = string.IsNullOrEmpty(ope.TypeName)? "": ope.TypeName; var text = visibility + " " + ope.Name + "(" + paras + ")" + ": " + typeName; var para = new Paragraph(new Run(text)) { HorizontalAlignment = Mkamo.Common.DataType.HorizontalAlignment.Left, Padding = Insets.Empty, }; return(new StyledText(para) { Font = MemopadApplication.Instance.Settings.GetDefaultUmlFont(), VerticalAlignment = VerticalAlignment.Top, }); } else { return(new StyledText()); } }
protected override void RefreshEditor(RefreshContext context, SimpleRect figure, UmlOperation model) { var text = UmlTextUtil.GetOperationText(model); var run = new Run(text); var para = new Paragraph(run) { Padding = Insets.Empty, HorizontalAlignment = Mkamo.Common.DataType.HorizontalAlignment.Left, }; var st = new StyledText.Core.StyledText(para) { Font = MemopadApplication.Instance.Settings.GetDefaultUmlFont(), VerticalAlignment = Mkamo.Common.DataType.VerticalAlignment.Center, }; if (model.IsStatic) { run.Font = new FontDescription(run.Font, run.Font.Style | FontStyle.Underline); } if (model.IsAbstract) { run.Font = new FontDescription(run.Font, run.Font.Style | FontStyle.Italic); } figure.StyledText = st; figure.AdjustSize(); var clsFig = Host.Parent.Parent.Figure as INode; if (clsFig != null) { clsFig.AdjustSize(); } }
public static FocusUndoer CommitInterfaceFocus(IFocus focus, object model, object value, bool isRedo, out bool isCancelled) { var elem = (UmlClassifier)model; var oldName = elem.Name; var oldStereotype = elem.Stereotype; var strs = ((StyledText)value).Lines; var newName = ""; var newStereotype = ""; if (strs.Any()) { var stereotypes = new HashSet <string>(); foreach (var str in strs) { if (!string.IsNullOrEmpty(str)) { var parsed = default(string[]); if (UmlTextUtil.ParseStereotype(str, out parsed)) { foreach (var s in parsed) { if (!s.Equals("interface", StringComparison.OrdinalIgnoreCase)) { stereotypes.Add(s); } } } else { newName = str.Trim(); } } } var arr = stereotypes.ToArray(); Array.Sort(arr); newStereotype = string.Join(", ", arr); } isCancelled = false; if (newName == oldName && newStereotype == oldStereotype) { return(null); } else { elem.Name = newName; elem.Stereotype = newStereotype; return((f, m) => { var cls = (UmlClassifier)m; cls.Name = oldName; cls.Stereotype = oldStereotype; }); } }
protected override void RefreshEditor(RefreshContext context, UmlClassFigure figure, UmlClass model) { var stereotypeRun = string.IsNullOrEmpty(model.Stereotype)? null: new Run(UmlTextUtil.GetStereotypeText(model)); var nameRun = new Run(model.Name); var para = default(Paragraph); if (stereotypeRun == null) { para = new Paragraph(nameRun) { Padding = Insets.Empty, HorizontalAlignment = Mkamo.Common.DataType.HorizontalAlignment.Center, }; } else { para = new Paragraph(stereotypeRun) { Padding = Insets.Empty, HorizontalAlignment = Mkamo.Common.DataType.HorizontalAlignment.Center, }; var line = new LineSegment(); line.InsertBefore(nameRun); para.InsertAfter(line); } var st = new StyledText.Core.StyledText(para) { Font = MemopadApplication.Instance.Settings.GetDefaultUmlFont(), VerticalAlignment = Mkamo.Common.DataType.VerticalAlignment.Top, }; if (model.IsAbstract) { nameRun.Font = new FontDescription(nameRun.Font, nameRun.Font.Style | FontStyle.Italic); } figure.StyledText = st; var layout = (ListLayout)figure.Layout; layout.Padding = new Insets( 0, figure.StyledTextBounds.Height + figure.Padding.Height, 0, 0 ); figure.InvalidateLayout(); figure.AdjustSize(); UpdateMemoMarkHandles(model); }
private void UpdateMemberEndNameLabel(LineEdge figure, UmlProperty end, bool isSource) { var locKind = isSource? "EdgeFirstDistance": "EdgeLastDistance"; var nameLabels = figure.Children.Where( fig => { var constraint = figure.GetLayoutConstraint(fig) as object[]; var kind = (string)constraint[0]; var dir = (LocateDirectionKind)constraint[3]; return(kind == locKind && dir == LocateDirectionKind.Left); } ); var name = end.Name; if (string.IsNullOrEmpty(name)) { foreach (var label in nameLabels.ToArray()) { figure.Children.Remove(label); } } else { var text = name; if (!StringUtil.IsNullOrWhitespace(end.Stereotype)) { text = UmlTextUtil.GetStereotypeText(end) + " " + text; } if (end.Visibility != UmlVisibilityKind.None) { text = UmlTextUtil.GetVisibilityText(end.Visibility) + " " + text; } if (nameLabels.Any()) { var label = nameLabels.First() as INode; label.StyledText = CreateLabelStyledText(text); } else { var label = new Mkamo.Figure.Figures.Label(); label.StyledText = CreateLabelStyledText(text); figure.Children.Add(label); var constraint = IsOrthogonal() ? new object[] { locKind, 4, 0, LocateDirectionKind.Left } : new object[] { locKind, 8, 8, LocateDirectionKind.Left }; figure.SetLayoutConstraint(label, constraint); } } }
public static FocusUndoer CommitUmlOperationFocus(IFocus focus, object model, object value, bool isRedo, out bool isCancelled) { var ope = (UmlOperation)model; var oldName = ope.Name; var oldVisibility = ope.Visibility; var oldParams = ope.Parameters; var oldTypeName = ope.TypeName; var strs = ((StyledText)value).Lines; var newValue = strs.Any() ? strs[0] : ""; string newVisibilityText, newName, newParams, newTypeName; isCancelled = !UmlTextUtil.ParseUmlOperation(newValue, out newVisibilityText, out newName, out newParams, out newTypeName); if (isCancelled) { return(null); } var newVisibility = UmlTextUtil.GetVisibility(newVisibilityText); if (newName == oldName && newVisibility == oldVisibility && newParams == oldParams && newTypeName == oldTypeName) { return(null); } else { ope.Name = newName; ope.Visibility = UmlTextUtil.GetVisibility(newVisibilityText); ope.Parameters = newParams; ope.TypeName = newTypeName; return((f, m) => { var o = (UmlOperation)m; o.Name = oldName; o.Visibility = oldVisibility; o.Parameters = oldParams; o.TypeName = oldTypeName; }); } }
private void UpdateMemberEndMultiplicityLabel(LineEdge figure, UmlProperty end, bool isSource) { var locKind = isSource? "EdgeFirstDistance": "EdgeLastDistance"; var multiLabels = figure.Children.Where( fig => { var constraint = figure.GetLayoutConstraint(fig) as object[]; var kind = (string)constraint[0]; var dir = (LocateDirectionKind)constraint[3]; return(kind == locKind && dir == LocateDirectionKind.Right); } ); var text = UmlTextUtil.GetMultiplicityText(end); if (string.IsNullOrEmpty(text)) { foreach (var label in multiLabels.ToArray()) { figure.Children.Remove(label); } } else { if (multiLabels.Any()) { var label = multiLabels.First() as INode; label.StyledText = CreateLabelStyledText(text); } else { var label = new Mkamo.Figure.Figures.Label(); label.StyledText = CreateLabelStyledText(text); figure.Children.Add(label); var constraint = IsOrthogonal() ? new object[] { locKind, 4, 0, LocateDirectionKind.Right } : new object[] { locKind, 8, 8, LocateDirectionKind.Right }; figure.SetLayoutConstraint(label, constraint); } } }
public static FocusUndoer CommitUmlPropertyFocus(IFocus focus, object model, object value, bool isRedo, out bool isCancelled) { var prop = (UmlProperty)model; var oldName = prop.Name; var oldVisibility = prop.Visibility; var oldTypeName = prop.TypeName; var strs = ((StyledText)value).Lines; var newValue = strs.Any() ? strs[0] : ""; string newVisibilityText, newName, newTypeName; isCancelled = !UmlTextUtil.ParseUmlProperty(newValue, out newVisibilityText, out newName, out newTypeName); if (isCancelled) { return(null); } var newVisibility = UmlTextUtil.GetVisibility(newVisibilityText); if (newName == oldName && newVisibility == oldVisibility && newTypeName == oldTypeName) { return(null); } else { prop.Name = newName; prop.Visibility = UmlTextUtil.GetVisibility(newVisibilityText); prop.TypeName = newTypeName; return((f, m) => { var p = (UmlProperty)m; p.Name = oldName; p.Visibility = oldVisibility; p.TypeName = oldTypeName; }); } }