|
1 /////////////////////////////////////////////////////////////////////////////// |
|
2 // The ImageLabel class implements a control that displays an image |
|
3 |
|
4 // Constructor. |
|
5 function ImageLabel(id, caption, image) { |
|
6 if (id != UI_NO_INIT_ID) { |
|
7 this.init(id, caption, image); |
|
8 } |
|
9 } |
|
10 |
|
11 // Label inherits from Control. |
|
12 ImageLabel.prototype = new Control(UI_NO_INIT_ID); |
|
13 |
|
14 // Content element for label text. |
|
15 ImageLabel.prototype.contentElement = null; |
|
16 |
|
17 // Content element for label text. |
|
18 ImageLabel.prototype.image = null; |
|
19 |
|
20 // Initializer - called from constructor. |
|
21 ImageLabel.prototype.init = function(id, caption, image) { |
|
22 uiLogger.debug("ImageLabel.init(" + id + ", " + caption + ", " + image + ")"); |
|
23 |
|
24 // call superclass initializer |
|
25 Control.prototype.init.call(this, id, caption); |
|
26 |
|
27 this.image = image; |
|
28 |
|
29 // create content element |
|
30 this.contentElement = document.createElement("div"); |
|
31 this.controlElement.appendChild(this.contentElement); |
|
32 |
|
33 // set the image |
|
34 this.setImage(image); |
|
35 } |
|
36 |
|
37 // Returns the enabled state for the control. |
|
38 ImageLabel.prototype.isEnabled = function() { |
|
39 return true; |
|
40 } |
|
41 |
|
42 // Returns the focusable state for the control. |
|
43 ImageLabel.prototype.isFocusable = function() { |
|
44 return false; |
|
45 } |
|
46 |
|
47 // Returns the control text. |
|
48 ImageLabel.prototype.getImage = function() { |
|
49 return this.contentElement.innerHTML; |
|
50 } |
|
51 |
|
52 // Sets the text for the control. |
|
53 ImageLabel.prototype.setText = function(text) { |
|
54 uiLogger.debug("Label.setText(" + text + ")"); |
|
55 this.contentElement.innerHTML = (text == null) ? "" : text; |
|
56 this.updateStyleFromState(); |
|
57 } |
|
58 |
|
59 // Updates the style of the control to reflects the state of the control. |
|
60 ImageLabel.prototype.updateStyleFromState = function() { |
|
61 uiLogger.debug("Label.updateStyleFromState()"); |
|
62 |
|
63 // set element class names |
|
64 this.setClassName(this.rootElement, "Control"); |
|
65 this.setClassName(this.assemblyElement, "ControlAssembly ControlAssemblyNormal"); |
|
66 this.setClassName(this.captionElement, "ControlCaption ControlCaptionNormal"); |
|
67 this.setClassName(this.controlElement, "ControlElement"); |
|
68 this.setClassName(this.contentElement, "LabelText"); |
|
69 } |