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.
1.1 --- a/Client/Client.cs Wed Oct 22 12:17:52 2014 +0200
1.2 +++ b/Client/Client.cs Sat Oct 25 13:35:11 2014 +0200
1.3 @@ -76,19 +76,19 @@
1.4 Channel.SetLayout(aLayout);
1.5 }
1.6
1.7 - public void SetText(TextField aTextField)
1.8 + public void SetText(DataField aField)
1.9 {
1.10 - Channel.SetText(aTextField);
1.11 + Channel.SetText(aField);
1.12 }
1.13
1.14 - public void SetTexts(System.Collections.Generic.IList<TextField> aTextFields)
1.15 + public void SetTexts(System.Collections.Generic.IList<DataField> aFields)
1.16 {
1.17 - Channel.SetTexts(aTextFields);
1.18 + Channel.SetTexts(aFields);
1.19 }
1.20
1.21 - public void SetBitmap(BitmapField aBitmapField)
1.22 + public void SetBitmap(DataField aField)
1.23 {
1.24 - Channel.SetBitmap(aBitmapField);
1.25 + Channel.SetBitmap(aField);
1.26 }
1.27
1.28 public int ClientCount()
2.1 --- a/Client/MainForm.cs Wed Oct 22 12:17:52 2014 +0200
2.2 +++ b/Client/MainForm.cs Sat Oct 25 13:35:11 2014 +0200
2.3 @@ -20,13 +20,13 @@
2.4 Client iClient;
2.5 Callback iCallback;
2.6 ContentAlignment Alignment;
2.7 - TextField iTextFieldTop;
2.8 + DataField iTextFieldTop;
2.9
2.10 public MainForm()
2.11 {
2.12 InitializeComponent();
2.13 Alignment = ContentAlignment.MiddleLeft;
2.14 - iTextFieldTop = new TextField(0);
2.15 + iTextFieldTop = new DataField(0);
2.16 }
2.17
2.18
2.19 @@ -143,10 +143,10 @@
2.20 //iClient.SetText(1, "Bottom");
2.21 //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft);
2.22
2.23 - iClient.SetTexts(new TextField[]
2.24 + iClient.SetTexts(new DataField[]
2.25 {
2.26 - new TextField(0, textBoxTop.Text, Alignment),
2.27 - new TextField(1, textBoxBottom.Text, Alignment)
2.28 + new DataField(0, textBoxTop.Text, Alignment),
2.29 + new DataField(1, textBoxBottom.Text, Alignment)
2.30 });
2.31 }
2.32
2.33 @@ -177,7 +177,7 @@
2.34 graphics.DrawLine(blackPen, x1, y2, x2, y1);
2.35 }
2.36
2.37 - BitmapField field = new BitmapField(0, bitmap);
2.38 + DataField field = new DataField(0, bitmap);
2.39 field.ColumnSpan = 2;
2.40 iClient.SetBitmap(field);
2.41 }
2.42 @@ -218,17 +218,17 @@
2.43 }
2.44
2.45 //Create a bitmap field from the bitmap we just created
2.46 - BitmapField field = new BitmapField(0, bitmap);
2.47 + DataField field = new DataField(0, bitmap);
2.48 //We want our bitmap field to span across two rows
2.49 field.RowSpan = 2;
2.50 //Send it to our server
2.51 iClient.SetBitmap(field);
2.52
2.53 //Set texts
2.54 - iClient.SetTexts(new TextField[]
2.55 + iClient.SetTexts(new DataField[]
2.56 {
2.57 - new TextField(1, textBoxTop.Text, Alignment),
2.58 - new TextField(2, textBoxBottom.Text, Alignment)
2.59 + new DataField(1, textBoxTop.Text, Alignment),
2.60 + new DataField(2, textBoxBottom.Text, Alignment)
2.61 });
2.62
2.63 }
3.1 --- a/Interface/Interface.cs Wed Oct 22 12:17:52 2014 +0200
3.2 +++ b/Interface/Interface.cs Sat Oct 25 13:35:11 2014 +0200
3.3 @@ -66,8 +66,39 @@
3.4 Index = 0;
3.5 ColumnSpan = 1;
3.6 RowSpan = 1;
3.7 + //Text
3.8 + Text = "";
3.9 + Alignment = ContentAlignment.MiddleLeft;
3.10 + //Bitmap
3.11 + Bitmap = null;
3.12 }
3.13
3.14 + //Text constructor
3.15 + public DataField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft)
3.16 + {
3.17 + ColumnSpan = 1;
3.18 + RowSpan = 1;
3.19 + Index = aIndex;
3.20 + Text = aText;
3.21 + Alignment = aAlignment;
3.22 + //
3.23 + Bitmap = null;
3.24 + }
3.25 +
3.26 + //Bitmap constructor
3.27 + public DataField(int aIndex, Bitmap aBitmap)
3.28 + {
3.29 + ColumnSpan = 1;
3.30 + RowSpan = 1;
3.31 + Index = aIndex;
3.32 + Bitmap = aBitmap;
3.33 + //Text
3.34 + Text = "";
3.35 + Alignment = ContentAlignment.MiddleLeft;
3.36 + }
3.37 +
3.38 +
3.39 + //Generic layout properties
3.40 [DataMember]
3.41 public int Index { get; set; }
3.42
3.43 @@ -82,55 +113,21 @@
3.44
3.45 [DataMember]
3.46 public int RowSpan { get; set; }
3.47 -
3.48 - }
3.49 -
3.50 -
3.51 - /// <summary>
3.52 - /// TextField can be send to our server to be displayed on the screen.
3.53 - /// </summary>
3.54 - [DataContract]
3.55 - public class TextField : DataField
3.56 - {
3.57 - public TextField()
3.58 - {
3.59 - Index = 0;
3.60 - Text = "";
3.61 - Alignment = ContentAlignment.MiddleLeft;
3.62 - }
3.63 -
3.64 - public TextField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft)
3.65 - {
3.66 - Index = aIndex;
3.67 - Text = aText;
3.68 - Alignment = aAlignment;
3.69 - }
3.70 -
3.71 +
3.72 + //Text properties
3.73 [DataMember]
3.74 public string Text { get; set; }
3.75
3.76 [DataMember]
3.77 public ContentAlignment Alignment { get; set; }
3.78 - }
3.79
3.80 - /// <summary>
3.81 - /// TextField can be send to our server to be displayed on the screen.
3.82 - /// </summary>
3.83 - [DataContract]
3.84 - public class BitmapField : DataField
3.85 - {
3.86 - public BitmapField()
3.87 - {
3.88 - }
3.89 -
3.90 - public BitmapField(int aIndex, Bitmap aBitmap)
3.91 - {
3.92 - Index = aIndex;
3.93 - Bitmap = aBitmap;
3.94 - }
3.95 -
3.96 + //Bitmap properties
3.97 [DataMember]
3.98 public Bitmap Bitmap { get; set; }
3.99 +
3.100 + //
3.101 + public bool HasBitmap { get{ return Bitmap!=null;} }
3.102 +
3.103 }
3.104
3.105 /// <summary>
3.106 @@ -164,14 +161,14 @@
3.107 /// </summary>
3.108 /// <param name="aTextFieldIndex"></param>
3.109 [OperationContract(IsOneWay = true)]
3.110 - void SetText(TextField aTextField);
3.111 + void SetText(DataField aField);
3.112
3.113 /// <summary>
3.114 /// Allows a client to set multiple text fields at once.
3.115 /// </summary>
3.116 /// <param name="aTexts"></param>
3.117 [OperationContract(IsOneWay = true)]
3.118 - void SetTexts(System.Collections.Generic.IList<TextField> aTextFields);
3.119 + void SetTexts(System.Collections.Generic.IList<DataField> aFields);
3.120
3.121 /// <summary>
3.122 /// Put the given bitmap in the given field on your display.
3.123 @@ -179,7 +176,7 @@
3.124 /// </summary>
3.125 /// <param name="aBitmapField"></param>
3.126 [OperationContract(IsOneWay = true)]
3.127 - void SetBitmap(BitmapField aBitmapField);
3.128 + void SetBitmap(DataField aBitmapField);
3.129
3.130 /// <summary>
3.131 /// Provides the number of clients currently connected
4.1 --- a/Server/MainForm.cs Wed Oct 22 12:17:52 2014 +0200
4.2 +++ b/Server/MainForm.cs Sat Oct 25 13:35:11 2014 +0200
4.3 @@ -25,10 +25,10 @@
4.4 //Delegates are used for our thread safe method
4.5 public delegate void AddClientDelegate(string aSessionId, ICallback aCallback);
4.6 public delegate void RemoveClientDelegate(string aSessionId);
4.7 - public delegate void SetTextDelegate(string SessionId, TextField aTextField);
4.8 - public delegate void SetBitmapDelegate(string SessionId, BitmapField aTextField);
4.9 + public delegate void SetTextDelegate(string SessionId, DataField aField);
4.10 + public delegate void SetBitmapDelegate(string SessionId, DataField aField);
4.11 public delegate void SetLayoutDelegate(string SessionId, TableLayout aLayout);
4.12 - public delegate void SetTextsDelegate(string SessionId, System.Collections.Generic.IList<TextField> aTextFields);
4.13 + public delegate void SetTextsDelegate(string SessionId, System.Collections.Generic.IList<DataField> aFields);
4.14 public delegate void SetClientNameDelegate(string aSessionId, string aName);
4.15
4.16
4.17 @@ -776,7 +776,7 @@
4.18 ///
4.19 /// </summary>
4.20 /// <param name="aSessionId"></param>
4.21 - /// <param name="aTextField"></param>
4.22 + /// <param name="aLayout"></param>
4.23 public void SetClientLayoutThreadSafe(string aSessionId, TableLayout aLayout)
4.24 {
4.25 if (this.InvokeRequired)
4.26 @@ -802,14 +802,14 @@
4.27 ///
4.28 /// </summary>
4.29 /// <param name="aSessionId"></param>
4.30 - /// <param name="aTextField"></param>
4.31 - public void SetClientTextThreadSafe(string aSessionId, TextField aTextField)
4.32 + /// <param name="aField"></param>
4.33 + public void SetClientTextThreadSafe(string aSessionId, DataField aField)
4.34 {
4.35 if (this.InvokeRequired)
4.36 {
4.37 //Not in the proper thread, invoke ourselves
4.38 SetTextDelegate d = new SetTextDelegate(SetClientTextThreadSafe);
4.39 - this.Invoke(d, new object[] { aSessionId, aTextField });
4.40 + this.Invoke(d, new object[] { aSessionId, aField });
4.41 }
4.42 else
4.43 {
4.44 @@ -818,19 +818,19 @@
4.45 if (client != null)
4.46 {
4.47 //Make sure all our texts are in place
4.48 - while (client.Fields.Count < (aTextField.Index + 1))
4.49 + while (client.Fields.Count < (aField.Index + 1))
4.50 {
4.51 //Add a text field with proper index
4.52 - client.Fields.Add(new TextField(client.Fields.Count));
4.53 + client.Fields.Add(new DataField(client.Fields.Count));
4.54 }
4.55 - client.Fields[aTextField.Index] = aTextField;
4.56 + client.Fields[aField.Index] = aField;
4.57
4.58 //We are in the proper thread
4.59 - if (tableLayoutPanel.Controls[aTextField.Index] is MarqueeLabel)
4.60 + if (tableLayoutPanel.Controls[aField.Index] is MarqueeLabel)
4.61 {
4.62 - MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aTextField.Index];
4.63 - label.Text = aTextField.Text;
4.64 - label.TextAlign = aTextField.Alignment;
4.65 + MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aField.Index];
4.66 + label.Text = aField.Text;
4.67 + label.TextAlign = aField.Alignment;
4.68 }
4.69 else
4.70 {
4.71 @@ -847,13 +847,13 @@
4.72 ///
4.73 /// </summary>
4.74 /// <param name="aTexts"></param>
4.75 - public void SetClientTextsThreadSafe(string aSessionId, System.Collections.Generic.IList<TextField> aTextFields)
4.76 + public void SetClientTextsThreadSafe(string aSessionId, System.Collections.Generic.IList<DataField> aFields)
4.77 {
4.78 if (this.InvokeRequired)
4.79 {
4.80 //Not in the proper thread, invoke ourselves
4.81 SetTextsDelegate d = new SetTextsDelegate(SetClientTextsThreadSafe);
4.82 - this.Invoke(d, new object[] { aSessionId, aTextFields });
4.83 + this.Invoke(d, new object[] { aSessionId, aFields });
4.84 }
4.85 else
4.86 {
4.87 @@ -863,18 +863,18 @@
4.88 if (client != null)
4.89 {
4.90 //Populate our client with the given text fields
4.91 - foreach (TextField textField in aTextFields)
4.92 + foreach (DataField field in aFields)
4.93 {
4.94 //Make sure all our texts are in place
4.95 - while (client.Fields.Count < (textField.Index + 1))
4.96 + while (client.Fields.Count < (field.Index + 1))
4.97 {
4.98 //Add a text field with proper index
4.99 - client.Fields.Add(new TextField(client.Fields.Count));
4.100 + client.Fields.Add(new DataField(client.Fields.Count));
4.101 }
4.102 - client.Fields[textField.Index] = textField;
4.103 + client.Fields[field.Index] = field;
4.104 }
4.105 //Put each our text fields in a label control
4.106 - foreach (TextField field in aTextFields)
4.107 + foreach (DataField field in aFields)
4.108 {
4.109 if (tableLayoutPanel.Controls[field.Index] is MarqueeLabel)
4.110 {
4.111 @@ -892,7 +892,6 @@
4.112 }
4.113 }
4.114
4.115 -
4.116 UpdateClientTreeViewNode(client);
4.117 }
4.118 }
4.119 @@ -903,13 +902,13 @@
4.120 /// </summary>
4.121 /// <param name="aSessionId"></param>
4.122 /// <param name="aTextField"></param>
4.123 - public void SetClientBitmapThreadSafe(string aSessionId, BitmapField aBitmapField)
4.124 + public void SetClientBitmapThreadSafe(string aSessionId, DataField aField)
4.125 {
4.126 if (this.InvokeRequired)
4.127 {
4.128 //Not in the proper thread, invoke ourselves
4.129 SetBitmapDelegate d = new SetBitmapDelegate(SetClientBitmapThreadSafe);
4.130 - this.Invoke(d, new object[] { aSessionId, aBitmapField });
4.131 + this.Invoke(d, new object[] { aSessionId, aField });
4.132 }
4.133 else
4.134 {
4.135 @@ -918,19 +917,19 @@
4.136 if (client != null)
4.137 {
4.138 //Make sure all our texts are in place
4.139 - while (client.Fields.Count < (aBitmapField.Index + 1))
4.140 + while (client.Fields.Count < (aField.Index + 1))
4.141 {
4.142 //Add a text field with proper index
4.143 - client.Fields.Add(new TextField(client.Fields.Count));
4.144 + client.Fields.Add(new DataField(client.Fields.Count));
4.145 }
4.146
4.147 - client.Fields[aBitmapField.Index] = aBitmapField;
4.148 + client.Fields[aField.Index] = aField;
4.149
4.150 //We are in the proper thread
4.151 - if (tableLayoutPanel.Controls[aBitmapField.Index] is PictureBox)
4.152 + if (tableLayoutPanel.Controls[aField.Index] is PictureBox)
4.153 {
4.154 - PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aBitmapField.Index];
4.155 - pictureBox.Image = aBitmapField.Bitmap;
4.156 + PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aField.Index];
4.157 + pictureBox.Image = aField.Bitmap;
4.158 }
4.159 else
4.160 {
4.161 @@ -1026,18 +1025,14 @@
4.162 //For each text add a new entry
4.163 foreach (DataField field in aClient.Fields)
4.164 {
4.165 - if (field is TextField)
4.166 + if (!field.HasBitmap)
4.167 {
4.168 - TextField textField = (TextField)field;
4.169 + DataField textField = (DataField)field;
4.170 textsRoot.Nodes.Add(new TreeNode("[Text]" + textField.Text));
4.171 }
4.172 - else if (field is BitmapField)
4.173 - {
4.174 - textsRoot.Nodes.Add(new TreeNode("[Bitmap]"));
4.175 - }
4.176 else
4.177 {
4.178 - textsRoot.Nodes.Add(new TreeNode("[Unknown]"));
4.179 + textsRoot.Nodes.Add(new TreeNode("[Bitmap]"));
4.180 }
4.181 }
4.182 }
4.183 @@ -1210,7 +1205,7 @@
4.184 if (aClient.Fields.Count <= tableLayoutPanel.Controls.Count)
4.185 {
4.186 //No client field specified, create a text field by default
4.187 - aClient.Fields.Add(new TextField(aClient.Fields.Count));
4.188 + aClient.Fields.Add(new DataField(aClient.Fields.Count));
4.189 }
4.190
4.191 //Create a control corresponding to the field specified for that cell
4.192 @@ -1243,7 +1238,7 @@
4.193 private Control CreateControlForDataField(DataField aField)
4.194 {
4.195 Control control=null;
4.196 - if (aField is TextField)
4.197 + if (!aField.HasBitmap)
4.198 {
4.199 MarqueeLabel label = new SharpDisplayManager.MarqueeLabel();
4.200 label.AutoEllipsis = true;
4.201 @@ -1262,12 +1257,11 @@
4.202
4.203 label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
4.204 label.UseCompatibleTextRendering = true;
4.205 - TextField textField = (TextField)aField;
4.206 - label.Text = textField.Text;
4.207 + label.Text = aField.Text;
4.208 //
4.209 control = label;
4.210 }
4.211 - else if (aField is BitmapField)
4.212 + else
4.213 {
4.214 //Create picture box
4.215 PictureBox picture = new PictureBox();
4.216 @@ -1278,8 +1272,7 @@
4.217 picture.Margin = new System.Windows.Forms.Padding(0);
4.218 picture.Name = "pictureBox" + aField;
4.219 //Set our image
4.220 - BitmapField bitmapField = (BitmapField)aField;
4.221 - picture.Image = bitmapField.Bitmap;
4.222 + picture.Image = aField.Bitmap;
4.223 //
4.224 control = picture;
4.225 }
5.1 --- a/Server/Session.cs Wed Oct 22 12:17:52 2014 +0200
5.2 +++ b/Server/Session.cs Sat Oct 25 13:35:11 2014 +0200
5.3 @@ -60,21 +60,21 @@
5.4 }
5.5
5.6 //From IDisplayService
5.7 - public void SetTexts(System.Collections.Generic.IList<TextField> aTextFields)
5.8 + public void SetTexts(System.Collections.Generic.IList<DataField> aFields)
5.9 {
5.10 - SharpDisplayManager.Program.iMainForm.SetClientTextsThreadSafe(SessionId, aTextFields);
5.11 + SharpDisplayManager.Program.iMainForm.SetClientTextsThreadSafe(SessionId, aFields);
5.12 }
5.13
5.14 //
5.15 - public void SetText(TextField aTextField)
5.16 + public void SetText(DataField aField)
5.17 {
5.18 - SharpDisplayManager.Program.iMainForm.SetClientTextThreadSafe(SessionId, aTextField);
5.19 + SharpDisplayManager.Program.iMainForm.SetClientTextThreadSafe(SessionId, aField);
5.20 }
5.21
5.22 //
5.23 - public void SetBitmap(BitmapField aBitmapField)
5.24 + public void SetBitmap(DataField aField)
5.25 {
5.26 - SharpDisplayManager.Program.iMainForm.SetClientBitmapThreadSafe(SessionId, aBitmapField);
5.27 + SharpDisplayManager.Program.iMainForm.SetClientBitmapThreadSafe(SessionId, aField);
5.28 }
5.29
5.30 ///