|
1 // //////////////////////////////////////////////////////////////////////////// |
|
2 // Symbian Foundation Example Code |
|
3 // |
|
4 // This software is in the public domain. No copyright is claimed, and you |
|
5 // may use it for any purpose without license from the Symbian Foundation. |
|
6 // No warranty for any purpose is expressed or implied by the authors or |
|
7 // the Symbian Foundation. |
|
8 // //////////////////////////////////////////////////////////////////////////// |
|
9 |
|
10 /////////////////////////////////////////////////////////////////////////////// |
|
11 // The ImageLabel class implements a control that displays an image |
|
12 |
|
13 // Constructor. |
|
14 function ImageLabel(id, caption, image) { |
|
15 if (id != UI_NO_INIT_ID) { |
|
16 this.init(id, caption, image); |
|
17 } |
|
18 } |
|
19 |
|
20 // Label inherits from Control. |
|
21 ImageLabel.prototype = new Control(UI_NO_INIT_ID); |
|
22 |
|
23 // Content element for the ImageLabel |
|
24 ImageLabel.prototype.contentElement = null; |
|
25 |
|
26 // DOM element for image |
|
27 ImageLabel.prototype.image = null; |
|
28 |
|
29 // DOM element for text |
|
30 ImageLabel.prototype.text = null; |
|
31 |
|
32 // Initializer - called from constructor. |
|
33 ImageLabel.prototype.init = function(id, caption, image) { |
|
34 uiLogger.debug("ImageLabel.init(" + id + ", " + caption + ", " + image + ")"); |
|
35 |
|
36 // call superclass initializer |
|
37 Control.prototype.init.call(this, id, null); |
|
38 |
|
39 // create content element |
|
40 this.contentElement = document.createElement("div"); |
|
41 this.controlElement.appendChild(this.contentElement); |
|
42 |
|
43 this.image = image; |
|
44 this.label = caption; |
|
45 this.updateContentElement(); |
|
46 } |
|
47 |
|
48 // Returns the enabled state for the control. |
|
49 ImageLabel.prototype.isEnabled = function() { |
|
50 return true; |
|
51 } |
|
52 |
|
53 // Returns the focusable state for the control. |
|
54 ImageLabel.prototype.isFocusable = function() { |
|
55 return false; |
|
56 } |
|
57 |
|
58 // Returns the button image (URL); null if none. |
|
59 ImageLabel.prototype.getImage = function() { |
|
60 return image; |
|
61 } |
|
62 |
|
63 // Sets the button image (URL); null if none. |
|
64 ImageLabel.prototype.setImage = function(image) { |
|
65 this.image = image; |
|
66 } |
|
67 |
|
68 // Sets the text |
|
69 ImageLabel.prototype.setLabel = function(text) { |
|
70 this.label = label; |
|
71 } |
|
72 |
|
73 ImageLabel.prototype.updateContentElement = function(){ |
|
74 var buf = ""; |
|
75 if ( this.image != null ) { |
|
76 buf += "<img src=" + this.image+" ALIGN=MIDDLE>"; |
|
77 } |
|
78 if (this.label != null ) { |
|
79 buf += this.label; |
|
80 } |
|
81 this.contentElement.innerHTML = buf; |
|
82 } |
|
83 |
|
84 // Updates the style of the control to reflects the state of the control. |
|
85 ImageLabel.prototype.updateStyleFromState = function() { |
|
86 uiLogger.debug("Label.updateStyleFromState()"); |
|
87 |
|
88 // set element class names |
|
89 this.setClassName(this.rootElement, "Control"); |
|
90 this.setClassName(this.assemblyElement, "ControlAssembly ControlAssemblyNormal"); |
|
91 this.setClassName(this.captionElement, "ControlCaption ControlCaptionNormal"); |
|
92 this.setClassName(this.controlElement, "ControlElement"); |
|
93 this.setClassName(this.contentElement, "ContentPanelCaptionText"); |
|
94 } |