/// <summary> /// Initializes the styles. /// </summary> protected virtual void InitializeStyles() { customerNodeStyle = new NodeControlNodeStyle("CustomerNodeTemplate"); productNodeStyle = new NodeControlNodeStyle("ProductNodeTemplate"); labelStyle = new LabelControlLabelStyle("LabelTemplate"); edgeStyle = new EdgeSegmentControlEdgeStyle("EdgeSegmentTemplate") { SegmentThickness = 5, PathStyle = new PolylineEdgeStyle { Pen = new Pen(Brushes.Black, 5) } }; portStyle = new PortControlPortStyle("PortTemplate") { RenderSize = new SizeD(5, 5) }; // set an initial default size for all nodes Graph.NodeDefaults.Size = new SizeD(150, 80); // and set the customer node style as the default Graph.NodeDefaults.Style = customerNodeStyle; // the same for the edges labels.... Graph.EdgeDefaults.Labels.Style = labelStyle; // edges.... Graph.EdgeDefaults.Style = edgeStyle; // and the ports Graph.NodeDefaults.Ports.Style = portStyle; }
/// <summary> /// Creates a GraphBuilder instance that's preconfigured with our demo's styles. /// </summary> internal static (GraphBuilder, NodesSource <INeo4jNode>, EdgesSource <IRelationship>) CreateGraphBuilder(GraphControl graphControl, IGraph graph, List <INeo4jNode> nodes, List <IRelationship> edges) { var builder = new GraphBuilder(graph); var nodesSource = builder.CreateNodesSource(nodes, n => n.Id); nodesSource.NodeCreator.TagProvider = n => n; var nodeStyle = new NodeControlNodeStyle("NodeStyle"); nodesSource.NodeCreator.Defaults.Style = nodeStyle; var edgesSource = builder.CreateEdgesSource(edges, e => e.StartNodeId, e => e.EndNodeId, e => e.Id); edgesSource.EdgeCreator.Defaults.Style = new BezierEdgeStyle { TargetArrow = Arrows.Default }; var labelBinding = edgesSource.EdgeCreator.CreateLabelBinding(item => item.Type); labelBinding.Defaults.LayoutParameter = new EdgeSegmentLabelModel().CreateParameterFromSource(0, 0, EdgeSides.AboveEdge); var context = graphControl.CreateRenderContext(); builder.NodeCreated += (sender, e) => { // Ensure that nodes have the correct size e.Graph.SetNodeLayout(e.Item, RectD.FromCenter(e.Item.Layout.GetCenter(), nodeStyle.GetPreferredSize(context, e.Item))); }; return(builder, nodesSource, edgesSource); }
protected virtual void OnLoaded(object src, EventArgs args) { InitializeInputModes(); // Decorate the lookup of the nodes to change the default behavior // for moving, selection paint, resizing, etc. IGraph graph = graphControl.Graph; ILookupDecorator decorator = graph.Lookup <ILookupDecorator>(); if (decorator != null && decorator.CanDecorate(typeof(INode))) { decorator.AddLookup(typeof(INode), new UMLNodeLookupChainLink()); } // register a node grid with the canvas' input mode context lookup GridConstraintProvider <INode> nodeGrid = new GridConstraintProvider <INode>(20); IContextLookupChainLink gridLink = Lookups.AddingLookupChainLink(typeof(IGridConstraintProvider <INode>), nodeGrid); graphControl.InputModeContextLookupChain.Add(gridLink); // remove the highlight indicator manager from the input context - disables highlight hints IContextLookupChainLink hidingLink = Lookups.HidingLookupChainLink(typeof(HighlightIndicatorManager <IModelItem>)); graphControl.InputModeContextLookupChain.Add(hidingLink); // Create a style var umlStyle = new NodeControlNodeStyle("ClassInfoNodeStyle"); graph.NodeDefaults.Style = umlStyle; // Add a sample node INode node = CreateNode(null, graphControl.Graph, new PointD(100, 100), null); node.Tag = CreateDefaultClassInfo(); // Enable clipboard graphControl.Clipboard = new GraphClipboard { ToClipboardCopier = { Clone = GraphCopier.CloneTypes.Tags, ReferentialIdentityTypes = GraphCopier.CloneTypes.All }, FromClipboardCopier = { Clone = GraphCopier.CloneTypes.Tags, ReferentialIdentityTypes = GraphCopier.CloneTypes.All }, DuplicateCopier = { Clone = GraphCopier.CloneTypes.Tags, ReferentialIdentityTypes = GraphCopier.CloneTypes.All } }; }
/// <summary> /// Initializes the graph instance setting default styles /// and creating a small sample graph. /// </summary> protected virtual void InitializeGraph() { IGraph graph = graphControl.Graph; /// Enable undo/redo. graph.SetUndoEngineEnabled(true); graph.NodeDefaults.Size = new SizeD(120, 60); var style = new NodeControlNodeStyle("ClipboardStyle"); // set the style as the default for all new nodes graph.NodeDefaults.Style = style; graph.NodeDefaults.Labels.LayoutParameter = ExteriorLabelModel.North; graph.EdgeDefaults.Labels.LayoutParameter = NinePositionsEdgeLabelModel.CenterAbove; // add customized copy support for this demo graph.GetDecorator().NodeDecorator.ClipboardHelperDecorator.SetImplementation(new TaggedNodeClipboardHelper()); // Create nodes and an edge. var sharedBusinessObject = CreateBusinessObject(); INode node1 = graph.CreateNode(new PointD(100, 100)); node1.Tag = sharedBusinessObject; INode node2 = graph.CreateNode(new PointD(350, 100)); node2.Tag = sharedBusinessObject; INode node3 = graph.CreateNode(new PointD(100, 200)); node3.Tag = CreateBusinessObject(); graph.AddLabel(node1, "Label 1"); graph.AddLabel(node2, "Label 2"); graph.AddLabel(graph.CreateEdge(node1, node2), "Shared Object"); // reset the Undo queue so the initial graph creation cannot be undone graph.GetUndoEngine().Clear(); // register specialized copiers that can deal with our business objects graphControl.Clipboard.FromClipboardCopier.NodeCopied += NodeCopiedOnPaste; graphControl.Clipboard.ToClipboardCopier.NodeCopied += NodeCopiedOnCopy; // now initialize the second graph var graph2 = graphControl2.Graph; graph2.SetUndoEngineEnabled(true); graph2.NodeDefaults = graph.NodeDefaults; graph2.GetDecorator().NodeDecorator.ClipboardHelperDecorator.SetImplementation(new TaggedNodeClipboardHelper()); graphControl2.Clipboard = graphControl.Clipboard; }
private void InitializeGraph() { // create new nodestyle that delegates to other // styles for different zoom ranges var nodeStyle = new NodeControlNodeStyle("EmployeeNodeControlStyle"); graphControl.CurrentItemChanged += graphControl_CurrentItemChanged; graphControl.Graph.NodeDefaults.Style = nodeStyle; graphControl.Graph.NodeDefaults.Size = new SizeD(250, 100); graphControl.Graph.EdgeDefaults.Style = new PolylineEdgeStyle { SmoothingLength = 10 }; }
public BusinessModelAdapterWindow() { InitializeComponent(); // create a sample list of customers // create the template Customer dummyCustomer = new Customer("Enter A Name", 0); customers = new ObservableCollection <Customer>(); this.Resources.Add("DummyCustomer", dummyCustomer); Customer customer1 = new Customer("Mr. Tester", 42); Customer customer2 = new Customer("Mrs. Tester", 43); Customer customer3 = new Customer("Baby Tester", 2); Customer customer4 = new Customer("Aunt Tester", 34); this.customers.Add(customer1); this.customers.Add(customer2); this.customers.Add(customer3); this.customers.Add(customer4); // add some relationships between customers customer2.RelatedCustomers.Add(customer3); customer2.RelatedCustomers.Add(customer4); customer1.RelatedCustomers.Add(customer2); customer2.RelatedCustomers.Add(customer1); // publish the list so that the listview can pick it up this.Resources.Add("Customers", this.customers); // configure the GraphControl GraphEditorInputMode editorInputMode = new GraphEditorInputMode(); // configure some structural edits editorInputMode.CreateBendInputMode.Enabled = false; editorInputMode.ShowHandleItems = GraphItemTypes.Edge; editorInputMode.DeletableItems = GraphItemTypes.None; editorInputMode.CreateEdgeInputMode.Enabled = true; editorInputMode.CreateEdgeInputMode.EdgeCreator = EdgeCreator; // register custom code for the creation of new entities editorInputMode.NodeCreator = NodeCreator; // set the mode graphControl.InputMode = editorInputMode; // define the default edge style ArcEdgeStyle style = new ArcEdgeStyle { Pen = new Pen(Brushes.Black, 2), Height = 30, TargetArrow = Arrows.Default, ProvideHeightHandle = false }; Graph.EdgeDefaults.Style = style; // fetch the node style from the xaml templates customerNodeStyle = new NodeControlNodeStyle("CustomerNodeStyle") { OutlineShape = new System.Windows.Shapes.Rectangle { RadiusX = 3, RadiusY = 3 } }; // now create the graph from the bindinglist CreateGraph(this.customers); // register for change notification ((INotifyCollectionChanged)customers).CollectionChanged += customers_CollectionChanged; layout = CreateLayout(); }