Source for file YLayout.class.php

Documentation is available at YLayout.class.php

  1. <?php
  2.  
  3. require_once(HARMONI."GUIManager/Layout.interface.php");
  4. require_once(HARMONI."GUIManager/StyleCollection.class.php");
  5. require_once(HARMONI."GUIManager/StyleProperties/MarginSP.class.php");
  6. require_once(HARMONI."GUIManager/StyleProperties/PaddingSP.class.php");
  7. require_once(HARMONI."GUIManager/StyleProperties/BorderSP.class.php");
  8.  
  9. /**
  10. * <code>YLayout</code> renders components sequentially and vertically.
  11. * <br /><br />
  12. * Layouts are assigned to Containers and they specify how (in terms of location,
  13. * not appearance) the sub-<code>Components</code> are going to be rendered on the screen.
  14. *
  15. * @package harmoni.gui.layouts
  16. *
  17. * @copyright Copyright &copy; 2005, Middlebury College
  18. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  19. *
  20. * @version $Id: YLayout.class.php,v 1.12 2007/09/04 20:25:22 adamfranco Exp $
  21. */
  22. class YLayout extends LayoutInterface {
  23.  
  24. /**
  25. * The constructor.
  26. * @access public
  27. ***/
  28. function YLayout() {
  29. $this->_renderDirection ='Left-Right/Top-Bottom';
  30. }
  31. /**
  32. * Set the direction of component rendering from the default of Left-Right/Top-Bottom.
  33. * Allowed values:
  34. * Left-Right/Top-Bottom
  35. * Top-Bottom/Left-Right
  36. * Right-Left/Top-Bottom
  37. * Top-Bottom/Right-Left
  38. * Left-Right/Bottom-Top
  39. * Bottom-Top/Left-Right
  40. * Right-Left/Bottom-Top
  41. * Bottom-Top/Right-Left
  42. *
  43. * @param string $direction
  44. * @return void
  45. * @access public
  46. * @since 8/18/06
  47. */
  48. function setRenderDirection ($direction) {
  49. ArgumentValidator::validate($direction, ChoiceValidatorRule::getRule(
  50. 'Left-Right/Top-Bottom',
  51. 'Top-Bottom/Left-Right',
  52. 'Right-Left/Top-Bottom',
  53. 'Top-Bottom/Right-Left',
  54. 'Left-Right/Bottom-Top',
  55. 'Bottom-Top/Left-Right',
  56. 'Right-Left/Bottom-Top',
  57. 'Bottom-Top/Right-Left'));
  58. $this->_renderDirection = $direction;
  59. }
  60.  
  61. /**
  62. * Lays out and renders the given container and its components. The Layout
  63. * object should arrange the <code>Components</code> in a well-defined manner
  64. * and then call the <code>render()</code> methods of each individual component.
  65. * @access public
  66. * @param ref object The container to render.
  67. * @param ref object theme The Theme object to use in producing the result
  68. * of this method.
  69. * @param string tabs This is a string (normally a bunch of tabs) that will be
  70. * prepended to each text line. This argument is optional but its usage is highly
  71. * recommended in order to produce a nicely formatted HTML output.
  72. ***/
  73. function render($container, $theme, $tabs = "") {
  74. // Get the components
  75. // render the component in separate table cell
  76. $components =$container->getComponents();
  77. if (ereg('Bottom-Top', $this->_renderDirection))
  78. $keys = array_reverse(array_keys($components));
  79. else
  80. $keys = array_keys($components);
  81. foreach ($keys as $key) {
  82. $component =$components[$key];
  83. if (!is_object($component)) {
  84. throw new Exception("Invalid component");
  85. }
  86. $styles = array();
  87. // width and height of the component
  88. $width = $container->getComponentWidth($key + 1);
  89. $height = $container->getComponentHeight($key + 1);
  90. if (!is_null($width))
  91. $styles[] = "width: $width;";
  92. if (!is_null($height))
  93. $styles[] = "height: $height;";
  94.  
  95. // include halign and valign
  96. $halign = $valign = "";
  97. switch ($container->getComponentAlignmentX($key + 1)) {
  98. case LEFT: $styles[] = "margin-left: 0px; margin-right: auto;"; break;
  99. case CENTER: $styles[] = "margin-left: auto; margin-right: auto;"; break;
  100. case RIGHT: $styles[] = "margin-left: auto; margin-right: 0px;"; break;
  101. }
  102. switch ($container->getComponentAlignmentY($key + 1)) {
  103. case TOP: $styles[] = "valign: top;"; break;
  104. case CENTER: $styles[] = "valign: middle;"; break;
  105. case BOTTOM: $styles[] = "valign: bottom"; break;
  106. }
  107. echo $tabs."\t<div style=\"".implode(" ", $styles)."\">\n";
  108. $component->render($theme, $tabs."\t\t");
  109. echo "\n".$tabs."\t</div>\n";
  110. }
  111. }
  112. /**
  113. * Returns any CSS code that might be needed in order for this <code>Layout</code>
  114. * to render properly.
  115. * @access public
  116. * @param string tabs This is a string (normally a bunch of tabs) that will be
  117. * prepended to each text line. This argument is optional but its usage is highly
  118. * recommended in order to produce a nicely formatted HTML output.
  119. * @return string The CSS code that might be needed in order for this <code>Layout</code>
  120. * to render properly.
  121. ***/
  122. function getCSS($tabs = "") {
  123. return "";
  124. }
  125. }
  126.  
  127. ?>

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