home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / monitor.pkg < prev    next >
Encoding:
Text File  |  2004-03-24  |  8.6 KB  |  273 lines

  1. <refentry id="{@id}">
  2.  <refnamediv>
  3.   <refname>Using Progress Monitors</refname>
  4.   <refpurpose>an easy way to display progress in a dialog</refpurpose>
  5.  </refnamediv>
  6.  <refsynopsisdiv>
  7.   <refsynopsisdivinfo>
  8.    <author>
  9.     by Laurent Laville
  10.     <authorblurb>{@link mailto:pear@laurent-laville.org}</authorblurb>
  11.    </author>
  12.    <copyright>November 2003, Laurent Laville</copyright>
  13.    <releaseinfo>HTML_Progress 1.0+</releaseinfo>
  14.   </refsynopsisdivinfo>
  15.  </refsynopsisdiv>
  16.  {@toc}
  17.  <refsect1 id="{@id intro}">
  18.   <title>Introduction</title>
  19.   <para>
  20.    A progress monitor is an easy way to display progress in a dialog. Note that the progress
  21.    monitor doesn't itself cancel the task. It provides the GUI and API to allow the user/program
  22.    to do so easily.
  23.   </para>
  24.  </refsect1>
  25.  <refsect1 id="{@id easymon}">
  26.   <title>Easy Monitoring</title>
  27.   <para>
  28.    To produce such result in this example :
  29.    <para><graphic fileref="../media/screenshots/monitor_simple.png"></graphic></para>
  30.    we will use the {@link http://pear.php.net/package/HTML_Page HTML_Page} package solution
  31.    as a base class for XHTML page generation. 
  32.   </para>
  33.   <para>
  34.    First, we need the {@link HTML_Progress_Monitor} class ressource 
  35.    ({@tutorial monitor.pkg#easymon.ex1-listing line 2}) to allow creation of a new instance 
  36.    <emphasis>$progressMonitor</emphasis> ({@tutorial monitor.pkg#easymon.ex1-listing line 16}).
  37.    Others steps are only necessary to prepare display of progress dialog :
  38.   </para>
  39.   <para>
  40.    <unorderedlist>
  41.     <listitem>HTML_Page::<emphasis>addStyleDeclaration()</emphasis> method 
  42.      ({@tutorial monitor.pkg#easymon.ex1-listing line 18})
  43.       to add an inline stylesheet, required to display the progress bar.
  44.     </listitem>
  45.     <listitem>HTML_Page::<emphasis>addScriptDeclaration()</emphasis> method 
  46.      ({@tutorial monitor.pkg#easymon.ex1-listing line 21})
  47.      to add inline javascript, required to manage the progress bar.
  48.     </listitem>
  49.     <listitem>HTML_Page::<emphasis>addBodyContent()</emphasis> method 
  50.      ({@tutorial monitor.pkg#easymon.ex1-listing line 24})
  51.      to include html progress structure.
  52.     </listitem>
  53.    </unorderedlist>
  54.   </para>
  55.   <para>
  56.    At {@tutorial monitor.pkg#easymon.ex1-listing line 28}, the final result is sent to browser
  57.    for displaying, while in same time ({@tutorial monitor.pkg#easymon.ex1-listing line 30}) we
  58.    launch execution of progress monitoring.
  59.   </para>
  60.   <para>
  61.     {@link HTML_Progress_Monitor::run()} method checks with help of 
  62.     {@link HTML_Progress_Monitor::isCanceled()} if the user canceled the task or if the task
  63.     exited normally (reach 100%).
  64.   </para>
  65.   <refsect2 id="{@id ex1-listing}">
  66.    <title>Full example1 listing</title>
  67.    <programlisting role="php">
  68.    <![CDATA[
  69. <?php
  70. require_once ('HTML/Progress/monitor.php');
  71. require_once ('HTML/Page.php');
  72.  
  73. $p = new HTML_Page(array(
  74.         'charset'  => 'utf-8',
  75.         'lineend'  => OS_WINDOWS ? 'win' : 'unix',
  76.         'doctype'  => "XHTML 1.0 Strict",
  77.         'language' => 'en',
  78.         'cache'    => 'false'
  79.      ));        
  80.  
  81. $p->setTitle("PEAR::HTML_Progress - Simple Monitor demo");
  82. $p->setMetaData("author", "Laurent Laville");
  83.  
  84. $progressMonitor = new HTML_Progress_Monitor();
  85.  
  86. $p->addStyleDeclaration(
  87.     $progressMonitor->getStyle()
  88.     );
  89. $p->addScriptDeclaration(
  90.     $progressMonitor->getScript()
  91.     );
  92. $p->addBodyContent(
  93.     $progressMonitor->toHtml()
  94.     );
  95.  
  96. $p->display();
  97.  
  98. $progressMonitor->run();
  99.  
  100. ?>
  101.    ]]>
  102.    </programlisting>
  103.   </refsect2>
  104.  </refsect1>
  105.  <refsect1 id="{@id customon}">
  106.   <title>Customize Monitoring</title>
  107.   <para>
  108.    In previous example, we have seen the most easy way to create a progress monitor, with
  109.    default look-and-feel. 
  110.   </para>
  111.   <para>
  112.    Now we want, in the following example, choose our own graphical chart. 
  113.    <para><graphic fileref="../media/screenshots/monitor_complex.png"></graphic></para>
  114.    To do so, we will need a template engine. We've choosen the 
  115.    {@link http://pear.php.net/package/HTML_Template_IT HTML_Template_IT} package,
  116.    which is included in PEAR bundle base distribution, but of course you can used your own 
  117.    template engine.
  118.   </para>
  119.   <para>
  120.    Here again, we need the {@link HTML_Progress_Monitor} class ressource 
  121.    ({@tutorial monitor.pkg#easymon.ex2-listing line 2}) to allow creation of a new instance 
  122.    <emphasis>$progressMonitor</emphasis> ({@tutorial monitor.pkg#easymon.ex2-listing line 59}).
  123.    The two next steps display and run the monitor.    
  124.   </para>
  125.   <para>
  126.    <unorderedlist>
  127.     <listitem><emphasis>display()</emphasis> method 
  128.      ({@tutorial monitor.pkg#easymon.ex2-listing lines 53,60})
  129.       send the final template engine parsing result to browser.
  130.     </listitem>
  131.     <listitem><emphasis>run()</emphasis> method 
  132.      ({@tutorial monitor.pkg#easymon.ex2-listing line 61}) 
  133.      launch execution of progress monitoring.
  134.     </listitem>
  135.    </unorderedlist>
  136.   </para>
  137.   <para>Look and feel is defined ({@tutorial monitor.pkg#easymon.ex2-listing lines 28,29,30})
  138.    in <emphasis>attachProgress()</emphasis> method, where we create instance of progress bar
  139.    ({@tutorial monitor.pkg#easymon.ex2-listing line 24}).
  140.   </para>
  141.   <para>
  142.    Mandatory default ressources (JavaScript, CSS) were integrated in HTML template at 
  143.    {@tutorial monitor.pkg#easymon.ex2-listing lines 45,46}.
  144.   </para>
  145.   <para>
  146.    Now it's up to you to extends default {@link HTML_Progress_Monitor} class to your own 
  147.    template engine and graphical chart. Easy isn't it !?
  148.   </para>
  149.   <refsect2 id="{@id ex2-listing}">
  150.    <title>Full example2 listing</title>
  151.    <programlisting role="php">
  152.    <![CDATA[
  153. <?php
  154. require_once ('HTML/Progress/monitor.php');
  155. require_once ('HTML/QuickForm/Renderer/ITStatic.php');
  156. require_once ('HTML/Template/ITX.php');
  157.  
  158. class ProgressMonitor extends HTML_Progress_Monitor
  159. {
  160.     
  161.     function ProgressMonitor()
  162.     {
  163.         $this->_id = md5(microtime());
  164.  
  165.         $this->_form = new HTML_QuickForm('form');
  166.         
  167.         $this->_form->addElement('header', 'windowsname', 'Progress...');
  168.         $this->_form->addElement('static', 'progress');
  169.         $this->_form->addElement('submit', 'cancel', 'Cancel');
  170.         
  171.         $this->attachProgress();
  172.     }
  173.  
  174.     function attachProgress()
  175.     {
  176.         $this->_progress = new HTML_Progress();
  177.         $this->_progress->setIncrement(10);
  178.  
  179.         $ui =& $this->_progress->getUI();
  180.         $ui->setProgressAttributes('background-color=#EEE');
  181.         $ui->setCellAttributes('inactive-color=#FFF active-color=#444444');
  182.         $ui->setStringAttributes('background-color=#EEE color=navy');
  183.  
  184.         $this->_progress->addListener($this);
  185.         
  186.         $bar =& $this->_form->getElement('progress');
  187.         $bar->setText( $this->_progress->toHtml() );
  188.     }
  189.  
  190.     function toHtml()
  191.     {
  192.         $tpl =& new HTML_Template_ITX('.');
  193.         $tpl->loadTemplateFile('monitor.html');
  194.  
  195.         $js  = $this->getScript();
  196.         $css = $this->getStyle();
  197.         $tpl->setVariable("monitor_script", $js);
  198.         $tpl->setVariable("monitor_style", $css);
  199.  
  200.         $renderer =& new HTML_QuickForm_Renderer_ITStatic($tpl);       
  201.         $this->_form->accept($renderer);
  202.         return $tpl->get();
  203.     }
  204.  
  205.     function display()
  206.     {
  207.         print $this->toHtml();
  208.     }
  209. }
  210.  
  211. $progressMonitor = new ProgressMonitor();
  212. $progressMonitor->display();
  213. $progressMonitor->run();
  214.  
  215. ?>
  216.    ]]>
  217.    </programlisting>
  218.    <para><title>HTML template - monitor.html file</title>
  219.    <example>
  220.    <![CDATA[
  221. <!DOCTYPE html
  222.     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  223.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  224.  
  225. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  226. <head>
  227. <title>PEAR::HTML_Progress - Complex Monitor demo</title>
  228. <style type="text/css">
  229.    th {
  230.    font-family: sans-serif;
  231.    font-size : small;
  232.    color : #FFF;
  233.    background-color : #AAA;
  234.    }
  235.    .maintable {
  236.    border : thin dashed #D0D0D0;
  237.    background-color : #EEE;
  238.    }
  239. {monitor_style}
  240. </style>
  241. <script type="text/javascript">
  242. {monitor_script}
  243. </script>
  244. </head>
  245. <body>
  246.  
  247. <form {form_attributes}>
  248.  
  249. <table class="maintable" width="600" align="center">
  250. <tr><td valign="top">
  251.   <table width="100%" cellpadding="4">
  252.   <tr><th>{form_header_windowsname}</th></tr>
  253.   <tr><td>{form_progress_html}</td></tr>
  254.   </table>
  255. </td>
  256. </tr>
  257. </table>
  258. <table width="600" align="center">
  259. <tr>
  260.   <td align="right">{form_cancel_html}</td>
  261. </tr>
  262. </table>
  263. </form>
  264.  
  265. </body>
  266. </html>
  267.    ]]>
  268.    </example>
  269.    </para>
  270.   </refsect2>
  271.  </refsect1>
  272. </refentry>
  273.