Source for file XLayout.class.php

Documentation is available at XLayout.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>XLayout</code> renders components sequentially and horizontally.
  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: XLayout.class.php,v 1.9 2007/09/04 20:25:22 adamfranco Exp $
  21. */
  22. class XLayout extends LayoutInterface {
  23.  
  24. /**
  25. * The constructor.
  26. * @access public
  27. ***/
  28. function XLayout() {
  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. // print html for container (a table)
  75. echo $tabs."<table width=\"100%\" border=\"0\" cellpadding=\"0px\" cellspacing=\"0px\">\n";
  76. echo $tabs."\t<tr>\n";
  77. // Get the components
  78. $components =$container->getComponents();
  79. if (ereg('Right-Left', $this->_renderDirection))
  80. $keys = array_reverse(array_keys($components));
  81. else
  82. $keys = array_keys($components);
  83. foreach ($keys as $key) {
  84. $component =$components[$key];
  85. // width and height of the component
  86. $width = $height = "";
  87. $width = $container->getComponentWidth($key + 1);
  88. $height = $container->getComponentHeight($key + 1);
  89. if (isset($width)) $width = " width=\"$width\"";
  90. if (isset($height)) $height = " height=\"$height\"";
  91.  
  92. // include halign and valign
  93. $halign = $valign = "";
  94. switch ($container->getComponentAlignmentX($key + 1)) {
  95. case LEFT: $halign = " align=\"left\""; break;
  96. case CENTER: $halign = " align=\"center\""; break;
  97. case RIGHT: $halign = " align=\"right\""; break;
  98. }
  99. switch ($container->getComponentAlignmentY($key + 1)) {
  100. case TOP: $valign = " valign=\"top\""; break;
  101. case CENTER: $valign = " valign=\"middle\""; break;
  102. case BOTTOM: $valign = " valign=\"bottom\""; break;
  103. }
  104. // render the component in separate table cell
  105. echo $tabs."\t<td $width$height$halign$valign>\n";
  106. $component->render($theme, $tabs."\t\t");
  107. echo "\n".$tabs."\t</td>\n";
  108. }
  109.  
  110. echo $tabs."\t</tr>\n";
  111. echo $tabs."</table>\n";
  112. }
  113. /**
  114. * Returns any CSS code that might be needed in order for this <code>Layout</code>
  115. * to render properly.
  116. * @access public
  117. * @param string tabs This is a string (normally a bunch of tabs) that will be
  118. * prepended to each text line. This argument is optional but its usage is highly
  119. * recommended in order to produce a nicely formatted HTML output.
  120. * @return string The CSS code that might be needed in order for this <code>Layout</code>
  121. * to render properly.
  122. ***/
  123. function getCSS($tabs = "") {
  124. return "";
  125. }
  126. }
  127.  
  128. ?>

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