NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/Chameleon/trunk/Chameleon/Label.php

Revision 13 (checked in by jcleary, 17 years ago)

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * Label Class
4  *
5  * @project     CWC2
6  * @revision    $Id: Label.php,v 1.19 2003/10/27 20:46:18 sfournier Exp $
7  * @purpose     Helper class to manage label attributes
8  * @author      DM Solutions Group (assefa@dmsolutions.ca)
9  * @copyright
10  * <b>Copyright (c) 2002, DM Solutions Group Inc.</b>
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  */
29
30 /**
31  * a utility class for displaying a label next to some contents.  The label
32  * can be styled by adding values to the widget's tag.
33  */
34 class CWCLabel
35 {
36     var $moParent;
37     var $mnPosition = 8;
38     var $mszVAlign = "";
39     var $mszHAlign = "";
40     var $mszLabel = "";
41     var $mszClass = "CWCLabelClass";
42     var $mszStyle = "";
43
44     /**
45      * construct a new label widget
46      */
47     function CWCLabel( &$oParent )
48     {
49         $this->moParent =& $oParent;
50         $oParent->maAttributes["LABEL"] = new StringAttribute( "LABEL", false );
51         $oParent->maAttributes["LABELPOSITION"] = new IntegerAttribute( "LABELPOSITION", false, 0, 8 );
52         $oParent->maAttributes["LABELHALIGN"] = new StringAttribute( "LABELHALIGN",
53                                           false, array( "LEFT", "CENTER", "RIGHT" ) );
54         $oParent->maAttributes["LABELVALIGN"] = new StringAttribute( "LABELVALIGN", false,
55                                           array( "TOP", "MIDDLE", "BOTTOM" ));
56         $oParent->maAttributes["LABELCLASS"] = new StringAttribute( "LABELCLASS", false );
57         $oParent->maAttributes["LABELSTYLE"] = new StringAttribute( "LABELSTYLE", false );
58     }
59
60     /**
61      * initialize default values
62      */
63     function InitDefaults()
64     {
65     }
66
67     /**
68      * draw the label with some contents
69      */
70     function DrawPublish( $szContent = "" )
71     {
72         $szLabel = "";
73         $szClass = $this->mszClass;
74         $szStyle = $this->mszStyle;
75         $nPos = 8; //$this->mnPosition;
76         $hAlign = $this->mszHAlign;
77         $vAlign = $this->mszVAlign;
78
79         if ( isset( $this->moParent->maParams["LABEL"] ) )
80             $szLabel = $this->moParent->maParams["LABEL"];
81
82         // this decodes any HTML characters (&lt;, &gt; for instance) that
83         // are in the label, which allows us to embed HTML in a label.
84         $trans = array_flip( get_html_translation_table(HTML_SPECIALCHARS) );
85         $szLabel = strtr( $szLabel, $trans );
86
87         if (trim($szLabel) == "")
88             return $szContent;
89
90         if ( isset( $this->moParent->maParams["LABELCLASS"] ) )
91             $szClass = $this->moParent->maParams["LABELCLASS"];
92         if ( isset( $this->moParent->maParams["LABELSTYLE"] ) )
93             $szStyle = $this->moParent->maParams["LABELSTYLE"];
94
95         if (strlen($szClass) > 0)
96             $szClass = " CLASS=\"$szClass\"";
97         if (strlen($szStyle) > 0)
98             $szStyle = " STYLE=\"$szStyle\"";
99
100         //put together the result
101         $szLabel = "<SPAN$szClass$szStyle>$szLabel</SPAN>";
102
103         //position content in a table if necessary
104         if ($szContent != "")
105         {
106             $cell1 = $cell2 = $cell3 = $cell4 = "";
107             $valign1 = $valign2 = $valign3 = $valign4 = "";
108             $halign1 = $halign2 = $halign3 = $halign4 = "";
109
110             if ( isset( $this->moParent->maParams["LABELPOSITION"] ) )
111                 $nPos = intval($this->moParent->maParams["LABELPOSITION"]);
112
113             if ( isset( $this->moParent->maParams["LABELHALIGN"] ) )
114                 $hAlign = " HALIGN=\"".$this->moParent->maParams["LABELHALIGN"]."\"";
115
116             if ( isset( $this->moParent->maParams["LABELVALIGN"] ) )
117                 $vAlign = " VALIGN=\"".$this->moParent->maParams["LABELVALIGN"]."\"";
118
119             switch( $nPos )
120             {
121               case 1:
122                 $cell1 = $szLabel;
123                 $valign1 = $vAlign;
124                 $halign1 = $hAlign;
125                 $cell4 = $szContent;
126                 break;
127               case 2:
128                 $cell1 = $szLabel;
129                 $valign1 = $vAlign;
130                 $halign1 = $hAlign;
131                 $cell3 = $szContent;
132                 break;
133               case 3:
134                 $cell2 = $szLabel;
135                 $valign2 = $vAlign;
136                 $halign2 = $hAlign;
137                 $cell3 = $szContent;
138                 break;
139               case 4:
140                 $cell2 = $szLabel;
141                 $valign2 = $vAlign;
142                 $halign2 = $hAlign;
143                 $cell1 = $szContent;
144                 break;
145               case 5:
146                 $cell4 = $szLabel;
147                 $valign4 = $vAlign;
148                 $halign4 = $hAlign;
149                 $cell1 = $szContent;
150                 break;
151               case 6:
152                 $cell3 = $szLabel;
153                 $valign3 = $vAlign;
154                 $halign3 = $hAlign;
155                 $cell1 = $szContent;
156                 break;
157               case 7:
158                 $cell3 = $szLabel;
159                 $valign3 = $vAlign;
160                 $halign3 = $hAlign;
161                 $cell2 = $szContent;
162                 break;
163               case 8:
164                 $cell1 = $szLabel;
165                 $valign1 = $vAlign;
166                 $halign1 = $hAlign;
167                 $cell2 = $szContent;
168                 break;
169             }
170
171             $szResult = '<table border="0" cellspacing="0" cellpadding="1">'."\n";
172             $szResult .= '  <tr>'."\n";
173             if ($cell1 != "")
174             {
175                 $szResult .= '    <td'.$valign1.$halign1.'>'.$cell1.'</td>'."\n";
176             }
177             if ($cell2 != "")
178             {
179                 $szResult .= '    <td'.$valign2.$halign2.'>'.$cell2.'</td>'."\n";
180             }
181             $szResult .= '  </tr>'."\n";
182             if ($cell3 != "" || $cell4 != "")
183             {
184                 $szResult .= '  <tr>'."\n";
185                 $szResult .= '    <td'.$valign3.$halign3.'>'.$cell3.'</td>'."\n";
186                 $szResult .= '    <td'.$valign4.$halign4.'>'.$cell4.'</td>'."\n";
187                 $szResult .= '  </tr>'."\n";
188             }
189             $szResult .= '</table>'."\n";
190         }
191         else
192         {
193             $szResult = $szLabel;
194         }
195
196         return $szResult;
197     }
198 }
199
Note: See TracBrowser for help on using the browser.