Examples TOCexamples

Default ProgressBar Observer

$Date: 2005/07/25 12:27:28 $

 Table of contents

Introduction

This example requires :


This example will run a ProgressBar in determinate mode that will log into a flat file ('progress_observer.log') each changes.

Here are the contents of that file :

A default progress bar observer is created at line 21, and attached at line 23

[Top]

 Render options

speed = 100 is set at line 16
HTML_Progress::setAnimSpeed()
increment = 10 is set at line 18
HTML_Progress::setIncrement()
border painted with all default options at line 17 (color=black, shape=solid).
Set size to 2 pixels at line 30.
HTML_Progress::setBorderPainted()
HTML_Progress_UI::setBorderAttributes()

[Top]

 Output

Screenshot

[Top]

 PHP source syntax highlight

  1. <?php
  2. /**
  3.  * Observer ProgressBar example. Uses the default observer class.
  4.  *
  5.  * @version    $Id: default.php,v 1.2 2005/07/25 12:27:28 farell Exp $
  6.  * @author     Laurent Laville <pear@laurent-laville.org>
  7.  * @package    HTML_Progress
  8.  * @subpackage Examples
  9.  */
  10.  
  11. require_once 'HTML/Progress.php';
  12. require_once 'HTML/Progress/observer.php';
  13.  
  14. // 1. Creates ProgressBar
  15. $bar = new HTML_Progress();
  16. $bar->setAnimSpeed(100);
  17. $bar->setBorderPainted(true);
  18. $bar->setIncrement(10);
  19.  
  20. // 2. Creates and attach a listener
  21. $observer = new HTML_Progress_Observer();
  22.  
  23. $ok = $bar->addListener($observer);
  24. if (!$ok) {
  25.     die ("Cannot add a valid listener to progress bar !");
  26. }
  27.  
  28. // 3. Changes look-and-feel of ProgressBar
  29. $ui =& $bar->getUI();
  30. $ui->setBorderAttributes('width = 2');                     // border: 2px, solid, #000000
  31. $ui->setComment('Standard Observer ProgressBar example');
  32. ?>
  33. <!DOCTYPE html
  34.     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  35.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  36.  
  37. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  38. <head>
  39. <title>Standard Observer ProgressBar example</title>
  40. <style type="text/css">
  41. <!--
  42. <?php echo $bar->getStyle(); ?>
  43.  
  44. body {
  45.     background-color: #FFFFFF;
  46.     color: #000000;
  47.     font-family: Verdana, Arial;
  48. }
  49.  
  50. a:visited, a:active, a:link {
  51.     color: navy;
  52. }
  53. // -->
  54. </style>
  55. <script type="text/javascript">
  56. <!--
  57. <?php echo $bar->getScript(); ?>
  58. //-->
  59. </script>
  60. </head>
  61. <body>
  62.  
  63. <?php
  64. echo $bar->toHTML();
  65. $bar->run();
  66. ?>
  67.  
  68. <form>
  69. Contents of file 'progress_observer.log' generated by HTML_Progress_Observer class
  70. <textarea readOnly="true" rows="12" cols="80" wrap="virtual">
  71. a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:10;}
  72. a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:20;}
  73. a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:30;}
  74. a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:40;}
  75. a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:50;}
  76. a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:60;}
  77. a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:70;}
  78. a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:80;}
  79. a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:90;}
  80. a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:100;}
  81. </textarea>
  82. </form>
  83.  
  84. </body>
  85. </html>

[Top]