Examples TOCexamples

Determinate Monitor

$Date: 2005/07/25 12:15:50 $

 Table of contents

Introduction

This example requires :

Be aware that:


This example will run a simple ProgressBar Monitor, in determinate mode, with a class-method user callback.

Color scheme came from a UI pre-set model (class) called Progress_Default2, defined on lines 14 to 24.

The user callback defined on lines 26 to 36, and attached on progress bar at line 43, will echo each time +10% is reached.

QF renderer rules are defined on lines 73 to 85.

[Top]

 Render options

Here are the progress attributes:
background-color = #e0e0e0
HTML_Progress_UI::setProgressAttributes()
Here are the progress string attributes:
color            = #996
background-color = #CCCC99
HTML_Progress_UI::setStringAttributes()
Here are the progress cells attributes:
active-color = #996
HTML_Progress_UI::setCellAttributes()

[Top]

 Output

Screenshot

[Top]

 PHP source syntax highlight

  1. <?php
  2. /**
  3.  * Monitor example with a new form template and progress bar
  4.  * color scheme. Used a class-method as user callback.
  5.  *
  6.  * @version    $Id: method_callback.php,v 1.2 2005/07/25 12:15:50 farell Exp $
  7.  * @author     Laurent Laville <pear@laurent-laville.org>
  8.  * @package    HTML_Progress
  9.  * @subpackage Examples
  10.  */
  11.  
  12. require_once 'HTML/Progress/monitor.php';
  13.  
  14. class Progress_Default2 extends HTML_Progress_UI
  15. {
  16.     function Progress_Default2()
  17.     {
  18.         parent::HTML_Progress_UI();
  19.  
  20.         $this->setProgressAttributes(array('background-color' => '#e0e0e0'));
  21.         $this->setStringAttributes(array('color' => '#996', 'background-color' => '#CCCC99'));
  22.         $this->setCellAttributes(array('active-color' => '#996'));
  23.     }
  24. }
  25.  
  26. class myClassHandler
  27. {
  28.     function myMethodHandler($progressValue, &$bar)
  29.     {
  30.         if (fmod($progressValue,10) == 0) {
  31.             echo "myMethodHandler -> progress value is = $progressValue <br/>\n";
  32.         }
  33.         $bar->sleep();
  34.     }
  35. }
  36. $obs = new myClassHandler();
  37.  
  38. $monitor = new HTML_Progress_Monitor('frmMonitor3', array(
  39.     'button' => array('style' => 'width:80px;')
  40.     )
  41. );
  42.  
  43. $progress = new HTML_Progress();
  44. $progress->setUI('Progress_Default2');   // Attach a progress ui-model
  45. $progress->setAnimSpeed(20);
  46. $progress->setProgressHandler(array(&$obs, 'myMethodHandler'));
  47.  
  48. $monitor->setProgressElement($progress);
  49. ?>
  50. <html>
  51. <head>
  52. <title>ProgressBar Monitor - Default renderer </title>
  53. <style type="text/css">
  54. <!--
  55. .progressStatus {
  56.     color:#000000;
  57.     font-size:10px;
  58. }
  59. <?php echo $monitor->getStyle(); ?>
  60. // -->
  61. </style>
  62. <script type="text/javascript">
  63. <!--
  64. <?php echo $monitor->getScript(); ?>
  65. //-->
  66. </script>
  67. </head>
  68. <body>
  69.  
  70.  
  71. <?php
  72. $renderer =& HTML_QuickForm::defaultRenderer();
  73. $renderer->setFormTemplate('
  74. <form{attributes}>
  75.  <table width="450" border="0" cellpadding="3" cellspacing="2" bgcolor="#CCCC99">
  76.  {content}
  77.  </table>
  78. </form>
  79. ');
  80. $renderer->setHeaderTemplate('
  81.  <tr>
  82.    <td style="white-space:nowrap;background:#996;color:#ffc;" align="left" colspan="2"><b>{header}</b></td>
  83.  </tr>
  84. ');
  85. $monitor->accept($renderer);
  86.  
  87. echo $renderer->toHtml();
  88. $monitor->run();
  89. ?>
  90.  
  91. </body>
  92. </html>

[Top]