Пример #1
0
        private void editor_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = ((ComboBox)sender).SelectedIndex;

            if (index >= 0 && index < m_Options.Length)
            {
                m_LineEnding = m_Options[index];
                RaiseValueChanged();
            }
        }
Пример #2
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                LineEnding    lineEnding    = (LineEnding)value;
                TypeConverter enumConverter = TypeDescriptor.GetConverter(typeof(LineCap));
                string        result        = String.Format("{0};{1}",
                                                            enumConverter.ConvertToString(context, culture, (LineCap)lineEnding.StartCap),
                                                            enumConverter.ConvertToString(context, culture, (LineCap)lineEnding.EndCap));
                return(result);
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
        private static string GetPolyLineStyleVariant(DrawingPolyline drawing)
        {
            // Style variants of DrawingPolyline: polyline, curve, arrow curve, arrow polyline, arrow polyline dash, arrow polyline squiggly.
            if (!drawing.DrawingStyle.Elements.ContainsKey("arrows") || !drawing.DrawingStyle.Elements.ContainsKey("line shape") || !drawing.DrawingStyle.Elements.ContainsKey("curved"))
            {
                return("Polyline");
            }

            StyleElementLineEnding elementLineEnding = drawing.DrawingStyle.Elements["arrows"] as StyleElementLineEnding;
            StyleElementLineShape  elementLineShape  = drawing.DrawingStyle.Elements["line shape"] as StyleElementLineShape;
            StyleElementToggle     elementCurved     = drawing.DrawingStyle.Elements["curved"] as StyleElementToggle;

            if (elementLineEnding == null || elementLineShape == null || elementCurved == null)
            {
                return("Polyline");
            }

            LineEnding valueLineEnding = (LineEnding)elementLineEnding.Value;
            LineShape  valueLineShape  = (LineShape)elementLineShape.Value;
            bool       valueCurved     = (bool)elementCurved.Value;

            if (valueLineEnding == LineEnding.None)
            {
                if (!valueCurved)
                {
                    return("Polyline");
                }
                else
                {
                    return("Curve");
                }
            }
            else
            {
                switch (valueLineShape)
                {
                case LineShape.Solid: return("ArrowPolyline");

                case LineShape.Dash: return("ArrowPolylineDash");

                case LineShape.Squiggle: return("ArrowPolylineSquiggly");

                default: return("Polyline");
                }
            }
        }
Пример #4
0
        private void editor_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox editor = sender as ComboBox;

            if (editor == null)
            {
                return;
            }

            if (editor.SelectedIndex < 0)
            {
                return;
            }

            value = options[editor.SelectedIndex];
            RaiseValueChanged();
        }
Пример #5
0
        public override void ReadXML(XmlReader xmlReader)
        {
            xmlReader.ReadStartElement();
            string s = xmlReader.ReadElementContentAsString("Value", "");

            LineEnding value = LineEnding.None;

            try
            {
                TypeConverter lineEndingConverter = TypeDescriptor.GetConverter(typeof(LineEnding));
                value = (LineEnding)lineEndingConverter.ConvertFromString(s);
            }
            catch (Exception)
            {
                log.ErrorFormat("An error happened while parsing XML for Line ending. {0}", s);
            }

            this.value = options.IndexOf(value) >= 0 ? value : defaultValue;
            xmlReader.ReadEndElement();
        }
Пример #6
0
        public override void ReadXML(XmlReader _xmlReader)
        {
            _xmlReader.ReadStartElement();
            string s = _xmlReader.ReadElementContentAsString("Value", "");

            LineEnding value = LineEnding.None;

            try
            {
                TypeConverter lineEndingConverter = TypeDescriptor.GetConverter(typeof(LineEnding));
                value = (LineEnding)lineEndingConverter.ConvertFromString(s);
            }
            catch (Exception)
            {
                // The input XML couldn't be parsed. Keep the default value.
            }

            // Restrict to the actual list of "athorized" values.
            m_LineEnding = (Array.IndexOf(m_Options, value) >= 0) ? value : LineEnding.None;

            _xmlReader.ReadEndElement();
        }
