Some serious updates to the new Printer system. It's now almost usable.
[isso.git] / PrinterElement.php
1 <?php
2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Printer Element Abstract Class (PrinterElement.php)
24 *
25 * @package ISSO
26 */
27
28 /**
29 * Printer Element
30 *
31 * This abstract class is used for all printer elements and describes
32 * the basic functionality of an element.
33 *
34 * @author Blue Static
35 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
36 * @version $Revision$
37 * @package ISSO
38 *
39 */
40 abstract class BSPrinterElement
41 {
42 /**
43 * Style information
44 * @var array
45 */
46 protected $style = array();
47
48 /**
49 * The CSS class to use
50 * @var string
51 */
52 protected $cssClass = ':swap:';
53
54 /**
55 * Tells the element to paint itself (and any children)
56 */
57 public abstract function paint();
58
59 // ###################################################################
60 /**
61 * Sets the CSS class to use. Use ":swap:" to alternate
62 *
63 * @param string CSS class
64 */
65 public function setCssClass($class)
66 {
67 $this->cssClass = $class;
68 }
69
70 // ###################################################################
71 /**
72 * Sets the style information
73 */
74 public function setStyle(Array $attributes)
75 {
76 $this->style = $attributes;
77 }
78
79 // ###################################################################
80 /**
81 * Returns a string of CSS style attributes
82 *
83 * @return string CSS attributes
84 */
85 protected function _prepareStyle()
86 {
87 if (empty($this->style) AND empty($this->cssClass))
88 {
89 return;
90 }
91
92 if ($this->cssClass == ':swap:')
93 {
94 BSFunctions::SwapCssClasses();
95 $class = BSFunctions::$cssClass;
96 }
97 else
98 {
99 $class = $this->cssClass;
100 }
101
102 $attrs = array();
103
104 foreach ($this->style AS $prop => $value)
105 {
106 $attrs[] = $prop . ': ' . $value;
107 }
108
109 $style = implode('; ', $attrs);
110
111 $string = '';
112 if ($class)
113 {
114 $string .= ' class="' . $class . '"';
115 }
116 if ($style)
117 {
118 $string .= ' style="' . $style . '"';
119 }
120
121 return $string;
122 }
123 }
124
125 /*=====================================================================*
126 || ###################################################################
127 || # $HeadURL$
128 || # $Id$
129 || ###################################################################
130 \*=====================================================================*/
131 ?>