Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorCss/Css/CssRect.cs @ 12762

Last change on this file since 12762 was 12762, checked in by aballeit, 9 years ago

#2283 GUI updates, Tree-chart, MCTS Version 2 (prune leaves)

File size: 2.9 KB
Line 
1/// <developer>niklas@protocol7.com</developer>
2/// <completed>100</completed>
3///
4using System;
5using System.Text.RegularExpressions;
6
7namespace SharpVectors.Dom.Css
8{
9  /// <summary>
10  /// The Rect interface is used to represent any rect value. This interface reflects the values in the underlying style property. Hence, modifications made to the CSSPrimitiveValue objects modify the style property.
11  /// </summary>
12  public sealed class CssRect : ICssRect
13  {
14        #region Private Fields
15
16        private static Regex delim = new Regex(@"\s+,?\s*|,\s*", RegexOptions.Compiled);
17
18        private bool readOnly;
19       
20        #endregion
21
22    #region Constructors
23
24    /// <summary>
25    /// Constructs a new Rect
26    /// </summary>
27    /// <param name="s">The string to parse that contains the Rect structure</param>
28    /// <param name="readOnly">Specifies if the Rect should be read-only</param>
29    public CssRect(string rectString, bool readOnly)
30    {
31      this.readOnly = readOnly;
32
33            if (rectString == null)
34            {
35                rectString = String.Empty;
36            }
37
38            // remove leading and trailing whitespace
39            // NOTE: Need to check if .NET whitespace = SVG (XML) whitespace
40            rectString = rectString.Trim();
41
42            if (rectString.Length > 0)
43            {   
44                string[] parts = rectString.Split(' ');
45                if (parts.Length != 4)
46                {
47                    parts = delim.Split(rectString);
48                }
49          if (parts.Length == 4)
50          {
51            _top    = new CssPrimitiveLengthValue(parts[0], readOnly);
52            _right  = new CssPrimitiveLengthValue(parts[1], readOnly);
53            _bottom = new CssPrimitiveLengthValue(parts[2], readOnly);
54            _left   = new CssPrimitiveLengthValue(parts[3], readOnly);
55          }
56          else
57          {
58                    throw new DomException(DomExceptionType.SyntaxErr);
59                }
60            }
61    }
62    #endregion
63
64    #region IRect Members
65
66    private CssPrimitiveValue _left;
67    /// <summary>
68    /// This attribute is used for the left of the rect.
69    /// </summary>
70    public ICssPrimitiveValue Left
71    {
72      get
73      {
74        return _left;
75      }
76    }
77
78    private CssPrimitiveValue _bottom;
79    /// <summary>
80    /// This attribute is used for the bottom of the rect.
81    /// </summary>
82    public ICssPrimitiveValue Bottom
83    {
84      get
85      {
86        return _bottom;
87      }
88    }
89
90    private CssPrimitiveValue _right;
91    /// <summary>
92    /// This attribute is used for the right of the rect.
93    /// </summary>
94    public ICssPrimitiveValue Right
95    {
96      get
97      {
98        return _right;
99      }
100    }
101
102    private CssPrimitiveValue _top;
103    /// <summary>
104    /// This attribute is used for the top of the rect.
105    /// </summary>
106    public ICssPrimitiveValue Top
107    {
108      get
109      {
110        return _top;
111      }
112    }
113
114    #endregion
115  }
116}
Note: See TracBrowser for help on using the repository browser.