SvgAngle.cs :  » GUI » SharpVectorGraphics » SharpVectors » Dom » Svg » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » SharpVectorGraphics 
SharpVectorGraphics » SharpVectors » Dom » Svg » SvgAngle.cs
using System;
using SharpVectors.Dom.Css;
using System.Text.RegularExpressions;

namespace SharpVectors.Dom.Svg{
  /// <summary>
  /// Summary description for SvgAngle.
  /// </summary>
  public class SvgAngle : ISvgAngle
  {
    private CssPrimitiveAngleValue cssAngle;

    /// <summary>
    /// Creates a SvgAngle value
    /// </summary>
    /// <param name="s">The string to parse for the angle value</param>
    /// <param name="defaultValue">The default value for the angle.</param>
    /// <param name="readOnly">Specifies if the value should be read-only</param>
    public SvgAngle(string baseVal, string defaultValue, bool readOnly)
    {
      baseVal = baseVal.Trim();
      if(baseVal.Length == 0) baseVal = defaultValue;

      baseVal = SvgNumber.ScientificToDec(baseVal);

      cssAngle = new CssPrimitiveAngleValue(baseVal, readOnly);

      this.readOnly = readOnly;
    }

    private bool readOnly;

    #region Implementation of ISvgAngle
    /// <summary>
    ///  Reset the value as a number with an associated unitType, thereby replacing the values for all of the attributes on the object.
    /// </summary>
    /// <param name="unitType">The unitType for the angle value (e.g., SvgAngleTypeDEG).</param>
    /// <param name="valueInSpecifiedUnits">The angle value</param>
    public void NewValueSpecifiedUnits(SvgAngleType unitType, double valueInSpecifiedUnits)
    {
      cssAngle.SetFloatValue((CssPrimitiveType)unitType, valueInSpecifiedUnits);
    }

    /// <summary>
    ///  Preserve the same underlying stored value, but reset the stored unit identifier to the given unitType. Object attributes unitType, valueAsSpecified and valueAsString might be modified as a result of this method.
    /// </summary>
    /// <param name="unitType">The unitType to switch to (e.g., SvgAngleTypeDEG).</param>
    public void ConvertToSpecifiedUnits(SvgAngleType unitType)
    {
      double newValue = cssAngle.GetFloatValue((CssPrimitiveType)unitType);
      cssAngle.SetFloatValue((CssPrimitiveType)unitType, newValue);
    }

    /// <summary>
    /// The type of the value as specified by one of the constants specified above
    /// </summary>
    public SvgAngleType UnitType
    {
      get
      {
        return (SvgAngleType)cssAngle.PrimitiveType;
      }
    }
  
    /// <summary>
    ///  The angle value as a floating point value, in degrees. Setting this attribute will cause valueInSpecifiedUnits and valueAsString to be updated automatically to reflect this setting.
    /// </summary>
    /// <exception cref="DomException">NO_MODIFICATION_ALLOWED_ERR: Raised on an attempt to change the value of a readonly attribute.</exception>
    public double Value
    {
      get
      {
        return cssAngle.GetFloatValue(CssPrimitiveType.Deg);
      }
      set
      {
        if(readOnly) throw new DomException(DomExceptionType.NoModificationAllowedErr, "Cannot set readonly angle value");

        CssPrimitiveType oldType = cssAngle.PrimitiveType;
        cssAngle.SetFloatValue(CssPrimitiveType.Deg, value);      
        ConvertToSpecifiedUnits((SvgAngleType)oldType);
      }
    }

    /// <summary>
    ///  The angle value as a floating point value, in the units expressed by unitType. Setting this attribute will cause value and valueAsString to be updated automatically to reflect this setting.
    /// </summary>
    /// <exception cref="DomException">NO_MODIFICATION_ALLOWED_ERR: Raised on an attempt to change the value of a readonly attribute.</exception>
    public double ValueInSpecifiedUnits
    {
      get
      {
        return cssAngle.GetFloatValue(cssAngle.PrimitiveType);
      }
      set
      {
        if(readOnly) throw new DomException(DomExceptionType.NoModificationAllowedErr, "Cannot set readonly angle value");
        cssAngle.SetFloatValue(cssAngle.PrimitiveType, value);
      }
    }

    /// <summary>
    ///  The angle value as a string value, in the units expressed by unitType. Setting this attribute will cause value and valueInSpecifiedUnits to be updated automatically to reflect this setting.
    /// </summary>
    /// <exception cref="DomException">NO_MODIFICATION_ALLOWED_ERR: Raised on an attempt to change the value of a readonly attribute.</exception>
    public string ValueAsString
    {
      get
      {
        return cssAngle.CssText;
      }
      set
      {
        if(readOnly) throw new DomException(DomExceptionType.NoModificationAllowedErr, "Cannot set readonly angle value");
        cssAngle = new CssPrimitiveAngleValue(value, false);
      }

    }
    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.