PageRenderTime 50ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/AODL/Document/Styles/ParagraphStyle.cs

https://bitbucket.org/chrisc/aodl
C# | 204 lines | 88 code | 13 blank | 103 comment | 4 complexity | 6411f683c96fb042908f7c72632a3548 MD5 | raw file
  1. /*************************************************************************
  2. *
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
  4. *
  5. * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
  6. *
  7. * Use is subject to license terms.
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  10. * use this file except in compliance with the License. You may obtain a copy
  11. * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
  12. * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. *
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. *
  21. ************************************************************************/
  22. using System.Xml.Linq;
  23. using AODL.Document.Styles.Properties;
  24. namespace AODL.Document.Styles
  25. {
  26. /// <summary>
  27. /// Represent the style for a Paragraph object.
  28. /// </summary>
  29. public class ParagraphStyle : AbstractStyle
  30. {
  31. /// <summary>
  32. /// Initializes a new instance of the <see cref="ParagraphStyle"/> class.
  33. /// </summary>
  34. /// <param name="document">The document.</param>
  35. /// <param name="styleName">Name of the style.</param>
  36. public ParagraphStyle(IDocument document, string styleName)
  37. {
  38. Document = document;
  39. Node = new XElement(Ns.Style + "style");
  40. Node.SetAttributeValue(Ns.Style + "name", styleName);
  41. Node.SetAttributeValue(Ns.Style + "family", FamiliyStyles.Paragraph);
  42. Node.SetAttributeValue(Ns.Style + "parent-style-name", ParentStyles.Standard.ToString());
  43. InitStandards();
  44. }
  45. /// <summary>
  46. /// Initializes a new instance of the <see cref="ParagraphStyle"/> class.
  47. /// </summary>
  48. /// <param name="document">The document.</param>
  49. /// <param name="node">The node.</param>
  50. public ParagraphStyle(IDocument document, XElement node)
  51. {
  52. Document = document;
  53. Node = node;
  54. InitStandards();
  55. }
  56. /// <summary>
  57. /// Gets or sets the paragraph properties.
  58. /// </summary>
  59. /// <value>The paragraph properties.</value>
  60. public ParagraphProperties ParagraphProperties
  61. {
  62. get
  63. {
  64. foreach (IProperty property in PropertyCollection)
  65. if (property is ParagraphProperties)
  66. return (ParagraphProperties) property;
  67. ParagraphProperties parProperties = new ParagraphProperties(this);
  68. PropertyCollection.Add(parProperties);
  69. return parProperties;
  70. }
  71. set
  72. {
  73. if (PropertyCollection.Contains(value))
  74. PropertyCollection.Remove(value);
  75. PropertyCollection.Add(value);
  76. }
  77. }
  78. /// <summary>
  79. /// Gets or sets the text properties.
  80. /// </summary>
  81. /// <value>The text properties.</value>
  82. public TextProperties TextProperties
  83. {
  84. get
  85. {
  86. foreach (IProperty property in PropertyCollection)
  87. if (property is TextProperties)
  88. return (TextProperties) property;
  89. TextProperties textProperties = new TextProperties(this);
  90. PropertyCollection.Add(textProperties);
  91. return textProperties;
  92. }
  93. set
  94. {
  95. if (PropertyCollection.Contains(value))
  96. PropertyCollection.Remove(value);
  97. PropertyCollection.Add(value);
  98. }
  99. }
  100. /// <summary>
  101. /// The parent style of this object.
  102. /// </summary>
  103. public string ParentStyle
  104. {
  105. get { return (string) Node.Attribute(Ns.Style + "parent-style-name"); }
  106. set { Node.SetAttributeValue(Ns.Style + "parent-style-name", value); }
  107. }
  108. /// <summary>
  109. /// The parent style of this object.
  110. /// </summary>
  111. public string ListStyleName
  112. {
  113. get { return (string) Node.Attribute(Ns.Style + "list-style-name"); }
  114. set { Node.SetAttributeValue(Ns.Style + "list-style-name", value); }
  115. }
  116. /// <summary>
  117. /// The family style.
  118. /// </summary>
  119. public string Family
  120. {
  121. get { return (string) Node.Attribute(Ns.Style + "family"); }
  122. set { Node.SetAttributeValue(Ns.Style + "family", value); }
  123. }
  124. /// <summary>
  125. /// Inits the standards.
  126. /// </summary>
  127. private void InitStandards()
  128. {
  129. PropertyCollection = new IPropertyCollection();
  130. PropertyCollection.Inserted += PropertyCollection_Inserted;
  131. PropertyCollection.Removed += PropertyCollection_Removed;
  132. // this.Document.Styles.Add(this);
  133. }
  134. /// <summary>
  135. /// Properties the collection_ inserted.
  136. /// </summary>
  137. /// <param name="index">The index.</param>
  138. /// <param name="value">The value.</param>
  139. private void PropertyCollection_Inserted(int index, object value)
  140. {
  141. Node.Add(((IProperty) value).Node);
  142. }
  143. /// <summary>
  144. /// Properties the collection_ removed.
  145. /// </summary>
  146. /// <param name="index">The index.</param>
  147. /// <param name="value">The value.</param>
  148. private static void PropertyCollection_Removed(int index, object value)
  149. {
  150. ((IProperty) value).Node.Remove();
  151. }
  152. }
  153. }
  154. /*
  155. * $Log: ParagraphStyle.cs,v $
  156. * Revision 1.2 2008/04/29 15:39:54 mt
  157. * new copyright header
  158. *
  159. * Revision 1.1 2007/02/25 08:58:49 larsbehr
  160. * initial checkin, import from Sourceforge.net to OpenOffice.org
  161. *
  162. * Revision 1.2 2006/01/29 18:52:51 larsbm
  163. * - Added support for common styles (style templates in OpenOffice)
  164. * - Draw TextBox import and export
  165. * - DrawTextBox html export
  166. *
  167. * Revision 1.1 2006/01/29 11:28:23 larsbm
  168. * - Changes for the new version. 1.2. see next changelog for details
  169. *
  170. * Revision 1.6 2006/01/05 10:31:10 larsbm
  171. * - AODL merged cells
  172. * - AODL toc
  173. * - AODC batch mode, splash screen
  174. *
  175. * Revision 1.5 2005/11/20 17:31:20 larsbm
  176. * - added suport for XLinks, TabStopStyles
  177. * - First experimental of loading dcuments
  178. * - load and save via importer and exporter interfaces
  179. *
  180. * Revision 1.4 2005/10/22 15:52:10 larsbm
  181. * - Changed some styles from Enum to Class with statics
  182. * - Add full support for available OpenOffice fonts
  183. *
  184. * Revision 1.3 2005/10/09 15:52:47 larsbm
  185. * - Changed some design at the paragraph usage
  186. * - add list support
  187. *
  188. * Revision 1.2 2005/10/08 07:55:35 larsbm
  189. * - added cvs tags
  190. *
  191. */