Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

toolbar-james.class.php

Go to the documentation of this file.
00001 <?
00002 
00003 // Clase ToolBarJames
00004 
00005 /* Pretende ser una sencilla forma de establecer barras de herramientas
00006   en las páginas WEB.
00007   su forma de uso básica sería:
00008   
00009   $barraher = new ToolBarJames();
00010   
00011   $barraher->AddButton("nombre1", "enlace1", "imagen1");
00012   $barraher->AddButton("nombre2", "enlace2", "imagen2");
00013   
00014   $barraher->PrintAll();        // Muestra la barra con imagenes
00015   $barraher->PrintOnlyText();   // No muestra imágenes, sólo texto
00016 */
00017 
00018 
00019 /* Definición de constantes */
00020 define("BUTTON_WIDTH", 100);
00021 
00022 class ToolBarJames
00023 {
00024         
00025         // Propiedades de la barra de herramientas
00026         var $width;
00027         var $align;
00028 
00029         // Número de botones
00030         var $numButtons;
00031         
00032         // Array con los botones
00033         var $buttons;
00034         
00035         // Clase de la hoja de estilos que usa
00036         var $cssToolbar;
00037         var $cssButton;
00038         
00039         // Fija un marco destino para los enlaces de la toolbar
00040         var $target;
00041         
00042         // Tamaño de los botones
00043         var $buttonWidth;
00044         
00045         
00046         // ToolBarJames([$align [, $width_sin_%])
00047         function ToolBarJames()
00048         {
00049                 $this->numButtons = 0;
00050                 $this->width = 100;
00051                 $this->align = "center";
00052                 $this->cssToolbar = "ToolBarJames";
00053                 $this->cssButton = "TBButton";
00054                 $this->target = "";
00055                 $this->buttonWidth = BUTTON_WIDTH;
00056                 
00057                 switch (func_num_args())
00058                 {
00059                         case 2:
00060                                 $this->width = func_get_arg(1);
00061                         case 1:
00062                                 $this->align = func_get_arg(0);
00063                 }
00064         }
00065         
00066         
00067         function setCssClasses($toolbar, $button)
00068         {
00069                 $this->cssToolbar = $toolbar;
00070                 $this->cssButton = $button;
00071         }
00072         
00073         
00074         function setTarget($target)
00075         {
00076                 $this->target = $target;
00077         }
00078         
00079 
00080         function setButtonWidth($buttonWidth)
00081         {
00082                 $this->buttonWidth = $buttonWidth;
00083         }
00084 
00085 
00086         // AddButton($name, $link [, $image])
00087         function AddButton($name, $link)
00088         {
00089                 if (func_num_args() == 3)
00090                         $image = func_get_arg(2);
00091                 else
00092                         $image = "";
00093                 
00094                 $this->buttons[$this->numButtons] = new TBButton($name, $link, $image);
00095 
00096                 $this->numButtons++;
00097         }
00098         
00099 
00100         // AddButtonSelected($name, $link [, $image])
00101         function AddButtonSelected($name, $link)
00102         {
00103                 if (func_num_args() == 3)
00104                         $image = func_get_arg(2);
00105                 else
00106                         $image = "";
00107                 
00108                 $this->buttons[$this->numButtons] = new TBButton($name, $link, $image);
00109                 
00110                 $this->buttons[$this->numButtons]->setSelected(true);
00111 
00112                 $this->numButtons++;
00113         }
00114 
00115         
00116         // PrintAll([$autoAdjust]) por defecto true
00117         function PrintAll()
00118         {
00119                 /* Comprobamos si ha seleccionado autoajuste (por defecto)
00120                 o no */
00121                 if (func_num_args() == 1)
00122                 {
00123                         $autoAdjust = func_get_arg(0);
00124                         $this->PrintCommon(true, $autoAdjust);
00125                 }
00126                 else
00127                         $this->PrintCommon(true, true);
00128         }
00129         
00130 
00131         // PrintOnlyText([$autoAdjust]) por defecto true
00132         function PrintOnlyText()
00133         {
00134                 /* Comprobamos si ha seleccionado autoajuste (por defecto)
00135                 o no */
00136                 if (func_num_args() == 1)
00137                 {
00138                         $autoAdjust = func_get_arg(0);
00139                         $this->PrintCommon(false, $autoAdjust);
00140                 }
00141                 else
00142                         $this->PrintCommon(false, true);
00143         }
00144         
00145         
00146         // Realiza la tarea común de imprimir
00147         function PrintCommon($all, $autoAdjust)
00148         {
00149                 /* Calculamos el tamaño de las celdas */
00150                 if ($autoAdjust)
00151                         $html_width = floor(100/$this->numButtons)."%";
00152                 else
00153                         $html_width = $this->buttonWidth;;
00154                 
00155                 print "<table width='".$this->width."%' class='".$this->cssToolbar."' align='".$this->align."'>\n";
00156                 print "<tr>\n";
00157                 
00158                 /* Si no era con autoajuste, añadimos celdas para conseguir 
00159                 que no lo sea */
00160                 if ((! $autoAdjust) and (($this->align=="center") || ($this->align=="right")))
00161                         echo "\t<td>&nbsp;</td>\n";
00162                         
00163 
00164                 
00165                 for ($i = 0; $i < $this->numButtons; $i++)
00166                 {
00167                         echo "\t<td class='".$this->cssButton."' width='".$html_width."' align='center'>\n";
00168                         /* Imprimimos con imagen o sin imagen, según corresponda */
00169                         if ($all)
00170                                 $this->buttons[$i]->PrintAll($this->cssButton, $this->target);                  
00171                         else
00172                                 $this->buttons[$i]->PrintOnlyText($this->cssButton, $this->target);
00173                         echo "\t</td>\n";
00174                 }
00175                 
00176                 
00177                 /* Si no era con autoajuste, añadimos celdas para conseguir 
00178                 que no lo sea */
00179                 if ((! $autoAdjust) and (($this->align=="center") || ($this->align=="left")))
00180                         echo "\t<td>&nbsp;</td>\n";
00181                         
00182                         
00183                 print "</tr>\n";
00184                 print "</table>\n";     
00185         }
00186         
00187         
00188 }
00189 
00190 
00191 // Clase para el manejo de los botones de ToolBarJames
00192 
00193 class TBButton
00194 {
00195 
00196         var $name;
00197         var $image;
00198         var $link;
00199         
00200         var $selected;
00201         
00202         function TBButton($namep,  $linkp, $imagep)
00203         {
00204                 $this->name = $namep;
00205                 $this->image = $imagep;
00206                 $this->link = $linkp;
00207                 $this->selected = false;                
00208         }
00209         
00210         function setSelected($sel)
00211         {
00212                 $this->selected = $sel;
00213         }
00214         
00215         
00216         //PrintAll(css [, target])
00217         function PrintAll($cssClass)
00218         {
00219                 /* Obtenemos argumentos */
00220                 if (func_num_args() == 2)
00221                         $target = func_get_arg(1);
00222                         
00223                 /* Comprobamos si está seleccionado */
00224                 if ($this->selected)
00225                         $css = $cssClass."Selected";
00226                 else
00227                         $css = $cssClass;
00228                         
00229                 /* Si no tiene imagen imprimimos con la otra */
00230                 if ($this->image == "")
00231                         $this->PrintOnlyText();
00232                 else
00233                 {
00234                         echo "\t\t<div class='".$css."'>\n";
00235 
00236                         $aTag = "class='".$css."' href='".$this->link."' ";
00237                         if ($target)
00238                                 $aTag .= "target='".$target."' ";
00239                         echo "\t\t<a ".$aTag." >\n";
00240 
00241                         echo "\t\t<img src='".$this->image."' alt='".$this->name."' border=0>\n";
00242                         echo "\t\t<br>&nbsp;&nbsp;".$this->name."&nbsp;&nbsp;</a></div>\n";
00243                 }
00244         }
00245         
00246         
00247         //PrintOnlyText(css [, target])
00248         function PrintOnlyText($cssClass)
00249         {
00250                 /* Obtenemos argumentos */
00251                 if (func_num_args() == 2)
00252                         $target = func_get_arg(1);
00253                         
00254                 /* Comprobamos si está seleccionado */
00255                 if ($this->selected)
00256                         $css = $cssClass."Selected";
00257                 else
00258                         $css = $cssClass;
00259                         
00260                 echo "\t\t<div class='".$css."'>\n";
00261                                 
00262                 $aTag = "class='".$css."' href='".$this->link."' ";
00263                 if ($target)
00264                         $aTag .= "target='".$target."' ";
00265                 echo "\t\t<a ".$aTag." >\n";
00266                 
00267                 echo "\t\t".$this->name."</a></div>\n";
00268         }
00269 
00270 }

Generated on Wed Nov 19 20:29:35 2003 for James by doxygen 1.3.4