📄 container.java
字号:
//# } else {
//# this.yOffset = offset;
//# }
//#endif
}
} else if ( (gameAction == Canvas.LEFT && keyCode != Canvas.KEY_NUM4)
|| (gameAction == Canvas.UP && keyCode != Canvas.KEY_NUM2) ) {
if (this.focusedItem != null
&& this.enableScrolling
&& offset + this.focusedItem.relativeY < 0 ) // this.focusedItem.yTopPos < this.yTop )
{
if (gameAction == Canvas.LEFT) {
return false;
}
// keep the focus do scroll upwards:
//#debug
//# System.out.println("Container(" + this + "): scrolling up: keeping focus, focusedIndex=" + this.focusedIndex + ", focusedItem.yTopPos=" + this.focusedItem.relativeY + ", this.availableHeight=" + this.availableHeight + ", targetYOffset=" + this.targetYOffset);
} else {
processed = shiftFocus( false, 0 );
}
//#debug
//# System.out.println("Container(" + this + "): upward shift by one item succeded: " + processed + ", focusedIndex=" + this.focusedIndex );
if ((!processed) && this.enableScrolling && (offset < 0)) {
// scroll upwards:
//#if polish.Container.ScrollDelta:defined
//#= offset += ${polish.Container.ScrollDelta};
//#else
offset += 30;
//#endif
if (offset > 0) {
offset = 0;
}
//#if polish.css.scroll-mode
//# if (this.scrollSmooth) {
//#endif
this.targetYOffset = offset;
//#if polish.css.scroll-mode
//# } else {
//# this.yOffset = offset;
//# }
//#endif
//#debug
//# System.out.println("Up/Left: Increasing (target)YOffset to " + offset);
processed = true;
}
}
return processed;
}
/* (non-Javadoc)
* @see de.enough.polish.ui.Item#handleKeyReleased(int, int)
*/
protected boolean handleKeyReleased(int keyCode, int gameAction) {
if (this.itemsList.size() == 0) {
return false;
}
if (this.focusedItem != null) {
Item item = this.focusedItem;
if ( item.handleKeyReleased( keyCode, gameAction ) ) {
if (this.enableScrolling && item.internalX != -9999) {
scroll(gameAction, item);
}
//#debug
//# System.out.println("Container(" + this + "): handleKeyReleased consumed by item " + item.getClass().getName() + "/" + item );
return true;
}
}
return super.handleKeyReleased(keyCode, gameAction);
}
/* (non-Javadoc)
* @see de.enough.polish.ui.Item#handleKeyRepeated(int, int)
*/
protected boolean handleKeyRepeated(int keyCode, int gameAction) {
if (this.itemsList.size() == 0) {
return false;
}
if (this.focusedItem != null) {
Item item = this.focusedItem;
if ( item.handleKeyRepeated( keyCode, gameAction ) ) {
if (this.enableScrolling && item.internalX != -9999) {
scroll(gameAction, item);
}
//#debug
//# System.out.println("Container(" + this + "): handleKeyRepeated consumed by item " + item.getClass().getName() + "/" + item );
return true;
}
}
return false;
// note: in previous versions a keyRepeat event was just re-asigned to a keyPressed event. However, this resulted
// in non-logical behavior when an item wants to ignore keyRepeast events and only press "real" keyPressed events.
// So now events are ignored by containers when they are ignored by their currently focused item...
//return super.handleKeyRepeated(keyCode, gameAction);
}
/**
* Shifts the focus to the next or the previous item.
*
* @param forwardFocus true when the next item should be focused, false when
* the previous item should be focused.
* @param steps how many steps forward or backward the search for the next focusable item should be started,
* 0 for the current item, negative values go backwards.
* @return true when the focus could be moved to either the next or the previous item.
*/
private boolean shiftFocus(boolean forwardFocus, int steps ) {
if ( this.items == null ) {
//#debug
//# System.out.println("shiftFocus fails: this.items==null");
return false;
}
//System.out.println("|");
Item focItem = this.focusedItem;
//#if polish.css.colspan
//# int i = this.focusedIndex;
//# if (steps != 0) {
//# //System.out.println("ShiftFocus: steps=" + steps + ", forward=" + forwardFocus);
//# int doneSteps = 0;
//# steps = Math.abs( steps ) + 1;
//# Item item = this.items[i];
//# while( doneSteps <= steps) {
//# doneSteps += item.colSpan;
//# if (doneSteps >= steps) {
//# //System.out.println("bailing out at too many steps: focusedIndex=" + this.focusedIndex + ", startIndex=" + i + ", steps=" + steps + ", doneSteps=" + doneSteps);
//# break;
//# }
//# if (forwardFocus) {
//# i++;
//# if (i == this.items.length - 1 ) {
//# i = this.items.length - 2;
//# break;
//# } else if (i == this.items.length) {
//# i = this.items.length - 1;
//# break;
//# }
//# } else {
//# i--;
//# if (i < 0) {
//# i = 1;
//# break;
//# }
//# }
//# item = this.items[i];
//# //System.out.println("focusedIndex=" + this.focusedIndex + ", startIndex=" + i + ", steps=" + steps + ", doneSteps=" + doneSteps);
//# }
//# if (doneSteps >= steps && item.colSpan != 1) {
//# if (forwardFocus) {
//# i--;
//# if (i < 0) {
//# i = this.items.length - 1;
//# }
//# //System.out.println("forward: Adjusting startIndex to " + i );
//# } else {
//# i = (i + 1) % this.items.length;
//# //System.out.println("backward: Adjusting startIndex to " + i );
//# }
//# }
//# }
//#else
int i = this.focusedIndex + steps;
if (i > this.items.length) {
i = this.items.length - 2;
}
if (i < 0) {
i = 1;
}
//#endif
Item item = null;
//#if polish.Container.allowCycling != false
boolean allowCycle = this.enableScrolling && this.allowCycling;
if (allowCycle) {
//#if polish.css.scroll-mode
//# if (!this.scrollSmooth) {
//# if (forwardFocus) {
//# // when you scroll to the bottom and
//# // there is still space, do
//# // scroll first before cycling to the
//# // first item:
//# allowCycle = (this.yOffset + this.itemHeight <= this.availableHeight);
//# // #debug
//# // System.out.println("allowCycle-calculation ( forward non-smoothScroll): yOffset=" + this.yOffset + ", itemHeight=" + this.itemHeight + " (together="+ (this.yOffset + this.itemHeight) + ", height=" + this.height);
//# } else {
//# // when you scroll to the top and
//# // there is still space, do
//# // scroll first before cycling to the
//# // last item:
//# allowCycle = (this.yOffset == 0);
//# }
//# } else {
//#endif
if (forwardFocus) {
// when you scroll to the bottom and
// there is still space, do
// scroll first before cycling to the
// first item:
allowCycle = (this.targetYOffset + this.itemHeight <= this.availableHeight + 1);
// #debug
//System.out.println("allowCycle-calculation ( forward non-smoothScroll): targetYOffset=" + this.targetYOffset + ", contentHeight=" + this.contentHeight + " (together="+ (this.targetYOffset + this.contentHeight) + ", targetYOfset+itemHeight=" + (this.targetYOffset + this.itemHeight) + ", availableHeight=" + this.availableHeight );
} else {
// when you scroll to the top and
// there is still space, do
// scroll first before cycling to the
// last item:
allowCycle = (this.targetYOffset == 0) || (this.targetYOffset == 1);
}
//#if polish.css.scroll-mode
//# }
//#endif
}
//#if polish.Container.allowCycling != false
//#debug
//# System.out.println("shiftFocus of " + this + ": allowCycle(local)=" + allowCycle + ", allowCycle(global)=" + this.allowCycling + ", isFoward=" + forwardFocus + ", enableScrolling=" + this.enableScrolling + ", targetYOffset=" + this.targetYOffset + ", yOffset=" + this.yOffset + ", focusedIndex=" + this.focusedIndex + ", start=" + i );
//#endif
//#endif
while (true) {
if (forwardFocus) {
i++;
if (i >= this.items.length) {
//#if polish.Container.allowCycling != false
if (allowCycle) {
allowCycle = false;
i = 0;
//#debug
//# System.out.println("allowCycle: Restarting at the beginning");
} else {
break;
}
//#else
//# break;
//#endif
}
} else {
i--;
if (i < 0) {
//#if polish.Container.allowCycling != false
if (allowCycle) {
allowCycle = false;
i = this.items.length - 1;
//#debug
//# System.out.println("allowCycle: Restarting at the end");
} else {
break;
}
//#else
//# break;
//#endif
}
}
item = this.items[i];
if (item.appearanceMode != Item.PLAIN) {
break;
}
}
if (item == null || item.appearanceMode == Item.PLAIN || item == focItem) {
//#debug
//# System.out.println("got original focused item: " + (item == focItem) + ", item==null:" + (item == null) + ", mode==PLAIN:" + (item == null ? false:(item.appearanceMode == PLAIN)) );
return false;
}
int direction = Canvas.UP;
if (forwardFocus) {
direction = Canvas.DOWN;
}
focus(i, item, direction );
return true;
}
/**
* Retrieves the index of the item which is currently focused.
*
* @return the index of the focused item, -1 when none is focused.
*/
public int getFocusedIndex() {
return this.focusedIndex;
}
/**
* Retrieves the currently focused item.
*
* @return the currently focused item, null when there is no focusable item in this container.
*/
public Item getFocusedItem() {
return this.focusedItem;
}
/* (non-Javadoc)
* @see de.enough.polish.ui.Item#setStyle(de.enough.polish.ui.Style)
*/
public void setStyle(Style style) {
//#if polish.debug.debug
//# if (this.parent == null) {
//#debug
//# System.out.println("Container.setStyle without boolean parameter for container " + toString() );
//# }
//#endif
setStyle(style, false);
}
/**
* Sets the style of this container.
*
* @param style the style
* @param ignoreBackground when true is given, the background and border-settings
* will be ignored.
*/
public void setStyle( Style style, boolean ignoreBackground) {
super.setStyle(style);
if (ignoreBackground) {
this.background = null;
this.border = null;
this.borderWidth = 0;
this.marginTop = 0;
this.marginBottom = 0;
this.marginLeft = 0;
this.marginRight = 0;
}
//#if polish.css.focused-style
this.focusedTopMargin = this.focusedStyle.marginTop + this.focusedStyle.paddingTop;
if (this.focusedStyle.border != null) {
this.focusedTopMargin += this.focusedStyle.border.borderWidth;
}
if (this.focusedStyle.background != null) {
this.focusedTopMargin += this.focusedStyle.background.borderWidth;
}
//#endif
//#ifdef polish.css.view-type
// ContainerView viewType = (ContainerView) style.getObjectProperty("view-type");
// if (this instanceof ChoiceGroup) {
// System.out.println("SET.STYLE / CHOICEGROUP: found view-type (1): " + (viewType != null) + " for " + this);
// }
if (this.view != null) {
ContainerView viewType = (ContainerView) this.view; // (ContainerView) style.getObjectProperty(39);
this.containerView = viewType;
this.view = null; // set to null so that this container can control the view completely. This is necessary for scrolling, for example.
viewType.parentContainer = this;
viewType.focusFirstElement = this.autoFocusEnabled;
//#if polish.Container.allowCycling != false
viewType.allowCycling = this.allowCycling;
//#else
//# viewType.allowCycling = false;
//#endif
}
//#endif
//#ifdef polish.css.columns
if (this.containerView == null) {
Integer columns = style.getIntProperty(4);
if (columns != null) {
if (columns.intValue() > 1) {
//System.out.println("Container: Using default container view for displaying table");
this.containerView = new ContainerView();
this.containerView.parentContainer = this;
this.containerView.focusFirstElement = this.autoFocusEnabled;
//#if polish.Container.allowCycling != false
this.containerView.allowCycling = this.allowCycling;
//#else
//# this.containerView.allowCycling = false;
//#endif
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -