Exemple #1
0
        private static IAnnotationLayout CreateRealLayout(string storedLayoutId)
        {
            try
            {
                StoredAnnotationLayout storedLayout = GetStoredLayout(storedLayoutId);
                if (storedLayout != null)
                {
                    return(storedLayout.Clone());
                }

                //just return an empty layout.
                return(new AnnotationLayout());
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e);

                var layout = new AnnotationLayout();
                var item   = new BasicTextAnnotationItem("errorbox", "errorbox", @"LabelError",
                                                         SR.MessageErrorLoadingAnnotationLayout);
                var box = new AnnotationBox(new RectangleF(0.5F, 0.90F, 0.5F, 0.10F), item)
                {
                    Bold              = true,
                    Color             = "Red",
                    Justification     = AnnotationBox.JustificationBehaviour.Right,
                    NumberOfLines     = 5,
                    VerticalAlignment = AnnotationBox.VerticalAlignmentBehaviour.Bottom
                };

                layout.AnnotationBoxes.Add(box);
                return(layout);
            }
        }
            private void DeserializeAnnotationBoxes(StoredAnnotationBoxGroup group, XmlNodeList annotationBoxNodes)
            {
                foreach (XmlElement annotationBoxNode in annotationBoxNodes)
                {
                    string normalizedRectangleString = annotationBoxNode.GetAttribute("normalized-rectangle");

                    RectangleF normalizedRectangle;
                    if (!DeserializeNormalizedRectangle(normalizedRectangleString, out normalizedRectangle))
                    {
                        continue;
                    }

                    XmlElement boxSettingsNode = (XmlElement)annotationBoxNode.SelectSingleNode("box-settings");

                    AnnotationBox newBox = group.DefaultBoxSettings.Clone();
                    newBox.NormalizedRectangle = normalizedRectangle;

                    if (boxSettingsNode != null)
                    {
                        DeserializeBoxSettings(newBox, boxSettingsNode);
                    }

                    string annotationItemIdentifier = annotationBoxNode.GetAttribute("annotation-item-id");
                    foreach (IAnnotationItem item in _availableAnnotationItems)
                    {
                        if (item.GetIdentifier() == annotationItemIdentifier)
                        {
                            newBox.AnnotationItem = item;
                            break;
                        }
                    }

                    group.AnnotationBoxes.Add(newBox);
                }
            }
 public StoredAnnotationBoxGroup(string identifier)
 {
     Platform.CheckForEmptyString(identifier, "identifier");
     _identifier         = identifier;
     _defaultBoxSettings = new AnnotationBox();
     _annotationBoxes    = new AnnotationBoxList();
 }
            private void SerializeAnnotationBoxSettings(AnnotationBox annotationBox, AnnotationBox defaultSettings, XmlElement boxSettingsNode)
            {
                //only save values that are different from the defaults.
                if (annotationBox.Bold != defaultSettings.Bold)
                {
                    boxSettingsNode.SetAttribute("bold", annotationBox.Bold ? "true" : "false");
                }
                if (annotationBox.Italics != defaultSettings.Italics)
                {
                    boxSettingsNode.SetAttribute("italics", annotationBox.Italics ? "true" : "false");
                }
                if (annotationBox.Font != defaultSettings.Font)
                {
                    boxSettingsNode.SetAttribute("font", annotationBox.Font);
                }
                if (annotationBox.Color != defaultSettings.Color)
                {
                    boxSettingsNode.SetAttribute("color", annotationBox.Color);
                }
                if (annotationBox.NumberOfLines != defaultSettings.NumberOfLines)
                {
                    boxSettingsNode.SetAttribute("number-of-lines", annotationBox.NumberOfLines.ToString(System.Globalization.CultureInfo.InvariantCulture));
                }
                if (annotationBox.Truncation != defaultSettings.Truncation)
                {
                    boxSettingsNode.SetAttribute("truncation", annotationBox.Truncation.ToString());
                }
                if (annotationBox.Justification != defaultSettings.Justification)
                {
                    boxSettingsNode.SetAttribute("justification", annotationBox.Justification.ToString());
                }
                if (annotationBox.VerticalAlignment != defaultSettings.VerticalAlignment)
                {
                    boxSettingsNode.SetAttribute("vertical-alignment", annotationBox.VerticalAlignment.ToString());
                }
                if (annotationBox.FitWidth != defaultSettings.FitWidth)
                {
                    boxSettingsNode.SetAttribute("fit-width", annotationBox.FitWidth ? "true" : "false");
                }

                XmlElement configurationSettingsNode = this.Document.CreateElement("configuration-settings");

                if (annotationBox.ConfigurationOptions.ShowLabel != defaultSettings.ConfigurationOptions.ShowLabel)
                {
                    configurationSettingsNode.SetAttribute("show-label", annotationBox.ConfigurationOptions.ShowLabel ? "true" : "false");
                }

                if (annotationBox.ConfigurationOptions.ShowLabelIfValueEmpty != defaultSettings.ConfigurationOptions.ShowLabelIfValueEmpty)
                {
                    configurationSettingsNode.SetAttribute("show-label-if-empty", annotationBox.ConfigurationOptions.ShowLabelIfValueEmpty ? "true" : "false");
                }

                if (configurationSettingsNode.Attributes.Count > 0)
                {
                    boxSettingsNode.AppendChild(configurationSettingsNode);
                }
            }