Пример #7
0
        public override void ReadXML(XmlReader xmlReader)
        {
            xmlReader.ReadStartElement();
            string s = xmlReader.ReadElementContentAsString("Value", "");

            LineEnding value = LineEnding.None;

            try
            {
                TypeConverter lineEndingConverter = TypeDescriptor.GetConverter(typeof(LineEnding));
                value = (LineEnding)lineEndingConverter.ConvertFromString(s);
            }
            catch (Exception)
            {
                log.ErrorFormat("An error happened while parsing XML for Line ending. {0}", s);
            }

            // Restrict to the actual list of "athorized" values.
            lineEnding = (Array.IndexOf(Options, value) >= 0) ? value : LineEnding.None;

            xmlReader.ReadEndElement();
        }
        private static string GetLineStyleVariant(DrawingLine drawing)
        {
            // Style variants of DrawingLine: line, arrow, arrow dash, arrow squiggly.
            if (!drawing.DrawingStyle.Elements.ContainsKey("arrows") || !drawing.DrawingStyle.Elements.ContainsKey("line shape"))
            {
                return("Line");
            }

            StyleElementLineEnding elementLineEnding = drawing.DrawingStyle.Elements["arrows"] as StyleElementLineEnding;
            StyleElementLineShape  elementLineShape  = drawing.DrawingStyle.Elements["line shape"] as StyleElementLineShape;

            if (elementLineEnding == null || elementLineShape == null)
            {
                return("Line");
            }

            LineEnding valueLineEnding = (LineEnding)elementLineEnding.Value;
            LineShape  valueLineShape  = (LineShape)elementLineShape.Value;

            if (valueLineEnding == LineEnding.None)
            {
                return("Line");
            }
            else
            {
                switch (valueLineShape)
                {
                case LineShape.Solid: return("Arrow");

                case LineShape.Dash: return("ArrowDash");

                case LineShape.Squiggle: return("ArrowSquiggly");

                default: return("Line");
                }
            }
        }
Пример #9
0
 public StyleElementLineEnding(LineEnding initialValue)
 {
     value = options.IndexOf(initialValue) >= 0 ? initialValue : defaultValue;
 }
Пример #10
0
        private void DoBindWrite(string targetProperty, object value)
        {
            // Check type and import value if compatible with the target prop.
            bool imported = false;

            switch (targetProperty)
            {
            case "Color":
            {
                if (value is Color)
                {
                    color    = (Color)value;
                    imported = true;
                }
                break;
            }

            case "LineSize":
            {
                if (value is int)
                {
                    lineSize = (int)value;
                    imported = true;
                }

                break;
            }

            case "LineShape":
            {
                if (value is LineShape)
                {
                    lineShape = (LineShape)value;
                    imported  = true;
                }

                break;
            }

            case "LineEnding":
            {
                if (value is LineEnding)
                {
                    lineEnding = (LineEnding)value;
                    imported   = true;
                }

                break;
            }

            case "TrackShape":
            {
                if (value is TrackShape)
                {
                    trackShape = (TrackShape)value;
                    imported   = true;
                }

                break;
            }

            case "Curved":
            {
                if (value is Boolean)
                {
                    curved   = (Boolean)value;
                    imported = true;
                }

                break;
            }

            case "Font":
            {
                if (value is int)
                {
                    // Recreate the font changing just the size.
                    string    fontName  = font.Name;
                    FontStyle fontStyle = font.Style;
                    font.Dispose();
                    font     = new Font(fontName, (int)value, fontStyle);
                    imported = true;
                }
                break;
            }

            case "Bicolor":
            {
                if (value is Color)
                {
                    bicolor.Background = (Color)value;
                    imported           = true;
                }
                break;
            }

            case "GridDivisions":
            {
                if (value is int)
                {
                    gridDivisions = (int)value;
                    imported      = true;
                }
                break;
            }

            default:
            {
                log.DebugFormat("Unknown target property \"{0}\".", targetProperty);
                break;
            }
            }

            if (imported)
            {
                if (ValueChanged != null)
                {
                    ValueChanged(null, EventArgs.Empty);
                }
            }
            else
            {
                log.DebugFormat("Could not import value \"{0}\" to property \"{1}\".", value.ToString(), targetProperty);
            }
        }
Пример #11
0
 public StyleElementLineEnding(LineEnding _default)
 {
     m_LineEnding = (Array.IndexOf(m_Options, _default) >= 0) ? _default : LineEnding.None;
 }
Пример #12
0
 public StyleElementLineEnding(LineEnding defaultValue)
 {
     lineEnding = (Array.IndexOf(Options, defaultValue) >= 0) ? defaultValue : LineEnding.None;
 }