uidesigner/com.nokia.sdt.symbian.tests/data/images/components/testImplLibrary.js
author cawthron
Tue, 24 Mar 2009 22:20:21 -0500
changeset 2 d760517a8095
permissions -rw-r--r--
new
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
cawthron
parents:
diff changeset
     1
/*
cawthron
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
cawthron
parents:
diff changeset
     3
* All rights reserved.
cawthron
parents:
diff changeset
     4
* This component and the accompanying materials are made available
cawthron
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
cawthron
parents:
diff changeset
     6
* which accompanies this distribution, and is available
cawthron
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
cawthron
parents:
diff changeset
     8
*
cawthron
parents:
diff changeset
     9
* Initial Contributors:
cawthron
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
cawthron
parents:
diff changeset
    11
*
cawthron
parents:
diff changeset
    12
* Contributors:
cawthron
parents:
diff changeset
    13
*
cawthron
parents:
diff changeset
    14
* Description: 
cawthron
parents:
diff changeset
    15
*
cawthron
parents:
diff changeset
    16
*/
cawthron
parents:
diff changeset
    17
// This file has routines which initialize component implementations
cawthron
parents:
diff changeset
    18
// according to patterns.
cawthron
parents:
diff changeset
    19
cawthron
parents:
diff changeset
    20
include ("testMessageLibrary.js")
cawthron
parents:
diff changeset
    21
cawthron
parents:
diff changeset
    22
strings = getLocalizedStrings("testImplLibrary");
cawthron
parents:
diff changeset
    23
cawthron
parents:
diff changeset
    24
//	Set up direct label editing implementation for a component with
cawthron
parents:
diff changeset
    25
//	one editable label
cawthron
parents:
diff changeset
    26
//	@param prototype the impl prototype to update
cawthron
parents:
diff changeset
    27
//	@param property the name of the edited property
cawthron
parents:
diff changeset
    28
//	@param areafunction a function, taking an instance and laf, which returns the
cawthron
parents:
diff changeset
    29
//		editable area of the label (or null).  If null, the default behavior is
cawthron
parents:
diff changeset
    30
//		to use the entire rendered area.
cawthron
parents:
diff changeset
    31
//	@param fontfunction a function, taking an instance and laf, which returns the
cawthron
parents:
diff changeset
    32
//		IFont to edit with (or null).  If null, the default behavior is to return
cawthron
parents:
diff changeset
    33
//		null, indicating a default system font.
cawthron
parents:
diff changeset
    34
function setupCommonDirectLabelEditing(prototype, property, areafunction, fontfunction) {
cawthron
parents:
diff changeset
    35
cawthron
parents:
diff changeset
    36
	prototype.getPropertyPaths = function(instance) {
cawthron
parents:
diff changeset
    37
		return [ property ];
cawthron
parents:
diff changeset
    38
	}
cawthron
parents:
diff changeset
    39
cawthron
parents:
diff changeset
    40
	prototype.getLabelBounds = function(instance, propertyPath, laf) {
cawthron
parents:
diff changeset
    41
		if (areafunction)
cawthron
parents:
diff changeset
    42
			return areafunction(instance, laf);
cawthron
parents:
diff changeset
    43
		var size = instance.properties.size;
cawthron
parents:
diff changeset
    44
	    return new Rectangle(0, 0, size.width, size.height);
cawthron
parents:
diff changeset
    45
	}
cawthron
parents:
diff changeset
    46
cawthron
parents:
diff changeset
    47
	prototype.getLabelFont = function(instance, propertyPath, laf) {
cawthron
parents:
diff changeset
    48
		if (fontfunction)
cawthron
parents:
diff changeset
    49
			return fontfunction(instance, laf)
cawthron
parents:
diff changeset
    50
		return null;
cawthron
parents:
diff changeset
    51
	}
cawthron
parents:
diff changeset
    52
}
cawthron
parents:
diff changeset
    53
cawthron
parents:
diff changeset
    54
//	Set up direct image editing implementation for a component
cawthron
parents:
diff changeset
    55
//	with one image property.  This sets up a standard validation
cawthron
parents:
diff changeset
    56
//	check (images must be BMP or SVG if scalable UI enabled), and
cawthron
parents:
diff changeset
    57
//	warns about scaled images if the image is a bitmap and its size 
cawthron
parents:
diff changeset
    58
//	doesn't match the rendered area.
cawthron
parents:
diff changeset
    59
//	<p>
cawthron
parents:
diff changeset
    60
//	The validation logic is added to the prototype as "commonValidateImage" --
cawthron
parents:
diff changeset
    61
//	you may override this behavior in your "validateImage" call.
cawthron
parents:
diff changeset
    62
//
cawthron
parents:
diff changeset
    63
//	@param prototype the impl prototype to update
cawthron
parents:
diff changeset
    64
//	@param property the name of the edited property
cawthron
parents:
diff changeset
    65
//	@param areafunction a function, taking an instance and laf, or null.
cawthron
parents:
diff changeset
    66
//		If not null, the function which returns a rectangle for the clickable area 
cawthron
parents:
diff changeset
    67
//		of the rendered area to respond to as well as the preferred size of the image.
cawthron
parents:
diff changeset
    68
//		If null, the default behavior is to use the entire rendered area.
cawthron
parents:
diff changeset
    69
function setupCommonDirectImageEditing(prototype, property, areafunction) {
cawthron
parents:
diff changeset
    70
cawthron
parents:
diff changeset
    71
	prototype.getImagePropertyPaths = function(instance) {
cawthron
parents:
diff changeset
    72
		return [ property ];
cawthron
parents:
diff changeset
    73
	}
cawthron
parents:
diff changeset
    74
cawthron
parents:
diff changeset
    75
	prototype.getImageBounds = function(instance, propertyPath, laf) {
cawthron
parents:
diff changeset
    76
		println( "image: " + instance.properties[propertyPath].bmpfile + "/" 
cawthron
parents:
diff changeset
    77
				+instance.properties[propertyPath].bmpid + "/" 
cawthron
parents:
diff changeset
    78
				+instance.properties[propertyPath].bmpmask );
cawthron
parents:
diff changeset
    79
				
cawthron
parents:
diff changeset
    80
		if (areafunction) 
cawthron
parents:
diff changeset
    81
			return areafunction(instance, laf);
cawthron
parents:
diff changeset
    82
		var size = instance.properties.size;
cawthron
parents:
diff changeset
    83
	    return new Rectangle(0, 0, size.width, size.height);
cawthron
parents:
diff changeset
    84
	}
cawthron
parents:
diff changeset
    85
cawthron
parents:
diff changeset
    86
	function isBMPFile(file) {
cawthron
parents:
diff changeset
    87
		var lower = file.toLowerCase();
cawthron
parents:
diff changeset
    88
		return lower.endsWith(".bmp");
cawthron
parents:
diff changeset
    89
	}
cawthron
parents:
diff changeset
    90
cawthron
parents:
diff changeset
    91
	function isSVGFile(file) {
cawthron
parents:
diff changeset
    92
		var lower = file.toLowerCase();
cawthron
parents:
diff changeset
    93
		println ("SVG check: lower="+lower);
cawthron
parents:
diff changeset
    94
		return lower.endsWith(".svg") || lower.endsWith(".svgt");
cawthron
parents:
diff changeset
    95
	}
cawthron
parents:
diff changeset
    96
cawthron
parents:
diff changeset
    97
	prototype.commonValidateImage = function(instance, propertyId, laf, file, size) {
cawthron
parents:
diff changeset
    98
	
cawthron
parents:
diff changeset
    99
		var bounds = this.getImageBounds(instance, propertyId.substring(propertyId.lastIndexOf('.')+1), laf)
cawthron
parents:
diff changeset
   100
		
cawthron
parents:
diff changeset
   101
		//println("validating " + file + " @" + size +" for " + propertyId + " in " + bounds);
cawthron
parents:
diff changeset
   102
	
cawthron
parents:
diff changeset
   103
		var lower = file.toLowerCase();
cawthron
parents:
diff changeset
   104
		if (!isBMPFile(file) && !isSVGFile(file)) {
cawthron
parents:
diff changeset
   105
			return buildSimpleErrorStatus(
cawthron
parents:
diff changeset
   106
				strings.getString("imageTypeOnlyBmpOrSvgError"), [ file ]);
cawthron
parents:
diff changeset
   107
		}
cawthron
parents:
diff changeset
   108
	
cawthron
parents:
diff changeset
   109
	 	// unknown size --> ignore
cawthron
parents:
diff changeset
   110
		if (size == null)
cawthron
parents:
diff changeset
   111
			return null;
cawthron
parents:
diff changeset
   112
		
cawthron
parents:
diff changeset
   113
		if (!isSVGFile(file)) {
cawthron
parents:
diff changeset
   114
			if (size.x != bounds.width || size.y != bounds.height)
cawthron
parents:
diff changeset
   115
				return buildSimpleWarningStatus(
cawthron
parents:
diff changeset
   116
					strings.getString("scaledOrCroppedImageSizeMsg"), 
cawthron
parents:
diff changeset
   117
					new Array( bounds.width, bounds.height ));
cawthron
parents:
diff changeset
   118
		}
cawthron
parents:
diff changeset
   119
		
cawthron
parents:
diff changeset
   120
		return null;
cawthron
parents:
diff changeset
   121
	}
cawthron
parents:
diff changeset
   122
cawthron
parents:
diff changeset
   123
	prototype.validateImage = prototype.commonValidateImage;
cawthron
parents:
diff changeset
   124
}