TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file ChartPen.php

Documentation is available at ChartPen.php

  1. <?php
  2.  
  3. /**
  4.  * ChartPen class
  5.  *
  6.  * Description: Common Chart Pen. Pen used to draw lines and borders
  7.  *
  8.  * @author
  9.  * @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  10.  * @version 1.0
  11.  * @package TeeChartPHP
  12.  * @subpackage drawing
  13.  * @link http://www.steema.com
  14.  */
  15.  
  16. class ChartPen extends TeeBase {
  17.  
  18.     public $color;
  19.     public $dashStyle;
  20.     public $width;
  21.     public $endCap;
  22. //    public $dashCap = DashCap.FLAT;
  23.     public $visible = true;
  24.  
  25.     protected $defaultColor;
  26.     protected $defaultEndCap;
  27.     protected $defaultStyle;
  28.  
  29.     private $transparency;
  30.     protected $defaultVisible=false;
  31.     protected $usesVisible=false;
  32.     private $stroke;
  33.     private $colorChanged;
  34.     private $dashWidth=1;
  35.  
  36.  
  37.     // Interceptors
  38.     function __get$property {
  39.       $method ="get{$property}";
  40.       if method_exists$this$method ) ) {
  41.         return $this->$method();
  42.       }
  43.     }
  44.  
  45.     function __set $property,$value {
  46.       $method ="set{$property}";
  47.       if method_exists$this$method ) ) {
  48.         return $this->$method($value);
  49.       }
  50.     }
  51.  
  52.     public function ChartPen($c$startColor=null$startVisible=true,
  53.                     $startWidth=1$startEndCap=-1$startStyle=null{
  54.  
  55.         if ($startColor == null)
  56.             $startColor=new Color(0,0,0,0,true);  
  57.  
  58.         if ($startEndCap==null{
  59.          //  TODO  $tmpLineCap=new LineCap();
  60.          //   $startEndCap = $tmpLineCap->BEVEL;
  61.         }
  62.  
  63.         if ($startStyle==null{
  64.             $startStyle=DashStyle::$SOLID;
  65.         }
  66.  
  67.         parent::__construct($c);
  68.                
  69.         $this->usesVisible=true;
  70.         $this->defaultColor = $startColor;
  71.         $this->color = $this->defaultColor;
  72.         $this->defaultVisible = $startVisible;
  73.         $this->visible = $this->defaultVisible;
  74.  
  75.         $this->width = $startWidth;
  76.  
  77.         $this->endCap = $startEndCap;
  78.         $this->defaultEndCap = $startEndCap;
  79.  
  80.         $this->dashStyle = $startStyle;
  81.         $this->defaultStyle = $startStyle;
  82.  
  83.         $this->recreateStroke();
  84.     }
  85.  
  86.     public function reset({
  87.         $this->setColor(new Color(0,0,0));
  88.         $this->setWidth(1);
  89.  
  90.         $this->setStyle(DashStyle::$SOLID);
  91.  
  92.         /* TODO
  93.         setEndCap(LineCap.ROUND);
  94.         setDashCap(DashCap.FLAT);
  95.         */
  96.         $this->setTransparency(0);
  97.     }
  98.  
  99.     public function internalAssign($p{
  100.         $this->dashStyle = $p->dashStyle;
  101.         $this->width = $p->width;
  102.         $this->color = $p->color;
  103.         $this->endCap = $p->endCap;
  104. // TODO        $this->dashCap = $p->dashCap;
  105.         $this->visible = $p->visible;
  106.         $this->transparency $p->transparency;
  107.         $this->stroke $p->stroke;
  108.     }
  109.  
  110.     public function assign($p{
  111.         $this->internalAssign($p);
  112.         $this->changed();
  113.     }
  114.  
  115.     //CDI AssignVisiblePenColor
  116.     public function _assign($p$value{
  117.         $this->internalAssign($p);
  118.         $this->color = $value;
  119.         $this->changed();
  120.     }
  121.  
  122.     public function setUsesVisible($value{
  123.         $this->usesVisible = $value;
  124.     }
  125.  
  126.     protected function shouldSerializeColor({
  127.         return $this->color != $this->defaultColor;
  128.     }
  129.  
  130.     public function setDefaultColor($value{
  131.         $this->defaultColor = $value;
  132.         $this->color = $value;
  133.     }
  134.  
  135.     public function _setColor($value{
  136.         $this->setColor(new Color($value));
  137.     }
  138.  
  139.     public function setColor($value{
  140.         if ($this->color != $value{
  141.             $this->color = $value;
  142.  
  143.             if ($this->colorChanged != null{
  144.                 $this->colorChanged->invoke($thisnullnull);
  145.             }
  146.  
  147.             $this->invalidate();
  148.         }
  149.     }
  150.  
  151.     public function setDefaultStyle($value{
  152.         $this->defaultStyle = $value;
  153.         $this->setStyle($value);
  154.     }
  155.  
  156.     public function setDefaultVisible($value{
  157.         $this->defaultVisible = $value;
  158.         $this->visible = $value;
  159.     }
  160.  
  161.     protected function shouldSerializeVisible({
  162.         return $this->visible != $this->defaultVisible;
  163.     }
  164.  
  165.     /**
  166.      * Determines if the pen will draw lines or not.
  167.      *
  168.      * @return boolean 
  169.      */
  170.     public final function getVisible({
  171.         return $this->visible;
  172.     }
  173.  
  174.     /**
  175.      * Determines if the pen will draw lines or not.
  176.      *
  177.      * @param value boolean
  178.      */
  179.     public function setVisible($value{
  180.         $this->visible = $this->setBooleanProperty($this->visible$value);
  181.     }
  182.  
  183.     /**
  184.      * Sets Transparency level from 0 to 100%. <br>
  185.      * Default value: 0
  186.      *
  187.      * @return int 
  188.      */
  189.     public function getTransparency({
  190.         return (127*$this->transparency/100);        
  191.     }
  192.  
  193.     /**
  194.      * Sets Transparency level from 0 to 100%. <br>
  195.      * Default value: 0
  196.      *
  197.      * @param value int
  198.      */
  199.     public function setTransparency($value{
  200.         $this->transparency $this->setIntegerProperty($this->transparency$value);
  201.     }
  202.  
  203.     /**
  204.      * Determines the color used by the pen to draw lines on the Drawing.
  205.      * It can be any valid color constant like Color.Red, Color.Green, etc. <br>
  206.      * A special color constant unique to TeeChart is: Color.EMPTY.
  207.      * This is the "default color". <br><br>
  208.      * Each TeeChart drawing object has a different default color. For example,
  209.      * the tChart.getFrame() property has a default color of Color.BLACK.
  210.      *
  211.      *
  212.      * @return Color 
  213.      */
  214.     public function getColor({
  215.         if ($this->transparency == 0{
  216.             return $this->color;
  217.         else {
  218.             return $this->color->transparentColor($this->transparency);
  219.         }
  220.     }
  221.  
  222.     protected function shouldSerializeEndCap({
  223.         return $this->endCap != $this->defaultEndCap;
  224.     }
  225.  
  226.     /**
  227.      * Style of line endings.
  228.      *
  229.      * @return LineCap 
  230.      */
  231.     public function getEndCap({
  232.         return $this->endCap;
  233.     }
  234.  
  235.     /**
  236.      * Style of line endings.
  237.      *
  238.      * @param value LineCap
  239.      */
  240.     public function setEndCap($value{
  241.         if ($this->endCap != $value{
  242.             $this->endCap = $value;
  243.             $this->recreateStroke();
  244.             $this->invalidate();
  245.         }
  246.     }
  247.  
  248.     public function getStroke({
  249.         if ($this->stroke == null{
  250.             $this->recreateStroke();
  251.         }
  252.         return $this->stroke;
  253.     }
  254.  
  255.     // "stroke" is cached due to speed reasons.
  256.     // creating a BasicStroke is a slow operation.
  257.     private function recreateStroke({
  258. /*        if ($this->dashStyle ==  DashStyle::$SOLID) {
  259.             // todo remove ... imagesetthickness ( resource image, int thickness)
  260.             $this->stroke = new BasicStroke($this->width, $this->dashCap.getValue(), $this->endCap.getValue());
  261.         } else {
  262.             $this->stroke = new $this->BasicStroke($this->width, $this->dashCap.getValue(), $this->endCap.getValue(),
  263.                                      1,
  264.                                      $this->dashStyle.getDash(), 0);
  265.         }
  266. */
  267.     }
  268.  
  269.     private function changed({
  270.         /** @todo FINISH / NECESSARY? */
  271.         /*
  272.          if (this == chart.getGraphics3D().getPen()) {
  273.              chart.getGraphics3D().Changed(this);
  274.                 }
  275.          */
  276.     }
  277.  
  278.     public function invalidate({
  279.         parent::invalidate();
  280.         $this->changed();
  281.     }
  282.  
  283.     /**
  284.      * Defines segment ending style of dashed lines.<br>
  285.      * Default value: DashCap.Flat
  286.      *
  287.      * @return DashCap 
  288.      */
  289.     public function getDashCap({
  290.         return $this->dashCap;
  291.     }
  292.  
  293.     public function setDashCap($value{
  294.         if ($this->dashCap != $value{
  295.             $this->dashCap $value;
  296.             $this->recreateStroke();
  297.             $this->invalidate();
  298.         }
  299.     }
  300.  
  301.     /**
  302.      * Determines the width of lines the pen draws.<br>
  303.      * Default value: 1
  304.      *
  305.      * @return int 
  306.      */
  307.     public function getWidth({
  308.         return $this->width;
  309.     }
  310.  
  311.     /**
  312.      * Determines the width of lines the pen draws.<br>
  313.      * Default value: 1
  314.      *
  315.      * @param value int
  316.      */
  317.     public function setWidth($value{
  318.         if ($this->width != $value{
  319.             $this->width = $this->setIntegerProperty($this->width$value);
  320.             $this->recreateStroke();
  321.         }
  322.     }
  323.  
  324.     protected function shouldSerializeStyle({
  325.         return $this->dashStyle != $this->defaultStyle;
  326.     }
  327.  
  328.     /**
  329.      * Determines the style in which the pen draw lines on the Drawing.
  330.      *
  331.      * @return DashStyle 
  332.      */
  333.     public function getStyle({
  334.         return $this->dashStyle;
  335.     }
  336.  
  337.     /**
  338.      * Determines the style in which the pen draw lines on the Drawing.
  339.      *
  340.      * @param value DashStyle
  341.      */
  342.     public function setStyle($value{
  343.         if ($this->dashStyle != $value{
  344.             $this->dashStyle = $value;
  345.             $this->setDashWidth($this->getWidth());
  346.             // TODO maybe remove ? pep $this->recreateStroke();
  347.             $this->invalidate();
  348.         }
  349.     }
  350.  
  351.     public function getDashWidth({
  352.         return $this->dashWidth;
  353.     }
  354.  
  355.     public function setDashWidth($value{
  356.         $this->dashWidth $value;
  357.     }
  358. }
  359. ?>

Documentation generated on Wed, 16 Jun 2010 12:04:22 +0200 by phpDocumentor 1.4.1