Source for file StyleProperty.class.php

Documentation is available at StyleProperty.class.php

  1. <?php
  2.  
  3. require_once(HARMONI."GUIManager/StyleProperty.interface.php");
  4.  
  5. /**
  6. * This StyleProperty generic class allows one to create a StyleProperty of arbitrary nature
  7. * from scratch. It has no default StyleComponents attached.
  8. *
  9. * A StyleProperty (SP) is one of the tree building pieces of CSS styles. It stores
  10. * information about a single CSS style property by storing one or more
  11. * <code>StyleComponents</code>.
  12. *
  13. * The other two CSS styles building pieces are <code>StyleComponents</code> and
  14. * <code>StyleCollections</code>. To clarify the relationship between these three
  15. * building pieces, consider the following example:
  16. * <pre>
  17. * div {
  18. * margin: 20px;
  19. * border: 1px solid #000;
  20. * }
  21. * </pre>
  22. * <code>div</code> is a <code>StyleCollection</code> consisting of 2
  23. * <code>StyleProperties</code>: <code>margin</code> and <code>border</code>. Each
  24. * of the latter consists of one or more <code>StyleComponents</code>. In
  25. * specific, <code>margin</code> consists of one <code>StyleComponent</code>
  26. * with the value <code>20px</code>, and <code>border</code> has three
  27. * <code>StyleComponents</code> with values <code>1px</code>, <code>solid</code>,
  28. * and <code>#000</code> correspondingly.
  29. *
  30. * @package harmoni.gui
  31. *
  32. * @copyright Copyright &copy; 2005, Middlebury College
  33. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  34. *
  35. * @version $Id: StyleProperty.class.php,v 1.13 2007/09/04 20:25:21 adamfranco Exp $
  36. */
  37. class StyleProperty extends StylePropertyInterface {
  38.  
  39. /**
  40. * The display name of this StyleProperty.
  41. * @var string _displayName
  42. * @access private
  43. */
  44. var $_displayName;
  45. /**
  46. * The description of this StyleProperty.
  47. * @var string _description
  48. * @access private
  49. */
  50. var $_description;
  51. /**
  52. * The name of this StyleProperty.
  53. * @var string _name
  54. * @access private
  55. */
  56. var $_name;
  57. /**
  58. * An array of the StyleComponents contained by this StyleProperty.
  59. * @var array _SCs
  60. * @access private
  61. */
  62. var $_SCs;
  63. /**
  64. * The constructor.
  65. * @access public
  66. * @param string name The name of this StyleProperty.
  67. * @param ref mixed SCs Either one or an array of a few StyleComponents to be contained
  68. * by this StyleProperty.
  69. * @param string displayName The display name of this StyleProperty.
  70. * @param string description The description of this StyleProperty.
  71. ***/
  72. function StyleProperty($name, $displayName, $description) {
  73. $this->_name = $name;
  74. $this->_SCs = array();
  75.  
  76. $this->_displayName = $displayName;
  77. $this->_description = $description;
  78. }
  79. /**
  80. * Sets the id
  81. *
  82. * @param object HarmoniId $id
  83. * @return void
  84. * @access public
  85. * @since 4/26/06
  86. */
  87. function setId ($id) {
  88. if (!is_object($id))
  89. throwError(new Error("GUIMANAGER", "STRING ID PASSED"));
  90. $this->_id =$id;
  91. }
  92. /**
  93. * Answers the id
  94. *
  95. * @return object HarmoniId
  96. * @access public
  97. * @since 4/26/06
  98. */
  99. function getId () {
  100. if (isset($this->_id)){
  101. return $this->_id;
  102. }else{
  103. $im = Services::getService("Id");
  104. $this->_id = $im->createId();
  105. return $this->_id;
  106. }
  107. }
  108.  
  109. /**
  110. * Returns the CSS code for this StyleProperty.
  111. * @access public
  112. * @return string The CSS code for this StyleProperty.
  113. ***/
  114. function getCSS() {
  115. if (count($this->_SCs) == 0)
  116. return "";
  117. $css = $this->_name.": ";
  118.  
  119. $values = array();
  120. foreach (array_keys($this->_SCs) as $key)
  121. $values[] = $this->_SCs[$key]->getValue();
  122.  
  123. $css .= implode(" ", $values);
  124.  
  125. $css .= ";";
  126. return $css;
  127. }
  128. /**
  129. * Returns the name of this StyleProperty.
  130. * @access public
  131. * @return string The name of this StyleProperty.
  132. ***/
  133. function getName() {
  134. return $this->_name;
  135. }
  136.  
  137. /**
  138. * Returns the display name of this StyleProperty.
  139. * @access public
  140. * @return string The display name of this StyleProperty.
  141. ***/
  142. function getDisplayName() {
  143. return $this->_displayName;
  144. }
  145. /**
  146. * Returns the description of this StlyeProperty.
  147. * @access public
  148. * @return string The description of this StlyeProperty.
  149. ***/
  150. function getDescription() {
  151. return $this->_description;
  152. }
  153.  
  154. /**
  155. * Adds one StyleComponent to this StyleProperty.
  156. * @access public
  157. * @param ref object A StyleComponent object.
  158. ***/
  159. function addSC($sc) {
  160. ArgumentValidator::validate($sc, ExtendsValidatorRule::getRule("StyleComponentInterface"), true);
  161. // $this->_SCs[] =$sc;
  162. // print "_SCs[".get_class($sc)."] = ".$sc->getDisplayName().";<br/>";
  163. $this->_SCs[get_class($sc)] =$sc;
  164. }
  165.  
  166. /**
  167. * Returns the StyleComponents of this StyleProperty in a suitable
  168. * for CSS generation order.
  169. * @access public$this->_SCs
  170. * @return array An array of the StyleComponents of this StyleProperty.
  171. ***/
  172. function getSCs() {
  173. return $this->_SCs;
  174. }
  175. /**
  176. * Returns the StyleComponent with the given class
  177. *
  178. * @param string $class the class of the StyleComponent
  179. * @access public
  180. * @return ref object StyleComponent
  181. ***/
  182. function getStyleComponent($class) {
  183. $class = strtolower($class);
  184. if(isset($this->_SCs[$class])){
  185. return $this->_SCs[$class];
  186. }else{
  187. $null=null;
  188. return $null;
  189. }
  190. }
  191. /**
  192. * Answers the list of possible SCs for the SP as an array of class names.
  193. *
  194. * @return array
  195. * @access public
  196. * @static
  197. * @since 5/2/06
  198. */
  199. function getSCList () {
  200. if (isset($this->_SCList))
  201. return $this->_SCList;
  202. return array();
  203. }
  204. /**
  205. * Return HTML to nested inside of the component's block. This includes
  206. * things such as corner images.
  207. *
  208. * See the example below:
  209. * <pre>
  210. * <div class='block3'>
  211. *
  212. * <!-- preHTML start -->
  213. * <div class="content">
  214. * <img class="borderTL" src="images/block3_TL.gif" width="14" height="14" />
  215. * <img class="borderTR" src="images/block3_TR.gif" width="14" height="14" />
  216. * <!-- preHTML end -->
  217. *
  218. * <h1>Hello world! (this is when my component renders itself)</h1>
  219. *
  220. * <!-- postHTML start -->
  221. * <div class="roundedCornerSpacer">&nbsp;</div>
  222. * </div>
  223. * <div class="bottomCorners">
  224. * <img class="borderBL" src="images/block3_BL.gif" width="14" height="14" />
  225. * <img class="borderBR" src="images/block3_BR.gif" width="14" height="14" />
  226. * </div>
  227. * <!-- postHTML end -->
  228. *
  229. * </div>
  230. * </pre>
  231. *
  232. * @param string $tabs
  233. * @return string
  234. * @access public
  235. * @since 11/22/05
  236. */
  237. function getPreHTML ($tabs) {
  238. return "";
  239. }
  240. /**
  241. * Return HTML to nested inside of the component's block. This includes
  242. * things such as corner images.
  243. *
  244. * See the example below:
  245. * <pre>
  246. * <div class='block3'>
  247. *
  248. * <!-- preHTML start -->
  249. * <div class="content">
  250. * <img class="borderTL" src="images/block3_TL.gif" width="14" height="14" />
  251. * <img class="borderTR" src="images/block3_TR.gif" width="14" height="14" />
  252. * <!-- preHTML end -->
  253. *
  254. * <h1>Hello world! (this is when my component renders itself)</h1>
  255. *
  256. * <!-- postHTML start -->
  257. * <div class="roundedCornerSpacer">&nbsp;</div>
  258. * </div>
  259. * <div class="bottomCorners">
  260. * <img class="borderBL" src="images/block3_BL.gif" width="14" height="14" />
  261. * <img class="borderBR" src="images/block3_BR.gif" width="14" height="14" />
  262. * </div>
  263. * <!-- postHTML end -->
  264. *
  265. * </div>
  266. * </pre>
  267. *
  268. * @param string $tabs
  269. * @return string
  270. * @access public
  271. * @since 11/22/05
  272. */
  273. function getPostHTML ($tabs) {
  274. return "";
  275. }
  276. }
  277.  
  278. ?>

Documentation generated on Wed, 19 Sep 2007 10:26:59 -0400 by phpDocumentor 1.3.0RC3