private string generateTextLine(int lineNumber)
        {
            const int charsPerButton = 4;
            int       buttonsPerLine = (SegmentType == SegmentType.Segment2x8 ? 8 : 4);
            int       startIndex     = (buttonsPerLine * lineNumber);

            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < buttonsPerLine; i++)
            {
                BindableColorButton button = GetButton(startIndex + i);
                string rawText;
                if (button == null || string.IsNullOrEmpty(button.Text))
                {
                    rawText = string.Empty;
                }
                else
                {
                    rawText = button.Text;
                }

                builder.Append(rawText.ClipOrPad(charsPerButton));

                //One character space between buttons
                builder.Append(' ');
            }
            return(builder.ToString());
        }
 protected void OnButtonUpdated(BindableColorButton button, string propertyName)
 {
     if (ButtonUpdated != null)
     {
         ButtonUpdated(button, new PropertyChangedEventArgs(propertyName));
     }
 }
        public void ClearButton(int buttonIndex)
        {
            BindableColorButton button = GetButton(buttonIndex);

            if (button != null)
            {
                button.Clear();
            }
        }
        public BindableColorButton SetButton(int buttonIndex, string text, FrontPanelColors color, bool dim, ButtonFunction function, int value)
        {
            BindableColorButton button = GetButton(buttonIndex);

            if (button != null)
            {
                button.SetButton(text, color, dim, function, value);
            }

            return(button);
        }
        public void CopyFrom(Segment segment, LcdDisplayMode lcdTextSource)
        {
            if (segment == null)
            {
                return;
            }

            this.SegmentType = segment.Type;
            this.PortID      = segment.PortID;
            this.LcdMode     = lcdTextSource;

            if (lcdMode == LcdDisplayMode.Segment)
            {
                int lineWidth = 40;
                int lineCount = 2;

                if (segmentType == SegmentType.Segment4x4)
                {
                    lineWidth = 20;
                    lineCount = 4;
                }

                string text = segment.GetDisplayText();

                //Sanity check on text field length
                int totalWidth = lineWidth * lineCount;
                if (text.Length < totalWidth)
                {
                    text = text.ClipOrPad(totalWidth);
                }

                for (int i = 0; i < lineCount; i++)
                {
                    int    startIndex = lineWidth * i;
                    string subString  = text.Substring(startIndex, lineWidth);
                    setTextLine(i, subString);
                }
            }

            //Update buttons
            foreach (ColorButton button in segment.ColorButtons)
            {
                BindableColorButton thisButton = GetButton(button.ControlID);
                thisButton.AlternateColorIndex = button.BlinkColor;
                thisButton.Blink2x             = button.Blink2x;
                thisButton.ColorIndex          = button.Color;
                thisButton.Dim   = button.Dim;
                thisButton.Text  = button.Text;
                thisButton.Value = button.Value;
            }
        }
        public BindableSegment()
        {
            for (int i = 0; i < 16; i++)
            {
                BindableColorButton button = new BindableColorButton()
                {
                    ButtonIndex = i
                };
                button.PropertyChanged += new PropertyChangedEventHandler(button_PropertyChanged);
                buttons.Add(button);
            }

            buttons.CollectionItemChanged += Buttons_CollectionItemChanged;
            UpdateTextLines();
        }