cvs: pear /HTML_Progress/examples/observer complex.html complex.php default.html default.php simple.html simple.php
| From: | Laurent Laville | Date: | Sun, 27 Jun 2004 13:08:28 +0000 |
| Subject: | cvs: pear /HTML_Progress/examples/observer complex.html complex.php default.html default.php simple.html simple.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-21183@lists.php.net to get a copy of this message | ||
farell Sun Jun 27 09:08:28 2004 EDT
Added files:
/pear/HTML_Progress/examples/observer complex.html complex.php
default.html default.php
simple.html simple.php
Log:
HTML_Progress examples reorganized by category
http://cvs.php.net/co.php/pear/HTML_Progress/examples/observer/complex.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/observer/complex.html +++ pear/HTML_Progress/examples/observer/complex.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="robots" content="index,nofollow" /> <meta name="keywords" content"="HTML_Progress, observer, progress meter" /> <meta name="description" content"="HTML_Progress_Observer allow to handle 2 bars master and slave" /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: Complex ProgressBar Observer</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="../examples.css" /> </head> <body> <a name="top"> <p><a href="index.html"><img src="../images/home.gif" alt="Examples TOC"/>examples</a></p> <h1><span class="chapter">Complex ProgressBar Observer </span></h1> <p align="right">$Date: 2004/06/27 13:08:28 $</p> <div class="toc"> Table of contents </div> <ul> <li><a href="#intro">Introduction<a> <li><a href="#render">Render options<a> <li><a href="#output">Output</a> <li><a href="#source">PHP source syntax highlight<a> <li><a href="#run">Play demo<a> </ul> <a name="intro"> <h2><img src="../images/info.gif"/> Introduction</h2> <p>This example requires : <ul> <li>PEAR::HTML_Progress 1.2.0RC3 or better (see source at lines 12, 13).</li> </ul> </p> <hr/> <p><b>This example will run a complex observer mechanism which run two progress bar. At each full loop of first bar, second bar is increment until this last one reach 100%.</b></p> <p>All explains are in source code comments. Just a big warning: NEVER forget the line 145.</p> <p>[<a href="#top">Top</a>]</p> <a name="render"> <h2><img src="../images/config.gif"/> Render options </h2> Here are options to build the 1st progress bar : <pre> background-color = #e0e0e0 </pre> <div class="fig">HTML_Progress_UI::setProgressAttributes()</div> Here are options to build the 1st progress bar string : <pre> valign = left color = red background-color = lightblue </pre> <div class="fig">HTML_Progress_UI::setStringAttributes()</div> Here are options to build the 2nd progress bar border : <pre> width = 1 style = solid color = navy </pre> <div class="fig">HTML_Progress_UI::setBorderAttributes()</div> Here are options to build the 2nd progress bar cell : <pre> active-color = #3874B4 inactive-color = #EEEECC </pre> <div class="fig">HTML_Progress_UI::setCellAttributes()</div> Here are options to build the 2nd progress bar string : <pre> width = 100 align = center valign = right color = yellow background-color = lightblue </pre> <div class="fig">HTML_Progress_UI::setStringAttributes()</div> <p>[<a href="#top">Top</a>]</p> <a name="output"> <h2><img src="../images/image.gif"/> Output</h2> <h3>Screenshot </h3> <p><img src="../screenshots/observer_complex.png"/></p> <p>[<a href="#top">Top</a>]</p> <a name="source"> <h2><img src="../images/source.gif"/> PHP source syntax highlight</h2> <a target="_blank" href="../highlighter.php?file=observer/complex.php">Open</a> source listing in a new window. <p>[<a href="#top">Top</a>]</p> <a name="run"> <h2><img src="../images/run.gif"/> Play demo</h2> <p><a href="complex.php">Run</a> the script.</p> <p>[<a href="#top">Top</a>]</p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/observer/complex.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/observer/complex.php +++ pear/HTML_Progress/examples/observer/complex.php <?php @include '../include_path.php'; /** * Observer ProgressBar example. Uses a custom observer class * that handled progress of the second bar. * * @version $Id: complex.php,v 1.1 2004/06/27 13:08:28 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/Progress.php'; require_once 'HTML/Progress/observer.php'; // 1. Defines ProgressBar observer class Bar1Observer extends HTML_Progress_Observer { function Bar1Observer() { $this->HTML_Progress_Observer(); } function notify($event) { global $bar2; if (is_array($event)) { $log = isset($event['log']) ? $event['log'] : "undefined event id."; $val = isset($event['value']) ? $event['value'] : "unknown value"; switch (strtolower($log)) { case 'incvalue': // if you want to do special on each step of progress bar1; it's here !!! break; case 'setvalue': if ($val == 0) { // updates $bar2 because $bar1 has completed a full loop $bar2->incValue(); $bar2->display(); } default: } } } } // 2. Creates ProgressBar $bar1 = new HTML_Progress(HTML_PROGRESS_BAR_VERTICAL); $bar1->setAnimSpeed(50); $bar1->setIncrement(10); $bar1->setIdent('PB1'); $bar2 = new HTML_Progress(HTML_PROGRESS_BAR_VERTICAL); $bar2->setAnimSpeed(50); $bar2->setIncrement(25); $bar2->setIdent('PB2'); $bar2->setBorderPainted(true); // 3. Creates and attach a listener $observer = new Bar1Observer(); $ok = $bar1->addListener($observer); if (!$ok) { die ("Cannot add a valid listener to progress bar !"); } // 4. Changes look-and-feel of ProgressBar $ui1 =& $bar1->getUI(); $ui1->setComment('Complex Observer ProgressBar example'); $ui1->setTabOffset(1); $ui1->setProgressAttributes(array( 'background-color' => '#e0e0e0' )); $ui1->setStringAttributes(array( 'valign' => 'left', 'color' => 'red', 'background-color' => 'lightblue' )); $ui2 =& $bar2->getUI(); $ui2->setTabOffset(1); $ui2->setBorderAttributes(array( 'width' => 1, 'style' => 'solid', 'color' => 'navy' )); $ui2->setCellAttributes(array( 'active-color' => '#3874B4', 'inactive-color' => '#EEEECC' )); $ui2->setStringAttributes(array( 'width' => '100', 'align' => 'center', 'valign' => 'right', 'color' => 'yellow', 'background-color' => 'lightblue' )); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Complex Observer ProgressBar example</title> <style type="text/css"> <!-- <?php echo $bar1->getStyle(); echo $bar2->getStyle(); ?> table.container { background-color: lightblue; border: 2; border-color: navy; border-style: dashed; cell-spacing: 4; cell-padding: 8; width: 50%; } // --> </style> <script type="text/javascript"> <!-- <?php echo $bar1->getScript(); ?> //--> </script> </head> <body> <h1><?php echo basename(__FILE__); ?></h1> <table class="container"> <tr> <td width="25%" align="center"> <?php echo $bar1->toHTML(); ?> </td> <td width="25%" align="center"> <?php echo $bar2->toHTML(); ?> </td> </tr> </table> <?php do { $bar1->display(); $bar1->process(); // warning: don't forget it (even for a demo) if ($bar1->getPercentComplete() == 1) { $bar1->setValue(0); // the 1st progress bar has reached 100%, do a new loop } else { $bar1->incValue(); // updates 1st progress bar } } while($bar2->getPercentComplete() < 1); ?> <p><< <a href="../index.html">Back examples TOC</a></p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/observer/default.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/observer/default.html +++ pear/HTML_Progress/examples/observer/default.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="robots" content="index,nofollow" /> <meta name="keywords" content"="HTML_Progress, observer, progress meter" /> <meta name="description" content"="HTML_Progress logs all changes in its observer pattern" /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: Default ProgressBar Observer</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="../examples.css" /> </head> <body> <a name="top"> <p><a href="../index.html"><img src="../images/home.gif" alt="Examples TOC"/>examples</a></p> <h1><span class="chapter">Default ProgressBar Observer </span></h1> <p align="right">$Date: 2004/06/27 13:08:28 $</p> <div class="toc"> Table of contents </div> <ul> <li><a href="#intro">Introduction<a> <li><a href="#render">Render options<a> <li><a href="#output">Output</a> <li><a href="#source">PHP source syntax highlight<a> <li><a href="#run">Play demo<a> </ul> <a name="intro"> <h2><img src="../images/info.gif"/> Introduction</h2> <p>This example requires : <ul> <li>PEAR::HTML_Progress 1.2.0RC3 or better (see source at lines 11, 12).</li> </ul> </p> <hr/> <p><b>This example will run a ProgressBar in determinate mode that will log into a flat file ('progress_observer.log') each changes.</b></p> <p>Here are the contents of that file : <form> <textarea readOnly="true" rows="12" cols="80" wrap="virtual"> a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:10;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:20;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:30;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:40;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:50;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:60;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:70;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:80;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:90;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:100;} </textarea> </form> <p>A default progress bar observer is created at line 21, and attached at line 23 <p>[<a href="#top">Top</a>]</p> <a name="render"> <h2><img src="../images/config.gif"/> Render options </h2> <pre> speed = 100 is set at line 16 </pre> <div class="fig">HTML_Progress::setAnimSpeed()</div> <pre> increment = 10 is set at line 18 </pre> <div class="fig">HTML_Progress::setIncrement()</div> <pre> border painted with all default options at line 17 (color=black, shape=solid). Set size to 2 pixels at line 30. </pre> <div class="fig">HTML_Progress::setBorderPainted()</div> <div class="fig">HTML_Progress_UI::setBorderAttributes()</div> <p>[<a href="#top">Top</a>]</p> <a name="output"> <h2><img src="../images/image.gif"/> Output</h2> <h3>Screenshot </h3> <p><img src="../screenshots/observer_standard.png"/></p> <p>[<a href="#top">Top</a>]</p> <a name="source"> <h2><img src="../images/source.gif"/> PHP source syntax highlight</h2> <a target="_blank" href="../highlighter.php?file=observer/default.php">Open</a> source listing in a new window. <p>[<a href="#top">Top</a>]</p> <a name="run"> <h2><img src="../images/run.gif"/> Play demo</h2> <p><a href="default.php">Run</a> the script.</p> <p>[<a href="#top">Top</a>]</p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/observer/default.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/observer/default.php +++ pear/HTML_Progress/examples/observer/default.php <?php @include '../include_path.php'; /** * Observer ProgressBar example. Uses the default observer class. * * @version $Id: default.php,v 1.1 2004/06/27 13:08:28 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/Progress.php'; require_once 'HTML/Progress/observer.php'; // 1. Creates ProgressBar $bar = new HTML_Progress(); $bar->setAnimSpeed(100); $bar->setBorderPainted(true); $bar->setIncrement(10); // 2. Creates and attach a listener $observer = new HTML_Progress_Observer(); $ok = $bar->addListener($observer); if (!$ok) { die ("Cannot add a valid listener to progress bar !"); } // 3. Changes look-and-feel of ProgressBar $ui =& $bar->getUI(); $ui->setBorderAttributes('width = 2'); // border: 2px, solid, #000000 $ui->setComment('Standard Observer ProgressBar example'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Standard Observer ProgressBar example</title> <style type="text/css"> <!-- <?php echo $bar->getStyle(); ?> body { background-color: #FFFFFF; color: #000000; font-family: Verdana, Arial; } a:visited, a:active, a:link { color: navy; } // --> </style> <script type="text/javascript"> <!-- <?php echo $bar->getScript(); ?> //--> </script> </head> <body> <h1><?php echo basename(__FILE__); ?></h1> <?php echo $bar->toHTML(); $bar->run(); ?> <form> Contents of file 'progress_observer.log' generated by HTML_Progress_Observer class <textarea readOnly="true" rows="12" cols="80" wrap="virtual"> a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:10;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:20;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:30;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:40;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:50;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:60;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:70;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:80;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:90;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:100;} </textarea> </form> <p><< <a href="../index.html">Back examples TOC</a></p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/observer/simple.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/observer/simple.html +++ pear/HTML_Progress/examples/observer/simple.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="robots" content="index,nofollow" /> <meta name="keywords" content"="HTML_Progress, observer, progress meter" /> <meta name="description" content"="HTML_Progress logs all changes in its observer pattern" /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: Simple ProgressBar Observer</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="../examples.css" /> </head> <body> <a name="top"> <p><a href="../index.html"><img src="../images/home.gif" alt="Examples TOC"/>examples</a></p> <h1><span class="chapter">Simple ProgressBar Observer </span></h1> <p align="right">$Date: 2004/06/27 13:08:28 $</p> <div class="toc"> Table of contents </div> <ul> <li><a href="#intro">Introduction<a> <li><a href="#render">Render options<a> <li><a href="#output">Output</a> <li><a href="#source">PHP source syntax highlight<a> <li><a href="#run">Play demo<a> </ul> <a name="intro"> <h2><img src="../images/info.gif"/> Introduction</h2> <p>This example requires : <ul> <li>PEAR::HTML_Progress 1.2.0RC3 or better (see source at lines 11, 12).</li> </ul> </p> <hr/> <p><b>This example will run a ProgressBar with a custom class observer mechanism. Output could be send to screen or on flat file 'observer_complex.log'.</b></p> <p>Here are the contents of that file : <form> <textarea readOnly="true" rows="21" cols="50" wrap="virtual"> incValue = 5 incValue = 10 incValue = 15 incValue = 20 incValue = 25 incValue = 30 incValue = 35 incValue = 40 incValue = 45 incValue = 50 incValue = 55 incValue = 60 incValue = 65 incValue = 70 incValue = 75 incValue = 80 incValue = 85 incValue = 90 incValue = 95 incValue = 100 </textarea> </form> <p>[<a href="#top">Top</a>]</p> <a name="render"> <h2><img src="../images/config.gif"/> Render options </h2> <pre> speed = 50 is set at line 46 </pre> <div class="fig">HTML_Progress::setAnimSpeed()</div> <pre> increment = 5 is set at line 47 </pre> <div class="fig">HTML_Progress::setIncrement()</div> <p>[<a href="#top">Top</a>]</p> <a name="output"> <h2><img src="../images/image.gif"/> Output</h2> <h3>Screenshot </h3> <p><img src="../screenshots/observer_simple.png"/></p> <p>[<a href="#top">Top</a>]</p> <a name="source"> <h2><img src="../images/source.gif"/> PHP source syntax highlight</h2> <a target="_blank" href="../highlighter.php?file=observer/simple.php">Open</a> source listing in a new window. <p>[<a href="#top">Top</a>]</p> <a name="run"> <h2><img src="../images/run.gif"/> Play demo</h2> <p><a href="simple.php?out=screen">Run</a> the screen version.</p> <p><a href="simple.php?out=file">Run</a> the file version.</p> <p>[<a href="#top">Top</a>]</p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/observer/simple.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/observer/simple.php +++ pear/HTML_Progress/examples/observer/simple.php <?php @include '../include_path.php'; /** * Observer ProgressBar example. Uses a custom observer class. * * @version $Id: simple.php,v 1.1 2004/06/27 13:08:28 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/Progress.php'; require_once 'HTML/Progress/observer.php'; // 1. Defines ProgressBar observer class MyObserver extends HTML_Progress_Observer { var $_console; var $_out; function MyObserver($out) { $this->_console = '.' . DIRECTORY_SEPARATOR . 'observer_complex.log'; $this->HTML_Progress_Observer(); $this->_out = strtolower($out); } function notify($event) { if (is_array($event)) { $log = isset($event['log']) ? $event['log'] : "undefined event id."; $val = isset($event['value']) ? $event['value'] : "unknown value"; $msg = "$log = $val"; } else { $msg = $event; } if ($this->_out == 'file') { error_log("$msg \n", 3, $this->_console); } else { print ("$msg <br />\n"); } } } // 2. Creates ProgressBar $bar = new HTML_Progress(); $bar->setAnimSpeed(50); $bar->setIncrement(5); // 3. Creates and attach a listener $observer = new MyObserver($_GET['out']); $ok = $bar->addListener($observer); if (!$ok) { die ("Cannot add a valid listener to progress bar !"); } // 4. Changes look-and-feel of ProgressBar $ui = $bar->getUI(); $ui->setComment('Simple Observer ProgressBar example'); ?> <html> <head> <title>Simple Observer ProgressBar example</title> <style type="text/css"> <!-- <?php echo $bar->getStyle(); ?> // --> </style> <script type="text/javascript"> <!-- <?php echo $bar->getScript(); ?> //--> </script> </head> <body> <h1><?php echo basename(__FILE__); ?></h1> <?php echo $bar->toHTML(); $bar->run(); ?> <p><< <a href="../index.html">Back examples TOC</a></p> </body> </html>
http://cvs.php.net/co.php/pear/HTML_Progress/examples/observer/complex.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/observer/complex.html +++ pear/HTML_Progress/examples/observer/complex.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="robots" content="index,nofollow" /> <meta name="keywords" content"="HTML_Progress, observer, progress meter" /> <meta name="description" content"="HTML_Progress_Observer allow to handle 2 bars master and slave" /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: Complex ProgressBar Observer</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="../examples.css" /> </head> <body> <a name="top"> <p><a href="index.html"><img src="../images/home.gif" alt="Examples TOC"/>examples</a></p> <h1><span class="chapter">Complex ProgressBar Observer </span></h1> <p align="right">$Date: 2004/06/27 13:08:28 $</p> <div class="toc"> Table of contents </div> <ul> <li><a href="#intro">Introduction<a> <li><a href="#render">Render options<a> <li><a href="#output">Output</a> <li><a href="#source">PHP source syntax highlight<a> <li><a href="#run">Play demo<a> </ul> <a name="intro"> <h2><img src="../images/info.gif"/> Introduction</h2> <p>This example requires : <ul> <li>PEAR::HTML_Progress 1.2.0RC3 or better (see source at lines 12, 13).</li> </ul> </p> <hr/> <p><b>This example will run a complex observer mechanism which run two progress bar. At each full loop of first bar, second bar is increment until this last one reach 100%.</b></p> <p>All explains are in source code comments. Just a big warning: NEVER forget the line 145.</p> <p>[<a href="#top">Top</a>]</p> <a name="render"> <h2><img src="../images/config.gif"/> Render options </h2> Here are options to build the 1st progress bar : <pre> background-color = #e0e0e0 </pre> <div class="fig">HTML_Progress_UI::setProgressAttributes()</div> Here are options to build the 1st progress bar string : <pre> valign = left color = red background-color = lightblue </pre> <div class="fig">HTML_Progress_UI::setStringAttributes()</div> Here are options to build the 2nd progress bar border : <pre> width = 1 style = solid color = navy </pre> <div class="fig">HTML_Progress_UI::setBorderAttributes()</div> Here are options to build the 2nd progress bar cell : <pre> active-color = #3874B4 inactive-color = #EEEECC </pre> <div class="fig">HTML_Progress_UI::setCellAttributes()</div> Here are options to build the 2nd progress bar string : <pre> width = 100 align = center valign = right color = yellow background-color = lightblue </pre> <div class="fig">HTML_Progress_UI::setStringAttributes()</div> <p>[<a href="#top">Top</a>]</p> <a name="output"> <h2><img src="../images/image.gif"/> Output</h2> <h3>Screenshot </h3> <p><img src="../screenshots/observer_complex.png"/></p> <p>[<a href="#top">Top</a>]</p> <a name="source"> <h2><img src="../images/source.gif"/> PHP source syntax highlight</h2> <a target="_blank" href="../highlighter.php?file=observer/complex.php">Open</a> source listing in a new window. <p>[<a href="#top">Top</a>]</p> <a name="run"> <h2><img src="../images/run.gif"/> Play demo</h2> <p><a href="complex.php">Run</a> the script.</p> <p>[<a href="#top">Top</a>]</p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/observer/complex.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/observer/complex.php +++ pear/HTML_Progress/examples/observer/complex.php <?php @include '../include_path.php'; /** * Observer ProgressBar example. Uses a custom observer class * that handled progress of the second bar. * * @version $Id: complex.php,v 1.1 2004/06/27 13:08:28 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/Progress.php'; require_once 'HTML/Progress/observer.php'; // 1. Defines ProgressBar observer class Bar1Observer extends HTML_Progress_Observer { function Bar1Observer() { $this->HTML_Progress_Observer(); } function notify($event) { global $bar2; if (is_array($event)) { $log = isset($event['log']) ? $event['log'] : "undefined event id."; $val = isset($event['value']) ? $event['value'] : "unknown value"; switch (strtolower($log)) { case 'incvalue': // if you want to do special on each step of progress bar1; it's here !!! break; case 'setvalue': if ($val == 0) { // updates $bar2 because $bar1 has completed a full loop $bar2->incValue(); $bar2->display(); } default: } } } } // 2. Creates ProgressBar $bar1 = new HTML_Progress(HTML_PROGRESS_BAR_VERTICAL); $bar1->setAnimSpeed(50); $bar1->setIncrement(10); $bar1->setIdent('PB1'); $bar2 = new HTML_Progress(HTML_PROGRESS_BAR_VERTICAL); $bar2->setAnimSpeed(50); $bar2->setIncrement(25); $bar2->setIdent('PB2'); $bar2->setBorderPainted(true); // 3. Creates and attach a listener $observer = new Bar1Observer(); $ok = $bar1->addListener($observer); if (!$ok) { die ("Cannot add a valid listener to progress bar !"); } // 4. Changes look-and-feel of ProgressBar $ui1 =& $bar1->getUI(); $ui1->setComment('Complex Observer ProgressBar example'); $ui1->setTabOffset(1); $ui1->setProgressAttributes(array( 'background-color' => '#e0e0e0' )); $ui1->setStringAttributes(array( 'valign' => 'left', 'color' => 'red', 'background-color' => 'lightblue' )); $ui2 =& $bar2->getUI(); $ui2->setTabOffset(1); $ui2->setBorderAttributes(array( 'width' => 1, 'style' => 'solid', 'color' => 'navy' )); $ui2->setCellAttributes(array( 'active-color' => '#3874B4', 'inactive-color' => '#EEEECC' )); $ui2->setStringAttributes(array( 'width' => '100', 'align' => 'center', 'valign' => 'right', 'color' => 'yellow', 'background-color' => 'lightblue' )); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Complex Observer ProgressBar example</title> <style type="text/css"> <!-- <?php echo $bar1->getStyle(); echo $bar2->getStyle(); ?> table.container { background-color: lightblue; border: 2; border-color: navy; border-style: dashed; cell-spacing: 4; cell-padding: 8; width: 50%; } // --> </style> <script type="text/javascript"> <!-- <?php echo $bar1->getScript(); ?> //--> </script> </head> <body> <h1><?php echo basename(__FILE__); ?></h1> <table class="container"> <tr> <td width="25%" align="center"> <?php echo $bar1->toHTML(); ?> </td> <td width="25%" align="center"> <?php echo $bar2->toHTML(); ?> </td> </tr> </table> <?php do { $bar1->display(); $bar1->process(); // warning: don't forget it (even for a demo) if ($bar1->getPercentComplete() == 1) { $bar1->setValue(0); // the 1st progress bar has reached 100%, do a new loop } else { $bar1->incValue(); // updates 1st progress bar } } while($bar2->getPercentComplete() < 1); ?> <p><< <a href="../index.html">Back examples TOC</a></p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/observer/default.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/observer/default.html +++ pear/HTML_Progress/examples/observer/default.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="robots" content="index,nofollow" /> <meta name="keywords" content"="HTML_Progress, observer, progress meter" /> <meta name="description" content"="HTML_Progress logs all changes in its observer pattern" /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: Default ProgressBar Observer</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="../examples.css" /> </head> <body> <a name="top"> <p><a href="../index.html"><img src="../images/home.gif" alt="Examples TOC"/>examples</a></p> <h1><span class="chapter">Default ProgressBar Observer </span></h1> <p align="right">$Date: 2004/06/27 13:08:28 $</p> <div class="toc"> Table of contents </div> <ul> <li><a href="#intro">Introduction<a> <li><a href="#render">Render options<a> <li><a href="#output">Output</a> <li><a href="#source">PHP source syntax highlight<a> <li><a href="#run">Play demo<a> </ul> <a name="intro"> <h2><img src="../images/info.gif"/> Introduction</h2> <p>This example requires : <ul> <li>PEAR::HTML_Progress 1.2.0RC3 or better (see source at lines 11, 12).</li> </ul> </p> <hr/> <p><b>This example will run a ProgressBar in determinate mode that will log into a flat file ('progress_observer.log') each changes.</b></p> <p>Here are the contents of that file : <form> <textarea readOnly="true" rows="12" cols="80" wrap="virtual"> a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:10;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:20;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:30;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:40;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:50;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:60;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:70;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:80;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:90;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:100;} </textarea> </form> <p>A default progress bar observer is created at line 21, and attached at line 23 <p>[<a href="#top">Top</a>]</p> <a name="render"> <h2><img src="../images/config.gif"/> Render options </h2> <pre> speed = 100 is set at line 16 </pre> <div class="fig">HTML_Progress::setAnimSpeed()</div> <pre> increment = 10 is set at line 18 </pre> <div class="fig">HTML_Progress::setIncrement()</div> <pre> border painted with all default options at line 17 (color=black, shape=solid). Set size to 2 pixels at line 30. </pre> <div class="fig">HTML_Progress::setBorderPainted()</div> <div class="fig">HTML_Progress_UI::setBorderAttributes()</div> <p>[<a href="#top">Top</a>]</p> <a name="output"> <h2><img src="../images/image.gif"/> Output</h2> <h3>Screenshot </h3> <p><img src="../screenshots/observer_standard.png"/></p> <p>[<a href="#top">Top</a>]</p> <a name="source"> <h2><img src="../images/source.gif"/> PHP source syntax highlight</h2> <a target="_blank" href="../highlighter.php?file=observer/default.php">Open</a> source listing in a new window. <p>[<a href="#top">Top</a>]</p> <a name="run"> <h2><img src="../images/run.gif"/> Play demo</h2> <p><a href="default.php">Run</a> the script.</p> <p>[<a href="#top">Top</a>]</p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/observer/default.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/observer/default.php +++ pear/HTML_Progress/examples/observer/default.php <?php @include '../include_path.php'; /** * Observer ProgressBar example. Uses the default observer class. * * @version $Id: default.php,v 1.1 2004/06/27 13:08:28 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/Progress.php'; require_once 'HTML/Progress/observer.php'; // 1. Creates ProgressBar $bar = new HTML_Progress(); $bar->setAnimSpeed(100); $bar->setBorderPainted(true); $bar->setIncrement(10); // 2. Creates and attach a listener $observer = new HTML_Progress_Observer(); $ok = $bar->addListener($observer); if (!$ok) { die ("Cannot add a valid listener to progress bar !"); } // 3. Changes look-and-feel of ProgressBar $ui =& $bar->getUI(); $ui->setBorderAttributes('width = 2'); // border: 2px, solid, #000000 $ui->setComment('Standard Observer ProgressBar example'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Standard Observer ProgressBar example</title> <style type="text/css"> <!-- <?php echo $bar->getStyle(); ?> body { background-color: #FFFFFF; color: #000000; font-family: Verdana, Arial; } a:visited, a:active, a:link { color: navy; } // --> </style> <script type="text/javascript"> <!-- <?php echo $bar->getScript(); ?> //--> </script> </head> <body> <h1><?php echo basename(__FILE__); ?></h1> <?php echo $bar->toHTML(); $bar->run(); ?> <form> Contents of file 'progress_observer.log' generated by HTML_Progress_Observer class <textarea readOnly="true" rows="12" cols="80" wrap="virtual"> a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:10;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:20;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:30;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:40;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:50;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:60;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:70;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:80;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:90;} a:2:{s:3:"log";s:8:"incValue";s:5:"value";i:100;} </textarea> </form> <p><< <a href="../index.html">Back examples TOC</a></p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/observer/simple.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/observer/simple.html +++ pear/HTML_Progress/examples/observer/simple.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="robots" content="index,nofollow" /> <meta name="keywords" content"="HTML_Progress, observer, progress meter" /> <meta name="description" content"="HTML_Progress logs all changes in its observer pattern" /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: Simple ProgressBar Observer</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="../examples.css" /> </head> <body> <a name="top"> <p><a href="../index.html"><img src="../images/home.gif" alt="Examples TOC"/>examples</a></p> <h1><span class="chapter">Simple ProgressBar Observer </span></h1> <p align="right">$Date: 2004/06/27 13:08:28 $</p> <div class="toc"> Table of contents </div> <ul> <li><a href="#intro">Introduction<a> <li><a href="#render">Render options<a> <li><a href="#output">Output</a> <li><a href="#source">PHP source syntax highlight<a> <li><a href="#run">Play demo<a> </ul> <a name="intro"> <h2><img src="../images/info.gif"/> Introduction</h2> <p>This example requires : <ul> <li>PEAR::HTML_Progress 1.2.0RC3 or better (see source at lines 11, 12).</li> </ul> </p> <hr/> <p><b>This example will run a ProgressBar with a custom class observer mechanism. Output could be send to screen or on flat file 'observer_complex.log'.</b></p> <p>Here are the contents of that file : <form> <textarea readOnly="true" rows="21" cols="50" wrap="virtual"> incValue = 5 incValue = 10 incValue = 15 incValue = 20 incValue = 25 incValue = 30 incValue = 35 incValue = 40 incValue = 45 incValue = 50 incValue = 55 incValue = 60 incValue = 65 incValue = 70 incValue = 75 incValue = 80 incValue = 85 incValue = 90 incValue = 95 incValue = 100 </textarea> </form> <p>[<a href="#top">Top</a>]</p> <a name="render"> <h2><img src="../images/config.gif"/> Render options </h2> <pre> speed = 50 is set at line 46 </pre> <div class="fig">HTML_Progress::setAnimSpeed()</div> <pre> increment = 5 is set at line 47 </pre> <div class="fig">HTML_Progress::setIncrement()</div> <p>[<a href="#top">Top</a>]</p> <a name="output"> <h2><img src="../images/image.gif"/> Output</h2> <h3>Screenshot </h3> <p><img src="../screenshots/observer_simple.png"/></p> <p>[<a href="#top">Top</a>]</p> <a name="source"> <h2><img src="../images/source.gif"/> PHP source syntax highlight</h2> <a target="_blank" href="../highlighter.php?file=observer/simple.php">Open</a> source listing in a new window. <p>[<a href="#top">Top</a>]</p> <a name="run"> <h2><img src="../images/run.gif"/> Play demo</h2> <p><a href="simple.php?out=screen">Run</a> the screen version.</p> <p><a href="simple.php?out=file">Run</a> the file version.</p> <p>[<a href="#top">Top</a>]</p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/observer/simple.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/observer/simple.php +++ pear/HTML_Progress/examples/observer/simple.php <?php @include '../include_path.php'; /** * Observer ProgressBar example. Uses a custom observer class. * * @version $Id: simple.php,v 1.1 2004/06/27 13:08:28 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTML/Progress.php'; require_once 'HTML/Progress/observer.php'; // 1. Defines ProgressBar observer class MyObserver extends HTML_Progress_Observer { var $_console; var $_out; function MyObserver($out) { $this->_console = '.' . DIRECTORY_SEPARATOR . 'observer_complex.log'; $this->HTML_Progress_Observer(); $this->_out = strtolower($out); } function notify($event) { if (is_array($event)) { $log = isset($event['log']) ? $event['log'] : "undefined event id."; $val = isset($event['value']) ? $event['value'] : "unknown value"; $msg = "$log = $val"; } else { $msg = $event; } if ($this->_out == 'file') { error_log("$msg \n", 3, $this->_console); } else { print ("$msg <br />\n"); } } } // 2. Creates ProgressBar $bar = new HTML_Progress(); $bar->setAnimSpeed(50); $bar->setIncrement(5); // 3. Creates and attach a listener $observer = new MyObserver($_GET['out']); $ok = $bar->addListener($observer); if (!$ok) { die ("Cannot add a valid listener to progress bar !"); } // 4. Changes look-and-feel of ProgressBar $ui = $bar->getUI(); $ui->setComment('Simple Observer ProgressBar example'); ?> <html> <head> <title>Simple Observer ProgressBar example</title> <style type="text/css"> <!-- <?php echo $bar->getStyle(); ?> // --> </style> <script type="text/javascript"> <!-- <?php echo $bar->getScript(); ?> //--> </script> </head> <body> <h1><?php echo basename(__FILE__); ?></h1> <?php echo $bar->toHTML(); $bar->run(); ?> <p><< <a href="../index.html">Back examples TOC</a></p> </body> </html>