📄 choicegroup.java
字号:
//#condition polish.usePolishGui// generated by de.enough.doc2java.Doc2Java (www.enough.de) on Sat Dec 06 15:06:44 CET 2003/* * Copyright (c) 2004-2005 Robert Virkus / Enough Software * * This file is part of J2ME Polish. * * J2ME Polish is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * J2ME Polish is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with J2ME Polish; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Commercial licenses are also available, please * refer to the accompanying LICENSE.txt or visit * http://www.j2mepolish.org for details. */package de.enough.polish.ui;import javax.microedition.lcdui.*;import de.enough.polish.util.Locale;/** * A <code>ChoiceGroup</code> is a group of selectable elements intended to be * placed within a <CODE>Form</CODE>. The group may be created with a mode that requires a * single choice to be made or that allows multiple choices. The * implementation is responsible for providing the graphical representation of * these modes and must provide visually different graphics for different * modes. For example, it might use "radio buttons" for the * single choice * mode and "check boxes" for the multiple choice mode. * * <p> <strong>Note:</strong> most of the essential methods have been * specified in the <CODE>Choice</CODE> interface.</p> * <HR> * * @author Robert Virkus, robert@enough.de * @since MIDP 1.0 */public class ChoiceGroup extends Container implements Choice//#if polish.ChoiceGroup.suppressMarkCommands == true //#define tmp.suppressMarkCommands//#else //#define tmp.allowMarkCommands//#endif//#if polish.ChoiceGroup.suppressSelectCommand == true //#define tmp.suppressSelectCommand//#else //#define tmp.allowSelectCommand//#endif//#if tmp.suppressMarkCommands && tmp.suppressSelectCommand //#define tmp.suppressAllCommands//#else , ItemCommandListener//#endif{ //#ifndef tmp.suppressMarkCommands //#ifdef polish.i18n.useDynamicTranslations public static Command MARK_COMMAND = new Command( Locale.get("polish.command.mark"), Command.ITEM, 9 ); //#elifdef polish.command.mark:defined //#= public static final Command MARK_COMMAND = new Command("${polish.command.mark}", Command.ITEM, 9 ); //#else //# public static final Command MARK_COMMAND = new Command( "Mark", Command.ITEM, 9 ); //#endif //#ifdef polish.i18n.useDynamicTranslations public static Command UNMARK_COMMAND = new Command( Locale.get("polish.command.unmark"), Command.ITEM, 9 ); //#elifdef polish.command.mark:defined //#= public static final Command UNMARK_COMMAND = new Command("${polish.command.unmark}", Command.ITEM, 10 ); //#else //# public static final Command UNMARK_COMMAND = new Command( "Unmark", Command.ITEM, 10 ); //#endif //#endif private int selectedIndex; //private boolean isExclusive; private boolean isMultiple; private int choiceType; private boolean isImplicit; private Command selectCommand; //#ifdef polish.usePopupItem private static Image popupImage; private boolean isPopup; private int popupColor = 0; private int popupBackgroundColor = 0xFFFFFF; private IconItem popupItem; private boolean isPopupClosed; //private int popupOpenY; private int popupParentOpenY; private int originalContentWidth; private int originalContentHeight; //#endif //#ifndef tmp.suppressAllCommands private ItemCommandListener additionalItemCommandListener; //#endif //#if ! tmp.suppressSelectCommand && polish.css.view-type private boolean isSelectCommandAdded; //#endif //#if polish.css.view-type || polish.css.columns //#define tmp.supportViewType //#endif /** * Creates a new, empty <code>ChoiceGroup</code>, specifying its * title and its type. * The type must be one of <code>EXCLUSIVE</code>, * <code>MULTIPLE</code>, or <code>POPUP</code>. The * <code>IMPLICIT</code> * choice type is not allowed within a <code>ChoiceGroup</code>. * * @param label the item's label (see Item) * @param choiceType EXCLUSIVE, MULTIPLE, or POPUP * @throws IllegalArgumentException - if choiceType is not one of EXCLUSIVE, MULTIPLE, or POPUP * @see Choice#EXCLUSIVE * @see Choice#MULTIPLE * @see Choice#IMPLICIT * @see Choice#POPUP */ public ChoiceGroup( String label, int choiceType) { this( label, choiceType, new String[0], null, null, false ); } /** * Creates a new, empty <code>ChoiceGroup</code>, specifying its * title and its type. * The type must be one of <code>EXCLUSIVE</code>, * <code>MULTIPLE</code>, or <code>POPUP</code>. The * <code>IMPLICIT</code> * choice type is not allowed within a <code>ChoiceGroup</code>. * * @param label the item's label (see Item) * @param choiceType EXCLUSIVE, MULTIPLE, or POPUP * @param style the CSS style for this item * @throws IllegalArgumentException if choiceType is not one of EXCLUSIVE, MULTIPLE, or POPUP * @see Choice#EXCLUSIVE * @see Choice#MULTIPLE * @see Choice#IMPLICIT * @see Choice#POPUP */ public ChoiceGroup( String label, int choiceType, Style style) { this( label, choiceType, new String[0], null, style, false ); } /** * Creates a new <code>ChoiceGroup</code>, specifying its title, * the type of the * <code>ChoiceGroup</code>, and an array of <code>Strings</code> * and <code>Images</code> to be used as its * initial contents. * * <p>The type must be one of <code>EXCLUSIVE</code>, * <code>MULTIPLE</code>, or <code>POPUP</code>. The * <code>IMPLICIT</code> * type is not allowed for <code>ChoiceGroup</code>.</p> * * <p>The <code>stringElements</code> array must be non-null and * every array element * must also be non-null. The length of the * <code>stringElements</code> array * determines the number of elements in the <code>ChoiceGroup</code>. The * <code>imageElements</code> array * may be <code>null</code> to indicate that the * <code>ChoiceGroup</code> elements have no images. * If the * <code>imageElements</code> array is non-null, it must be the * same length as the * <code>stringElements</code> array. Individual elements of the * <code>imageElements</code> array * may be <code>null</code> in order to indicate the absence of an * image for the * corresponding <code>ChoiceGroup</code> element. Non-null elements * of the * <code>imageElements</code> array may refer to mutable or * immutable images.</p> * * @param label the item's label (see Item) * @param choiceType EXCLUSIVE, MULTIPLE, or POPUP * @param stringElements set of strings specifying the string parts of the ChoiceGroup elements * @param imageElements set of images specifying the image parts of the ChoiceGroup elements * @throws NullPointerException if stringElements is null or if the stringElements array contains any null elements * @throws IllegalArgumentException if the imageElements array is non-null and has a different length from the stringElements array * or if choiceType is not one of EXCLUSIVE, MULTIPLE, or POPUP * @see Choice#EXCLUSIVE * @see Choice#MULTIPLE * @see Choice#IMPLICIT * @see Choice#POPUP */ public ChoiceGroup( String label, int choiceType, String[] stringElements, Image[] imageElements) { this( label, choiceType, stringElements, imageElements, null, false ); } /** * Creates a new <code>ChoiceGroup</code>, specifying its title, * the type of the * <code>ChoiceGroup</code>, and an array of <code>Strings</code> * and <code>Images</code> to be used as its * initial contents. * * <p>The type must be one of <code>EXCLUSIVE</code>, * <code>MULTIPLE</code>, or <code>POPUP</code>. The * <code>IMPLICIT</code> * type is not allowed for <code>ChoiceGroup</code>.</p> * * <p>The <code>stringElements</code> array must be non-null and * every array element * must also be non-null. The length of the * <code>stringElements</code> array * determines the number of elements in the <code>ChoiceGroup</code>. The * <code>imageElements</code> array * may be <code>null</code> to indicate that the * <code>ChoiceGroup</code> elements have no images. * If the * <code>imageElements</code> array is non-null, it must be the * same length as the * <code>stringElements</code> array. Individual elements of the * <code>imageElements</code> array * may be <code>null</code> in order to indicate the absence of an * image for the * corresponding <code>ChoiceGroup</code> element. Non-null elements * of the * <code>imageElements</code> array may refer to mutable or * immutable images.</p> * * @param label the item's label (see Item) * @param choiceType EXCLUSIVE, MULTIPLE, or POPUP * @param stringElements set of strings specifying the string parts of the ChoiceGroup elements * @param imageElements set of images specifying the image parts of the ChoiceGroup elements * @param style The CSS style for this item * @throws NullPointerException if stringElements is null or if the stringElements array contains any null elements * @throws IllegalArgumentException if the imageElements array is non-null and has a different length from the stringElements array * or if choiceType is not one of EXCLUSIVE, MULTIPLE, or POPUP * @see Choice#EXCLUSIVE * @see Choice#MULTIPLE * @see Choice#IMPLICIT * @see Choice#POPUP */ public ChoiceGroup( String label, int choiceType, String[] stringElements, Image[] imageElements, Style style ) { this( label, choiceType, stringElements, imageElements, style, false ); } /** * Creates a new <code>ChoiceGroup</code>, specifying its title, * the type of the * <code>ChoiceGroup</code>, and an array of <code>Strings</code> * and <code>Images</code> to be used as its * initial contents. * * <p>The type must be one of <code>EXCLUSIVE</code>, * <code>MULTIPLE</code>, or <code>POPUP</code>. The * <code>IMPLICIT</code> * type is not allowed for <code>ChoiceGroup</code>.</p> * * <p>The <code>stringElements</code> array must be non-null and * every array element * must also be non-null. The length of the * <code>stringElements</code> array * determines the number of elements in the <code>ChoiceGroup</code>. The * <code>imageElements</code> array * may be <code>null</code> to indicate that the * <code>ChoiceGroup</code> elements have no images. * If the * <code>imageElements</code> array is non-null, it must be the * same length as the * <code>stringElements</code> array. Individual elements of the * <code>imageElements</code> array * may be <code>null</code> in order to indicate the absence of an * image for the * corresponding <code>ChoiceGroup</code> element. Non-null elements * of the * <code>imageElements</code> array may refer to mutable or * immutable images.</p> * * @param label the item's label (see Item) * @param choiceType EXCLUSIVE, MULTIPLE, or POPUP * @param stringElements set of strings specifying the string parts of the ChoiceGroup elements * @param imageElements set of images specifying the image parts of the ChoiceGroup elements * @param style The CSS style for this item * @param allowImplicit true when the Choice.IMPLICIT choiceType is also allowed * @throws NullPointerException if stringElements is null or if the stringElements array contains any null elements * @throws IllegalArgumentException if the imageElements array is non-null and has a different length from the stringElements array * or if choiceType is not one of EXCLUSIVE, MULTIPLE, or POPUP (unless allowImplicit is defined) * @see Choice#EXCLUSIVE * @see Choice#MULTIPLE * @see Choice#IMPLICIT * @see Choice#POPUP */ public ChoiceGroup( String label, int choiceType, String[] stringElements, Image[] imageElements, Style style, boolean allowImplicit ) { this( label, choiceType, buildChoiceItems(stringElements, imageElements, choiceType, style), style, allowImplicit ); } /** * Creates a new <code>ChoiceGroup</code>, specifying its title, * the type of the * <code>ChoiceGroup</code>, and an array of <code>ChoiceItem</code>s * to be used as its initial contents. * * <p>The type must be one of <code>EXCLUSIVE</code>, * <code>MULTIPLE</code>, or <code>POPUP</code>. The * <code>IMPLICIT</code> * type is not allowed for <code>ChoiceGroup</code>.</p> * * <p>The <code>items</code>s array must be non-null and * every <code>ChoiceItem</code> must have its text be a non-null * <code>String</code>. * The length of the <code>items</code> array * determines the number of elements in the <code>ChoiceGroup</code>.</p> * * @param label the item's label (see Item) * @param choiceType EXCLUSIVE, MULTIPLE, or POPUP * @param items set of <code>ChoiceItem</code>s specifying the ChoiceGroup elements * @throws NullPointerException if <code>items</code> is null * or if getText() for one of the <code>ChoiceItem</code> in the array * retuns a null <code>String</code>. * @throws IllegalArgumentException if choiceType is not one of EXCLUSIVE, MULTIPLE, or POPUP (unless allowImplicit is defined) * @see Choice#EXCLUSIVE * @see Choice#MULTIPLE * @see Choice#IMPLICIT * @see Choice#POPUP */ public ChoiceGroup( String label, int choiceType, ChoiceItem[] items) { this( label, choiceType, items, null, false ); } /** * Creates a new <code>ChoiceGroup</code>, specifying its title, * the type of the * <code>ChoiceGroup</code>, and an array of <code>ChoiceItem</code>s * to be used as its initial contents. * * <p>The type must be one of <code>EXCLUSIVE</code>, * <code>MULTIPLE</code>, or <code>POPUP</code>. The * <code>IMPLICIT</code> * type is not allowed for <code>ChoiceGroup</code>.</p> * * <p>The <code>items</code>s array must be non-null and * every <code>ChoiceItem</code> must have its text be a non-null * <code>String</code>. * The length of the <code>items</code> array * determines the number of elements in the <code>ChoiceGroup</code>.</p> * * @param label the item's label (see Item) * @param choiceType EXCLUSIVE, MULTIPLE, or POPUP * @param items set of <code>ChoiceItem</code>s specifying the ChoiceGroup elements * @param style The CSS style for this item * @throws NullPointerException if <code>items</code> is null * or if getText() for one of the <code>ChoiceItem</code> in the array * retuns a null <code>String</code>. * @throws IllegalArgumentException if choiceType is not one of EXCLUSIVE, MULTIPLE, or POPUP (unless allowImplicit is defined) * @see Choice#EXCLUSIVE * @see Choice#MULTIPLE * @see Choice#IMPLICIT * @see Choice#POPUP */ public ChoiceGroup( String label, int choiceType, ChoiceItem[] items, Style style ) { this( label, choiceType, items, style, false ); } /** * Creates a new <code>ChoiceGroup</code>, specifying its title, * the type of the * <code>ChoiceGroup</code>, and an array of <code>ChoiceItem</code>s * to be used as its initial contents. * * <p>The type must be one of <code>EXCLUSIVE</code>, * <code>MULTIPLE</code>, or <code>POPUP</code>. The * <code>IMPLICIT</code> * type is not allowed for <code>ChoiceGroup</code>.</p> * * <p>The <code>items</code>s array must be non-null and * every <code>ChoiceItem</code> must have its text be a non-null * <code>String</code>. * The length of the <code>items</code> array * determines the number of elements in the <code>ChoiceGroup</code>.</p> * * @param label the item's label (see Item) * @param choiceType EXCLUSIVE, MULTIPLE, or POPUP * @param items set of <code>ChoiceItem</code>s specifying the ChoiceGroup elements * @param style The CSS style for this item * @param allowImplicit true when the Choice.IMPLICIT choiceType is also allowed * @throws NullPointerException if <code>items</code> is null * or if getText() for one of the <code>ChoiceItem</code> in the array * retuns a null <code>String</code>. * @throws IllegalArgumentException if choiceType is not one of EXCLUSIVE, MULTIPLE, or POPUP (unless allowImplicit is defined) * @see Choice#EXCLUSIVE * @see Choice#MULTIPLE * @see Choice#IMPLICIT * @see Choice#POPUP */ public ChoiceGroup( String label, int choiceType, ChoiceItem[] items, Style style, boolean allowImplicit ) { super( label, false, style, -1, -1 ); if (choiceType == Choice.EXCLUSIVE) { //this.isExclusive = true; } else if (choiceType == Choice.MULTIPLE) { this.isMultiple = true; //#ifdef polish.usePopupItem } else if (choiceType == Choice.POPUP) { this.isPopup = true; this.isPopupClosed = true; this.popupItem = new IconItem( null, null, style ); this.popupItem.setImageAlign( Graphics.RIGHT ); this.popupItem.setAppearanceMode( BUTTON ); this.popupItem.parent = this; //#endif } else if (choiceType == Choice.IMPLICIT && allowImplicit ) { this.isImplicit = true; this.autoFocusEnabled = true; } else { //#ifdef polish.verboseDebug
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -