Methods Summary |
---|
int | calculateHeight(StringItem strItem, int type)
int params[] = getParameters(strItem);
switch (type) {
case EMPTY:
return 0;
case EMPTY_LABEL:
return calculateHeightEmptyLabel(params,
getNumOfIsPerLine(strItem.str).length);
case EMPTY_TEXT:
return calculateHeightEmptyText(params,
getNumOfIsPerLine(strItem.label).length);
case SAME_LINE:
return calculateHeightSameLine(params);
case MULT_LINE:
return calculateHeightMultLines(params,
getNumOfIsPerLine(strItem.label).length,
getNumOfIsPerLine(strItem.str).length);
default:
System.err.println("Incorrect type passing");
return 0;
}
|
int | calculateHeightEmptyLabel(int[] params, int numOfLines)
return params[ITEM_TOP_PAD] +
params[CONTENT_LEFT_PAD] +
params[TEXT_FONT_HEIGHT]*numOfLines +
params[CONTENT_RIGHT_PAD] +
params[ITEM_BOTTOM_PAD];
|
int | calculateHeightEmptyText(int[] params, int numOfLines)
return params[ITEM_TOP_PAD] +
params[LABEL_FONT_HEIGHT]*numOfLines +
params[ITEM_BOTTOM_PAD];
|
int | calculateHeightMultLines(int[] params, int labelNumLines, int textNumLines)
return params[ITEM_TOP_PAD] +
labelNumLines*params[LABEL_FONT_HEIGHT] +
params[LABEL_BODY_VERTICAL_PAD] +
params[CONTENT_TOP_PAD] +
labelNumLines*params[TEXT_FONT_HEIGHT] +
params[CONTENT_BOTTOM_PAD] +
params[ITEM_BOTTOM_PAD];
|
int | calculateHeightSameLine(int[] params)
int contentHeight = params[CONTENT_LEFT_PAD] +
params[TEXT_FONT_HEIGHT] +
params[CONTENT_RIGHT_PAD];
return params[ITEM_TOP_PAD] + params[ITEM_BOTTOM_PAD] +
(params[LABEL_FONT_HEIGHT] > contentHeight ?
params[LABEL_FONT_HEIGHT] : contentHeight);
|
int | calculateWidth(StringItem strItem, int type)
int params[] = getParameters(strItem);
switch (type) {
case EMPTY:
return 0;
case EMPTY_LABEL:
return calculateWidthEmptyLabel(params,
getNumOfIsPerLine(strItem.str));
case EMPTY_TEXT:
return calculateWidthEmptyText(params,
getNumOfIsPerLine(strItem.label));
case SAME_LINE:
// we rely on the fact that both label and text are present
// and not empty
return calculateWidthSameLine(params,
getNumOfIsPerLine(strItem.label)[0],
getNumOfIsPerLine(strItem.str)[0]);
case MULT_LINE:
return calculateWidthMultLines(params,
getNumOfIsPerLine(strItem.label),
getNumOfIsPerLine(strItem.str));
default:
System.err.println("Incorrect type passing");
return 0;
}
|
int | calculateWidthEmptyLabel(int[] params, int[] numOfIperLine)
int maxIs = 0;
for (int i=0; i<numOfIperLine.length; i++) {
if (numOfIperLine[i] > maxIs) {
maxIs = numOfIperLine[i];
}
}
return params[ITEM_LEFT_PAD] +
params[CONTENT_LEFT_PAD] +
maxIs*params[TEXT_I_WIDTH]+
params[CONTENT_RIGHT_PAD] +
params[ITEM_RIGHT_PAD];
|
int | calculateWidthEmptyText(int[] params, int[] numOfIperLine)
int maxIs = 0;
for (int i=0; i<numOfIperLine.length; i++) {
if (numOfIperLine[i] > maxIs) {
maxIs = numOfIperLine[i];
}
}
return params[ITEM_LEFT_PAD] +
maxIs*params[LABEL_I_WIDTH]+
params[ITEM_RIGHT_PAD];
|
int | calculateWidthMultLines(int[] params, int[] labelNumOfIperLine, int[] textNumOfIperLine)
int labelMaxI = 0;
for(int i=0; i<labelNumOfIperLine.length; i++) {
if (labelNumOfIperLine[i] > labelMaxI) {
labelMaxI = labelNumOfIperLine[i];
}
}
labelMaxI *= params[LABEL_I_WIDTH];
int textMaxI = 0;
for(int i=0; i<textNumOfIperLine.length; i++) {
if (textNumOfIperLine[i] > textMaxI) {
textMaxI = textNumOfIperLine[i];
}
}
textMaxI *= params[TEXT_I_WIDTH];
textMaxI += params[CONTENT_LEFT_PAD] + params[CONTENT_RIGHT_PAD];
return params[ITEM_LEFT_PAD] + params[ITEM_RIGHT_PAD] +
(labelMaxI > textMaxI ? labelMaxI : textMaxI);
|
int | calculateWidthSameLine(int[] params, int labelNumOfI, int textNumOfI)
return params[ITEM_LEFT_PAD] +
labelNumOfI*params[LABEL_I_WIDTH] +
params[LABEL_BODY_HORIZ_PAD] +
params[CONTENT_LEFT_PAD] +
textNumOfI*params[TEXT_I_WIDTH]+
params[CONTENT_RIGHT_PAD] +
params[ITEM_RIGHT_PAD];
|
javax.microedition.lcdui.TestStringItemSizing$StringItemInfo[] | createTestArray()
// -----------------------------------------------------------------------
// utilities
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[] | getNumOfIsPerLine(java.lang.String str)
if (str == null || str.length() == 0) {
return new int[]{0};
}
int lines = 1;
for(int i=0; i < str.length(); i++) {
if (str.charAt(i) == '\n") {
lines++;
}
}
int return_array[] = new int[lines];
int j = 0, numOfIs = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '\n") {
return_array[j] = numOfIs;
numOfIs = 0;
j++;
} else {
numOfIs++;
}
}
return_array[j] = numOfIs;
return return_array;
|
int[] | getParameters(StringItem strItem)
// Hyperlink and Button appearance settings are ignored
// if there are no commands added
// If a command is added to a StringItem with PLAIN appearance mode
// it is changed to be HYPERLINK
switch(strItem.getAppearanceMode()) {
case Item.PLAIN:
return (strItem.numCommands == 0 ?
PLAIN_PRMS : HYPERLINK_PRMS);
case Item.HYPERLINK:
return (strItem.numCommands == 0 ?
PLAIN_PRMS : HYPERLINK_PRMS);
case Item.BUTTON:
return (strItem.numCommands == 0 ?
PLAIN_PRMS : BUTTON_PRMS);
}
return null;
|
public void | runTests()
StringItemInfo newItemInfos[] = createTestArray();
for (int i = 0 ; i < newItemInfos.length; i++) {
declare("testPreferredWidth StringItem(" +
newItemInfos[i].description);
testDefaultPreferredWidth(newItemInfos[i]);
declare("testPreferredHeight StringItem(" +
newItemInfos[i].description);
testDefaultPreferredHeight(newItemInfos[i]);
}
|
public void | testDefaultPreferredHeight(javax.microedition.lcdui.TestStringItemSizing$StringItemInfo strItemInfo)
assertEquals(calculateHeight(strItemInfo.strItem, strItemInfo.type),
strItemInfo.strItem.stringItemLF.lGetPreferredHeight(-1));
|
public void | testDefaultPreferredWidth(javax.microedition.lcdui.TestStringItemSizing$StringItemInfo strItemInfo)
assertEquals(calculateWidth(strItemInfo.strItem, strItemInfo.type),
strItemInfo.strItem.stringItemLF.lGetPreferredWidth(-1));
|