Inheritance: BaseElement, ISerializable, IControllable
Exemplo n.º 1
0
		public void StartEdit(BaseElement el, TextBox textBox)
		{
			if (!(el is ILabelElement)) return;

			if (((ILabelElement) el).Label.ReadOnly) return;

			this.siteLabelElement = el;
			this.labelElement = ((ILabelElement) siteLabelElement).Label;
			this.labelTextBox = textBox;
			if (siteLabelElement is BaseLinkElement)
				this.direction = LabelEditDirection.Both;
			else
				this.direction = LabelEditDirection.UpDown;
			
			EditLabelAction.SetTextBoxLocation(siteLabelElement, labelTextBox);

			labelTextBox.AutoSize = true;
			labelTextBox.Show();
			labelTextBox.Text = labelElement.Text;
			labelTextBox.Font = labelElement.Font;
			labelTextBox.WordWrap = labelElement.Wrap;
			
			labelElement.Invalidate();
			
			switch(labelElement.Alignment)
			{
				case StringAlignment.Near:
					labelTextBox.TextAlign = HorizontalAlignment.Left;
					break;
				case StringAlignment.Center:
					labelTextBox.TextAlign = HorizontalAlignment.Center;
					break;
				case StringAlignment.Far:
					labelTextBox.TextAlign = HorizontalAlignment.Right;
					break;
			}	

			labelTextBox.KeyPress += new KeyPressEventHandler(labelTextBox_KeyPress);
			labelTextBox.Focus();
			center.X = textBox.Location.X + (textBox.Size.Width / 2);
			center.Y = textBox.Location.Y + (textBox.Size.Height / 2);
		}
