Beispiel #1
0
        private void menuRemoveItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem source    = sender as ToolStripMenuItem;
            GraphItemAdapter  graphItem = source.Tag as GraphItemAdapter;

            plotSurface.Remove(graphItem.LinePlot, false);
            graphItems.Remove(graphItem);

            ToolStripItem removeItem = null;

            foreach (ToolStripItem button in toolStripItems.Items)
            {
                if (object.Equals(button.Tag, graphItem))
                {
                    removeItem = button;
                    break;
                }
            }

            if (removeItem != null)
            {
                toolStripItems.Items.Remove(removeItem);
            }

            graphItem.Dispose();
        }
Beispiel #2
0
        private void menuSourceUnits_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem menuitem  = sender as ToolStripMenuItem;
            GraphItemAdapter  graphItem = menuitem.Tag as GraphItemAdapter;

            Unit sourceUnit = UnitConverter.GetUnit(menuitem.Text);

            if (sourceUnit != null)
            {
                graphItem.SourceUnits = sourceUnit;
                // start with identity conversion
                graphItem.Conversion = UnitConverter.GetConversion(sourceUnit, sourceUnit);

                // find the menuDestUnitCollection menu item two levels up
                ToolStripDropDownButton parent2          = (ToolStripDropDownButton)menuitem.OwnerItem.OwnerItem;
                ToolStripMenuItem       destUnitMenuItem = (ToolStripMenuItem)parent2.DropDownItems["menuDestUnitCollection"];
                PopulateDestUnits(destUnitMenuItem, sourceUnit, graphItem);

                menuitem.Checked = true;
                ToolStripMenuItem parent1 = (ToolStripMenuItem)menuitem.OwnerItem;
                foreach (ToolStripMenuItem child in parent1.DropDownItems)
                {
                    if (child != menuitem)
                    {
                        child.Checked = false;
                    }
                }
            }
        }
Beispiel #3
0
        private void menuDestUnits_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem menuitem  = sender as ToolStripMenuItem;
            GraphItemAdapter  graphItem = menuitem.Tag as GraphItemAdapter;

            Unit destUnit = UnitConverter.GetUnit(menuitem.Text);

            graphItem.Conversion = UnitConverter.GetConversion(graphItem.SourceUnits, destUnit);

            menuitem.Checked = true;
            ToolStripMenuItem parent = (ToolStripMenuItem)menuitem.OwnerItem;

            foreach (ToolStripMenuItem item in parent.DropDownItems)
            {
                if (item != menuitem)
                {
                    item.Checked = false;
                }
            }
        }
Beispiel #4
0
        private void PopulateDestUnits(ToolStripMenuItem parent, Unit source, GraphItemAdapter graphItem)
        {
            if (source == null)
            {
                parent.Enabled = false;
            }
            else
            {
                parent.Enabled = true;
                parent.DropDownItems.Clear();

                List <string> items = new List <string>();

                foreach (UnitConversion conversion in UnitConverter.GetConversions(source))
                {
                    items.Add(conversion.To.Abbreviation ?? conversion.To.Name);
                }

                items.Sort();

                string targetConversionName = null;
                if (graphItem.Conversion != null)
                {
                    targetConversionName = graphItem.Conversion.To.Abbreviation ?? graphItem.Conversion.To.Name;
                }

                foreach (string name in items)
                {
                    ToolStripMenuItem item = new ToolStripMenuItem(name, null, menuDestUnits_Click);
                    item.Tag = graphItem;
                    if (name == targetConversionName)
                    {
                        item.Checked = true;
                    }

                    parent.DropDownItems.Add(item);
                }
            }
        }
Beispiel #5
0
        public void AddGraphItem(string item)
        {
            if (CanAddItem(item))
            {
                IDataItemClient dataItem    = OperationalInterface.Dataset[item];
                DataItemAdapter dataAdapter = DataItemAdapter.GetDefaultAdapter(dataItem);

                Color            itemColor = colors[colorInd++];
                GraphItemAdapter graphItem = new GraphItemAdapter(item, itemColor, windowSize, dataAdapter);

                // add tool bar button
                // create the image for the button
                Bitmap image = (Bitmap)Properties.Resources.GraphIcon.Clone();
                ImageColorizer.Colorize(image, itemColor);
                ToolStripDropDownButton button = new ToolStripDropDownButton(item, image);
                button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
                button.Tag          = graphItem;

                // add the drop down items
                ToolStripMenuItem menuSourceUnitSet = new ToolStripMenuItem("Item Units");
                foreach (Unit unit in UnitConverter.GetUnitsEnumerator())
                {
                    ToolStripMenuItem menuSourceUnit = new ToolStripMenuItem(unit.Abbreviation ?? unit.Name, null, menuSourceUnits_Click);
                    menuSourceUnit.Tag = graphItem;
                    if (object.Equals(unit, graphItem.SourceUnits))
                    {
                        menuSourceUnit.Checked = true;
                    }

                    menuSourceUnitSet.DropDownItems.Add(menuSourceUnit);
                }

                ToolStripMenuItem menuDestUnitSet = new ToolStripMenuItem("Dest Units");
                menuDestUnitSet.Name = "menuDestUnitCollection";
                if (graphItem.SourceUnits != null)
                {
                    graphItem.Conversion = UnitConverter.GetConversion(graphItem.SourceUnits, graphItem.SourceUnits);
                    PopulateDestUnits(menuDestUnitSet, graphItem.SourceUnits, graphItem);
                }
                else
                {
                    menuDestUnitSet.Enabled = false;
                }

                ToolStripMenuItem menuRemoveItem = new ToolStripMenuItem("Remove", Properties.Resources.Delete, menuRemoveItem_Click);
                menuRemoveItem.Tag = graphItem;

                // add the menu items to the button
                button.DropDownItems.Add(menuSourceUnitSet);
                button.DropDownItems.Add(menuDestUnitSet);
                button.DropDownItems.Add(new ToolStripSeparator());
                button.DropDownItems.Add(menuRemoveItem);

                toolStripItems.Items.Add(button);

                // add to the plot
                plotSurface.Add(graphItem.LinePlot);

                graphItems.Add(graphItem);
            }
        }