Source for file WStyleComponent.class.php

Documentation is available at WStyleComponent.class.php

  1. <?php
  2. /**
  3. * @since 8/09/2006
  4. * @package polyphony.guiwizardcomponents
  5. *
  6. * @copyright Copyright &copy; 2006, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: WStyleComponent.class.php,v 1.3 2007/09/19 14:04:46 adamfranco Exp $
  10. */
  11.  
  12.  
  13.  
  14. /**
  15. * This class allows for the creation of a Style Component selector.
  16. *
  17. * @since 8/09/2006
  18. * @package polyphony.guiwizardcomponents
  19. *
  20. * @copyright Copyright &copy; 2006, Middlebury College
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  22. *
  23. * @version $Id: WStyleComponent.class.php,v 1.3 2007/09/19 14:04:46 adamfranco Exp $
  24. */
  25. class WStyleComponent
  26. extends ErrorCheckingWizardComponent
  27. {
  28.  
  29. var $_wizardComponent;
  30. var $_getThemeCallBack;
  31. var $_collection;
  32. var $_property;
  33. var $_component;
  34. var $_showError;
  35. function WStyleComponent ($callBack, $component, $property, $collection) {
  36. $this->_getThemeCallBack = $callBack;
  37. $this->_collection = $collection;
  38. $this->_property = $property;
  39. $this->_component = $component;
  40. $styleComponent =$this->getStyleComponent();
  41. $rule = $styleComponent->getRule();
  42. $regex = $rule->getRegularExpression();
  43. //$this->setErrorText($styleComponent->getErrorDescription());
  44. //$this->setErrorRule($styleComponent->getRule());
  45. //$this->_showError=false;
  46. if(is_null($styleComponent)){
  47. throwError(new Error("The Component this references is based on cannot be null","WStyleComponent",true));
  48. }
  49. if (get_class($styleComponent) == 'colorsc') {
  50. $input = new WSelectOrNew();
  51. $input->addOption('', "(not set)");
  52. $digits = array("0","4","8","C","F");
  53. for($r =0; $r<count($digits); $r++){
  54. for($g =0; $g<count($digits); $g++){
  55. for($b =0; $b<count($digits); $b++){
  56. $val = '#'.$digits[$r].$digits[$g].$digits[$b];
  57. $arr = $styleComponent->getRGBArray($val);
  58. //num measures the "brightness" of the color.
  59. //I think green is "brighter" than red and red "brighter" than blue.
  60. $num = $arr[0]*3+$arr[1]*2+$arr[2];
  61. //Our threshold is 750.
  62. if($num > 750){
  63. $col = "000";
  64. }else{
  65. $col = "#FFF";
  66. }
  67. $input->addOption($val, $val, "color: ".$col."; background-color:".$val.";");
  68. }
  69. }
  70. }
  71.  
  72. // make sure the current color is a possibility.
  73. if (!is_null($styleComponent->getValue())){
  74. //$input->addOption($styleComponent->getValue(), $styleComponent->getValue(), "color: ".$col."; background-color:".$styleComponent->getValue().";");
  75. $input->setValue($styleComponent->getValue());
  76. }
  77. // if ([[colorwheel colors]])
  78. // generate options for colors
  79. } else if ($styleComponent->isLimitedToOptions()) {
  80. $input = new WSelectList();
  81. $input->addOption('', "(not set)");
  82. $options = $styleComponent->getOptions();
  83. foreach ($options as $opt) {
  84. $input->addOption($opt, $opt, strtolower(preg_replace("/[^a-zA-Z0-9:_-]/", "-", $styleComponent->getDisplayName())).": $opt;");
  85. }
  86. $input->setValue($styleComponent->getValue());
  87. } else if ($styleComponent->hasOptions()) {
  88. $input = new WSelectOrNew();
  89. $input->addOption('', "(not set)");
  90. $options = $styleComponent->getOptions();
  91. foreach ($options as $opt) {
  92. $input->addOption($opt, $opt, strtolower(preg_replace("/[^a-zA-Z0-9:_-]/", "-", $styleComponent->getDisplayName())).": $opt;");
  93. }
  94. $input->setValue($styleComponent->getValue());
  95. } else {
  96. $input = new WTextField();
  97. $input->setValue($styleComponent->getValue());
  98.  
  99. }
  100. if(!$styleComponent->isLimitedToOptions()){
  101. $input->setErrorRule(new WECRegex($regex));
  102. $input->setErrorText($styleComponent->getErrorDescription());
  103. }
  104. $this->_wizardComponent =$input;
  105. }
  106. function getStyleComponent(){
  107.  
  108. eval('$theme = '.$this->_getThemeCallBack."();");
  109. $collection =$theme->getStyleCollection($this->_collection);
  110. //print " ".$this->_collection;
  111. //print " ".$this->_property;
  112.  
  113. $property =$collection->getStyleProperty($this->_property);
  114. return $property->getStyleComponent($this->_component);
  115. }
  116. /*
  117. function getWizardRepresentation () {
  118. if (get_class($this) == 'colorsc') {
  119. $input = new WSelectOrNew();
  120. $input->addOption('', "(not set)");
  121. // make sure the current color is a possibility.
  122. if (!is_null($this->_value)){
  123. $input->addOption($this->_value, $this->_value, "background-color:$this->_value;");
  124. $input->setValue($this->_value);
  125. }
  126. // if ([[colorwheel colors]])
  127. // generate options for colors
  128. } else if ($this->_limitedToOptions) {
  129. $input = new WSelectList();
  130. $input->addOption('', "(not set)");
  131. foreach ($this->_options as $opt) {
  132. $input->addOption($opt, $opt, strtolower(preg_replace("/[^a-zA-Z0-9:_-]/", "-", $this->_displayName)).": $opt;");
  133. }
  134. $input->setValue($this->_value);
  135. } else if ($this->hasOptions()) {
  136. $input = new WSelectOrNew();
  137. $input->addOption('', "(not set)");
  138. foreach ($this->_options as $opt) {
  139. $input->addOption($opt, $opt, strtolower(preg_replace("/[^a-zA-Z0-9:_-]/", "-", $this->_displayName)).": $opt;");
  140. }
  141. $input->setValue($this->_value);
  142. } else {
  143. $input = new WTextField();
  144. $input->setValue($this->_value);
  145. }
  146. return $input;
  147. }
  148. */
  149. /**
  150. * Returns true if this component (and all child components if applicable) have valid values.
  151. * By default, this will just return TRUE.
  152. * @access public
  153. * @return boolean
  154. */
  155. function validate () {
  156. return $this->_wizardComponent->validate();
  157. //$styleComponent =$this->getStyleComponent();
  158. //$rule =$styleComponent->getRule();
  159. //$err = !$rule->check($styleComponent->getValue());
  160. //if (!$err) $this->_showError = true;
  161. //return $err;
  162. }
  163. /**
  164. * Tells the wizard component to update itself - this may include getting
  165. * form post data or validation - whatever this particular component wants to
  166. * do every pageload.
  167. * @param string $fieldName The field name to use when outputting form data or
  168. * similar parameters/information.
  169. * @access public
  170. * @return boolean - TRUE if everything is OK
  171. */
  172. function update ($fieldName) {
  173.  
  174. $this->_wizardComponent->update($fieldName);
  175. $styleComponent =$this->getStyleComponent();
  176. $val = $this->_wizardComponent->getAllValues();
  177.  
  178. $rule =$styleComponent->getRule();
  179. if($rule->check($val)){
  180. $styleComponent->setValue($val);
  181. }else{
  182. print "<br />failed: '".$val."'!";
  183. }
  184. $styleComponent->setValue($val);
  185. return true;
  186. }
  187. /**
  188. * Returns the values of wizard-components. Should return an array if children are involved,
  189. * otherwise a whatever type of object is expected.
  190. *
  191. * In this case, a "1" or a "0" is returned, depending on the checked state of the checkbox.
  192. * @access public
  193. * @return mixed
  194. */
  195. function getAllValues () {
  196. $ret = $this->_wizardComponent->getAllValues();
  197. return $ret;
  198. }
  199. /**
  200. * Returns a block of XHTML-valid code that contains markup for this specific
  201. * component.
  202. * @param string $fieldName The field name to use when outputting form data or
  203. * similar parameters/information.
  204. * @access public
  205. * @return string
  206. */
  207. function getMarkup ($fieldName) {
  208. $s="";
  209. $s.= $this->_wizardComponent->getMarkup($fieldName);
  210. //$errText = sprintf(,$this->getAllValues());
  211. //$errDescription = "Could not validate the color StyleComponent value \"%s\". Allowed formats are: #RGB, #RRGGBB, rgb(R,G,B), and rgb(R%%,G%%,B%%).";
  212. /*$errText = $this->getErrorText();
  213. //$errText = sprintf($errText,"32werwer4");
  214. $errRule =$this->getErrorRule();
  215. $errStyle = $this->getErrorStyle();
  216. //$errText= sprintf("Could not validate the color StyleComponent value \"%s\". Allowed formats are: #RGB, #RRGGBB, rgb(R,G,B), and rgb(R%%,G%%,B%%).",$this->_wizardComponent->getAllValues(),true);
  217. $val = $this->_wizardComponent->getAllValues();
  218. $errText= sprintf($errText,$val,$val,$val,$val);
  219. print $errText."<br />";
  220. $this->_showError = false;
  221. if ($errText && $errRule) {
  222. $s .= "<span id='".$fieldName."_error' style=\"padding-left: 10px; $errStyle\">&laquo; $errText</span>";
  223. $s .= Wizard::getValidationJavascript($fieldName, $errRule, $fieldName."_error", $this->_showError);
  224. $this->_showError = false;
  225. }*/
  226. return $s;
  227. }
  228. }
  229.  
  230. ?>

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