1 /** |
|
2 * Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /////////////////////////////////////////////////////////////////////////////// |
|
19 // The Label class implements a control that displays textual content. |
|
20 |
|
21 // Constructor. |
|
22 function Label(id, caption, text) { |
|
23 if (id != UI_NO_INIT_ID) { |
|
24 this.init(id, caption, text); |
|
25 } |
|
26 } |
|
27 |
|
28 // Label inherits from Control. |
|
29 Label.prototype = new Control(UI_NO_INIT_ID); |
|
30 |
|
31 // Content element for label text. |
|
32 Label.prototype.contentElement = null; |
|
33 |
|
34 // Initializer - called from constructor. |
|
35 Label.prototype.init = function(id, caption, text) { |
|
36 uiLogger.debug("Label.init(" + id + ", " + caption + ", " + text + ")"); |
|
37 |
|
38 // call superclass initializer |
|
39 Control.prototype.init.call(this, id, caption); |
|
40 |
|
41 // create content element |
|
42 this.contentElement = document.createElement("div"); |
|
43 this.controlElement.appendChild(this.contentElement); |
|
44 |
|
45 // set the text |
|
46 this.setText(text); |
|
47 }; |
|
48 |
|
49 // Returns the enabled state for the control. |
|
50 Label.prototype.isEnabled = function() { |
|
51 return true; |
|
52 }; |
|
53 |
|
54 // Returns the focusable state for the control. |
|
55 Label.prototype.isFocusable = function() { |
|
56 return false; |
|
57 }; |
|
58 |
|
59 // Returns the control text. |
|
60 Label.prototype.getText = function() { |
|
61 return this.contentElement.innerHTML; |
|
62 }; |
|
63 |
|
64 // Sets the text for the control. |
|
65 Label.prototype.setText = function(text) { |
|
66 uiLogger.debug("Label.setText(" + text + ")"); |
|
67 this.contentElement.innerHTML = (text == null) ? "" : text; |
|
68 this.updateStyleFromState(); |
|
69 }; |
|
70 |
|
71 // Updates the style of the control to reflects the state of the control. |
|
72 Label.prototype.updateStyleFromState = function() { |
|
73 uiLogger.debug("Label.updateStyleFromState()"); |
|
74 |
|
75 // set element class names |
|
76 this.setClassName(this.rootElement, "Control"); |
|
77 this.setClassName(this.assemblyElement, "ControlAssembly ControlAssemblyNormal"); |
|
78 this.setClassName(this.captionElement, "ControlCaption ControlCaptionNormal"); |
|
79 this.setClassName(this.controlElement, "ControlElement"); |
|
80 this.setClassName(this.contentElement, "LabelText"); |
|
81 }; |
|