⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 container.java

📁 j2me is based on j2mepolish, client & server for mobile application. menu sample
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			}
		//#endif

		//#if polish.css.scroll-mode
			//# Integer scrollModeInt = style.getIntProperty(85);
			//# if ( scrollModeInt != null ) {
				//# this.scrollSmooth = (scrollModeInt.intValue() == SCROLL_SMOOTH);
			//# }
		//#endif	
		//#ifdef tmp.supportViewType
			if (this.containerView != null) {
				this.containerView.setStyle(style);
			}
		//#endif
	}

	/**
	 * Parses the given URL and includes the index of the item, when there is an "%INDEX%" within the given url.
	 * @param url the resource URL which might include the substring "%INDEX%"
	 * @param item the item to which the URL belongs to. The item must be 
	 * 		  included in this container.
	 * @return the URL in which the %INDEX% is substituted by the index of the
	 * 		   item in this container. The url "icon%INDEX%.png" is resolved
	 * 		   to "icon1.png" when the item is the second item in this container.
	 * @throws NullPointerException when the given url or item is null
	 */
	public String parseIndexUrl(String url, Item item) {
		int pos = url.indexOf("%INDEX%");
		if (pos != -1) {
			int index = this.itemsList.indexOf( item );
			//TODO rob check if valid, when url ends with %INDEX%
			url = url.substring(0, pos) + index + url.substring( pos + 7 );
		}
		return url;
	}
	/**
	 * 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.containerView != null) {
					this.containerView.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.containerView != null && this.containerView.allowsAutoTraversal) {
			//#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(3);
					//# 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 );
			//#ifdef tmp.supportViewType
				if (this.containerView != null && originalStyle != null) {
					this.containerView.defocus( originalStyle );
					this.isInitialized = 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(3);
				//# }
				//# 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
			if (this.availableHeight != -1 && Math.abs(target - current) > this.availableHeight) {
				// maximally scroll one page:
				if (current < target) {
					current = target - this.availableHeight;
				} else {
					current = target + this.availableHeight;
				}
			}
			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.containerView != null ) {
				animated |= this.containerView.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.containerView != null) {
				this.containerView.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.containerView != null) {
				this.containerView.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 relX, int relY) {
		//# //System.out.println("Container.handlePointerPressed( x=" + x + ", y=" + y + "): adjustedY=" + (y - (this.yOffset  + this.marginTop + this.paddingTop )) );
		//# // an item within this container was selected:
		//# relY -= this.yOffset;
		//# 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(relX - (this.contentX + item.relativeX), relY - ( this.contentY + item.relativeY) );
			//# if (processed) {
				//#debug
				//# System.out.println("pointer event at " + relX + "," + relY + " consumed by focusedItem.");
				//# return true;
			//# }
		//# }
		//# if (!isInContentArea(relX, relY + this.yOffset)) {
			//# //System.out.println("Container.handlePointerPressed(): out of range, xLeft=" + this.xLeftPos + ", xRight="  + this.xRightPos + ", contentHeight=" + this.contentHeight );
			//# return false;
		//# }
		//# relX -= this.contentX;
		//# relY -= this.contentY;
		//#ifdef tmp.supportViewType
			//# if (this.containerView != null) {
				//# if ( this.containerView.handlePointerPressed(relX,relY) ) {
					//# return true;
				//# }
			//# }
		//#endif
		//# Item[] myItems = getItems();
		//# int itemRelX, itemRelY;
		//# for (int i = 0; i < myItems.length; i++) {
			//# item = myItems[i];
			//# itemRelX = relX - item.relativeX;
			//# itemRelY = relY - item.relativeY;
			//# if ( i == this.focusedIndex || (item.appearanceMode == Item.PLAIN) || !item.isInItemArea(itemRelX, itemRelY)) {
				//# // this item is not in the range or not suitable:
				//# continue;
			//# }
			//# // the pressed item has been found:
			//#debug
			//# System.out.println("Container.handlePointerPressed(" + relX + "," + relY + "): found item " + i + "=" + item + " at relative " + itemRelX + "," + itemRelY + ", itemHeight=" + item.itemHeight);
			//# // 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( itemRel

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -