179 lines
6.4 KiB
C#
179 lines
6.4 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.Drawing;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
using Telerik.WinControls;
|
|||
|
using Telerik.WinControls.Layouts;
|
|||
|
using Telerik.WinControls.Primitives;
|
|||
|
using Telerik.WinControls.UI;
|
|||
|
|
|||
|
namespace Dispatcher.maptab.UIClasses
|
|||
|
{
|
|||
|
public class ColorTreeContentElement : TreeNodeContentElement
|
|||
|
{
|
|||
|
StackLayoutElement nodeContentContainer;
|
|||
|
StackLayoutElement nodeRightContainer;
|
|||
|
LightVisualElement textElement;
|
|||
|
RadButtonElement buttonElement;
|
|||
|
private Color currentColor = Color.Transparent;
|
|||
|
private ColorUnitTreeNode node = null;
|
|||
|
|
|||
|
protected override Type ThemeEffectiveType
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return typeof(TreeNodeContentElement);
|
|||
|
}
|
|||
|
}
|
|||
|
protected override void InitializeFields()
|
|||
|
{
|
|||
|
base.InitializeFields();
|
|||
|
this.DrawBorder = true;
|
|||
|
this.NumberOfColors = 2;
|
|||
|
this.GradientStyle = GradientStyles.Linear;
|
|||
|
this.Margin = new Padding(5, 5, 5, 5);
|
|||
|
this.Shape = new RoundRectShape(2);
|
|||
|
this.StretchHorizontally = true;
|
|||
|
}
|
|||
|
|
|||
|
public override void Synchronize()
|
|||
|
{
|
|||
|
this.DrawFill = true;
|
|||
|
this.AutoToolTip = true;
|
|||
|
|
|||
|
TreeNodeElement treeNodeElement = this.NodeElement;
|
|||
|
node = (ColorUnitTreeNode)treeNodeElement.Data;
|
|||
|
//DataRowView rowView = (DataRowView)node.DataBoundItem;
|
|||
|
|
|||
|
currentColor = (Color)node.Color;
|
|||
|
|
|||
|
if (!node.Checked)
|
|||
|
buttonElement.Visibility = ElementVisibility.Hidden;
|
|||
|
else
|
|||
|
buttonElement.Visibility = ElementVisibility.Visible;
|
|||
|
|
|||
|
|
|||
|
if (node.Level == 0)
|
|||
|
{
|
|||
|
this.textElement.Text = node.Text;
|
|||
|
buttonElement.Visibility = ElementVisibility.Hidden;
|
|||
|
}
|
|||
|
else if (node.Level == 1)
|
|||
|
{
|
|||
|
this.textElement.Text = node.Text;
|
|||
|
this.buttonElement.Text = "";
|
|||
|
buttonElement.Visibility = ElementVisibility.Hidden;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.textElement.Text = node.Text;
|
|||
|
this.buttonElement.Text = "";
|
|||
|
buttonElement.ButtonFillElement.BackColor = currentColor;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
protected override void CreateChildElements()
|
|||
|
{
|
|||
|
this.Padding = new System.Windows.Forms.Padding(0);
|
|||
|
this.Margin = new System.Windows.Forms.Padding(0);
|
|||
|
|
|||
|
|
|||
|
nodeContentContainer = new StackLayoutElement();
|
|||
|
nodeContentContainer.Orientation = Orientation.Horizontal;
|
|||
|
nodeContentContainer.StretchHorizontally = true;
|
|||
|
nodeContentContainer.StretchVertically = true;
|
|||
|
nodeContentContainer.AutoSizeMode = RadAutoSizeMode.FitToAvailableSize;
|
|||
|
nodeContentContainer.Padding = new System.Windows.Forms.Padding(0);
|
|||
|
nodeContentContainer.Margin = new System.Windows.Forms.Padding(0);
|
|||
|
nodeContentContainer.Alignment = ContentAlignment.MiddleLeft;
|
|||
|
|
|||
|
textElement = new LightVisualElement();
|
|||
|
textElement.ShouldHandleMouseInput = false;
|
|||
|
textElement.NotifyParentOnMouseInput = true;
|
|||
|
textElement.StretchVertically = false;
|
|||
|
textElement.StretchHorizontally = true;
|
|||
|
textElement.TextAlignment = ContentAlignment.MiddleLeft;
|
|||
|
this.nodeContentContainer.Children.Add(textElement);
|
|||
|
|
|||
|
nodeRightContainer = new StackLayoutElement();
|
|||
|
nodeRightContainer.Orientation = Orientation.Horizontal;
|
|||
|
nodeRightContainer.AutoSizeMode = RadAutoSizeMode.FitToAvailableSize;
|
|||
|
nodeRightContainer.StretchHorizontally = false;
|
|||
|
nodeRightContainer.StretchVertically = true;
|
|||
|
nodeRightContainer.Padding = new System.Windows.Forms.Padding(0);
|
|||
|
nodeRightContainer.Margin = new System.Windows.Forms.Padding(0);
|
|||
|
nodeRightContainer.Alignment = ContentAlignment.MiddleRight;
|
|||
|
|
|||
|
|
|||
|
buttonElement = new RadButtonElement();
|
|||
|
buttonElement.Padding = new Padding(0, 0, 0, 0);
|
|||
|
buttonElement.Margin = new System.Windows.Forms.Padding(0);
|
|||
|
buttonElement.Click += buttonElement_Click;
|
|||
|
buttonElement.StretchVertically = true;
|
|||
|
buttonElement.MinSize = new Size(18, 18);
|
|||
|
buttonElement.MaxSize = new Size(18, 18);
|
|||
|
|
|||
|
|
|||
|
this.nodeRightContainer.Children.Add(buttonElement);
|
|||
|
this.nodeContentContainer.Children.Add(nodeRightContainer);
|
|||
|
|
|||
|
DockLayoutPanel.SetDock(this.buttonElement, Telerik.WinControls.Layouts.Dock.Right);
|
|||
|
|
|||
|
this.Children.Add(nodeContentContainer);
|
|||
|
//this.Children.Add(nodeRightContainer);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void buttonElement_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
RadColorDialog dialog = new RadColorDialog();
|
|||
|
dialog.SelectedColor = currentColor;
|
|||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|||
|
{
|
|||
|
// flag that the color had changed
|
|||
|
ColorChanged(new ColorChangedEventArgs()
|
|||
|
{
|
|||
|
oldColor = currentColor,
|
|||
|
newColor = dialog.SelectedColor,
|
|||
|
unitName = node.Text
|
|||
|
});
|
|||
|
|
|||
|
currentColor = dialog.SelectedColor;
|
|||
|
|
|||
|
this.SuspendLayout();
|
|||
|
this.buttonElement.ButtonFillElement.BackColor = currentColor;
|
|||
|
this.ResumeLayout(false, true);
|
|||
|
node.Color = currentColor;
|
|||
|
|
|||
|
//((Vehicle)MainForm2.vehicleHT[(String)vehiclesList.Rows[e.RowIndex].Cells[2].Value]).histcolor = color;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#region COLOR EVENT
|
|||
|
public class ColorChangedEventArgs : EventArgs
|
|||
|
{
|
|||
|
public Color newColor { get; set; }
|
|||
|
public Color oldColor { get; set; }
|
|||
|
public String unitName { get; set; }
|
|||
|
}
|
|||
|
public event EventHandler<ColorChangedEventArgs> OnColorChanged;
|
|||
|
/// <summary>
|
|||
|
/// Event raise for when the alerts are clicked
|
|||
|
/// </summary>
|
|||
|
protected virtual void ColorChanged(ColorChangedEventArgs e)
|
|||
|
{
|
|||
|
EventHandler<ColorChangedEventArgs> handler = this.OnColorChanged;
|
|||
|
if (handler != null)
|
|||
|
handler(this, e);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
}
|