Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file TLabel.php

Documentation is available at TLabel.php

  1. <?php
  2. namespace Adianti\Widget\Form;
  3.  
  4. use Adianti\Widget\Form\AdiantiWidgetInterface;
  5. use Adianti\Widget\Base\TElement;
  6. use Adianti\Widget\Base\TStyle;
  7. use Adianti\Widget\Form\TField;
  8.  
  9. /**
  10.  * Label Widget
  11.  *
  12.  * @version    7.4
  13.  * @package    widget
  14.  * @subpackage form
  15.  * @author     Pablo Dall'Oglio
  16.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  17.  * @license    http://www.adianti.com.br/framework-license
  18.  */
  19. class TLabel extends TField implements AdiantiWidgetInterface
  20. {
  21.     private $fontStyle;
  22.     private $embedStyle;
  23.     protected $value;
  24.     protected $size;
  25.     protected $id;
  26.     
  27.     /**
  28.      * Class Constructor
  29.      * @param  $value text label
  30.      */
  31.     public function __construct($value$color null$fontsize null$decoration null$size null)
  32.     {
  33.         $this->id   = 'tlabel_' mt_rand(10000000001999999999);
  34.         $stylename 'tlabel_style_'.$this->id;
  35.         
  36.         // set the label's content
  37.         $this->setValue($value);
  38.         
  39.         $this->embedStyle new TStyle($stylename);
  40.         
  41.         if (!empty($color))
  42.         {
  43.             $this->setFontColor($color);
  44.         }
  45.         
  46.         if (!empty($fontsize))
  47.         {
  48.             $this->setFontSize($fontsize);
  49.         }
  50.         
  51.         if (!empty($decoration))
  52.         {
  53.             $this->setFontStyle($decoration);
  54.         }
  55.         
  56.         if (!empty($size))
  57.         {
  58.             $this->setSize($size);
  59.         }
  60.         
  61.         // create a new element
  62.         $this->tag = new TElement('label');
  63.     }
  64.     
  65.     /**
  66.      * Clone the object
  67.      */
  68.     public function __clone()
  69.     {
  70.         parent::__clone();
  71.         $this->embedStyle clone $this->embedStyle;
  72.     }
  73.     
  74.     /**
  75.      * Define the font size
  76.      * @param $size Font size in pixels
  77.      */
  78.     public function setFontSize($size)
  79.     {
  80.         $this->embedStyle->{'font_size'}    (strpos($size'px'or strpos($size'pt')) $size $size.'pt';
  81.     }
  82.     
  83.     /**
  84.      * Define the style
  85.      * @param  $decoration text decorations (b=bold, i=italic, u=underline)
  86.      */
  87.     public function setFontStyle($decoration)
  88.     {
  89.         if (strpos(strtolower($decoration)'b'!== FALSE)
  90.         {
  91.             $this->embedStyle->{'font-weight''bold';
  92.         }
  93.         
  94.         if (strpos(strtolower($decoration)'i'!== FALSE)
  95.         {
  96.             $this->embedStyle->{'font-style''italic';
  97.         }
  98.         
  99.         if (strpos(strtolower($decoration)'u'!== FALSE)
  100.         {
  101.             $this->embedStyle->{'text-decoration''underline';
  102.         }
  103.     }
  104.     
  105.     /**
  106.      * Define the font face
  107.      * @param $font Font Family Name
  108.      */
  109.     public function setFontFace($font)
  110.     {
  111.         $this->embedStyle->{'font_family'$font;
  112.     }
  113.     
  114.     /**
  115.      * Define the font color
  116.      * @param $color Font Color
  117.      */
  118.     public function setFontColor($color)
  119.     {
  120.         $this->embedStyle->{'color'$color;
  121.     }
  122.     
  123.     /**
  124.      * Add a content inside the label
  125.      * @param $content 
  126.      */
  127.     function add($content)
  128.     {
  129.         $this->tag->add($content);
  130.         
  131.         if (is_string($content))
  132.         {
  133.             $this->value .= $content;
  134.         }
  135.     }
  136.     
  137.     /**
  138.      * Get value
  139.      */
  140.     public function getValue()
  141.     {
  142.         return $this->value;
  143.     }
  144.     
  145.     /**
  146.      * Shows the widget at the screen
  147.      */
  148.     public function show()
  149.     {
  150.         if ($this->size)
  151.         {
  152.             if (strstr((string) $this->size'%'!== FALSE)
  153.             {
  154.                 $this->embedStyle->{'width'$this->size;
  155.             }
  156.             else
  157.             {
  158.                 $this->embedStyle->{'width'$this->size 'px';
  159.             }
  160.         }
  161.         
  162.         // if the embed style has any content
  163.         if ($this->embedStyle->hasContent())
  164.         {
  165.             $this->setProperty('style'$this->embedStyle->getInline($this->getProperty('style')TRUE);
  166.         }
  167.         
  168.         $this->tag->{'id'$this->id;
  169.         
  170.         // add content to the tag
  171.         $this->tag->add($this->value);
  172.         
  173.         // show the tag
  174.         $this->tag->show();
  175.     }
  176. }