📄 midp2layoutview.java
字号:
// rowItem = (RowItem) this.currentRow.get(i);
// rowItem.x = x;
// x += rowItem.width + this.paddingHorizontal; // Next Item
/**
* Vertical Layout starts here
*/
// int layout = rowItem.item.getLayout();
// rowItem.y = this.contentHeight;
// if (Item.LAYOUT_VEXPAND == (layout & Item.LAYOUT_VEXPAND)) {
// // Vertical expansion is required, ignore all other
// rowItem.height = this.rowHeight;
// } else {
// layout = (layout & LAYOUT_VERTICAL);
// switch (layout) {
// case Item.LAYOUT_VCENTER :
// rowItem.y += ((this.rowHeight - rowItem.height) >> 1);
// break;
// case Item.LAYOUT_BOTTOM :
// rowItem.y += this.rowHeight - rowItem.height;
// break;
// }
// }
rowItem = (Item) this.currentRow.get(i);
rowItem.relativeX = x;
x += rowItem.itemWidth + this.paddingHorizontal; // Next Item
if (Item.LAYOUT_VEXPAND == (itemLayout & Item.LAYOUT_VEXPAND)) {
rowItem.relativeY = this.contentHeight;
if (Item.LAYOUT_VEXPAND == (itemLayout & Item.LAYOUT_VEXPAND)) {
// Vertical expansion is required, ignore all other
//rowItem.height = this.rowHeight;
} else {
itemLayout = (itemLayout & LAYOUT_VERTICAL);
switch (itemLayout) {
case Item.LAYOUT_VCENTER :
rowItem.relativeY += ((this.rowHeight - rowItem.itemHeight) >> 1);
break;
case Item.LAYOUT_BOTTOM :
rowItem.relativeY += this.rowHeight - rowItem.itemHeight;
break;
}
}
}
}
if (this.allRows.size() == 0) {
// Adding first row
this.contentHeight += this.rowHeight;
} else {
this.contentHeight += this.paddingVertical + this.rowHeight;
}
if ( this.rowWidth > this.contentWidth ) {
this.contentWidth = this.rowWidth;
}
// Get ready for next row
this.allRows.add(this.currentRow);
this.rowHeight = this.rowWidth = 0;
this.currentRow = new ArrayList();
}
/*
* (non-Javadoc)
*
* @see de.enough.polish.ui.ContainerView#paintContent(int, int, int, int,
* javax.microedition.lcdui.Graphics)
*/
protected void paintContent(Item parent, int x, int y, int leftBorder, int rightBorder,
Graphics g)
{
int clipX = g.getClipX();
int clipY = g.getClipY();
int clipWidth = g.getClipWidth();
int clipHeight = g.getClipHeight();
for (int i = 0; i < this.allRows.size(); i++) {
ArrayList row = (ArrayList) this.allRows.get(i);
for (int j = 0; j < row.size(); j++) {
Item rowItem = (Item) row.get(j);
int xItem = x + rowItem.relativeX;
paintItem(rowItem, i, xItem, y + rowItem.relativeY,
Math.max(leftBorder, xItem), Math.min(rightBorder, xItem + rowItem.itemWidth),
clipX, clipY, clipWidth, clipHeight, g);
}
}
}
/*
* (non-Javadoc)
*
* @see de.enough.polish.ui.ContainerView#getNextItem(int, int)
*/
protected Item getNextItem(int keyCode, int gameAction) {
if (this.allRows.size() == 0)
return null;
Item[] items = this.parentContainer.getItems();
if (this.focusedIndex >= items.length) {
for(int i=0; i < items.length; i++) {
if(items[i].appearanceMode != Item.PLAIN) {
focusItem(i, items[i], gameAction );
return items[i];
}
}
}
// Find out where the current focused item is.
Item focusedItem = items[this.focusedIndex];
int rowIndex = 0;
//int colIndex = 0;
int xOffset = 0;
for (int i = 0; i < this.allRows.size(); i++) {
ArrayList row = (ArrayList) this.allRows.get(i);
for (int j = 0; j < row.size(); j++) {
Item rowItem = (Item) row.get(j);
if (rowItem == focusedItem) {
rowIndex = i;
//colIndex = j;
xOffset = rowItem.relativeX + (rowItem.itemWidth >> 1);
i = 10000;
break;
}
}
// for (int j = 0; j < row.size(); j++) {
// RowItem rowItem = (RowItem) row.get(j);
// if (rowItem.item == focusedItem) {
// rowIndex = i;
// //colIndex = j;
// xOffset = rowItem.x + (rowItem.width >> 1);
// i = 10000;
// break;
// }
// }
}
Item item = null;
if (gameAction == Canvas.UP && keyCode != Canvas.KEY_NUM2) {
// Going Up
if (this.horizontalOffset == -1) {
this.horizontalOffset = xOffset;
}
while (rowIndex > 0) {
rowIndex--;
item = getItemByHorizontalOffset((ArrayList) this.allRows
.get(rowIndex), this.horizontalOffset);
if(item != null) break;
}
if(item == null){
// Can't go up any more
}
} else if (gameAction == Canvas.DOWN && keyCode != Canvas.KEY_NUM8) {
// Going Down
if (this.horizontalOffset == -1) {
this.horizontalOffset = xOffset;
}
while(rowIndex < (this.allRows.size() - 1)) {
rowIndex++;
item = getItemByHorizontalOffset((ArrayList) this.allRows
.get(rowIndex), this.horizontalOffset);
if(item != null) break;
}
if(item == null){
// Can't go Down any more
}
} else if (gameAction == Canvas.RIGHT && keyCode != Canvas.KEY_NUM6) {
// Going Right
this.horizontalOffset = -1; // Reset vertical movement position
item = getNextFocusableItem(items, true, 1, false);
} else if (gameAction == Canvas.LEFT && keyCode != Canvas.KEY_NUM4) {
// Going Left
this.horizontalOffset = -1; // Reset vertical movement position
item = getNextFocusableItem(items, false, 1, false);
}
// Finally set the focus if it has been found
if (item != null) {
for (int i = 0; i < items.length; i++) {
if (items[i] == item) {
focusItem(i, item, gameAction);
break;
}
}
}
else {
if (this.focusedIndex >= items.length) {
for(int i=0; i < items.length; i++) {
Item focItem = items[i];
if(focItem.appearanceMode != Item.PLAIN) {
focusItem(i, focItem, gameAction );
return focItem;
}
}
}
}
return item;
}
private Item getItemByHorizontalOffset(ArrayList row, int xOffset) {
Item item = null;
Item rowItem = null;
int distance = 60000;
int itemOffset = 0;
int itemDistance = 0;
for (int i = 0; i < row.size(); i++) {
rowItem = (Item) row.get(i);
if (rowItem.appearanceMode != Item.PLAIN) {
itemOffset = rowItem.relativeX + (rowItem.itemWidth >> 1);
itemDistance = xOffset - itemOffset;
if(itemDistance < 0) {
itemDistance = -itemDistance;
}
if (itemDistance < distance) {
distance = itemDistance;
item = rowItem;
}
}
}
return item;
// Item item = null;
// RowItem rowItem = null;
// int distance = 60000;
// int itemOffset = 0;
// int itemDistance = 0;
// for (int i = 0; i < row.size(); i++) {
// rowItem = (RowItem) row.get(i);
// if (rowItem.item.appearanceMode != Item.PLAIN) {
// itemOffset = rowItem.x + (rowItem.width >> 1);
// itemDistance = xOffset - itemOffset;
// if(itemDistance < 0) itemDistance = -itemDistance;
//
// if (itemDistance < distance) {
// distance = itemDistance;
// item = rowItem.item;
// }
// }
// }
// return item;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -