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

📄 choicegroup.java

📁 j2me polish学习的经典代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
					//# {
						//# notifyStateChanged();
					//# }
					//# if (this.isImplicit) {
						//# // call command listener:
						//# Screen scr = getScreen();
						//# if (scr != null) {
							//# Command selectCmd = this.selectCommand;
							//# if (selectCmd == null) {
								//# selectCmd = List.SELECT_COMMAND;
							//# }
							//# scr.callCommandListener( selectCmd );
						//# }
					//# }
					//# return true;
				//# }
			//#endif
			//# }
		//# }
		//#endif
		return processed;
	}
	
	//#ifdef polish.hasPointerEvents
	//# /* (non-Javadoc)
	 //# * @see de.enough.polish.ui.Item#handlePointerPressed(int, int)
	 //# */
	//# protected boolean handlePointerPressed(int x, int y) {
		//#debug
		//# System.out.println("ChoiceGroup.handlePointerPressed(" + x + ", " + y + ")");
		//#ifndef polish.usePopupItem
			//# boolean processed = super.handlePointerPressed(x, y);
			//# 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;
			//# if (this.focusedItem != null 
					//# && ( x >= this.focusedItem.xLeftPos ) 
					//# && ( x <= this.focusedItem.xRightPos ) 
					//# && ( y >= this.focusedItem.yTopPos ) 
					//# && ( y <= this.focusedItem.yBottomPos ) ) 
			//# {
				//# return handleKeyPressed( -1, Canvas.FIRE ) || processed;
			//# }
			//# return processed;
		//#else
			//# if (!this.isPopup) {
				//# super.handlePointerPressed(x, y);
				//# return handleKeyPressed( -1, Canvas.FIRE ); 
			//# }
			//# // this is a popup-item:
			//# if (this.isPopupClosed) {
				//# focus( this.selectedIndex );
				//# this.isPopupClosed = false;
			//# } else {
				//# y -= this.yOffset + this.marginTop + this.paddingTop;
				//# // select item at x,y and close this popup:
				//# // an item within this container was selected:
				//# Item[] myItems = getItems();
				//# for (int i = 0; i < myItems.length; i++) {
					//# Item item = myItems[i];
					//# if (y < item.yTopPos  || y > item.yBottomPos || x < item.xLeftPos || x > item.xRightPos) {
						//# // this item is not in the range:
						//# continue;
					//# }
					//# // found out the item:
					//# setSelectedIndex(i, true);
					//# if ( getScreen() instanceof Form) {
						//# notifyStateChanged();
					//# }
					//# break;
				//# }
				//# closePopup();
			//# }
			//# requestInit();
			//# return true;
		//#endif
	//# }	
	//#endif

	/**
	 * Sets the select command for this choice group.
	 *
	 * @param command the new select command
	 */
	protected void setSelectCommand(Command command) {
		this.selectCommand = command;
	}
	
	
	//#ifndef tmp.suppressAllCommands
	/**
	 * Sets the command for selecting this (and opening this POPUP) choicegroup.
	 * This implementation only works like described when not all ChoiceGroup command are deactivated
	 * by specifying the <variable name="polish.ChoiceGroup.suppressMarkCommands" value="true"/>
	 * and <variable name="polish.ChoiceGroup.suppressSelectCommand" value="true"/>
	 * preprocessing variables. When all commands are deactivated by the mentioned preprocessing variables,
	 * the implementation of Item is used instead.
	 * 
	 * @param cmd the new command for selecting this choice group
	 */
	public void setDefaultCommand(Command cmd) {
		if (this.choiceType == MULTIPLE) {
			//#ifndef tmp.suppressMarkCommands
				removeCommand( MARK_COMMAND );
			//#endif
		} else {
			//#ifndef tmp.suppressSelectCommand
				removeCommand( List.SELECT_COMMAND );
				if (this.selectCommand != null) {
					removeCommand( this.selectCommand );
				}
			//#endif
		}
		if (this.additionalItemCommandListener == null) {
			this.additionalItemCommandListener = this.itemCommandListener;
		}
		addCommand( cmd );
		this.selectCommand = cmd;
		this.defaultCommand = cmd;
		this.itemCommandListener = this;
	}
	//#endif
	
	//#ifdef polish.usePopupItem
	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#defocus(de.enough.polish.ui.Style)
	 */
	public void defocus(Style originalStyle) {
		if (this.isPopup) {
			if (this.isPopupClosed) {
				this.popupItem.setStyle( originalStyle );
			} else {
				this.isPopupClosed = true;
				requestInit();
			}
			setStyle( originalStyle );
			// now remove any commands which are associated with this item:
			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
		} else {
			super.defocus(originalStyle);
		}
	}
	//#endif

	//#ifdef polish.usePopupItem	
	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#focus(de.enough.polish.ui.Style, int)
	 */
	protected Style focus(Style focusStyle, int direction) {
		if (this.isPopup && this.isPopupClosed) {
			if (this.focusedStyle != null) {
				focusStyle = this.focusedStyle;
			}
			Style original = this.style;
			this.popupItem.setStyle( focusStyle );
			setStyle( focusStyle );
			// now remove any commands which are associated with this item:
			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 original;
		} else {
			return super.focus(focusStyle, direction);
		}
	}
	//#endif

	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Container#setStyle(de.enough.polish.ui.Style, boolean)
	 */
	public void setStyle(Style style, boolean ignoreBackground) {
		super.setStyle(style, ignoreBackground);
		//#ifdef polish.usePopupItem
			if (this.isPopup && this.popupItem != null) {
				this.popupItem.setStyle( style );
			}
			if (this.isPopup && this.popupItem.image == null ) {
				//#ifdef polish.css.popup-image
					//# String url = style.getProperty(13);
					//# if (url != null ) {
						//# this.popupItem.setImage( url );
					//# }
				//#endif
				//#ifdef polish.css.popup-color
					//# Integer color = style.getIntProperty(14);
					//# if (color != null) {
						//# this.popupColor = color.intValue();
					//# }
				//#endif
				//#ifdef polish.css.popup-background-color
					//# Integer bgColor = style.getIntProperty(15);
					//# if (bgColor != null) {
						//# this.popupBackgroundColor = bgColor.intValue();
					//# }
				//#endif
				//#if ! tmp.suppressSelectCommand && polish.css.view-type
					//# if (!this.isSelectCommandAdded && this.choiceType == EXCLUSIVE && this.view == null) {
						//# if (this.selectCommand != null) {
							//# addCommand( this.selectCommand );
						//# } else {
							//# addCommand( List.SELECT_COMMAND );
						//# }
						//# this.isSelectCommandAdded = true;				
					//# }
				//#endif
			}
		//#endif
		//#ifndef tmp.suppressAllCommands
		if (this.choiceType == MULTIPLE) {
			//#ifndef tmp.suppressMarkCommands
				//#ifdef polish.i18n.useDynamicTranslations
					//# String cmdLabel = "Mark";
					//# if (cmdLabel != MARK_COMMAND.getLabel()) {
						//# MARK_COMMAND = new Command( cmdLabel, Command.ITEM, 9 );
					//# }
					//# cmdLabel = "Unmark";
					//# if (cmdLabel != UNMARK_COMMAND.getLabel()) {
						//# UNMARK_COMMAND = new Command( cmdLabel, Command.ITEM, 10 );
					//# }
				//#endif					
				addCommand( MARK_COMMAND );
				addCommand( UNMARK_COMMAND );
			//#endif
		} else if (this.choiceType == EXCLUSIVE){
			//#if !tmp.suppressSelectCommand
				//#if polish.css.view-type
					//# if (this.view == null) {
				//#endif
					//#ifdef polish.i18n.useDynamicTranslations
						//# String cmdLabel = "Select";
						//# if (cmdLabel != List.SELECT_COMMAND.getLabel()) {
							//# List.SELECT_COMMAND = new Command( cmdLabel, Command.ITEM, 3 );
						//# }
					//#endif
					addCommand( List.SELECT_COMMAND );
				//#if polish.css.view-type
					//# }
				//#endif
			//#endif
		}
		this.itemCommandListener = this;
	//#endif
	}

	//#ifndef tmp.suppressAllCommands
	/* (non-Javadoc)
	 * @see de.enough.polish.ui.ItemCommandListener#commandAction(javax.microedition.lcdui.Command, de.enough.polish.ui.Item)
	 */
	public void commandAction(Command c, Item item) {
		//#if tmp.allowSelectCommand && tmp.allowMarkCommands
		if (c == List.SELECT_COMMAND || c == MARK_COMMAND || c == this.selectCommand  ) {
		//#elif tmp.allowSelectCommand
			//# if (c == List.SELECT_COMMAND || c == this.selectCommand ) {
		//#elif tmp.allowMarkCommands
			//# if (c == MARK_COMMAND || c == this.selectCommand ) {
		//#else
			//#abort Invalid combination of suppressed commands for a ChoiceGroup!
			//# if (false) {
		//#endif
			if (this.focusedIndex != -1) {
				setSelectedIndex( this.focusedIndex, true );
				if ( (this.choiceType != IMPLICIT) 
						//#ifdef polish.usePopupItem
						&& !(this.isPopup && !this.isPopupClosed)
						//#endif
						&& (this.getScreen() instanceof Form) ) {
					notifyStateChanged();
				}
				//#ifdef polish.usePopupItem
					if (this.isPopup) {
						if (this.isPopupClosed) {
							openPopup();
						} else {
							closePopup();
						}
						repaint();
					}
				//#endif
			}
			//#ifdef polish.usePopupItem
				else if (this.isPopup && this.isPopupClosed) {
					openPopup();				
				}
			//#endif
		//#ifdef tmp.allowMarkCommands
		} else if (c == UNMARK_COMMAND ) {
			if (this.focusedIndex != -1) {
				setSelectedIndex( this.focusedIndex, false );
				if ( (this.choiceType != IMPLICIT) 
						//#ifdef polish.usePopupItem
						&& !(this.isPopup && !this.isPopupClosed)
						//#endif
						&& (this.getScreen() instanceof Form) ) {
					notifyStateChanged();
				}
			}
		//#endif
		} else if (this.additionalItemCommandListener != null) {
			this.additionalItemCommandListener.commandAction(c, item);
		}
	}
	//#endif
	
	//#ifndef tmp.suppressAllCommands
	public void setItemCommandListener(ItemCommandListener l) {
		this.additionalItemCommandListener = l;
	}
	//#endif


}

⌨️ 快捷键说明

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