Removing specific functions for setting text and bitmap.
authorsl
Sun, 26 Oct 2014 16:16:57 +0100
changeset 752549a8055bd1
parent 72 fd0bb39a7818
child 76 906d88eb53fb
Removing specific functions for setting text and bitmap.
Now having a generic functions for setting any kind of fields.
Thus bitmaps can now be set together with text fields in a single server call.
Client/Client.cs
Client/MainForm.cs
Interface/Interface.cs
Server/MainForm.cs
Server/Session.cs
     1.1 --- a/Client/Client.cs	Sat Oct 25 13:35:11 2014 +0200
     1.2 +++ b/Client/Client.cs	Sun Oct 26 16:16:57 2014 +0100
     1.3 @@ -76,19 +76,14 @@
     1.4              Channel.SetLayout(aLayout);
     1.5          }
     1.6  
     1.7 -        public void SetText(DataField aField)
     1.8 +        public void SetField(DataField aField)
     1.9          {
    1.10 -            Channel.SetText(aField);
    1.11 +            Channel.SetField(aField);
    1.12          }
    1.13  
    1.14 -        public void SetTexts(System.Collections.Generic.IList<DataField> aFields)
    1.15 +        public void SetFields(System.Collections.Generic.IList<DataField> aFields)
    1.16          {
    1.17 -            Channel.SetTexts(aFields);
    1.18 -        }
    1.19 -
    1.20 -        public void SetBitmap(DataField aField)
    1.21 -        {
    1.22 -            Channel.SetBitmap(aField);
    1.23 +            Channel.SetFields(aFields);
    1.24          }
    1.25  
    1.26          public int ClientCount()
     2.1 --- a/Client/MainForm.cs	Sat Oct 25 13:35:11 2014 +0200
     2.2 +++ b/Client/MainForm.cs	Sun Oct 26 16:16:57 2014 +0100
     2.3 @@ -134,7 +134,7 @@
     2.4              //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft);
     2.5              iTextFieldTop.Text = textBoxTop.Text;
     2.6              iTextFieldTop.Alignment = Alignment;
     2.7 -            iClient.SetText(iTextFieldTop);
     2.8 +            iClient.SetField(iTextFieldTop);
     2.9          }
    2.10  
    2.11          private void buttonSetText_Click(object sender, EventArgs e)
    2.12 @@ -143,7 +143,7 @@
    2.13              //iClient.SetText(1, "Bottom");
    2.14              //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft);
    2.15  
    2.16 -            iClient.SetTexts(new DataField[]
    2.17 +            iClient.SetFields(new DataField[]
    2.18              {
    2.19                  new DataField(0, textBoxTop.Text, Alignment),
    2.20                  new DataField(1, textBoxBottom.Text, Alignment)
    2.21 @@ -179,7 +179,7 @@
    2.22  
    2.23              DataField field = new DataField(0, bitmap);
    2.24              field.ColumnSpan = 2;
    2.25 -            iClient.SetBitmap(field);
    2.26 +            iClient.SetField(field);
    2.27          }
    2.28  
    2.29          private void buttonBitmapLayout_Click(object sender, EventArgs e)
    2.30 @@ -221,12 +221,11 @@
    2.31              DataField field = new DataField(0, bitmap);
    2.32              //We want our bitmap field to span across two rows
    2.33              field.RowSpan = 2;
    2.34 -            //Send it to our server
    2.35 -            iClient.SetBitmap(field);
    2.36  
    2.37              //Set texts
    2.38 -            iClient.SetTexts(new DataField[]
    2.39 +            iClient.SetFields(new DataField[]
    2.40              {
    2.41 +                field,
    2.42                  new DataField(1, textBoxTop.Text, Alignment),
    2.43                  new DataField(2, textBoxBottom.Text, Alignment)
    2.44              });
     3.1 --- a/Interface/Interface.cs	Sat Oct 25 13:35:11 2014 +0200
     3.2 +++ b/Interface/Interface.cs	Sun Oct 26 16:16:57 2014 +0100
     3.3 @@ -126,8 +126,14 @@
     3.4          public Bitmap Bitmap { get; set; }
     3.5  
     3.6          //
     3.7 -        public bool HasBitmap { get{ return Bitmap!=null;} }
     3.8 -
     3.9 +        public bool IsBitmap { get{ return Bitmap!=null;} }
    3.10 +        //
    3.11 +        public bool IsText { get { return Bitmap == null; } }
    3.12 +        //
    3.13 +        public bool IsSameLayout(DataField aField)
    3.14 +        {
    3.15 +            return (aField.ColumnSpan == ColumnSpan && aField.RowSpan == RowSpan);
    3.16 +        }
    3.17      }
    3.18  
    3.19      /// <summary>
    3.20 @@ -156,27 +162,19 @@
    3.21          void SetLayout(TableLayout aLayout);
    3.22  
    3.23          /// <summary>
    3.24 -        /// Put the given text in the given field on your display.
    3.25 -        /// Fields are often just lines of text.
    3.26 +        /// Set the given field on your display.
    3.27 +        /// Fields are often just lines of text or bitmaps.
    3.28          /// </summary>
    3.29          /// <param name="aTextFieldIndex"></param>
    3.30          [OperationContract(IsOneWay = true)]
    3.31 -        void SetText(DataField aField);
    3.32 +        void SetField(DataField aField);
    3.33  
    3.34          /// <summary>
    3.35 -        /// Allows a client to set multiple text fields at once.
    3.36 +        /// Allows a client to set multiple fields at once.
    3.37          /// </summary>
    3.38 -        /// <param name="aTexts"></param>
    3.39 +        /// <param name="aFields"></param>
    3.40          [OperationContract(IsOneWay = true)]
    3.41 -        void SetTexts(System.Collections.Generic.IList<DataField> aFields);
    3.42 -
    3.43 -        /// <summary>
    3.44 -        /// Put the given bitmap in the given field on your display.
    3.45 -        /// Fields are often just lines of text.
    3.46 -        /// </summary>
    3.47 -        /// <param name="aBitmapField"></param>
    3.48 -        [OperationContract(IsOneWay = true)]
    3.49 -        void SetBitmap(DataField aBitmapField);
    3.50 +        void SetFields(System.Collections.Generic.IList<DataField> aFields);
    3.51  
    3.52          /// <summary>
    3.53          /// Provides the number of clients currently connected
     4.1 --- a/Server/MainForm.cs	Sat Oct 25 13:35:11 2014 +0200
     4.2 +++ b/Server/MainForm.cs	Sun Oct 26 16:16:57 2014 +0100
     4.3 @@ -26,9 +26,8 @@
     4.4      public delegate void AddClientDelegate(string aSessionId, ICallback aCallback);
     4.5      public delegate void RemoveClientDelegate(string aSessionId);
     4.6      public delegate void SetTextDelegate(string SessionId, DataField aField);
     4.7 -    public delegate void SetBitmapDelegate(string SessionId, DataField aField);
     4.8      public delegate void SetLayoutDelegate(string SessionId, TableLayout aLayout);
     4.9 -    public delegate void SetTextsDelegate(string SessionId, System.Collections.Generic.IList<DataField> aFields);
    4.10 +    public delegate void SetFieldsDelegate(string SessionId, System.Collections.Generic.IList<DataField> aFields);
    4.11      public delegate void SetClientNameDelegate(string aSessionId, string aName);
    4.12  
    4.13  
    4.14 @@ -803,43 +802,74 @@
    4.15          /// </summary>
    4.16          /// <param name="aSessionId"></param>
    4.17          /// <param name="aField"></param>
    4.18 -        public void SetClientTextThreadSafe(string aSessionId, DataField aField)
    4.19 +        public void SetClientFieldThreadSafe(string aSessionId, DataField aField)
    4.20          {
    4.21              if (this.InvokeRequired)
    4.22              {
    4.23                  //Not in the proper thread, invoke ourselves
    4.24 -                SetTextDelegate d = new SetTextDelegate(SetClientTextThreadSafe);
    4.25 +                SetTextDelegate d = new SetTextDelegate(SetClientFieldThreadSafe);
    4.26                  this.Invoke(d, new object[] { aSessionId, aField });
    4.27              }
    4.28              else
    4.29              {
    4.30 -                SetCurrentClient(aSessionId);
    4.31 -                ClientData client = iClients[aSessionId];
    4.32 -                if (client != null)
    4.33 +                //We are in the proper thread
    4.34 +                //Call the non-thread-safe variant
    4.35 +                SetClientField(aSessionId, aField);
    4.36 +            }
    4.37 +        }
    4.38 +
    4.39 +        /// <summary>
    4.40 +        /// 
    4.41 +        /// </summary>
    4.42 +        /// <param name="aSessionId"></param>
    4.43 +        /// <param name="aField"></param>
    4.44 +        private void SetClientField(string aSessionId, DataField aField)
    4.45 +        {            
    4.46 +            SetCurrentClient(aSessionId);
    4.47 +            ClientData client = iClients[aSessionId];
    4.48 +            if (client != null)
    4.49 +            {
    4.50 +                //Make sure all our fields are in place
    4.51 +                while (client.Fields.Count < (aField.Index + 1))
    4.52                  {
    4.53 -                    //Make sure all our texts are in place
    4.54 -                    while (client.Fields.Count < (aField.Index + 1))
    4.55 +                    //Add a text field with proper index
    4.56 +                    client.Fields.Add(new DataField(client.Fields.Count));
    4.57 +                }
    4.58 +
    4.59 +                if (client.Fields[aField.Index].IsSameLayout(aField))
    4.60 +                {
    4.61 +                    //Same layout just update our field
    4.62 +                    client.Fields[aField.Index] = aField;
    4.63 +                    //
    4.64 +                    if (aField.IsText && tableLayoutPanel.Controls[aField.Index] is MarqueeLabel)
    4.65                      {
    4.66 -                        //Add a text field with proper index
    4.67 -                        client.Fields.Add(new DataField(client.Fields.Count));
    4.68 -                    }
    4.69 -                    client.Fields[aField.Index] = aField;
    4.70 -
    4.71 -                    //We are in the proper thread
    4.72 -                    if (tableLayoutPanel.Controls[aField.Index] is MarqueeLabel)
    4.73 -                    {
    4.74 +                        //Text field control already in place, just change the text
    4.75                          MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aField.Index];
    4.76                          label.Text = aField.Text;
    4.77                          label.TextAlign = aField.Alignment;
    4.78                      }
    4.79 +                    else if (aField.IsBitmap && tableLayoutPanel.Controls[aField.Index] is PictureBox)
    4.80 +                    {
    4.81 +                        //Bitmap field control already in place just change the bitmap
    4.82 +                        PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aField.Index];
    4.83 +                        pictureBox.Image = aField.Bitmap;
    4.84 +                    }
    4.85                      else
    4.86                      {
    4.87 +                        //The requested control in our layout it not of the correct type
    4.88                          //Wrong control type, re-create them all
    4.89                          UpdateTableLayoutPanel(iCurrentClientData);
    4.90                      }
    4.91 -                    //
    4.92 -                    UpdateClientTreeViewNode(client);
    4.93                  }
    4.94 +                else
    4.95 +                {
    4.96 +                    //Different layout, need to rebuild it
    4.97 +                    client.Fields[aField.Index] = aField;
    4.98 +                    UpdateTableLayoutPanel(iCurrentClientData);
    4.99 +                }
   4.100 +
   4.101 +                //
   4.102 +                UpdateClientTreeViewNode(client);
   4.103              }
   4.104          }
   4.105  
   4.106 @@ -847,52 +877,20 @@
   4.107          ///
   4.108          /// </summary>
   4.109          /// <param name="aTexts"></param>
   4.110 -        public void SetClientTextsThreadSafe(string aSessionId, System.Collections.Generic.IList<DataField> aFields)
   4.111 +        public void SetClientFieldsThreadSafe(string aSessionId, System.Collections.Generic.IList<DataField> aFields)
   4.112          {
   4.113              if (this.InvokeRequired)
   4.114              {
   4.115                  //Not in the proper thread, invoke ourselves
   4.116 -                SetTextsDelegate d = new SetTextsDelegate(SetClientTextsThreadSafe);
   4.117 +                SetFieldsDelegate d = new SetFieldsDelegate(SetClientFieldsThreadSafe);
   4.118                  this.Invoke(d, new object[] { aSessionId, aFields });
   4.119              }
   4.120              else
   4.121              {
   4.122 -                SetCurrentClient(aSessionId);
   4.123 -                //We are in the proper thread
   4.124 -                ClientData client = iClients[aSessionId];
   4.125 -                if (client != null)
   4.126 +                //Put each our text fields in a label control
   4.127 +                foreach (DataField field in aFields)
   4.128                  {
   4.129 -                    //Populate our client with the given text fields
   4.130 -                    foreach (DataField field in aFields)
   4.131 -                    {
   4.132 -                        //Make sure all our texts are in place
   4.133 -                        while (client.Fields.Count < (field.Index + 1))
   4.134 -                        {
   4.135 -                            //Add a text field with proper index
   4.136 -                            client.Fields.Add(new DataField(client.Fields.Count));
   4.137 -                        }
   4.138 -                        client.Fields[field.Index] = field;
   4.139 -                    }
   4.140 -                    //Put each our text fields in a label control
   4.141 -                    foreach (DataField field in aFields)
   4.142 -                    {
   4.143 -                        if (tableLayoutPanel.Controls[field.Index] is MarqueeLabel)
   4.144 -                        {
   4.145 -                            //Proper control type just update the text
   4.146 -                            MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[field.Index];
   4.147 -                            label.Text = field.Text;
   4.148 -                            label.TextAlign = field.Alignment;
   4.149 -                        }
   4.150 -                        else
   4.151 -                        {
   4.152 -                            //Wrong control for the given field
   4.153 -                            //Update our layout thus re-creating our controls
   4.154 -                            UpdateTableLayoutPanel(iCurrentClientData);
   4.155 -                            break; //No need to keep on looping layout update will take care of everything
   4.156 -                        }
   4.157 -                    }
   4.158 -
   4.159 -                    UpdateClientTreeViewNode(client);
   4.160 +                    SetClientField(aSessionId, field);
   4.161                  }
   4.162              }
   4.163          }
   4.164 @@ -901,53 +899,6 @@
   4.165          ///
   4.166          /// </summary>
   4.167          /// <param name="aSessionId"></param>
   4.168 -        /// <param name="aTextField"></param>
   4.169 -        public void SetClientBitmapThreadSafe(string aSessionId, DataField aField)
   4.170 -        {
   4.171 -            if (this.InvokeRequired)
   4.172 -            {
   4.173 -                //Not in the proper thread, invoke ourselves
   4.174 -                SetBitmapDelegate d = new SetBitmapDelegate(SetClientBitmapThreadSafe);
   4.175 -                this.Invoke(d, new object[] { aSessionId, aField });
   4.176 -            }
   4.177 -            else
   4.178 -            {
   4.179 -                SetCurrentClient(aSessionId);
   4.180 -                ClientData client = iClients[aSessionId];
   4.181 -                if (client != null)
   4.182 -                {
   4.183 -                    //Make sure all our texts are in place
   4.184 -                    while (client.Fields.Count < (aField.Index + 1))
   4.185 -                    {
   4.186 -                        //Add a text field with proper index
   4.187 -                        client.Fields.Add(new DataField(client.Fields.Count));
   4.188 -                    }
   4.189 -
   4.190 -                    client.Fields[aField.Index] = aField;
   4.191 -
   4.192 -                    //We are in the proper thread
   4.193 -                    if (tableLayoutPanel.Controls[aField.Index] is PictureBox)
   4.194 -                    {
   4.195 -                        PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aField.Index];
   4.196 -                        pictureBox.Image = aField.Bitmap;
   4.197 -                    }
   4.198 -                    else
   4.199 -                    {
   4.200 -                        //Wrong control type re-create them all
   4.201 -                        UpdateTableLayoutPanel(iCurrentClientData);
   4.202 -                    }
   4.203 -                    //
   4.204 -                    UpdateClientTreeViewNode(client);
   4.205 -                }
   4.206 -            }
   4.207 -        }
   4.208 -
   4.209 -
   4.210 -
   4.211 -        /// <summary>
   4.212 -        ///
   4.213 -        /// </summary>
   4.214 -        /// <param name="aSessionId"></param>
   4.215          /// <param name="aName"></param>
   4.216          public void SetClientNameThreadSafe(string aSessionId, string aName)
   4.217          {
   4.218 @@ -1025,7 +976,7 @@
   4.219                      //For each text add a new entry
   4.220                      foreach (DataField field in aClient.Fields)
   4.221                      {
   4.222 -                        if (!field.HasBitmap)
   4.223 +                        if (!field.IsBitmap)
   4.224                          {
   4.225                              DataField textField = (DataField)field;
   4.226                              textsRoot.Nodes.Add(new TreeNode("[Text]" + textField.Text));
   4.227 @@ -1238,7 +1189,7 @@
   4.228          private Control CreateControlForDataField(DataField aField)
   4.229          {
   4.230              Control control=null;
   4.231 -            if (!aField.HasBitmap)
   4.232 +            if (!aField.IsBitmap)
   4.233              {
   4.234                  MarqueeLabel label = new SharpDisplayManager.MarqueeLabel();
   4.235                  label.AutoEllipsis = true;
     5.1 --- a/Server/Session.cs	Sat Oct 25 13:35:11 2014 +0200
     5.2 +++ b/Server/Session.cs	Sun Oct 26 16:16:57 2014 +0100
     5.3 @@ -59,22 +59,16 @@
     5.4              SharpDisplayManager.Program.iMainForm.SetClientLayoutThreadSafe(SessionId, aLayout);
     5.5          }
     5.6  
     5.7 -        //From IDisplayService
     5.8 -        public void SetTexts(System.Collections.Generic.IList<DataField> aFields)
     5.9 +        //
    5.10 +        public void SetField(DataField aField)
    5.11          {
    5.12 -            SharpDisplayManager.Program.iMainForm.SetClientTextsThreadSafe(SessionId, aFields);
    5.13 +            SharpDisplayManager.Program.iMainForm.SetClientFieldThreadSafe(SessionId, aField);
    5.14          }
    5.15  
    5.16 -        //
    5.17 -        public void SetText(DataField aField)
    5.18 +        //From IDisplayService
    5.19 +        public void SetFields(System.Collections.Generic.IList<DataField> aFields)
    5.20          {
    5.21 -            SharpDisplayManager.Program.iMainForm.SetClientTextThreadSafe(SessionId, aField);
    5.22 -        }
    5.23 -
    5.24 -        //
    5.25 -        public void SetBitmap(DataField aField)
    5.26 -        {
    5.27 -            SharpDisplayManager.Program.iMainForm.SetClientBitmapThreadSafe(SessionId, aField);
    5.28 +            SharpDisplayManager.Program.iMainForm.SetClientFieldsThreadSafe(SessionId, aFields);
    5.29          }
    5.30  
    5.31          ///