private void toolStripButtonMedRemove_Click(object sender, EventArgs e)
 {
     if (listBoxMedium.SelectedItem != null)
     {
         if (Materials.Count > 1)
         {
             int index = listBoxMedium.SelectedIndex;
             MaterialDataBinder binder = listBoxMedium.SelectedItem as MaterialDataBinder;
             Materials.Remove(binder);
             Materials.ResetBindings();
             backgroundMaterialEditor.Materials.Remove(binder);
             backgroundMaterialEditor.Materials.ResetBindings();
             foreach (LayerMaterialEditor editor in Editors)
             {
                 editor.Materials.Remove(binder);
                 editor.Materials.ResetBindings();
             }
             listBoxMedium.SelectedIndex = Math.Min(index, listBoxMedium.Items.Count - 1);
         }
         else
         {
             MaterialDataBinder binder = new MaterialDataBinder(new MaterialData());
             Materials[0] = binder;
             Materials.ResetBindings();
             backgroundMaterialEditor.Materials[0] = binder;
             backgroundMaterialEditor.Materials.ResetBindings();
             foreach (LayerMaterialEditor editor in Editors)
             {
                 editor.Materials[0] = binder;
                 editor.Materials.ResetBindings();
             }
         }
     }
 }
        private void toolStripButtonMedAdd_Click(object sender, EventArgs e)
        {
            MaterialDataBinder binder  = new MaterialDataBinder(new MaterialData(MaterialData.MaterialType.Dielectric));
            string             defName = binder.Data.Name;
            bool accepted;

            for (int suffix = 1; true; suffix++)
            {
                accepted = true;
                foreach (MaterialDataBinder item in Materials)
                {
                    if (binder.Data.Name == item.Data.Name)
                    {
                        accepted = false;
                        break;
                    }
                }
                if (accepted)
                {
                    break;
                }
                binder.Data.Name = defName + suffix.ToString();
            }

            Materials.Add(binder);
            Materials.ResetBindings();
            backgroundMaterialEditor.Materials.Add(binder);
            backgroundMaterialEditor.Materials.ResetBindings();
            foreach (LayerMaterialEditor editor in Editors)
            {
                editor.Materials.Add(binder);
                editor.Materials.ResetBindings();
            }
        }
        private void toolStripButtonMedLower_Click(object sender, EventArgs e)
        {
            int index = listBoxMedium.SelectedIndex;

            if (index < 0 || index >= listBoxMedium.Items.Count - 1)
            {
                return;
            }
            MaterialDataBinder binder = listBoxMedium.SelectedItem as MaterialDataBinder;

            Materials.RemoveAt(index);
            Materials.Insert(index + 1, binder);
            Materials.ResetBindings();
            backgroundMaterialEditor.Materials.RemoveAt(index);
            backgroundMaterialEditor.Materials.Insert(index + 1, binder);
            backgroundMaterialEditor.Materials.ResetBindings();
            foreach (LayerMaterialEditor editor in Editors)
            {
                editor.Materials.RemoveAt(index);
                editor.Materials.Insert(index + 1, binder);
                editor.Materials.ResetBindings();
            }
            listBoxMedium.SelectedIndex = index + 1;
        }
		private void toolStripButtonMedRemove_Click(object sender, EventArgs e)
			{
			if( listBoxMedium.SelectedItem != null )
				{
				if( Materials.Count > 1 )
					{
					int index = listBoxMedium.SelectedIndex;
					MaterialDataBinder binder = listBoxMedium.SelectedItem as MaterialDataBinder;
					Materials.Remove( binder );
					Materials.ResetBindings();
					backgroundMaterialEditor.Materials.Remove( binder );
					backgroundMaterialEditor.Materials.ResetBindings();
					foreach( LayerMaterialEditor editor in Editors )
						{
						editor.Materials.Remove( binder );
						editor.Materials.ResetBindings();
						}
					listBoxMedium.SelectedIndex = Math.Min( index, listBoxMedium.Items.Count - 1 );
					}
				else
					{
					MaterialDataBinder binder = new MaterialDataBinder( new MaterialData() );
					Materials[0] = binder;
					Materials.ResetBindings();
					backgroundMaterialEditor.Materials[0] = binder;
					backgroundMaterialEditor.Materials.ResetBindings();
					foreach( LayerMaterialEditor editor in Editors )
						{
						editor.Materials[0] = binder;
						editor.Materials.ResetBindings();
						}
					}
				}
			}
		private void toolStripButtonMedAdd_Click(object sender, EventArgs e)
			{
			MaterialDataBinder binder = new MaterialDataBinder( new MaterialData( MaterialData.MaterialType.Dielectric ) );
			string defName = binder.Data.Name;
			bool accepted;
			for( int suffix = 1 ; true ; suffix++ )
				{
				accepted = true;
				foreach( MaterialDataBinder item in Materials )
					if( binder.Data.Name == item.Data.Name )
						{
						accepted = false;
						break;
						}
				if( accepted )
					{
					break;
					}
				binder.Data.Name = defName + suffix.ToString();
				}

			Materials.Add( binder );
			Materials.ResetBindings();
			backgroundMaterialEditor.Materials.Add( binder );
			backgroundMaterialEditor.Materials.ResetBindings();
			foreach( LayerMaterialEditor editor in Editors )
				{
				editor.Materials.Add( binder );
				editor.Materials.ResetBindings();
				}
			}