📄 container.java
字号:
this.autoFocusEnabled = false;
}
}
}
this.containerView.initContent( this, firstLineWidth, lineWidth);
this.appearanceMode = this.containerView.appearanceMode;
this.contentWidth = this.containerView.contentWidth;
this.contentHeight = this.containerView.contentHeight;
if (requireScrolling && this.enableScrolling && this.focusedItem != null) {
//#debug
//# System.out.println("initContent(): scrolling autofocused or scroll-required item for view");
Item item = this.focusedItem;
scroll( 0, item.relativeX, item.relativeY, item.itemWidth, item.itemHeight );
}
return;
}
//#endif
boolean isLayoutShrink = (this.layout & LAYOUT_SHRINK) == LAYOUT_SHRINK;
boolean hasFocusableItem = false;
for (int i = 0; i < myItems.length; i++) {
Item item = myItems[i];
//System.out.println("initalising " + item.getClass().getName() + ":" + i);
int width = item.getItemWidth( lineWidth, lineWidth );
int height = item.itemHeight; // no need to call getItemHeight() since the item is now initialised...
// now the item should have a style, so it can be safely focused
// without loosing the style information:
if (item.appearanceMode != PLAIN) {
hasFocusableItem = true;
}
if (this.autoFocusEnabled && (i >= this.autoFocusIndex ) && (item.appearanceMode != Item.PLAIN)) {
this.autoFocusEnabled = false;
focus( i, item, 0 );
this.isScrollRequired = this.isScrollRequired && (this.autoFocusIndex != 0); // override setting in focus()
height = item.getItemHeight(lineWidth, lineWidth);
if (!isLayoutShrink) {
width = item.itemWidth; // no need to call getItemWidth() since the item is now initialised...
} else {
width = 0;
}
if (this.enableScrolling && this.autoFocusIndex != 0) {
//#debug
//# System.out.println("initContent(): scrolling autofocused item, autofocus-index=" + this.autoFocusIndex + ", i=" + i );
scroll( 0, 0, myContentHeight, width, height );
}
} else if (i == this.focusedIndex) {
if (isLayoutShrink) {
width = 0;
}
if (this.isScrollRequired) {
//#debug
//# System.out.println("initContent(): scroll is required.");
scroll( 0, 0, myContentHeight, width, height );
this.isScrollRequired = false;
}
}
if (width > myContentWidth) {
myContentWidth = width;
}
item.relativeY = myContentHeight;
if ( (item.layout & LAYOUT_CENTER) == LAYOUT_CENTER) {
item.relativeX = (lineWidth - width) / 2;
} else if ( (item.layout & LAYOUT_RIGHT) == LAYOUT_RIGHT) {
item.relativeX = (lineWidth - width);
} else {
item.relativeX = 0;
}
myContentHeight += height + this.paddingVertical;
//System.out.println("item.yTopPos=" + item.yTopPos);
}
if (!hasFocusableItem) {
this.appearanceMode = PLAIN;
} else {
this.appearanceMode = INTERACTIVE;
if (isLayoutShrink && this.focusedItem != null) {
Item item = this.focusedItem;
//System.out.println("container has shrinking layout and contains focuse item " + item);
item.isInitialized = false;
boolean doExpand = item.isLayoutExpand;
int width;
if (doExpand) {
item.isLayoutExpand = false;
width = item.getItemWidth( lineWidth, lineWidth );
item.isInitialized = false;
item.isLayoutExpand = true;
} else {
width = item.itemWidth;
}
if (width > myContentWidth) {
myContentWidth = width;
}
if ( this.minimumWidth != 0 && myContentWidth < this.minimumWidth ) {
myContentWidth = this.minimumWidth;
}
//myContentHeight += item.getItemHeight( lineWidth, lineWidth );
}
}
} catch (ArrayIndexOutOfBoundsException e) {
//#debug error
//# System.out.println("Unable to init container " + e );
}
this.contentHeight = myContentHeight;
this.contentWidth = myContentWidth;
}
int getContentScrollHeight() {
return this.availableHeight - (this.contentX + this.borderWidth + this.paddingBottom + this.marginBottom );
}
/* (non-Javadoc)
* @see de.enough.polish.ui.Item#paintContent(int, int, int, int, javax.microedition.lcdui.Graphics)
*/
protected void paintContent(int x, int y, int leftBorder, int rightBorder, Graphics g) {
// paints all items,
// the layout will be done according to this containers'
// layout or according to the items layout, when specified.
// adjust vertical start for scrolling:
//#if polish.debug.debug
//# if (this.enableScrolling) {
//# // g.setColor( 0xFFFF00 );
//# // g.drawLine( leftBorder, y, rightBorder, y + getContentScrollHeight() );
//# // g.drawLine( rightBorder, y, leftBorder, y + + getContentScrollHeight() );
//# // g.drawString( "" + this.availableHeight, x, y, Graphics.TOP | Graphics.LEFT );
//#debug
//# System.out.println("Container: drawing " + getClass().getName() + " with yOffset=" + this.yOffset );
//# }
//#endif
boolean setClipping = ( this.enableScrolling && this.itemHeight > this.availableHeight) ; //( this.yOffset != 0 && (this.marginTop != 0 || this.paddingTop != 0) );
int clipX = 0;
int clipY = 0;
int clipWidth = 0;
int clipHeight = 0;
if (setClipping) {
clipX = g.getClipX();
clipY = g.getClipY();
clipWidth = g.getClipWidth();
clipHeight = g.getClipHeight();
//g.clipRect(clipX, y - this.paddingTop, clipWidth, clipHeight - ((y - this.paddingTop) - clipY) );
g.clipRect(clipX, y, clipWidth, clipHeight - (y - clipY) );
}
x = leftBorder;
y += this.yOffset;
//#ifdef tmp.supportViewType
if (this.containerView != null) {
//#debug
//# System.out.println("fowarding paint call to " + this.containerView );
this.containerView.paintContent( this, x, y, leftBorder, rightBorder, g);
} else {
//#endif
Item[] myItems;
//synchronized (this.itemsList) {
myItems = this.items;
//}
int focusedX = x;
int focusedY = 0;
int focusedRightBorder = rightBorder;
if (!(this.isLayoutCenter || this.isLayoutRight)) {
// adjust the right border:
rightBorder = leftBorder + this.contentWidth;
}
int startY = g.getClipY();
int endY = startY + g.getClipHeight();
Item focItem = this.focusedItem;
int focIndex = this.focusedIndex;
for (int i = 0; i < myItems.length; i++) {
Item item = myItems[i];
// currently the NEWLINE_AFTER and NEWLINE_BEFORE layouts will be ignored,
// since after every item a line break will be done.
if (i == focIndex) {
focusedY = y;
item.getItemHeight( rightBorder - x, rightBorder - leftBorder );
} else if ( y + item.itemHeight >= startY && y < endY ){
// the currently focused item is painted last
item.paint(x, y, leftBorder, rightBorder, g);
// } else {
// System.out.println("skipping " + item);
}
y += item.itemHeight + this.paddingVertical;
}
// paint the currently focused item:
if (focItem != null) {
//System.out.println("Painting focusedItem " + this.focusedItem + " with width=" + this.focusedItem.itemWidth + " and with increased colwidth of " + (focusedRightBorder - focusedX) );
focItem.paint(focusedX, focusedY, focusedX, focusedRightBorder, g);
}
//#ifdef tmp.supportViewType
}
//#endif
Item item = this.focusedItem;
if (item != null) {
if (item.internalX != -9999) {
// inherit the internal area of the focused item:
this.internalX = item.contentX + item.internalX;
this.internalWidth = item.internalWidth;
this.internalY = item.contentY+ item.internalY;
this.internalHeight = item.internalHeight;
} else {
// use the item as my internal area:
this.internalX = item.relativeX ;
this.internalWidth = item.itemWidth;
this.internalY = item.relativeY; //(item.yTopPos - this.yOffset) - this.contentY;
this.internalHeight = item.itemHeight;
}
// outcommented by rob - 2006-07-13 - now positions are determined in the initContent() method already
// if (this.isFirstPaint) {
// this.isFirstPaint = false;
// if (this.enableScrolling) {
// if ( this.contentY + this.internalY + this.internalHeight > this.yBottom ) {
// //#debug
// System.out.println("first paint, now scrolling...");
// scroll( true, this.contentX, this.contentY + this.internalY, this.contentWidth, this.internalHeight + 3 ); // + 3 gives room for a focused border etc
// }
// }
// }
}
if (setClipping) {
g.setClip(clipX, clipY, clipWidth, clipHeight);
}
}
//#ifdef polish.useDynamicStyles
//# /* (non-Javadoc)
//# * @see de.enough.polish.ui.Item#getCssSelector()
//# */
//# protected String createCssSelector() {
//# return "container";
//# }
//#endif
/* (non-Javadoc)
* @see de.enough.polish.ui.Item#handleKeyPressed(int, int)
*/
protected boolean handleKeyPressed(int keyCode, int gameAction) {
if (this.itemsList.size() == 0) {
return false;
}
if (this.focusedItem != null) {
Item item = this.focusedItem;
if ( item.handleKeyPressed(keyCode, gameAction) ) {
if (item.internalX != -9999) {
if (this.enableScrolling) {
scroll(gameAction, item);
} else {
// adjust internal settings for root container:
this.internalX = item.relativeX + item.contentX + item.internalX;
this.internalY = item.relativeY + item.contentY + item.internalY;
this.internalWidth = item.internalWidth;
this.internalHeight = item.internalHeight;
//#debug
//# System.out.println("Adjusted internal area to x=" + this.internalX + ", y=" + this.internalY + ", w=" + this.internalWidth + ", h=" + this.internalHeight );
}
}
//#debug
//# System.out.println("Container(" + this + "): handleKeyPressed consumed by item " + item.getClass().getName() + "/" + item );
return true;
}
}
// now allow a navigation within the container:
//#ifdef tmp.supportViewType
if (this.containerView != null) {
boolean handled = this.containerView.handleKeyPressed(keyCode, gameAction);
if (handled) {
return true;
}
// Item next = this.view.getNextItem(keyCode, gameAction);
// if (next != null) {
// focus( this.view.focusedIndex, next, gameAction );
// return true;
// } else
if (this.enableScrolling) {
if (gameAction == Canvas.UP && this.targetYOffset < 0 ) {
// scroll the container view upwards without changing the focused item:
//#if polish.Container.ScrollDelta:defined
//#= this.targetYOffset += ${polish.Container.ScrollDelta};
//#else
this.targetYOffset += 30;
//#endif
if (this.targetYOffset > 0 ) {
this.targetYOffset = 0;
}
//#if polish.css.scroll-mode
//# if (!this.scrollSmooth) {
//# this.yOffset = this.targetYOffset;
//# }
//#endif
return true;
}
if (gameAction == Canvas.DOWN
&& (this.itemHeight + this.targetYOffset > (this.availableHeight)) )
{
// scroll the container view downwards without changing the focused item:
//#if polish.Container.ScrollDelta:defined
//#= this.targetYOffset -= ${polish.Container.ScrollDelta};
//#else
this.targetYOffset -= 30;
//#endif
//#if polish.css.scroll-mode
//# if (!this.scrollSmooth) {
//# this.yOffset = this.targetYOffset;
//# }
//#endif
return true;
}
}
return false;
}
//#endif
boolean processed = false;
int offset;
//#if polish.css.scroll-mode
//# if (this.scrollSmooth) {
//#endif
offset = this.targetYOffset;
//#if polish.css.scroll-mode
//# } else {
//# offset = this.yOffset;
//# }
//#endif
if ( (gameAction == Canvas.RIGHT && keyCode != Canvas.KEY_NUM6)
|| (gameAction == Canvas.DOWN && keyCode != Canvas.KEY_NUM8)) {
if (this.focusedItem != null
&& this.enableScrolling
&& ( (offset + this.focusedItem.relativeY + this.focusedItem.itemHeight > availableHeight)
|| ( this.focusedItem.internalX != -9999
&& offset + this.focusedItem.relativeY + this.focusedItem.contentY + this.focusedItem.internalY + this.focusedItem.internalHeight > availableHeight))
)
{
if (gameAction == Canvas.RIGHT) {
return false;
}
// keep the focus do scroll downwards:
//#debug
//# System.out.println("Container(" + this + "): scrolling down: keeping focus, focusedIndex=" + this.focusedIndex );
} else {
processed = shiftFocus( true, 0 );
}
//#debug
//# System.out.println("Container(" + this + "): forward shift by one item succeded: " + processed + ", focusedIndex=" + this.focusedIndex );
if ((!processed) && this.enableScrolling
&& ( (this.focusedItem != null && offset + this.focusedItem.relativeY + this.focusedItem.itemHeight > this.availableHeight)
|| offset + this.itemHeight > this.availableHeight)) {
// scroll downwards:
//#if polish.Container.ScrollDelta:defined
//#= offset -= ${polish.Container.ScrollDelta};
//#else
offset -= 30;
//#endif
//#debug
//# System.out.println("Down/Right: Reducing (target)YOffset to " + offset);
processed = true;
//#if polish.css.scroll-mode
//# if (this.scrollSmooth) {
//#endif
this.targetYOffset = offset;
//#if polish.css.scroll-mode
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -