/// <summary>
        /// Update the preview according to the current Editor state.
        /// In case of the preview a temporary object will only be updated.
        /// </summary>
        private void UpdatePreview()
        {
            labelObj style = mapControl.Target;

            if (style != null)
            {
                Update(style);
                if (style.getTextString() == null || style.getTextString() == "")
                {
                    style.setText("Sample Text");
                }
                style.setExpression("");
                mapControl.RefreshView();
            }
        }
        /// <summary>
        /// Refresh the controls according to the underlying object.
        /// </summary>
        public void RefreshView()
        {
            if (label == null)
            {
                return;
            }

            layerObj layer = null;

            if (target.GetParent().GetParent().GetType() == typeof(layerObj))
            {
                layer = target.GetParent().GetParent();
            }

            labelBindingControllerSize.InitializeBinding(target);

            textBoxExpression.Text = label.getExpressionString();
            textBoxText.Text       = label.getTextString();

            comboBoxAngleMode.Items.AddRange(new object[] { MS_POSITIONS_ENUM.MS_AUTO, MS_POSITIONS_ENUM.MS_AUTO2, MS_POSITIONS_ENUM.MS_FOLLOW, MS_POSITIONS_ENUM.MS_NONE });
            comboBoxAngleMode.SelectedItem     = (MS_POSITIONS_ENUM)label.anglemode;
            checkBoxAutoMinFeatureSize.Checked = (label.autominfeaturesize == mapscript.MS_TRUE);
            checkBoxAutoMinFeatureSize.Enabled = (layer != null && layer.labelcache == mapscript.MS_ON);
            checkBoxPartials.Checked           = (label.partials == mapscript.MS_TRUE);
            checkBoxPartials.Enabled           = (layer != null && layer.labelcache == mapscript.MS_ON);
            checkBoxForce.Checked = (label.force == mapscript.MS_TRUE);
            checkBoxForce.Enabled = (layer != null && layer.labelcache == mapscript.MS_ON);

            colorPickerColor.SetColor(label.color);
            labelBindingControllerColor.InitializeBinding(target);
            colorPickerOutlineColor.SetColor(label.outlinecolor);
            labelBindingControllerOutlineColor.InitializeBinding(target);
            colorPickerShadowColor.SetColor(label.shadowcolor);
            //STEPH: remove forcing size to 8 when it is 0
            textBoxSize.Text    = label.size.ToString();
            textBoxMinSize.Text = label.minsize.ToString();

            textBoxMaxSize.Text     = label.maxsize.ToString();
            textBoxMinDistance.Text = label.mindistance.ToString();
            textBoxOffsetX.Text     = label.offsetx.ToString();
            textBoxOffsetY.Text     = label.offsety.ToString();
            textBoxWrap.Text        = label.wrap.ToString();
            textBoxShadowSizeX.Text = label.shadowsizex.ToString();
            labelBindingControllerShadowSizeX.InitializeBinding(target);
            textBoxShadowSizeY.Text = label.shadowsizey.ToString();
            labelBindingControllerShadowSizeY.InitializeBinding(target);

            textBoxEncoding.Text = label.encoding;
            textBoxAngle.Text    = label.angle.ToString();
            labelBindingControllerAngle.InitializeBinding(target);

            comboBoxPosition.Items.AddRange(new object[] { MS_POSITIONS_ENUM.MS_UL, MS_POSITIONS_ENUM.MS_LR, MS_POSITIONS_ENUM.MS_UR, MS_POSITIONS_ENUM.MS_LL, MS_POSITIONS_ENUM.MS_CR, MS_POSITIONS_ENUM.MS_CL, MS_POSITIONS_ENUM.MS_UC, MS_POSITIONS_ENUM.MS_LC, MS_POSITIONS_ENUM.MS_CC, MS_POSITIONS_ENUM.MS_AUTO, MS_POSITIONS_ENUM.MS_XY });
            comboBoxPosition.SelectedItem = (MS_POSITIONS_ENUM)label.position;
            labelBindingControllerPosition.InitializeBinding(target);

            comboBoxAlign.DataSource   = Enum.GetValues(typeof(MS_ALIGN_VALUE));
            comboBoxAlign.SelectedItem = (MS_ALIGN_VALUE)label.align;

            comboBoxFont.Items.Add("(none)");
            if (map != null)
            {
                string key = null;
                while ((key = map.fontset.fonts.nextKey(key)) != null)
                {
                    if (File.Exists(map.fontset.fonts.get(key, "")))
                    {
                        comboBoxFont.Items.Add(key);
                        if (string.Compare(key, label.font, true) == 0)
                        {
                            comboBoxFont.SelectedItem = key;
                        }
                        if (string.Compare(key, "arial", true) == 0 && comboBoxFont.SelectedIndex < 0)
                        {
                            // set the default font to Arial if exists
                            comboBoxFont.SelectedItem = key;
                        }
                    }
                }
            }

            if (comboBoxFont.SelectedIndex < 0)
            {
                comboBoxFont.SelectedIndex = 0;
            }

            // preserve the current item when sorting
            object selectedItem = comboBoxFont.SelectedItem;

            comboBoxFont.Sorted       = true;
            comboBoxFont.SelectedItem = selectedItem;

            labelBindingControllerFont.InitializeBinding(target);

            textBoxPriority.Text = label.priority.ToString();
            labelBindingControllerPriority.InitializeBinding(target);

            if (label.minscaledenom >= 0)
            {
                textBoxMinScale.Text = label.minscaledenom.ToString();
            }
            else
            {
                textBoxMinScale.Text = "";
            }
            if (label.maxscaledenom >= 0)
            {
                textBoxMaxScale.Text = label.maxscaledenom.ToString();
            }
            else
            {
                textBoxMaxScale.Text = "";
            }

            textBoxMaxLength.Text      = label.maxlength.ToString();
            textBoxMinFeatureSize.Text = label.minfeaturesize.ToString();
            textBoxBuffer.Text         = label.buffer.ToString();
            textBoxRepeatDistance.Text = label.repeatdistance.ToString();

            RefreshStyles();

            UpdateControlState();

            SetDirty(false);
        }