SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
BlockDisplay.xaml.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Windows;
6 using System.Windows.Controls;
7 using System.Windows.Data;
8 using System.Windows.Documents;
9 using System.Windows.Input;
10 using System.Windows.Media;
11 using System.Windows.Media.Imaging;
12 using System.Windows.Navigation;
13 using System.Windows.Shapes;
14 
15 namespace SeciControls
16 {
20  public partial class BlockDisplay : UserControl, IUpdate
21  {
22  private List<String> _infoToDisplay = new List<String>();
23  private Brush _brushNormal = new SolidColorBrush(Colors.Black);
24  private Brush _brushOutOfRange = new SolidColorBrush(Colors.Red);
25  private Brush _brushDisabled = new SolidColorBrush(Colors.LightGray);
26  private List<TextBlock> _blocks = new List<TextBlock>();
27 
28  #region IsBigFontsProperty Dependency Property
29 
30  public static readonly DependencyProperty IsBigFontsProperty = DependencyProperty.RegisterAttached("IsBigFonts", typeof(Boolean),
31  typeof(BlockDisplay), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits));
32 
33  public static void SetIsBigFonts(UIElement element, Boolean value)
34  {
35  element.SetValue(IsBigFontsProperty, value);
36  }
37  public static Boolean GetIsBigFonts(UIElement element)
38  {
39  return (Boolean)element.GetValue(IsBigFontsProperty);
40  }
41 
42  #endregion
43 
44  public BlockDisplay()
45  {
46  InitializeComponent();
47  }
48 
49  public void SetBlocksToShow(String[] names)
50  {
51  _infoToDisplay.Clear();
52  if (names != null && names.GetLength(0) > 0)
53  {
54  for (int i=0; i < names.GetLength(0); ++i)
55  {
56  if (Seci.Managers.BlockMgr.Blocks[names[i]].Visible)
57  {
58  _infoToDisplay.Add(names[i]);
59  }
60  }
61  }
62 
63  if (_infoToDisplay.Count > 0)
64  {
65  this.Visibility = Visibility.Visible;
66  }
67  else
68  {
69  this.Visibility = Visibility.Collapsed;
70  }
71 
72  setupBlocks();
73  }
74 
75  #region IUpdate Members
76 
77  public void UpdateControl()
78  {
79  for (int i = 0; i < _infoToDisplay.Count; ++i)
80  {
81  try
82  {
83  String val = Seci.Managers.BlockMgr.GetFormattedBlockValue(_infoToDisplay[i], false, false, false);
84  TextBlock temp = _blocks[i];
85 
86  if (!Seci.Managers.BlockMgr.Blocks[_infoToDisplay[i]].BlockEnabled)
87  {
88  temp.Foreground = _brushDisabled;
89  }
90  else if (Seci.Managers.BlockMgr.Blocks[_infoToDisplay[i]].OutOfRange())
91  {
92  temp.Foreground = _brushOutOfRange;
93  }
94  else
95  {
96  temp.Foreground = _brushNormal;
97  }
98 
99  temp.Text = val;
100  }
101  catch (Exception e)
102  {
103  Console.WriteLine(e.Message);
104  }
105  }
106  }
107 
108  private void setupBlocks()
109  {
110  stackPnl.Children.Clear();
111  _blocks.Clear();
112 
113  //Check for groups
114  //List<String> groups = new List<String>();
115  //if (_infoToDisplay.Count > 0)
116  //{
117  // for (int i = 0; i < _infoToDisplay.Count; ++i)
118  // {
119  // string groupTemp;
120 
121  // if (String.IsNullOrEmpty(Seci.Managers.BlockMgr.Blocks[_infoToDisplay[i]].Group))
122  // {
123  // groupTemp = "None";
124  // }
125  // else
126  // {
127  // groupTemp = Seci.Managers.BlockMgr.Blocks[_infoToDisplay[i]].Group;
128  // }
129 
130  // if (!groups.Contains(groupTemp))
131  // {
132  // groups.Add(groupTemp);
133  // }
134  // }
135  //}
136 
137  var groups = Seci.Managers.BlockMgr.Groups;
138  if (groups.Count == 0 ||(groups.Count == 1 && groups[0].Name == "None")) //Ignore groupings
139  {
140  if (_infoToDisplay.Count > 0)
141  {
142  WrapPanel tempWrap = setupWrapPanel(null);
143 
144  Border border = createBorder();
145  border.Child = tempWrap;
146 
147  stackPnl.Children.Add(border);
148 
149  for (int i = 0; i < _infoToDisplay.Count; ++i)
150  {
151  TextBlock temp = createTextBlock(_infoToDisplay[i]);
152  _blocks.Add(temp);
153  tempWrap.Children.Add(temp);
154  }
155  }
156  }
157  else //Use groupings
158  {
159  Dictionary<String, WrapPanel> wraps = new Dictionary<string, WrapPanel>();
160 
161  //if (groups.Contains("None"))
162  //{
163  // //Move to end
164  // groups.Remove("None");
165  // groups.Sort();
166  // groups.Add("None");
167  //}
168  List<string> used = new List<string>();
169 
170  for (int i = 0; i < _infoToDisplay.Count; ++i)
171  {
172  if (!used.Contains(Seci.Managers.BlockMgr.Blocks[_infoToDisplay[i]].Group))
173  {
174  used.Add(Seci.Managers.BlockMgr.Blocks[_infoToDisplay[i]].Group);
175  }
176  }
177 
178  foreach (Seci.Definitions.BlockGroup group in groups)
179  {
180  //Only show the group if it has at least one block
181  if (used.Contains(group.Name))
182  {
183  WrapPanel wrap = setupWrapPanel(group.Name);
184  wraps.Add(group.Name, wrap);
185 
186  Border border = createBorder();
187  border.Child = wrap;
188 
189  stackPnl.Children.Add(border);
190  }
191  }
192 
193  for (int i = 0; i < _infoToDisplay.Count; ++i)
194  {
195  TextBlock temp = createTextBlock(_infoToDisplay[i]);
196  _blocks.Add(temp);
197  wraps[Seci.Managers.BlockMgr.Blocks[_infoToDisplay[i]].Group].Children.Add(temp);
198  }
199  }
200  }
201 
202  private Border createBorder()
203  {
204  Border temp = new Border();
205  temp.Style = (Style)FindResource("OuterBorderStyle");
206  return temp;
207  }
208 
209  private TextBlock createTextBlock(String text)
210  {
211  TextBlock temp = new TextBlock();
212  temp.Style = (Style)FindResource("StandardTextBlockStyle");
213  temp.Text = text;
214  return temp;
215  }
216 
217  private WrapPanel setupWrapPanel(String name)
218  {
219  WrapPanel wrap = new WrapPanel();
220  wrap.Style = (Style)FindResource("WrapPanelStyle");
221 
222  if (!String.IsNullOrEmpty(name))
223  {
224  TextBlock temp = new TextBlock();
225  temp.Style = (Style)FindResource("HeaderTextBlockStyle");
226  if (name == "None")
227  {
228  temp.Text = "Other";
229  }
230  else
231  {
232  temp.Text = name;
233  }
234  wrap.Children.Add(temp);
235  }
236 
237  return wrap;
238  }
239 
240  #endregion
241  }
242 }
Interaction logic for BlockDisplay.xaml
static void SetIsBigFonts(UIElement element, Boolean value)
static readonly DependencyProperty IsBigFontsProperty
void SetBlocksToShow(String[] names)
static Boolean GetIsBigFonts(UIElement element)
TextBlock createTextBlock(String text)
WrapPanel setupWrapPanel(String name)