teststringitemsizing.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 511 行 · 第 1/2 页

JAVA
511
字号
/* * 	 * * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER *  * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. *  * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). *  * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA *  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */package javax.microedition.lcdui;import com.sun.midp.i3test.*;public class TestStringItemSizing extends TestCase {    /**     * Maximum width available for items.     */    private final int MAX_WIDTH = 220;    // Parameter order for PLAIN_PRMS, HYPERLINK_PRMS, BUTTON_PRMS arrays    private final int ITEM_LEFT_PAD   = 0;    private final int ITEM_RIGHT_PAD  = 1;    private final int ITEM_TOP_PAD    = 2;    private final int ITEM_BOTTOM_PAD = 3;    private final int CONTENT_LEFT_PAD   = 4;    private final int CONTENT_RIGHT_PAD  = 5;    private final int CONTENT_TOP_PAD    = 6;    private final int CONTENT_BOTTOM_PAD = 7;    private final int LABEL_BODY_HORIZ_PAD = 8;    private final int LABEL_BODY_VERTICAL_PAD  = 9;    private final int LABEL_I_WIDTH     = 10;    private final int LABEL_FONT_HEIGHT = 11;    private final int TEXT_I_WIDTH      = 12;    private final int TEXT_FONT_HEIGHT  = 13;    // Padding, 'i' width and height values for     // different appearances of StringItem    private final int PLAIN_PRMS[] = new int[] {4, 4, 4, 4,						0, 0, 0, 0,						4, 0,						3, 13, 3, 15};    private final int HYPERLINK_PRMS[] = new int[] {4, 4, 4, 4,						    0, 0, 0, 0,						    4, 0,						    3, 13, 3, 15};    private final int BUTTON_PRMS[] = new int[] {4, 4, 4, 4,						 5, 5, 5, 5,						 4, 0,						 3, 13, 3, 15};    // StringItem types (in terms of internal layout)    private final int EMPTY       = 0;    private final int EMPTY_LABEL = 1; // text can be multiline    private final int EMPTY_TEXT  = 2; // label can be multiline    private final int SAME_LINE   = 3; // both text and label present (no \n)    private final int MULT_LINE   = 4; // both text and label present    private final String[] appearanceModeNames = new String[] {	                                          new String("Item.PLAIN"),						  new String("Item.HYPERLINK"),						  new String("Item.BUTTON")};    // The following StringItems are empty or are so narrow that we     // assume that they can be displayed with word wrapping    StringItemInfo itemInfos[] = {	//-------------Empty stringItems ----------------------------------	new StringItemInfo(new StringItem(null, null), EMPTY,			   "StringItem(null, null"),	new StringItemInfo(new StringItem("", ""), EMPTY,			   "StringItem(\"\", \"\""),	new StringItemInfo(new StringItem(null, ""), EMPTY,			   "StringItem(null, \"\""),	new StringItemInfo(new StringItem("", null), EMPTY,			   "StringItem(\"\", null"),	//--------------End of line --------------------------------------	new StringItemInfo(new StringItem("", "\n"), EMPTY_LABEL,			   "StringItem(\"\", \"\\n\""),	new StringItemInfo(new StringItem("\n", ""), EMPTY_TEXT, 			   "StringItem(\"\\n\", \"\""),	//--------------Empty label - Single line text----------------------	new StringItemInfo(new StringItem(null, "i"), EMPTY_LABEL,			   "StringItem(null, \"i\""),	//--------------Empty text - Single line label----------------------	new StringItemInfo(new StringItem("i", null), EMPTY_TEXT,			   "StringItem(\"i\", null"),	//--------------Narrow label and text on the same line	new StringItemInfo(new StringItem("i", "i"), SAME_LINE,			   "StringItem(\"i\", \"i\""),	//-------------Label or text is multiline---------	new StringItemInfo(new StringItem("i\ni",""), EMPTY_TEXT,			   "StringItem(\"i\\ni\", \"\""),	new StringItemInfo(new StringItem("","i\ni"), EMPTY_LABEL,			   "StringItem(\"\", \"i\\ni\""),	//-------------Narrow label and text are multiline	new StringItemInfo(new StringItem("ii\ni","i\nii"), MULT_LINE,			   "StringItem(\"ii\\ni\", \"i\\nii\"")    };    // the following 2 arrays represent different appearances that    // a StringItem could be created with (appearance is modified by    // add/remove commands)    // each strItem in the itemInfos[].strItem should be tested with    // all appearances modes from modes[] with a command added or note    // based on corresponding addCommands[] value    int modes[] = new int[]{Item.PLAIN, Item.HYPERLINK, Item.BUTTON,			    Item.PLAIN,Item.HYPERLINK, Item.BUTTON};    boolean addCommands[] = new boolean[] {false, true, true, 					 true, false, false};    // The sizing of the following StringItems is available width dependent    StringItemInfo itemInfosWidthDependent[] = new StringItemInfo[] {	// ------------- Label and text on the same line	new StringItemInfo(new StringItem("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					  Item.PLAIN),			   SAME_LINE,			   "StringItem(34is, 35is, Item.PLAIN)"),	new StringItemInfo(new StringItem("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					  Item.HYPERLINK),			   SAME_LINE,			   "StringItem(34is, 35is, Item.HYPERLINK)"),	new StringItemInfo(new StringItem("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					 "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					  Item.BUTTON),			   SAME_LINE,			   "StringItem(33is, 33is, Item.BUTTON)"),	new StringItemInfo(new StringItem("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					 "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					  Item.HYPERLINK),			   SAME_LINE,			   "StringItem(34is, 35is, Item.HYPERLINK) command added"),	new StringItemInfo(new StringItem("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					  "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					  Item.BUTTON),			   SAME_LINE,			   "StringItem(33is, 33is, Item.BUTTON) command added"),	new StringItemInfo(new StringItem("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					  Item.PLAIN),			   SAME_LINE,			   "StringItem(34is, 35is, Item.PLAIN) command added"),	//--------------Label and text on multiple lines	new StringItemInfo(new StringItem("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",				        "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					  Item.PLAIN),			   MULT_LINE,			   "StringItem(35is, 35is, Item.PLAIN)"),	new StringItemInfo(new StringItem("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",				        "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					  Item.HYPERLINK),			   MULT_LINE,			   "StringItem(35is, 35is, Item.HYPERLINK)"),	new StringItemInfo(new StringItem("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",				        "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					  Item.BUTTON),			   MULT_LINE,			   "StringItem(35is, 35is, Item.BUTTON)"),	new StringItemInfo(new StringItem("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",				        "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					  Item.HYPERLINK),			   MULT_LINE,			   "StringItem(35is, 35is, Item.HYPERLINK) command added"),	new StringItemInfo(new StringItem("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",				        "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					  Item.BUTTON),			   MULT_LINE,			   "StringItem(35is, 35is, Item.BUTTON) command added"),	new StringItemInfo(new StringItem("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",				        "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",					  Item.PLAIN),			   MULT_LINE,			   "StringItem(35is, 35is, Item.PLAIN) command added")	    };    boolean addCommandsToWidthDepInfos[] = 	new boolean[] {false, false, false, true, true, true,	               false, false, false, true, true, true};    // -----------------------------------------------------------------------    // utilities    StringItemInfo[] createTestArray() {	StringItemInfo newItemInfos[] = 	    new StringItemInfo[itemInfos.length*modes.length +			       itemInfosWidthDependent.length];	Command c = new Command("", Command.ITEM, 1);	for (int j, mode = 0; 	     mode < modes.length; 	     mode++) {	    j = itemInfos.length * mode;	    for (int i = 0; i < itemInfos.length; i++, j++) {		newItemInfos[j] = new StringItemInfo(				    new StringItem(itemInfos[i].strItem.label,						   itemInfos[i].strItem.str,						   modes[mode]),				    itemInfos[i].type,				    itemInfos[i].description + ", " +				    appearanceModeNames[modes[mode]] +")" +				    (addCommands[mode] ? " command added" : "")); 		if (addCommands[mode]) {		    newItemInfos[j].strItem.addCommand(c);		}	    }	}	// Copy elements from itemInfosWidthDependent and add commands 	// if needed	System.arraycopy(itemInfosWidthDependent, 0, 			 newItemInfos, itemInfos.length * modes.length, 			 itemInfosWidthDependent.length);	for (int i=itemInfos.length*modes.length, j=0; 	     i < newItemInfos.length; i++, j++) {	    if (addCommandsToWidthDepInfos[j]) {		newItemInfos[i].strItem.addCommand(c);	    }	}	return newItemInfos;    }    int calculateWidthEmptyLabel(int params[], int numOfIperLine[]) {	int maxIs = 0;	for (int i=0; i<numOfIperLine.length; i++) {	    if (numOfIperLine[i] > maxIs) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?