Exemple #5
0
        /// <summary>
        /// Creates a deep clone of this object.
        /// </summary>
        public AnnotationBox Clone()
        {
            AnnotationBox clone = new AnnotationBox();

            clone._alwaysVisible  = this._alwaysVisible;            // bool
            clone._annotationItem = this._annotationItem;           // clone copy reference
            if (this._annotationItemConfigurationOptions != null)
            {
                clone._annotationItemConfigurationOptions = this._annotationItemConfigurationOptions.Clone();
            }
            clone._bold                = this._bold;                // bool
            clone._color               = this._color;               // string
            clone._fitWidth            = this._fitWidth;            // bool
            clone._font                = this._font;                // string
            clone._italics             = this._italics;             // bool
            clone._justification       = this._justification;       // enum
            clone._normalizedRectangle = this._normalizedRectangle; // rect
            clone._numberOfLines       = this._numberOfLines;       // byte
            clone._truncation          = this._truncation;          //  enum
            clone._verticalAlignment   = this._verticalAlignment;   // enum
            clone._visible             = this._visible;             // bool
            return(clone);
        }
            private void SerializeAnnotationBoxes(IList <AnnotationBox> annotationBoxes, AnnotationBox defaultBoxSettings, XmlElement groupNode)
            {
                XmlElement boxesNode = this.Document.CreateElement("annotation-boxes");

                groupNode.AppendChild(boxesNode);

                foreach (AnnotationBox box in annotationBoxes)
                {
                    XmlElement boxNode = this.Document.CreateElement("annotation-box");
                    boxesNode.AppendChild(boxNode);

                    string normalizedRectangle = String.Format("{0:F6}\\{1:F6}\\{2:F6}\\{3:F6}", box.NormalizedRectangle.Left, box.NormalizedRectangle.Top, box.NormalizedRectangle.Right, box.NormalizedRectangle.Bottom);

                    boxNode.SetAttribute("normalized-rectangle", normalizedRectangle);
                    boxNode.SetAttribute("annotation-item-id", (box.AnnotationItem == null) ? "" : box.AnnotationItem.GetIdentifier());

                    XmlElement settingsNode = this.Document.CreateElement("box-settings");
                    SerializeAnnotationBoxSettings(box, defaultBoxSettings, settingsNode);

                    if (settingsNode.ChildNodes.Count > 0 || settingsNode.Attributes.Count > 0)
                    {
                        boxNode.AppendChild(settingsNode);
                    }
                }
            }
            private void DeserializeBoxSettings(AnnotationBox boxSettings, XmlElement boxSettingsNode)
            {
                string font              = boxSettingsNode.GetAttribute("font");
                string color             = boxSettingsNode.GetAttribute("color");
                string italics           = boxSettingsNode.GetAttribute("italics");
                string bold              = boxSettingsNode.GetAttribute("bold");
                string numberOfLines     = boxSettingsNode.GetAttribute("number-of-lines");
                string truncation        = boxSettingsNode.GetAttribute("truncation");
                string justification     = boxSettingsNode.GetAttribute("justification");
                string verticalAlignment = boxSettingsNode.GetAttribute("vertical-alignment");
                string fitWidth          = boxSettingsNode.GetAttribute("fit-width");
                string alwaysVisible     = boxSettingsNode.GetAttribute("always-visible");

                if (!String.IsNullOrEmpty(font))
                {
                    boxSettings.Font = font;
                }
                if (!String.IsNullOrEmpty(color))
                {
                    boxSettings.Color = color;
                }
                if (!String.IsNullOrEmpty(italics))
                {
                    boxSettings.Italics = (String.Compare("true", italics, true) == 0);
                }
                if (!String.IsNullOrEmpty(bold))
                {
                    boxSettings.Bold = (String.Compare("true", bold, true) == 0);
                }
                if (!String.IsNullOrEmpty(numberOfLines))
                {
                    byte result;
                    if (!byte.TryParse(numberOfLines, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out result))
                    {
                        result = 1;
                    }

                    boxSettings.NumberOfLines = result;
                }

                if (!String.IsNullOrEmpty(fitWidth))
                {
                    boxSettings.FitWidth = (String.Compare("true", fitWidth) == 0);
                }

                if (!String.IsNullOrEmpty(alwaysVisible))
                {
                    boxSettings.AlwaysVisible = (String.Compare("true", alwaysVisible, true) == 0);
                }

                if (!String.IsNullOrEmpty(truncation))
                {
                    AnnotationBox.TruncationBehaviour fromString = boxSettings.Truncation;
                    EnumConverter converter = new EnumConverter(typeof(AnnotationBox.TruncationBehaviour));
                    if (converter.IsValid(truncation))
                    {
                        boxSettings.Truncation = (AnnotationBox.TruncationBehaviour)converter.ConvertFromString(truncation);
                    }
                }

                if (!String.IsNullOrEmpty(justification))
                {
                    AnnotationBox.JustificationBehaviour fromString = boxSettings.Justification;
                    EnumConverter converter = new EnumConverter(typeof(AnnotationBox.JustificationBehaviour));
                    if (converter.IsValid(justification))
                    {
                        boxSettings.Justification = (AnnotationBox.JustificationBehaviour)converter.ConvertFromString(justification);
                    }
                }

                if (!String.IsNullOrEmpty(verticalAlignment))
                {
                    AnnotationBox.VerticalAlignmentBehaviour fromString = boxSettings.VerticalAlignment;
                    EnumConverter converter = new EnumConverter(typeof(AnnotationBox.VerticalAlignmentBehaviour));
                    if (converter.IsValid(verticalAlignment))
                    {
                        boxSettings.VerticalAlignment = (AnnotationBox.VerticalAlignmentBehaviour)converter.ConvertFromString(verticalAlignment);
                    }
                }

                XmlElement configurationSettings = (XmlElement)boxSettingsNode.SelectSingleNode("configuration-settings");

                if (configurationSettings != null)
                {
                    string showLabel        = configurationSettings.GetAttribute("show-label");
                    string showLabelIfEmpty = configurationSettings.GetAttribute("show-label-if-empty");
                    if (!String.IsNullOrEmpty(showLabel))
                    {
                        boxSettings.ConfigurationOptions.ShowLabel = (String.Compare("true", showLabel, true) == 0);
                    }
                    if (!String.IsNullOrEmpty(showLabelIfEmpty))
                    {
                        boxSettings.ConfigurationOptions.ShowLabelIfValueEmpty = (String.Compare("true", showLabelIfEmpty, true) == 0);
                    }
                }
            }
 /// <summary>
 /// Cloning constructor.
 /// </summary>
 /// <param name="source">The source object from which to clone.</param>
 /// <param name="context">This parameter is unused.</param>
 private StoredAnnotationBoxGroup(StoredAnnotationBoxGroup source, ICloningContext context)
 {
     this._identifier         = source._identifier;
     this._defaultBoxSettings = source._defaultBoxSettings.Clone();
     this._annotationBoxes    = source._annotationBoxes.Clone();
 }