Exemplo n.º 2
0
        private void UpdateLinkPosition(NodeElement node)
        {
            foreach (ConnectorElement conn in node.Connectors)
            {
                foreach (BaseElement el in conn.Links)
                {
                    BaseLinkElement lnk  = (BaseLinkElement)el;
                    IController     ctrl = ((IControllable)lnk).GetController();
                    if (ctrl is IMoveController)
                    {
                        IMoveController mctrl = (IMoveController)ctrl;
                        if (!mctrl.IsMoving)
                        {
                            lnk.NeedCalcLink = true;
                        }
                    }
                    else
                    {
                        lnk.NeedCalcLink = true;
                    }

                    if (lnk is ILabelElement)
                    {
                        LabelElement label = ((ILabelElement)lnk).Label;

                        ILabelController lblCtrl = ControllerHelper.GetLabelController(lnk);
                        if (lblCtrl != null)
                        {
                            lblCtrl.SetLabelPosition();
                        }
                        else
                        {
                            label.PositionBySite(lnk);
                        }
                        label.Invalidate();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static void SetTextBoxLocation(BaseElement el, TextBox tb)
        {
            if (!(el is ILabelElement))
            {
                return;
            }

            LabelElement lab = ((ILabelElement)el).Label;

            el.Invalidate();
            lab.Invalidate();

            if (lab.Text.Length > 0)
            {
                tb.Location = lab.Location;
                tb.Size     = lab.Size;
            }
            else
            {
                string tmpText = "XXXXXXX";
                Size   sizeTmp = DiagramUtil.MeasureString(tmpText, lab.Font, lab.Size.Width, lab.Format);

                if (el is BaseLinkElement)
                {
                    tb.Size     = sizeTmp;
                    tb.Location = new Point(el.Location.X + (el.Size.Width / 2) - (sizeTmp.Width / 2),
                                            el.Location.Y + (el.Size.Height / 2) - (sizeTmp.Height / 2));
                }
                else
                {
                    sizeTmp.Width = el.Size.Width;
                    tb.Size       = sizeTmp;
                    tb.Location   = new Point(el.Location.X,
                                              el.Location.Y + (el.Size.Height / 2) - (sizeTmp.Height / 2));
                }
            }

            SetTextBoxBorder(tb);
        }
Exemplo n.º 4
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            Point mousePoint;

            //ShowSelectionCorner((document.Action==DesignerAction.Select));

            switch (document.Action)
            {
            // SELECT
            case DesignerAction.Connect:
            case DesignerAction.Select:
                if (e.Button == MouseButtons.Left)
                {
                    mousePoint = Gsc2Goc(new Point(e.X, e.Y));

                    //Verify resize action
                    StartResizeElement(mousePoint);
                    if ((resizeAction != null) && (resizeAction.IsResizing))
                    {
                        break;
                    }

                    //Verify label editing
                    if (isEditLabel)
                    {
                        EndEditLabel();
                    }

                    // Search element by click
                    selectedElement = document.FindElement(mousePoint);
                    mousePoint      = AlignToGrid(mousePoint);

                    if (selectedElement != null)
                    {
                        //Events
                        ElementMouseEventArgs eventMouseDownArg = new ElementMouseEventArgs(selectedElement, e.X, e.Y);
                        OnElementMouseDown(eventMouseDownArg);

                        // Double-click to edit Label
                        if ((e.Clicks == 2) && (selectedElement is ILabelElement))
                        {
                            selectedLabel = ((ILabelElement)selectedElement).Label;
                            StartEditLabel();
                            break;
                        }

                        // Element selected
                        if (selectedElement is ConnectorElement)
                        {
                            StartAddLink((ConnectorElement)selectedElement, mousePoint);
                            selectedElement = null;
                        }
                        else
                        {
                            StartSelectElements(selectedElement, mousePoint);
                        }
                    }
                    else
                    {
                        // If click is on neutral area, clear selection
                        document.ClearSelection();
                        Point p = Gsc2Goc(new Point(e.X, e.Y));;
                        isMultiSelection       = true;
                        selectionArea.Visible  = true;
                        selectionArea.Location = p;
                        selectionArea.Size     = new Size(0, 0);

                        if (resizeAction != null)
                        {
                            resizeAction.ShowResizeCorner(false);
                        }
                    }
                    base.Invalidate();
                }
                break;

            // ADD
            case DesignerAction.Add:

                if (e.Button == MouseButtons.Left)
                {
                    mousePoint = Gsc2Goc(new Point(e.X, e.Y));
                    mousePoint = AlignToGrid(mousePoint);
                    StartAddElement(mousePoint);
                }
                break;

            // DELETE
            case DesignerAction.Delete:
                if (e.Button == MouseButtons.Left)
                {
                    mousePoint = Gsc2Goc(new Point(e.X, e.Y));
                    DeleteElement(mousePoint);
                }
                break;
            }

            base.OnMouseDown(e);
        }
Exemplo n.º 5
0
		public void EndEdit()
		{
			if (siteLabelElement == null) return;
			
			labelTextBox.KeyPress -= new KeyPressEventHandler(labelTextBox_KeyPress);

			ILabelController lblCtrl = ControllerHelper.GetLabelController(siteLabelElement);
			labelElement.Size = MeasureTextSize();
			labelElement.Text = labelTextBox.Text;
			labelTextBox.Hide();
			if (lblCtrl != null)
			{
				lblCtrl.SetLabelPosition();
			}
			else
			{
				labelElement.PositionBySite(siteLabelElement);
			}
			labelElement.Invalidate();
			siteLabelElement = null;
			labelElement = null;
			labelTextBox= null;
		}
Exemplo n.º 6
0
		protected override void OnMouseDown(MouseEventArgs e)
		{
			Point mousePoint;

			//ShowSelectionCorner((document.Action==DesignerAction.Select));

			switch (document.Action)
			{
				// SELECT
				case DesignerAction.Connect:
				case DesignerAction.Select:
					if (e.Button == MouseButtons.Left)
					{
						mousePoint = Gsc2Goc(new Point(e.X, e.Y));
						
						//Verify resize action
						StartResizeElement(mousePoint);
						if ((resizeAction != null) && (resizeAction.IsResizing)) break;

						//Verify label editing
						if (isEditLabel)
						{
							EndEditLabel();
						}

						// Search element by click
						selectedElement = document.FindElement(mousePoint);	
						
						if (selectedElement != null)
						{
							//Events
							ElementMouseEventArgs eventMouseDownArg = new ElementMouseEventArgs(selectedElement, e.X, e.Y);
							OnElementMouseDown(eventMouseDownArg);

							// Double-click to edit Label
							if ((e.Clicks == 2) && (selectedElement is ILabelElement))
							{
								selectedLabel = ((ILabelElement) selectedElement).Label;
								StartEditLabel();
								break;
							}

							// Element selected
							if (selectedElement is ConnectorElement)
							{
								StartAddLink((ConnectorElement) selectedElement, mousePoint);
								selectedElement = null;
							}
							else
								StartSelectElements(selectedElement, mousePoint);
						}
						else
						{
							// If click is on neutral area, clear selection
							document.ClearSelection();
							Point p = Gsc2Goc(new Point(e.X, e.Y));;
							isMultiSelection = true;
							selectionArea.Visible = true;
							selectionArea.Location = p;
							selectionArea.Size = new Size(0, 0);
							
							if (resizeAction != null)
								resizeAction.ShowResizeCorner(false);
						}
						base.Invalidate();
					}
					break;

				// ADD
				case DesignerAction.Add:

					if (e.Button == MouseButtons.Left)
					{
						mousePoint = Gsc2Goc(new Point(e.X, e.Y));
						StartAddElement(mousePoint);
					}
					break;

				// DELETE
				case DesignerAction.Delete:
					if (e.Button == MouseButtons.Left)
					{
						mousePoint = Gsc2Goc(new Point(e.X, e.Y));
						DeleteElement(mousePoint);
					}					
					break;
			}
			
			base.OnMouseDown (e);
		
		}
Exemplo n.º 7
0
        public void Start(Point mousePoint, Document document, OnElementMovingDelegate onElementMovingDelegate)
        {
            this.document = document;
            this.onElementMovingDelegate = onElementMovingDelegate;

            // Get Controllers
            moveCtrl = new IMoveController[document.SelectedElements.Count];
            IMoveController[] moveLabelCtrl = new IMoveController[document.SelectedElements.Count];
            for (int i = document.SelectedElements.Count - 1; i >= 0; i--)
            {
                moveCtrl[i] = ControllerHelper.GetMoveController(document.SelectedElements[i]);

                if ((moveCtrl[i] != null) && (moveCtrl[i].CanMove))
                {
                    onElementMovingDelegate(new ElementEventArgs(document.SelectedElements[i]));
                    moveCtrl[i].Start(mousePoint);

                    //ILabelElement - Move Label inside the element
                    if ((document.SelectedElements[i] is ILabelElement) &&
                        (ControllerHelper.GetLabelController(document.SelectedElements[i]) == null))
                    {
                        LabelElement label = ((ILabelElement)document.SelectedElements[i]).Label;
                        moveLabelCtrl[i] = ControllerHelper.GetMoveController(label);
                        if ((moveLabelCtrl[i] != null) && (moveLabelCtrl[i].CanMove))
                        {
                            moveLabelCtrl[i].Start(mousePoint);
                        }
                        else
                        {
                            moveLabelCtrl[i] = null;
                        }
                    }
                }
                else
                {
                    moveCtrl[i] = null;
                }
            }

            moveCtrl = (IMoveController[])DiagramUtil.ArrayHelper.Append(moveCtrl, moveLabelCtrl);
            moveCtrl = (IMoveController[])DiagramUtil.ArrayHelper.Shrink(moveCtrl, null);

            // Can't move only links
            bool isOnlyLink = true;

            foreach (IMoveController ctrl in moveCtrl)
            {
                // Verify
                if (ctrl != null)
                {
                    ctrl.OwnerElement.Invalidate();

                    if (!(ctrl.OwnerElement is BaseLinkElement) && !(ctrl.OwnerElement is LabelElement))
                    {
                        isOnlyLink = false;
                        break;
                    }
                }
            }
            if (isOnlyLink)
            {
                //End Move the Links
                foreach (IMoveController ctrl in moveCtrl)
                {
                    if (ctrl != null)
                    {
                        ctrl.End();
                    }
                }
                moveCtrl = new IMoveController[] { null };
            }

            //Upper selecion point controller
            UpdateUpperSelectionPoint();
            upperSelPointDragOffset.X = upperSelPoint.X - mousePoint.X;
            upperSelPointDragOffset.Y = upperSelPoint.Y - mousePoint.Y;

            isMoving = true;
        }