public void GetAttributeSpec() { var t = new MapTree(); var r = new MapNode(t, "r"); var c1 = new MapNode(r, "c1"); var c11 = new MapNode(c1, "c11"); var c12 = new MapNode(c1, "c12"); var c13 = new MapNode(c1, "c13"); var c2 = new MapNode(r, "c2"); var c3 = new MapNode(r, "c3", NodePosition.Left); c3.Folded = true; var c31 = new MapNode(c3, "c31"); var c311 = new MapNode(c31, "c311"); var c32 = new MapNode(c3, "c32"); c13.AddAttribute("Speed", "120 kph"); Assert.IsNotNull(t.GetAttributeSpec("Speed")); }
public void Undo() { node.AddAttribute(attribute); }
/// <summary> /// MapNode with it's descendent are created using 'xmlElement' /// </summary> /// <param name="xmlElement">Should be 'node' the element</param> /// <param name="tree"></param> /// <param name="parent">Parent to which deserialized MapNode is attached</param> /// <returns></returns> public MapNode Deserialize(XmlNode xmlElement, MapTree tree, MapNode parent = null) { // temp for holding Xml Attributes XmlAttribute att; string text = (att = xmlElement.Attributes["TEXT"]) != null ? att.Value : ""; string posStr = (att = xmlElement.Attributes["POSITION"]) != null ? att.Value : null; NodePosition pos = Convert.ToNodePosition(posStr); string id = (att = xmlElement.Attributes["ID"]) != null ? att.Value : null; MapNode node = (parent != null ? new MapNode(parent, text, pos, id) : new MapNode(tree, text, id)); if ((att = xmlElement.Attributes["LABEL"]) != null) { node.Label = att.Value; } if ((att = xmlElement.Attributes["FOLDED"]) != null) { var folded = att.Value; if (folded == "true") { node.Folded = true; } } if ((att = xmlElement.Attributes["LINK"]) != null) { node.Link = att.Value; } if ((att = xmlElement.Attributes["BACKGROUND_COLOR"]) != null) { node.BackColor = (Color) new ColorConverter().ConvertFromString( att.Value); } if ((att = xmlElement.Attributes["COLOR"]) != null) { node.Color = (Color) new ColorConverter().ConvertFromString( att.Value); } if ((att = xmlElement.Attributes["STYLE"]) != null) { node.Shape = Convert.ToNodeStyle(att.Value); } if ((att = xmlElement.Attributes["IMAGE"]) != null) { node.Image = att.Value; } if ((att = xmlElement.Attributes["IMAGEALIGNMENT"]) != null) { node.ImageAlignment = (ImageAlignment)Enum.Parse(typeof(ImageAlignment), att.Value, true); } if ((att = xmlElement.Attributes["IMAGEHEIGHT"]) != null) { node.ImageSize = new Size(node.ImageSize.Width, int.Parse(att.Value)); } if ((att = xmlElement.Attributes["IMAGEWIDTH"]) != null) { node.ImageSize = new Size(int.Parse(att.Value), node.ImageSize.Height); } for (var i = 0; i < xmlElement.ChildNodes.Count; i++) { XmlNode tmpXNode = xmlElement.ChildNodes[i]; if (tmpXNode.Name == "node") { this.Deserialize(tmpXNode, tree, node); } else if (tmpXNode.Name == "icon") { att = tmpXNode.Attributes["BUILTIN"]; if (att == null) { continue; } node.Icons.Add(att.Value); } else if (tmpXNode.Name == "font") { if (tmpXNode.Attributes["BOLD"] != null) { string boldStr = tmpXNode.Attributes["BOLD"].Value; if (boldStr == "true") { node.Bold = true; } } if (tmpXNode.Attributes["ITALIC"] != null) { string italic = tmpXNode.Attributes["ITALIC"].Value; if (italic == "true") { node.Italic = true; } } if (tmpXNode.Attributes["STRIKEOUT"] != null) { node.Strikeout = (tmpXNode.Attributes["STRIKEOUT"].Value == "true"); } if (tmpXNode.Attributes["NAME"] != null) { node.FontName = tmpXNode.Attributes["NAME"].Value; } if (tmpXNode.Attributes["SIZE"] != null) { node.FontSize = float.Parse(tmpXNode.Attributes["SIZE"].Value); } } else if (tmpXNode.Name == "edge") { if (tmpXNode.Attributes["COLOR"] != null) { node.LineColor = (Color) new ColorConverter().ConvertFromString(tmpXNode.Attributes["COLOR"].Value); } if (tmpXNode.Attributes["STYLE"] != null) { } if (tmpXNode.Attributes["WIDTH"] != null) { node.LineWidth = Convert.ToLineWidth(tmpXNode.Attributes["WIDTH"].Value); } if (tmpXNode.Attributes["PATTERN"] != null) { node.LinePattern = Convert.ToDashStyle(tmpXNode.Attributes["PATTERN"].Value); } } else if (tmpXNode.Name == "richcontent") { if (tmpXNode.Attributes["TYPE"] != null) { string rcType = tmpXNode.Attributes["TYPE"].Value; //if (rcType == "NODE") // node.RichContentType = NodeRichContentType.NODE; //else // node.RichContentType = NodeRichContentType.NOTE; //all rich content types are loaded as NOTE. If there are more than one on same node (FreeMind allows this), all merged into single note. if (node.NoteText == null) { node.NoteText = tmpXNode.InnerText; } else { node.NoteText = Environment.NewLine + Environment.NewLine + "---" + Environment.NewLine + tmpXNode.InnerText; } } } else if (tmpXNode.Name == "attribute") { string attibuteName = tmpXNode.Attributes["NAME"].Value; string value = null; XmlAttribute xmlAtt = tmpXNode.Attributes["VALUE"]; if (xmlAtt != null) { value = xmlAtt.Value; } node.AddAttribute(attibuteName, value); } } if ((att = xmlElement.Attributes["CREATED"]) != null) { node.Created = (new DateTime(1970, 1, 1)).AddMilliseconds( long.Parse(att.Value)); } // during serialization, modified should be the last attribute to be set // changing other attributes will update 'modified' // setting it at last ensures that the right value is deserialized if ((att = xmlElement.Attributes["MODIFIED"]) != null) { node.Modified = (new DateTime(1970, 1, 1)).AddMilliseconds( long.Parse(att.Value)); } return(node); }