# HG changeset patch # User sl # Date 1414236911 -7200 # Node ID fd0bb39a7818195f4209e1ed57ec75648843e9e3 # Parent f444344fc20514171fd5a3e79eea4359bdca4c49 Now having a single class for both text and bitmap field. Thus we should soon be able to use common functions to pass in fields. diff -r f444344fc205 -r fd0bb39a7818 Client/Client.cs --- a/Client/Client.cs Wed Oct 22 12:17:52 2014 +0200 +++ b/Client/Client.cs Sat Oct 25 13:35:11 2014 +0200 @@ -76,19 +76,19 @@ Channel.SetLayout(aLayout); } - public void SetText(TextField aTextField) + public void SetText(DataField aField) { - Channel.SetText(aTextField); + Channel.SetText(aField); } - public void SetTexts(System.Collections.Generic.IList aTextFields) + public void SetTexts(System.Collections.Generic.IList aFields) { - Channel.SetTexts(aTextFields); + Channel.SetTexts(aFields); } - public void SetBitmap(BitmapField aBitmapField) + public void SetBitmap(DataField aField) { - Channel.SetBitmap(aBitmapField); + Channel.SetBitmap(aField); } public int ClientCount() diff -r f444344fc205 -r fd0bb39a7818 Client/MainForm.cs --- a/Client/MainForm.cs Wed Oct 22 12:17:52 2014 +0200 +++ b/Client/MainForm.cs Sat Oct 25 13:35:11 2014 +0200 @@ -20,13 +20,13 @@ Client iClient; Callback iCallback; ContentAlignment Alignment; - TextField iTextFieldTop; + DataField iTextFieldTop; public MainForm() { InitializeComponent(); Alignment = ContentAlignment.MiddleLeft; - iTextFieldTop = new TextField(0); + iTextFieldTop = new DataField(0); } @@ -143,10 +143,10 @@ //iClient.SetText(1, "Bottom"); //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft); - iClient.SetTexts(new TextField[] + iClient.SetTexts(new DataField[] { - new TextField(0, textBoxTop.Text, Alignment), - new TextField(1, textBoxBottom.Text, Alignment) + new DataField(0, textBoxTop.Text, Alignment), + new DataField(1, textBoxBottom.Text, Alignment) }); } @@ -177,7 +177,7 @@ graphics.DrawLine(blackPen, x1, y2, x2, y1); } - BitmapField field = new BitmapField(0, bitmap); + DataField field = new DataField(0, bitmap); field.ColumnSpan = 2; iClient.SetBitmap(field); } @@ -218,17 +218,17 @@ } //Create a bitmap field from the bitmap we just created - BitmapField field = new BitmapField(0, bitmap); + DataField field = new DataField(0, bitmap); //We want our bitmap field to span across two rows field.RowSpan = 2; //Send it to our server iClient.SetBitmap(field); //Set texts - iClient.SetTexts(new TextField[] + iClient.SetTexts(new DataField[] { - new TextField(1, textBoxTop.Text, Alignment), - new TextField(2, textBoxBottom.Text, Alignment) + new DataField(1, textBoxTop.Text, Alignment), + new DataField(2, textBoxBottom.Text, Alignment) }); } diff -r f444344fc205 -r fd0bb39a7818 Interface/Interface.cs --- a/Interface/Interface.cs Wed Oct 22 12:17:52 2014 +0200 +++ b/Interface/Interface.cs Sat Oct 25 13:35:11 2014 +0200 @@ -66,8 +66,39 @@ Index = 0; ColumnSpan = 1; RowSpan = 1; + //Text + Text = ""; + Alignment = ContentAlignment.MiddleLeft; + //Bitmap + Bitmap = null; } + //Text constructor + public DataField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft) + { + ColumnSpan = 1; + RowSpan = 1; + Index = aIndex; + Text = aText; + Alignment = aAlignment; + // + Bitmap = null; + } + + //Bitmap constructor + public DataField(int aIndex, Bitmap aBitmap) + { + ColumnSpan = 1; + RowSpan = 1; + Index = aIndex; + Bitmap = aBitmap; + //Text + Text = ""; + Alignment = ContentAlignment.MiddleLeft; + } + + + //Generic layout properties [DataMember] public int Index { get; set; } @@ -82,55 +113,21 @@ [DataMember] public int RowSpan { get; set; } - - } - - - /// - /// TextField can be send to our server to be displayed on the screen. - /// - [DataContract] - public class TextField : DataField - { - public TextField() - { - Index = 0; - Text = ""; - Alignment = ContentAlignment.MiddleLeft; - } - - public TextField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft) - { - Index = aIndex; - Text = aText; - Alignment = aAlignment; - } - + + //Text properties [DataMember] public string Text { get; set; } [DataMember] public ContentAlignment Alignment { get; set; } - } - /// - /// TextField can be send to our server to be displayed on the screen. - /// - [DataContract] - public class BitmapField : DataField - { - public BitmapField() - { - } - - public BitmapField(int aIndex, Bitmap aBitmap) - { - Index = aIndex; - Bitmap = aBitmap; - } - + //Bitmap properties [DataMember] public Bitmap Bitmap { get; set; } + + // + public bool HasBitmap { get{ return Bitmap!=null;} } + } /// @@ -164,14 +161,14 @@ /// /// [OperationContract(IsOneWay = true)] - void SetText(TextField aTextField); + void SetText(DataField aField); /// /// Allows a client to set multiple text fields at once. /// /// [OperationContract(IsOneWay = true)] - void SetTexts(System.Collections.Generic.IList aTextFields); + void SetTexts(System.Collections.Generic.IList aFields); /// /// Put the given bitmap in the given field on your display. @@ -179,7 +176,7 @@ /// /// [OperationContract(IsOneWay = true)] - void SetBitmap(BitmapField aBitmapField); + void SetBitmap(DataField aBitmapField); /// /// Provides the number of clients currently connected diff -r f444344fc205 -r fd0bb39a7818 Server/MainForm.cs --- a/Server/MainForm.cs Wed Oct 22 12:17:52 2014 +0200 +++ b/Server/MainForm.cs Sat Oct 25 13:35:11 2014 +0200 @@ -25,10 +25,10 @@ //Delegates are used for our thread safe method public delegate void AddClientDelegate(string aSessionId, ICallback aCallback); public delegate void RemoveClientDelegate(string aSessionId); - public delegate void SetTextDelegate(string SessionId, TextField aTextField); - public delegate void SetBitmapDelegate(string SessionId, BitmapField aTextField); + public delegate void SetTextDelegate(string SessionId, DataField aField); + public delegate void SetBitmapDelegate(string SessionId, DataField aField); public delegate void SetLayoutDelegate(string SessionId, TableLayout aLayout); - public delegate void SetTextsDelegate(string SessionId, System.Collections.Generic.IList aTextFields); + public delegate void SetTextsDelegate(string SessionId, System.Collections.Generic.IList aFields); public delegate void SetClientNameDelegate(string aSessionId, string aName); @@ -776,7 +776,7 @@ /// /// /// - /// + /// public void SetClientLayoutThreadSafe(string aSessionId, TableLayout aLayout) { if (this.InvokeRequired) @@ -802,14 +802,14 @@ /// /// /// - /// - public void SetClientTextThreadSafe(string aSessionId, TextField aTextField) + /// + public void SetClientTextThreadSafe(string aSessionId, DataField aField) { if (this.InvokeRequired) { //Not in the proper thread, invoke ourselves SetTextDelegate d = new SetTextDelegate(SetClientTextThreadSafe); - this.Invoke(d, new object[] { aSessionId, aTextField }); + this.Invoke(d, new object[] { aSessionId, aField }); } else { @@ -818,19 +818,19 @@ if (client != null) { //Make sure all our texts are in place - while (client.Fields.Count < (aTextField.Index + 1)) + while (client.Fields.Count < (aField.Index + 1)) { //Add a text field with proper index - client.Fields.Add(new TextField(client.Fields.Count)); + client.Fields.Add(new DataField(client.Fields.Count)); } - client.Fields[aTextField.Index] = aTextField; + client.Fields[aField.Index] = aField; //We are in the proper thread - if (tableLayoutPanel.Controls[aTextField.Index] is MarqueeLabel) + if (tableLayoutPanel.Controls[aField.Index] is MarqueeLabel) { - MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aTextField.Index]; - label.Text = aTextField.Text; - label.TextAlign = aTextField.Alignment; + MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aField.Index]; + label.Text = aField.Text; + label.TextAlign = aField.Alignment; } else { @@ -847,13 +847,13 @@ /// /// /// - public void SetClientTextsThreadSafe(string aSessionId, System.Collections.Generic.IList aTextFields) + public void SetClientTextsThreadSafe(string aSessionId, System.Collections.Generic.IList aFields) { if (this.InvokeRequired) { //Not in the proper thread, invoke ourselves SetTextsDelegate d = new SetTextsDelegate(SetClientTextsThreadSafe); - this.Invoke(d, new object[] { aSessionId, aTextFields }); + this.Invoke(d, new object[] { aSessionId, aFields }); } else { @@ -863,18 +863,18 @@ if (client != null) { //Populate our client with the given text fields - foreach (TextField textField in aTextFields) + foreach (DataField field in aFields) { //Make sure all our texts are in place - while (client.Fields.Count < (textField.Index + 1)) + while (client.Fields.Count < (field.Index + 1)) { //Add a text field with proper index - client.Fields.Add(new TextField(client.Fields.Count)); + client.Fields.Add(new DataField(client.Fields.Count)); } - client.Fields[textField.Index] = textField; + client.Fields[field.Index] = field; } //Put each our text fields in a label control - foreach (TextField field in aTextFields) + foreach (DataField field in aFields) { if (tableLayoutPanel.Controls[field.Index] is MarqueeLabel) { @@ -892,7 +892,6 @@ } } - UpdateClientTreeViewNode(client); } } @@ -903,13 +902,13 @@ /// /// /// - public void SetClientBitmapThreadSafe(string aSessionId, BitmapField aBitmapField) + public void SetClientBitmapThreadSafe(string aSessionId, DataField aField) { if (this.InvokeRequired) { //Not in the proper thread, invoke ourselves SetBitmapDelegate d = new SetBitmapDelegate(SetClientBitmapThreadSafe); - this.Invoke(d, new object[] { aSessionId, aBitmapField }); + this.Invoke(d, new object[] { aSessionId, aField }); } else { @@ -918,19 +917,19 @@ if (client != null) { //Make sure all our texts are in place - while (client.Fields.Count < (aBitmapField.Index + 1)) + while (client.Fields.Count < (aField.Index + 1)) { //Add a text field with proper index - client.Fields.Add(new TextField(client.Fields.Count)); + client.Fields.Add(new DataField(client.Fields.Count)); } - client.Fields[aBitmapField.Index] = aBitmapField; + client.Fields[aField.Index] = aField; //We are in the proper thread - if (tableLayoutPanel.Controls[aBitmapField.Index] is PictureBox) + if (tableLayoutPanel.Controls[aField.Index] is PictureBox) { - PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aBitmapField.Index]; - pictureBox.Image = aBitmapField.Bitmap; + PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aField.Index]; + pictureBox.Image = aField.Bitmap; } else { @@ -1026,18 +1025,14 @@ //For each text add a new entry foreach (DataField field in aClient.Fields) { - if (field is TextField) + if (!field.HasBitmap) { - TextField textField = (TextField)field; + DataField textField = (DataField)field; textsRoot.Nodes.Add(new TreeNode("[Text]" + textField.Text)); } - else if (field is BitmapField) - { - textsRoot.Nodes.Add(new TreeNode("[Bitmap]")); - } else { - textsRoot.Nodes.Add(new TreeNode("[Unknown]")); + textsRoot.Nodes.Add(new TreeNode("[Bitmap]")); } } } @@ -1210,7 +1205,7 @@ if (aClient.Fields.Count <= tableLayoutPanel.Controls.Count) { //No client field specified, create a text field by default - aClient.Fields.Add(new TextField(aClient.Fields.Count)); + aClient.Fields.Add(new DataField(aClient.Fields.Count)); } //Create a control corresponding to the field specified for that cell @@ -1243,7 +1238,7 @@ private Control CreateControlForDataField(DataField aField) { Control control=null; - if (aField is TextField) + if (!aField.HasBitmap) { MarqueeLabel label = new SharpDisplayManager.MarqueeLabel(); label.AutoEllipsis = true; @@ -1262,12 +1257,11 @@ label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; label.UseCompatibleTextRendering = true; - TextField textField = (TextField)aField; - label.Text = textField.Text; + label.Text = aField.Text; // control = label; } - else if (aField is BitmapField) + else { //Create picture box PictureBox picture = new PictureBox(); @@ -1278,8 +1272,7 @@ picture.Margin = new System.Windows.Forms.Padding(0); picture.Name = "pictureBox" + aField; //Set our image - BitmapField bitmapField = (BitmapField)aField; - picture.Image = bitmapField.Bitmap; + picture.Image = aField.Bitmap; // control = picture; } diff -r f444344fc205 -r fd0bb39a7818 Server/Session.cs --- a/Server/Session.cs Wed Oct 22 12:17:52 2014 +0200 +++ b/Server/Session.cs Sat Oct 25 13:35:11 2014 +0200 @@ -60,21 +60,21 @@ } //From IDisplayService - public void SetTexts(System.Collections.Generic.IList aTextFields) + public void SetTexts(System.Collections.Generic.IList aFields) { - SharpDisplayManager.Program.iMainForm.SetClientTextsThreadSafe(SessionId, aTextFields); + SharpDisplayManager.Program.iMainForm.SetClientTextsThreadSafe(SessionId, aFields); } // - public void SetText(TextField aTextField) + public void SetText(DataField aField) { - SharpDisplayManager.Program.iMainForm.SetClientTextThreadSafe(SessionId, aTextField); + SharpDisplayManager.Program.iMainForm.SetClientTextThreadSafe(SessionId, aField); } // - public void SetBitmap(BitmapField aBitmapField) + public void SetBitmap(DataField aField) { - SharpDisplayManager.Program.iMainForm.SetClientBitmapThreadSafe(SessionId, aBitmapField); + SharpDisplayManager.Program.iMainForm.SetClientBitmapThreadSafe(SessionId, aField); } ///