📄 container.java
字号:
* Retrieves the position of the specified item. * * @param item the item * @return the position of the item, or -1 when it is not defined */ public int getPosition( Item item ) { return this.itemsList.indexOf( item ); } /* (non-Javadoc) * @see de.enough.polish.ui.Item#focus(de.enough.polish.ui.Style, int) */ protected Style focus(Style focusstyle, int direction ) { //#if polish.css.include-label if ( this.includeLabel || this.itemsList.size() == 0) { //#else //# if ( this.itemsList.size() == 0) { //#endif return super.focus( this.focusedStyle, direction ); } else { if (this.focusedStyle != null) { focusstyle = this.focusedStyle; } //#if tmp.supportViewType if (this.view != null) { this.view.focus(focusstyle, direction); //this.isInitialised = false; not required } //#endif this.isFocused = true; int newFocusIndex = this.focusedIndex; //if (this.focusedIndex == -1) { //#if tmp.supportViewType if (this.view != null && false) { //#endif Item[] myItems = getItems(); // focus the first interactive item... if (direction == Canvas.UP || direction == Canvas.LEFT ) { //System.out.println("Container: direction UP with " + myItems.length + " items"); for (int i = myItems.length; --i >= 0; ) { Item item = myItems[i]; if (item.appearanceMode != PLAIN) { newFocusIndex = i; break; } } } else { //System.out.println("Container: direction DOWN"); for (int i = 0; i < myItems.length; i++) { Item item = myItems[i]; if (item.appearanceMode != PLAIN) { newFocusIndex = i; break; } } } this.focusedIndex = newFocusIndex; if (newFocusIndex == -1) { //System.out.println("DID NOT FIND SUITEABLE ITEM"); // this container has only non-focusable items! return super.focus( this.focusedStyle, direction ); } //} //#if tmp.supportViewType } else if (this.focusedIndex == -1) { Item[] myItems = getItems(); //System.out.println("Container: direction DOWN through view type " + this.view); for (int i = 0; i < myItems.length; i++) { Item item = myItems[i]; if (item.appearanceMode != PLAIN) { newFocusIndex = i; break; } } this.focusedIndex = newFocusIndex; if (newFocusIndex == -1) { //System.out.println("DID NOT FIND SUITEABLE ITEM"); // this container has only non-focusable items! return super.focus( this.focusedStyle, direction ); } } //#endif Item item = (Item) this.itemsList.get( this.focusedIndex );// Style previousStyle = item.style;// if (previousStyle == null) {// previousStyle = StyleSheet.defaultStyle;// } focus( this.focusedIndex, item, direction ); if (item.commands == null && this.commands != null) { Screen scr = getScreen(); if (scr != null) { scr.setItemCommands(this); } } // change the label-style of this container: //#ifdef polish.css.label-style if (this.label != null) { Style labStyle = (Style) focusstyle.getObjectProperty("label-style"); if (labStyle != null) { this.labelStyle = this.label.style; this.label.setStyle( labStyle ); } } //#endif return this.style; } } /* (non-Javadoc) * @see de.enough.polish.ui.Item#defocus(de.enough.polish.ui.Style) */ public void defocus(Style originalStyle) { //#if polish.css.include-label if ( this.includeLabel || this.itemsList.size() == 0 || this.focusedIndex == -1) { //#else //# if ( this.itemsList.size() == 0 || this.focusedIndex == -1) { //#endif super.defocus( originalStyle ); } else { this.isFocused = false; Item item = this.focusedItem; //(Item) this.itemsList.get( this.focusedIndex ); item.defocus( this.itemStyle ); //#if tmp.supportViewType// if (this.view != null) {// //this.view.defocus( this.itemStyle );// this.isInitialised = false;// } //#endif this.isFocused = false; // now remove any commands which are associated with this item: if (item.commands == null && this.commands != null) { Screen scr = getScreen(); if (scr != null) { scr.removeItemCommands(this); } } // change the label-style of this container: //#ifdef polish.css.label-style Style tmpLabelStyle = null; if ( originalStyle != null) { tmpLabelStyle = (Style) originalStyle.getObjectProperty("label-style"); } if (tmpLabelStyle == null) { tmpLabelStyle = StyleSheet.labelStyle; } if (this.label != null && tmpLabelStyle != null && this.label.style != tmpLabelStyle) { this.label.setStyle( tmpLabelStyle ); } //#endif } } /* (non-Javadoc) * @see de.enough.polish.ui.Item#animate() */ public boolean animate() { boolean animated = false; // scroll the container: int target = this.targetYOffset; int current = this.yOffset; //#if polish.css.scroll-mode if (this.scrollSmooth && target != current ) { //#else //# if (target != current) { //#endif int speed = (target - current) / 3; speed += target > current ? 1 : -1; current += speed; if ( ( speed > 0 && current > target) || (speed < 0 && current < target ) ) { current = target; } this.yOffset = current;// if (this.focusedItem != null && this.focusedItem.backgroundYOffset != 0) {// this.focusedItem.backgroundYOffset = (this.targetYOffset - this.yOffset);// } // # debug //System.out.println("animate(): adjusting yOffset to " + this.yOffset ); animated = true; } if (this.background != null) { animated |= this.background.animate(); } if (this.focusedItem != null) { animated |= this.focusedItem.animate(); } //#ifdef tmp.supportViewType if ( this.view != null ) { animated |= this.view.animate(); } //#endif return animated; } /** * Called by the system to notify the item that it is now at least * partially visible, when it previously had been completely invisible. * The item may receive <code>paint()</code> calls after * <code>showNotify()</code> has been called. * * <p>The container implementation calls showNotify() on the embedded items.</p> */ protected void showNotify() { if (this.style != null && !this.isStyleInitialised) { setStyle( this.style ); } //#ifdef polish.useDynamicStyles else if (this.style == null) { initStyle(); } //#else else if (this.style == null && !this.isStyleInitialised) { //#debug System.out.println("Setting default style for container " + this ); setStyle( StyleSheet.defaultStyle ); } //#endif //#ifdef tmp.supportViewType if (this.view != null) { this.view.showNotify(); } //#endif Item[] myItems = getItems(); for (int i = 0; i < myItems.length; i++) { Item item = myItems[i]; if (item.style != null && !item.isStyleInitialised) { item.setStyle( item.style ); } //#ifdef polish.useDynamicStyles else if (item.style == null) { initStyle(); } //#else else if (item.style == null && !item.isStyleInitialised) { //#debug System.out.println("Setting default style for item " + item ); item.setStyle( StyleSheet.defaultStyle ); } //#endif item.showNotify(); } } /** * Called by the system to notify the item that it is now completely * invisible, when it previously had been at least partially visible. No * further <code>paint()</code> calls will be made on this item * until after a <code>showNotify()</code> has been called again. * * <p>The container implementation calls hideNotify() on the embedded items.</p> */ protected void hideNotify() { //#ifdef tmp.supportViewType if (this.view != null) { this.view.hideNotify(); } //#endif Item[] myItems = getItems(); for (int i = 0; i < myItems.length; i++) { Item item = myItems[i]; item.hideNotify(); } } //#ifdef polish.hasPointerEvents /* (non-Javadoc) * @see de.enough.polish.ui.Item#handlePointerPressed(int, int) */ protected boolean handlePointerPressed(int x, int y) { //System.out.println("Container.handlePointerPressed( x=" + x + ", y=" + y + "): adjustedY=" + (y - (this.yOffset + this.marginTop + this.paddingTop )) ); // an item within this container was selected: int labelHeight = 0; if (this.label != null) { labelHeight = this.label.itemHeight; // TODO: what if the label is on the same line??? } y -= this.yOffset + this.marginTop + this.paddingTop + labelHeight;// int lastYPos = this.yBottomPos;// if ( myItems.length != 0) {// Item lastItem = myItems[ myItems.length - 1];// if ( lastItem.backgroundHeight > lastItem.itemHeight ) {// lastYPos += (lastItem.backgroundHeight - lastItem.itemHeight);// }// } Item item = this.focusedItem; if (item != null) { // the focused item can extend the parent container, e.g. subcommands, // so give it a change to process the event itself: boolean processed = item.handlePointerPressed(x, y - item.yTopPos); if (processed) { return true; } } if (y < 0 || y > this.contentHeight || x < this.xLeftPos || x > this.xRightPos) { //System.out.println("Container.handlePointerPressed(): out of range, xLeft=" + this.xLeftPos + ", xRight=" + this.xRightPos + ", contentHeight=" + this.contentHeight ); return false; } //#ifdef tmp.supportViewType if (this.view != null) { if ( this.view.handlePointerPressed(x,y) ) { return true; } } //#endif Item[] myItems = getItems(); for (int i = 0; i < myItems.length; i++) { item = myItems[i]; if (y < item.yTopPos || y > item.yBottomPos || x < item.xLeftPos || x > item.xRightPos) { // check for internal positions (e.g. POPUP choice groups can be over this area): if ( item.backgroundHeight > item.itemHeight ) { if ( y > item.yTopPos + item.backgroundHeight && x > item.xLeftPos + item.backgroundWidth ) { //System.out.println("itemOutOfRange(" + i + "): yTop=" + item.yTopPos + ", bottom=" + item.yBottomPos + ", left=" + item.xLeftPos + ", right=" + item.xRightPos ); continue; } } else { // this item is not in the range: //System.out.println("itemOutOfRange(" + i + "): yTop=" + item.yTopPos + ", bottom=" + item.yBottomPos + ", left=" + item.xLeftPos + ", right=" + item.xRightPos ); continue; } } // the pressed item has been found: //#debug System.out.println("Container.keyPressed(): found item " + i + "=" + item); if ((item.appearanceMode != Item.PLAIN) && (i != this.focusedIndex)) { // only focus the item when it has not been focused already: focus(i, item, 0); // let the item also handle the pointer-pressing event: item.handlePointerPressed( x , y - item.yTopPos ); /* if (!item.handlePointerPressed( x , y )) { // simulate a FIRE keypress event: //handleKeyPressed( -1, Canvas.FIRE ); }*/ return true; // } else { // outcommented, because the focused item already has tried to handle the event above... //return item.handlePointerPressed( x , y ); //|| item.handleKeyPressed( -1, Canvas.FIRE ) ); } } return false; } //#endif /** * Moves the focus away from the specified item. * * @param item the item that currently has the focus */ public void requestDefocus( Item item ) { if (item == this.focusedItem) { boolean success = shiftFocus(true, 1); if (!success) { defocus(this.itemStyle); } } } /** * Requests the initialization of this container and all of its children items. */ public void requestFullInit() { requestInit(); for (int i = 0; i < this.itemsList.size(); i++) { Item item = (Item) this.itemsList.get(i); item.isInitialised = false; } }//#ifdef polish.Container.additionalMethods:defined //#include ${polish.Container.additionalMethods}//#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -