示例#1
0
        public void RemoveItem(StatusItem si)
        {
            List<Relation> tl = new List<Relation>();

            foreach (Relation r in relations)
            {
                if (r.Source == si || r.Target == si)
                {
                    tl.Add(r);
                }
            }

            if (tl.Count != 0)
            {
                foreach (Relation r in tl)
                {
                    relations.Remove(r);

                    bitfsm.removeRuleStep(r.Source.Name, r.Commands.ToArray());
                }
                tl.Clear();

                Refresh();
            }
        }
示例#2
0
        private void link(StatusItem src, HashSet<string> commands, StatusItem tgt, bool exact, bool force)
        {
            if (bitfsm.addRuleStep(src.Name, commands.ToArray(), tgt.Name, exact) || force)
            {
                string ln = "DUMMY_" + src.Name + "_" + tgt.Name;
                Label dummy = null;
                if (!Controls.ContainsKey(ln))
                {
                    dummy = new Label();
                    dummy.Name = ln;
                    dummy.AutoSize = true;
                    dummy.TextAlign = ContentAlignment.MiddleCenter;
                    dummy.BorderStyle = BorderStyle.FixedSingle;
                    dummy.MouseDown += (_sender, _e) =>
                        {
                            if (_e.Button == MouseButtons.Right)
                            {
                                menuRelation.Tag = dummy;
                                menuRelation.Show(dummy, 30, 20);
                            }
                        };
                    Controls.Add(dummy);
                    dummy.Tag = new List<Relation>();
                }
                else
                {
                    dummy = Controls[ln] as Label;
                }
                Relation r = new Relation(src, tgt, commands, exact);
                relations.Add(r);
                (dummy.Tag as List<Relation>).Add(r);

                Refresh();
            }
            else
            {
                MessageBox.Show(this, "Command(s) add failed", "Bitfsm Editor", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        StatusItem addStatusItem(string text)
        {
            foreach (Control c in Controls)
            {
                if (c.Name == text)
                {
                    MessageBox.Show(this, "A status item named " + text + " already exists", "Bitfsm Editor", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    return null;
                }
            }

            Random rand = new Random();
            int r = rand.Next(255);
            int g = rand.Next(255);
            int b = rand.Next(255);

            StatusItem si = new StatusItem();
            si.Location = new Point(Width / 2, Height / 2);
            si.TitleText = text;
            si.Name = text;
            si.TitleColor = Color.FromArgb(r, g, b);
            si.TitleTextColor = Color.FromArgb(255 - r, 255 - g, 255 - b);
            Controls.Add(si);

            si.AllowDrop = true;
            si.OnDragItem += (_sender, _e) =>
                {
                    (_sender as Control).DoDragDrop(_sender, DragDropEffects.Link);
                };
            si.OnDragEnterItem += (_sender, _e)=>
                {
                    if (_e.Data.GetDataPresent(typeof(StatusItem)))
                    {
                        StatusItem _si = _e.Data.GetData(typeof(StatusItem)) as StatusItem;
                        if (_si == _sender)
                        {
                            _e.Effect = DragDropEffects.None;
                        }
                        else
                        {
                            _e.Effect = DragDropEffects.Link;
                        }
                    }
                    else
                    {
                        _e.Effect = DragDropEffects.None;
                    }
                };
            si.OnDragDropItem += (_sender, _e) =>
                {
                    if (_e.Data.GetDataPresent(typeof(StatusItem)))
                    {
                        StatusItem _si = _e.Data.GetData(typeof(StatusItem)) as StatusItem;
                        if (_si != _sender)
                        {
                            link(_si, _sender as StatusItem);
                        }
                    }
                };
            si.Resize += (_sender, _e) =>
                {
                    Refresh();
                };
            si.MouseDown += (_sender, _e) =>
                {
                    if (_e.Button == MouseButtons.Right)
                    {
                        menuStatus.Tag = si;
                        menuStatus.Show(si, 30, 20);
                    }
                };

            return si;
        }
示例#4
0
 private void link(StatusItem src, StatusItem tgt)
 {
     FormCondition fc = new FormCondition(bitfsm);
     if (DialogResult.OK == fc.ShowDialog(this))
     {
         link(src, fc.Commands, tgt, fc.Exact, false);
     }
 }
示例#5
0
 public Relation(StatusItem src, StatusItem tgt, HashSet<string> cmds, bool ext)
 {
     source = src;
     target = tgt;
     commands = cmds;
     exact = ext;
 }