Ejemplo n.º 1
0
        public void InitializeInputModes()
        {
            // Create a default editor input mode
            GraphEditorInputMode editMode = new GraphEditorInputMode();

            // then customize it to suit our needs

            // orthogonal edges
            editMode.OrthogonalEdgeEditingContext = new OrthogonalEdgeEditingContext();

            // snapping
            editMode.SnapContext = new GraphSnapContext {
                CollectEdgeSnapLines            = false,
                CollectNodePairSegmentSnapLines = false,
                CollectNodePairSnapLines        = false,
                CollectPortSnapLines            = false,
                SnapBendAdjacentSegments        = false,
                SnapPortAdjacentSegments        = false,
                SnapBendsToSnapLines            = false,
                SnapSegmentsToSnapLines         = false,
                GridSnapType = GridSnapTypes.All,
                NodeGridConstraintProvider = new GridConstraintProvider <INode>(20),
                GridSnapDistance           = double.MaxValue,
                VisualizeSnapResults       = false,
            };


            // tweak the CreateEdgeInputMode
            editMode.CreateEdgeInputMode.ShowPortCandidates    = ShowPortCandidates.None;
            editMode.CreateEdgeInputMode.SnapToTargetCandidate = false;

            //Enable label editing only for edges and edge labels
            editMode.LabelEditableItems = GraphItemTypes.Edge | GraphItemTypes.EdgeLabel;

            // we add a command to the KeyboardInputMode, although this will not be triggered
            // by a keyboard gesture, this has the advantage that the command is disabled
            // if any of the input modes owns the mutex.
            editMode.KeyboardInputMode.AddCommandBinding(UMLClassStyle.AdjustNodeBoundsCommand,
                                                         delegate(object sender, ExecutedCommandEventArgs args) {
                INode node = args.Parameter as INode;
                if (node != null && node.Style is UMLClassStyle)
                {
                    UMLClassStyle style = (UMLClassStyle)node.Style;
                    var preferredSize   = style.GetPreferredSize(node);
                    preferredSize       = new SizeD(Math.Max(node.Layout.Width, preferredSize.Width), preferredSize.Height);
                    RectD newBounds     = new RectD(node.Layout.GetTopLeft(), preferredSize);
                    editMode.SetNodeLayout(node, newBounds);
                }
            });

            // customize the node creation
            editMode.NodeCreator = CreateNode;

            // and finally register our input mode with the control.
            graphControl.InputMode = editMode;
        }
Ejemplo n.º 2
0
 public UmlClickHandler(INode node, UMLClassStyle umlStyle)
 {
     this.node     = node;
     this.umlStyle = umlStyle;
 }
Ejemplo n.º 3
0
        public UMLClassStyleDemo()
        {
            InitializeComponent();
            InitializeInputModes();
            openButton.SetCommand(Commands.Open, graphControl);

            saveButton.SetCommand(Commands.SaveAs, graphControl);

            graphControl.FileOperationsEnabled = true;


            description.LoadFile(new MemoryStream(Resources.description), RichTextBoxStreamType.RichText);

            // Decorate the lookup of the nodes to change the default behavior
            // for moving, selection paint, resizing, etc.
            IGraph graph = graphControl.Graph;

            graph.SetUndoEngineEnabled(true);

            var nodeDecorator = graph.GetDecorator().NodeDecorator;

            // set a custom IPositionHandler for nodes with UMLClassStyle
            nodeDecorator.PositionHandlerDecorator.SetImplementationWrapper(
                node => node.Style is UMLClassStyle,
                (node, handler) => new UMLPositionHandler(handler, node));

            // for resizing the item using a shadow and grid
            nodeDecorator.ReshapeHandleProviderDecorator.SetImplementationWrapper(
                node => node.Style is UMLClassStyle,
                (node, provider) => {
                if (provider is ReshapeHandleProviderBase)
                {
                    ((ReshapeHandleProviderBase)provider).HandlePositions = HandlePositions.East | HandlePositions.West;
                }
                return(provider);
            });
            nodeDecorator.NodeSnapResultProviderDecorator.SetImplementation(node => node.Style is UMLClassStyle, new MyNodeSnapResultProvider());

            // constrain the size
            nodeDecorator.SizeConstraintProviderDecorator.SetImplementation(
                node => node.Style is UMLClassStyle,
                new NodeSizeConstraintProvider(new SizeD(100, 0), new SizeD(800, double.MaxValue)));


            // to decorate the node's lookup for types which are not provided with the GraphDecorator
            // we need to decorate the "low level" lookup decorator:
            var lookupDecorator = graph.SafeLookup <ILookupDecorator>();

            // set a custom IReshapeHandler
            // for dragging the item using a shadow and grid
            lookupDecorator.Add <INode, IReshapeHandler>((node, handler) => new UMLReshapeHandler(handler));

            // get the class info from the tag:
            lookupDecorator.Add <INode, ClassInfo>(node => node.Tag as ClassInfo);

            // 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
            UMLClassStyle umlStyle = new UMLClassStyle();

            graph.NodeDefaults.Style = umlStyle;
            graph.NodeDefaults.Size  = new SizeD(100, 100);

            // Add a sample node
            INode sampleNode = graph.CreateNode(new PointD(100, 100));

            sampleNode.Tag = CreateDefaultClassInfo();
            SizeF preferredSize = umlStyle.GetPreferredSize(sampleNode);

            graph.SetNodeLayout(sampleNode, new RectD(new PointD(100, 100), preferredSize));

            // 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
                }
            };
        }