/// <summary> /// Encodes an mxCell and wraps the XML up inside the /// XML of the user object (inversion). /// </summary> public override XmlNode AfterEncode(mxCodec enc, Object obj, XmlNode node) { if (obj is mxCell && node is XmlElement) { mxCell cell = (mxCell)obj; if (cell.Value != null) { if (cell.Value is XmlNode) { // Wraps the graphical annotation up in the // user object (inversion) by putting the // result of the default encoding into // a clone of the user object (node type 1) // and returning this cloned user object. XmlElement tmp = (XmlElement)node; node = enc.Document.ImportNode((XmlNode)cell.Value, true); node.AppendChild(tmp); // Moves the id attribute to the outermost // XML node, namely the node which denotes // the object boundaries in the file. String id = tmp.GetAttribute("id"); ((XmlElement)node).SetAttribute("id", id); tmp.RemoveAttribute("id"); } } } return(node); }
/* (non-Dotnetdoc) * see com.mxgraph.mxICell.Clone() */ public Object Clone() { mxCell cell = new mxCell(); cell.Collapsed = Collapsed; cell.Connectable = Connectable; cell.Edge = Edge; cell.Style = Style; cell.Vertex = Vertex; cell.Visible = Visible; mxGeometry geometry = Geometry; if (geometry != null) { cell.Geometry = geometry.Clone(); } Object value = Value; if (value is XmlNode) { cell.Value = ((XmlNode)value).CloneNode(true); } else { cell.Value = Value; } return(cell); }
/// <summary> /// Creates a new root cell with a default layer (child 0). /// </summary> public Object CreateRoot() { mxCell root = new mxCell(); root.Insert(new mxCell()); return(root); }
/// <summary> /// Clones the children of the source cell into the given target cell in /// this model and adds an entry to the mapping that maps from the source /// cell to the target cell with the same id or the clone of the source cell /// that was inserted into this model. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="cloneAllEdges"></param> /// <param name="mapping"></param> protected void MergeChildrenImpl(mxICell from, mxICell to, bool cloneAllEdges, Dictionary <Object, Object> mapping) { BeginUpdate(); try { int childCount = from.ChildCount(); for (int i = 0; i < childCount; i++) { mxICell cell = from.GetChildAt(i); String id = cell.Id; mxICell target = (mxICell)((id != null && (!IsEdge(cell) || !cloneAllEdges)) ? GetCell(id) : null); // Clones and adds the child if no cell exists for the id if (target == null) { mxCell clone = (mxCell)cell.Clone(); clone.Id = id; // Do *NOT* use model.add as this will move the edge away // from the parent in updateEdgeParent if maintainEdgeParent // is enabled in the target model target = to.Insert(clone); CellAdded(target); } // Stores the mapping for later reconnecting edges mapping[cell] = target; // Recurses MergeChildrenImpl(cell, target, cloneAllEdges, mapping); } } finally { EndUpdate(); } }
/* (non-Dotnetdoc) * see com.mxgraph.mxICell.Clone() */ public Object Clone() { mxCell cell = new mxCell(); cell.Collapsed = Collapsed; cell.Connectable = Connectable; cell.Edge = Edge; cell.Style = Style; cell.Vertex = Vertex; cell.Visible = Visible; mxGeometry geometry = Geometry; if (geometry != null) { cell.Geometry = geometry.Clone(); } Object value = Value; if (value is XmlNode) { cell.Value = ((XmlNode)value).CloneNode(true); } else { cell.Value = Value; } return cell; }
/// <summary> /// Creates a new vertex to be used in insertVertex. /// </summary> public Object CreateVertex(Object parent, string id, Object value, double x, double y, double width, double height, string style, bool relative) { mxGeometry geometry = new mxGeometry(x, y, width, height); geometry.Relative = relative; mxCell vertex = new mxCell(value, geometry, style); vertex.Id = id; vertex.Vertex = true; vertex.Connectable = true; return vertex; }
/// <summary> /// Creates the edge to be used in insertEdge. This implementation does /// not set the source and target of the edge, these are set when the /// edge is added to the model. /// </summary> public Object CreateEdge(Object parent, string id, Object value, Object source, Object target, string style) { mxCell edge = new mxCell(value, new mxGeometry(), style); edge.Id = id; edge.Edge = true; edge.Geometry.Relative = true; return edge; }
/// <summary> /// Decodes an mxCell and uses the enclosing XML node as /// the user object for the cell (inversion). /// </summary> public override XmlNode BeforeDecode(mxCodec dec, XmlNode node, Object obj) { XmlElement inner = (XmlElement)node; if (obj is mxCell) { mxCell cell = (mxCell)obj; String classname = GetName(); if (!node.Name.Equals(classname)) { // Passes the inner graphical annotation node to the // object codec for further processing of the cell. XmlNode tmp = inner.GetElementsByTagName(classname)[0]; if (tmp != null && tmp.ParentNode == node) { inner = (XmlElement)tmp; // Removes annotation and whitespace from node XmlNode tmp2 = tmp.PreviousSibling; while (tmp2 != null && tmp2.NodeType == XmlNodeType.Text) { XmlNode tmp3 = tmp2.PreviousSibling; if (tmp2.Value.Trim().Length == 0) { tmp2.ParentNode.RemoveChild(tmp2); } tmp2 = tmp3; } // Removes more whitespace tmp2 = tmp.NextSibling; while (tmp2 != null && tmp2.NodeType == XmlNodeType.Text) { XmlNode tmp3 = tmp2.PreviousSibling; if (tmp2.Value.Trim().Length == 0) { tmp2.ParentNode.RemoveChild(tmp2); } tmp2 = tmp3; } tmp.ParentNode.RemoveChild(tmp); } else { inner = null; } // Creates the user object out of the XML node XmlElement value = (XmlElement)node.CloneNode(true); cell.Value = value; String id = value.GetAttribute("id"); if (id != null) { cell.Id = id; value.RemoveAttribute("id"); } } else { cell.Id = ((XmlElement)node).GetAttribute("id"); } // Preprocesses and removes all Id-references // in order to use the correct encoder (this) // for the known references to cells (all). if (inner != null && idrefs != null) { foreach (string attr in idrefs) { string rf = inner.GetAttribute(attr); if (rf != null && rf.Length > 0) { inner.RemoveAttribute(attr); Object tmp = (dec.Objects.ContainsKey(rf)) ? dec.Objects[rf] : null; if (tmp == null) { tmp = dec.Lookup(rf); } if (tmp == null) { // Needs to decode forward reference XmlNode element = dec.GetElementById(rf); if (element != null) { mxObjectCodec decoder = mxCodecRegistry .GetCodec(element.Name); if (decoder == null) { decoder = this; } tmp = decoder.Decode(dec, element); } } SetFieldValue(obj, attr, tmp); } } } } return(inner); }
/// <summary> /// Creates a new root cell with a default layer (child 0). /// </summary> public Object CreateRoot() { mxCell root = new mxCell(); root.Insert(new mxCell()); return root; }