Improving layout change workflow efficiency.
2 // Copyright (C) 2014-2015 Stéphane Lenclud.
4 // This file is part of SharpDisplayManager.
6 // SharpDisplayManager is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // SharpDisplayManager is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with SharpDisplayManager. If not, see <http://www.gnu.org/licenses/>.
21 using System.Collections.Generic;
22 using System.ComponentModel;
27 using System.Threading.Tasks;
28 using System.Windows.Forms;
29 using System.ServiceModel;
30 using System.ServiceModel.Channels;
31 using System.Diagnostics;
32 using SharpLib.Display;
35 namespace SharpDisplayClient
37 public partial class MainForm : Form
39 public StartParams Params { get; set; }
44 ContentAlignment Alignment;
45 TextField iTextFieldTop;
53 InitializeComponent();
54 Alignment = ContentAlignment.MiddleLeft;
55 iTextFieldTop = new TextField(0);
58 public void OnCloseOrder()
66 /// <param name="sender"></param>
67 /// <param name="e"></param>
68 private void MainForm_Load(object sender, EventArgs e)
70 iClient = new Client();
71 iClient.CloseOrderEvent += OnCloseOrder;
74 //Connect using unique name
75 //string name = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt");
76 string name = "Client-" + (iClient.ClientCount() - 1);
77 iClient.SetName(name);
78 //Text = Text + ": " + name;
79 Text = "[[" + name + "]] " + iClient.SessionId;
82 textBoxTop.Text = iClient.Name;
83 textBoxBottom.Text = iClient.SessionId;
87 //Parameters where specified use them
88 if (Params.TopText != "")
90 textBoxTop.Text = Params.TopText;
93 if (Params.BottomText != "")
95 textBoxBottom.Text = Params.BottomText;
98 Location = Params.Location;
100 SetBasicLayoutAndText();
107 public delegate void CloseConnectionDelegate();
108 public delegate void CloseDelegate();
113 public void CloseConnectionThreadSafe()
115 if (this.InvokeRequired)
117 //Not in the proper thread, invoke ourselves
118 CloseConnectionDelegate d = new CloseConnectionDelegate(CloseConnectionThreadSafe);
119 this.Invoke(d, new object[] { });
123 //We are in the proper thread
126 string sessionId = iClient.SessionId;
127 Trace.TraceInformation("Closing client: " + sessionId);
129 Trace.TraceInformation("Closed client: " + sessionId);
139 public void CloseThreadSafe()
141 if (this.InvokeRequired)
143 //Not in the proper thread, invoke ourselves
144 CloseDelegate d = new CloseDelegate(CloseThreadSafe);
145 this.Invoke(d, new object[] { });
149 //We are in the proper thread
155 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
157 CloseConnectionThreadSafe();
160 public bool IsClientReady()
162 return (iClient != null && iClient.IsReady());
165 private void buttonAlignLeft_Click(object sender, EventArgs e)
167 Alignment = ContentAlignment.MiddleLeft;
168 textBoxTop.TextAlign = HorizontalAlignment.Left;
169 textBoxBottom.TextAlign = HorizontalAlignment.Left;
172 private void buttonAlignCenter_Click(object sender, EventArgs e)
174 Alignment = ContentAlignment.MiddleCenter;
175 textBoxTop.TextAlign = HorizontalAlignment.Center;
176 textBoxBottom.TextAlign = HorizontalAlignment.Center;
179 private void buttonAlignRight_Click(object sender, EventArgs e)
181 Alignment = ContentAlignment.MiddleRight;
182 textBoxTop.TextAlign = HorizontalAlignment.Right;
183 textBoxBottom.TextAlign = HorizontalAlignment.Right;
186 private void buttonSetTopText_Click(object sender, EventArgs e)
188 //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft);
189 iTextFieldTop.Text = textBoxTop.Text;
190 iTextFieldTop.Alignment = Alignment;
191 bool res = iClient.SetField(iTextFieldTop);
195 MessageBox.Show("Create you fields first", "Field update error", MessageBoxButtons.OK, MessageBoxIcon.Error);
201 private void buttonSetText_Click(object sender, EventArgs e)
203 SetBasicLayoutAndText();
206 void SetBasicLayoutAndText()
208 //Set one column two lines layout
209 TableLayout layout = new TableLayout(1, 2);
210 iClient.SetLayout(layout);
213 iClient.CreateFields(new DataField[]
215 new TextField(0, textBoxTop.Text, Alignment),
216 new TextField(1, textBoxBottom.Text, Alignment)
221 private void buttonLayoutUpdate_Click(object sender, EventArgs e)
223 //Define a 2 by 2 layout
224 TableLayout layout = new TableLayout(2,2);
225 //Second column only takes up 25%
226 layout.Columns[1].Width = 25F;
227 //Send layout to server
228 iClient.SetLayout(layout);
231 RecordingField recording = new RecordingField();
232 recording.IsActive = true;
235 iClient.CreateFields(new DataField[]
237 new TextField(0, textBoxTop.Text, Alignment),
238 new TextField(1, textBoxBottom.Text, Alignment),
239 new TextField(2, "Third text field", Alignment),
240 new TextField(3, "Forth text field", Alignment),
246 private void buttonSetBitmap_Click(object sender, EventArgs e)
253 Bitmap bitmap = new Bitmap(x2,y2);
254 Pen blackPen = new Pen(Color.Black, 3);
256 // Draw line to screen.
257 using (var graphics = Graphics.FromImage(bitmap))
259 graphics.DrawLine(blackPen, x1, y1, x2, y2);
260 graphics.DrawLine(blackPen, x1, y2, x2, y1);
263 DataField field = new BitmapField(0, bitmap);
264 //field.ColumnSpan = 2;
265 iClient.SetField(field);
268 private void buttonBitmapLayout_Click(object sender, EventArgs e)
270 SetLayoutWithBitmap();
274 /// Define a layout with a bitmap field on the left and two lines of text on the right.
276 private void SetLayoutWithBitmap()
278 //Define a 2 by 2 layout
279 TableLayout layout = new TableLayout(2, 2);
280 //First column only takes 25%
281 layout.Columns[0].Width = 25F;
282 //Second column takes up 75%
283 layout.Columns[1].Width = 75F;
284 //Send layout to server
285 iClient.SetLayout(layout);
287 //Set a bitmap for our first field
293 Bitmap bitmap = new Bitmap(x2, y2);
294 Pen blackPen = new Pen(Color.Black, 3);
296 // Draw line to screen.
297 using (var graphics = Graphics.FromImage(bitmap))
299 graphics.DrawLine(blackPen, x1, y1, x2, y2);
300 graphics.DrawLine(blackPen, x1, y2, x2, y1);
303 //Create a bitmap field from the bitmap we just created
304 BitmapField field = new BitmapField(0, bitmap);
305 //We want our bitmap field to span across two rows
309 iClient.CreateFields(new DataField[]
312 new TextField(1, textBoxTop.Text, Alignment),
313 new TextField(2, textBoxBottom.Text, Alignment)
318 private void buttonIndicatorsLayout_Click(object sender, EventArgs e)
320 //Define a 2 by 4 layout
321 TableLayout layout = new TableLayout(2, 4);
323 layout.Columns[0].Width = 87.5F;
325 layout.Columns[1].Width = 12.5F;
326 //Send layout to server
327 iClient.SetLayout(layout);
329 //Create a bitmap for our indicators field
335 Bitmap bitmap = new Bitmap(x2, y2);
336 Pen blackPen = new Pen(Color.Black, 3);
338 // Draw line to screen.
339 using (var graphics = Graphics.FromImage(bitmap))
341 graphics.DrawLine(blackPen, x1, y1, x2, y2);
342 graphics.DrawLine(blackPen, x1, y2, x2, y1);
345 //Create a bitmap field from the bitmap we just created
346 DataField indicator1 = new BitmapField(2, bitmap);
347 //Create a bitmap field from the bitmap we just created
348 DataField indicator2 = new BitmapField(3, bitmap);
349 //Create a bitmap field from the bitmap we just created
350 DataField indicator3 = new BitmapField(4, bitmap);
351 //Create a bitmap field from the bitmap we just created
352 DataField indicator4 = new BitmapField(5, bitmap);
355 TextField textFieldTop = new TextField(0, textBoxTop.Text, Alignment);
356 textFieldTop.RowSpan = 2;
358 TextField textFieldBottom = new TextField(1, textBoxBottom.Text, Alignment);
359 textFieldBottom.RowSpan = 2;
363 iClient.CreateFields(new DataField[]
375 private void buttonUpdateTexts_Click(object sender, EventArgs e)
378 bool res = iClient.SetFields(new DataField[]
380 new TextField(0, textBoxTop.Text, Alignment),
381 new TextField(1, textBoxBottom.Text, Alignment)
386 MessageBox.Show("Create you fields first", "Field update error", MessageBoxButtons.OK, MessageBoxIcon.Error);
391 private void buttonLayoutOneTextField_Click(object sender, EventArgs e)
393 //Set one column one line layout
394 TableLayout layout = new TableLayout(1, 1);
395 iClient.SetLayout(layout);
398 iClient.CreateFields(new DataField[]
400 new TextField(0, textBoxTop.Text, Alignment)