178 lines
6.6 KiB
C#
178 lines
6.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using Telerik.WinControls.UI;
|
|
using Telerik.WinControls.Layouts;
|
|
using System.Drawing;
|
|
using Telerik.WinControls;
|
|
using System.Windows.Forms;
|
|
using SafeMobileLib;
|
|
using System.ComponentModel;
|
|
|
|
namespace Safedispatch_4_0.Radio
|
|
{
|
|
class RadioGatewayStatusVisualItem : IconListViewVisualItem
|
|
{
|
|
private LightVisualElement imageElement;
|
|
private LightVisualElement titleElement;
|
|
//private LightVisualElement artistElement;
|
|
private StackLayoutPanel stackLayout;
|
|
|
|
protected override void CreateChildElements()
|
|
{
|
|
base.CreateChildElements();
|
|
|
|
stackLayout = new StackLayoutPanel();
|
|
stackLayout.Orientation = System.Windows.Forms.Orientation.Vertical;
|
|
stackLayout.AutoSize = true;
|
|
stackLayout.AutoSizeMode = RadAutoSizeMode.FitToAvailableSize;
|
|
stackLayout.StretchHorizontally = false;
|
|
stackLayout.StretchVertically = true;
|
|
stackLayout.Alignment = ContentAlignment.MiddleCenter;
|
|
|
|
imageElement = new LightVisualElement();
|
|
imageElement.DrawText = false;
|
|
imageElement.Size = new Size(45, 45);
|
|
imageElement.MaxSize = new Size(45, 45);
|
|
imageElement.ImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
|
imageElement.StretchHorizontally = true;
|
|
imageElement.StretchVertically = false;
|
|
imageElement.ShouldHandleMouseInput = false;
|
|
imageElement.AutoSize = true;
|
|
imageElement.AutoSizeMode = RadAutoSizeMode.WrapAroundChildren;
|
|
imageElement.ImageAlignment = ContentAlignment.TopCenter;
|
|
imageElement.Alignment = ContentAlignment.TopCenter;
|
|
//imageElement.Margin = new System.Windows.Forms.Padding(10, 5, 10, 5);
|
|
|
|
stackLayout.Children.Add(imageElement);
|
|
|
|
titleElement = new LightVisualElement();
|
|
titleElement.StretchHorizontally = true;
|
|
titleElement.StretchVertically = true;
|
|
titleElement.AutoSize = true;
|
|
titleElement.AutoSizeMode = RadAutoSizeMode.FitToAvailableSize;
|
|
titleElement.TextAlignment = ContentAlignment.BottomCenter;
|
|
titleElement.Margin = new Padding(5, 5, 5, 5);
|
|
titleElement.Font = new System.Drawing.Font("Segoe UI", 9, FontStyle.Bold, GraphicsUnit.Point);
|
|
titleElement.TextWrap = true;
|
|
titleElement.ShouldHandleMouseInput = false;
|
|
stackLayout.Children.Add(titleElement);
|
|
|
|
/*
|
|
artistElement = new LightVisualElement();
|
|
artistElement.TextAlignment = ContentAlignment.MiddleLeft;
|
|
artistElement.Margin = new Padding(10, 5, 10, 5);
|
|
artistElement.Font = new System.Drawing.Font("Segoe UI", 9, FontStyle.Bold | FontStyle.Italic, GraphicsUnit.Point);
|
|
artistElement.ForeColor = Color.FromArgb(255, 114, 118, 125);
|
|
stackLayout.Children.Add(artistElement);
|
|
*/
|
|
|
|
this.Children.Add(stackLayout);
|
|
|
|
this.Margin = new Padding(5);
|
|
//this.Shape = new RoundRectShape(3);
|
|
//this.BorderColor = Color.FromArgb(255, 110, 153, 210);
|
|
//this.BorderGradientStyle = GradientStyles.Solid;
|
|
//this.DrawBorder = true;
|
|
this.DrawText = false;
|
|
this.DrawFill = true;
|
|
this.BackColor = Color.FromArgb(255, 0, 139, 207);
|
|
this.GradientStyle = GradientStyles.Solid;
|
|
}
|
|
|
|
//private bool createdEventListener = false;
|
|
|
|
protected override void SynchronizeProperties()
|
|
{
|
|
|
|
|
|
base.SynchronizeProperties();
|
|
|
|
if (this.Data == null)
|
|
return;
|
|
|
|
|
|
RadioGateway radioGW = (RadioGateway)this.Data.DataBoundItem;
|
|
|
|
if (radioGW == null)
|
|
return;
|
|
|
|
/*
|
|
if (!createdEventListener)
|
|
{
|
|
Utils.WriteLine("CREATED PROPERTY CHANGED " + radioGW.Name, ConsoleColor.Green);
|
|
radioGW.PropertyChanged += radioGW_PropertyChanged;
|
|
createdEventListener = true;
|
|
}*/
|
|
|
|
UpdateUIElements(radioGW);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Listener and event handler for when a property changes value in
|
|
/// the gridData object. This will cause the grid element to redraw
|
|
/// with new values
|
|
/// </summary>
|
|
private void radioGW_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
{
|
|
//Utils.WriteLine("radioGW_PropertyChanged: " + e.PropertyName, ConsoleColor.Magenta);
|
|
switch (e.PropertyName)
|
|
{
|
|
case "radioState":
|
|
{
|
|
if (this.Data == null)
|
|
return;
|
|
|
|
RadioGateway radioGW = (RadioGateway)this.Data.DataBoundItem;
|
|
|
|
if (radioGW == null)
|
|
return;
|
|
|
|
// update the UI elements
|
|
UpdateUIElements(radioGW);
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void UpdateUIElements(RadioGateway radioGateway)
|
|
{
|
|
Bitmap image = Dispatcher.Properties.Resources.l_bullet_b;
|
|
|
|
switch(radioGateway.State1)
|
|
{
|
|
case RadioState.HANGTIME: image = Dispatcher.Properties.Resources.l_bullet_y; break;
|
|
case RadioState.IDLE: image = Dispatcher.Properties.Resources.l_bullet_b; break;
|
|
case RadioState.RX: image = Dispatcher.Properties.Resources.l_bullet_r; break;
|
|
case RadioState.TX: image = Dispatcher.Properties.Resources.l_bullet_g; break;
|
|
case RadioState.OFFLINE: image = Dispatcher.Properties.Resources.l_bullet_mo; break;
|
|
default: image = Dispatcher.Properties.Resources.l_bullet_mo; break;
|
|
}
|
|
this.imageElement.Image = image;
|
|
this.titleElement.Text = radioGateway.Name;
|
|
//this.artistElement.Text = radioGateway.Id + "." + radioGateway.Gw_id;
|
|
}
|
|
|
|
protected override SizeF MeasureOverride(SizeF availableSize)
|
|
{
|
|
SizeF measuredSize = base.MeasureOverride(availableSize);
|
|
|
|
this.stackLayout.Measure(measuredSize);
|
|
|
|
return measuredSize;
|
|
}
|
|
|
|
protected override SizeF ArrangeOverride(SizeF finalSize)
|
|
{
|
|
base.ArrangeOverride(finalSize);
|
|
|
|
this.stackLayout.Arrange(new RectangleF(PointF.Empty, finalSize));
|
|
|
|
return finalSize;
|
|
}
|
|
}
|
|
}
|