org.symbian.tools.wrttools/projecttemplates/WRTKit/UI/Label.js
author Eugene Ostroukhov <eugeneo@symbian.org>
Tue, 16 Mar 2010 18:01:11 -0700
changeset 273 b1f63c2c240c
parent 211 7b148352159e
permissions -rw-r--r--
Bug 2072 - Update .js files with EPL
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     1
/**
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     2
 * Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies).
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     3
 * All rights reserved.
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     4
 * This component and the accompanying materials are made available
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     6
 * which accompanies this distribution, and is available
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     8
 *
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     9
 * Initial Contributors:
273
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    10
 * Nokia Corporation - initial contribution.
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    11
 * 
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
    12
 * Contributors:
273
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    13
 * 
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    14
 * Description:
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    15
 * 
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
    16
 */
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    17
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    18
///////////////////////////////////////////////////////////////////////////////
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    19
// The Label class implements a control that displays textual content.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    20
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    21
// Constructor.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    22
function Label(id, caption, text) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    23
    if (id != UI_NO_INIT_ID) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    24
        this.init(id, caption, text);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    25
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    26
}
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    27
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    28
// Label inherits from Control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    29
Label.prototype = new Control(UI_NO_INIT_ID);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    30
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    31
// Content element for label text.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    32
Label.prototype.contentElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    33
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    34
// Initializer - called from constructor.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    35
Label.prototype.init = function(id, caption, text) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    36
    uiLogger.debug("Label.init(" + id + ", " + caption + ", " + text + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    37
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    38
    // call superclass initializer
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    39
    Control.prototype.init.call(this, id, caption);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    40
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    41
    // create content element
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    42
    this.contentElement = document.createElement("div");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    43
    this.controlElement.appendChild(this.contentElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    44
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    45
    // set the text
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    46
    this.setText(text);
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    47
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    48
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    49
// Returns the enabled state for the control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    50
Label.prototype.isEnabled = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    51
    return true;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    52
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    53
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    54
// Returns the focusable state for the control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    55
Label.prototype.isFocusable = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    56
    return false;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    57
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    58
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    59
// Returns the control text.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    60
Label.prototype.getText = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    61
    return this.contentElement.innerHTML;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    62
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    63
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    64
// Sets the text for the control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    65
Label.prototype.setText = function(text) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    66
    uiLogger.debug("Label.setText(" + text + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    67
    this.contentElement.innerHTML = (text == null) ? "" : text;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    68
    this.updateStyleFromState();
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    69
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    70
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    71
// Updates the style of the control to reflects the state of the control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    72
Label.prototype.updateStyleFromState = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    73
    uiLogger.debug("Label.updateStyleFromState()");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    74
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    75
    // set element class names
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    76
    this.setClassName(this.rootElement, "Control");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    77
    this.setClassName(this.assemblyElement, "ControlAssembly ControlAssemblyNormal");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    78
    this.setClassName(this.captionElement, "ControlCaption ControlCaptionNormal");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    79
    this.setClassName(this.controlElement, "ControlElement");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    80
    this.setClassName(this.contentElement, "LabelText");
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    81
};