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

📄 container.java

📁 j2me polish学习的经典代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			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(39);
//# //			if (this instanceof ChoiceGroup) {
//# //				System.out.println("SET.STYLE / CHOICEGROUP: found view-type (1): " + (viewType != null) + " for " + this);
//# //			}
			//# if (viewType != null) {
				//# if (this.view != null && this.view.getClass() == viewType.getClass()) {
					//# this.view.focusFirstElement = this.autoFocusEnabled;
					//# //System.out.println("SET.STYLE / CHOICEGROUP: found OLD view-type (2): " + viewType + " for " + this);
				//# } else {
					//# //System.out.println("SET.STYLE / CHOICEGROUP: found new view-type (2): " + viewType + " for " + this);
					//# try {
						//# if (viewType.parentContainer != null) {
							//# viewType = (ContainerView) viewType.getClass().newInstance();
						//# }
						//# viewType.parentContainer = this;
						//# viewType.focusFirstElement = this.autoFocusEnabled;
						//#if polish.Container.allowCycling != false
							//# viewType.allowCycling = this.allowCycling;
						//#else
							//# viewType.allowCycling = false;
						//#endif
						//# this.view = viewType;
					//# } catch (Exception e) {
						//#debug error
						//# System.out.println("Container: Unable to init view-type " + e );
						//# viewType = null;
					//# }
				//# }
			//# }
		//#endif
		//#ifdef polish.css.columns
			//# if (this.view == 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.view = new ContainerView();  
						//# this.view.parentContainer = this;
						//# this.view.focusFirstElement = this.autoFocusEnabled;
						//#if polish.Container.allowCycling != false
							//# this.view.allowCycling = this.allowCycling;
						//#else
							//# this.view.allowCycling = false;
						//#endif
					//# }
				//# }
			//# }
		//#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.view != null) {
				//# this.view.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.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(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 );
			//#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(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
			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)

⌨️ 快捷键说明

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