choicegrouplfimpl.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 621 行 · 第 1/2 页
JAVA
621 行
* is selected or not. * @param elementNum the index of an element in question * @return true if the element is selected, false - otherwise */ public boolean lIsSelected(int elementNum) { if (nativeId == DisplayableLFImpl.INVALID_NATIVE_ID) { return cg.cgElements[elementNum].selected; } return isSelected0(nativeId, elementNum); } // ***************************************************** // Package private methods // ***************************************************** /** * Called by event delivery to notify an ItemLF in current FormLF * of a change in its peer state. * * @param hint index of the element whose selection status has changed * @return always true so ItemStateListener should be notified */ boolean uCallPeerStateChanged(int hint) { // Any hint means selection has change // For types other than IMPLICIT List, notify itemStateListener. if (cg.choiceType != Choice.IMPLICIT) { return true; // notify itemStateListener } // For IMPLICIT List, notify commandListener List list; CommandListener cl; Command cmd; synchronized (Display.LCDUILock) { list = (List)cg.owner; if (list.listener == null || list.selectCommand == null || cg.numOfEls == 0) { return false; // No itemStateListener to notify } cl = list.listener; cmd = list.selectCommand; } try { synchronized (Display.calloutLock) { cl.commandAction(cmd, list); } } catch (Throwable thr) { Display.handleThrowable(thr); } return false; // No itemStateListener to notify } /** * Determine if this Item should have a newline after it * * @return true if it should have a newline after */ boolean equateNLA() { if (super.equateNLA()) { return true; } return ((cg.layout & Item.LAYOUT_2) != Item.LAYOUT_2); } /** * Determine if this Item should have a newline before it * * @return true if it should have a newline before */ boolean equateNLB() { if (super.equateNLB()) { return true; } return ((cg.layout & Item.LAYOUT_2) != Item.LAYOUT_2); } /** /** * Override <code>ItemLFImpl</code> method to sync with native resource * before hiding the native resource. Selection of native resource will * be preserved before the resource is hidden. */ void lHideNativeResource() { // sync selected flags and selectedIndex // before any visible native resource is deleted. if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) { syncSelectedIndex(); syncSelectedFlags(); } // Hide native resource super.lHideNativeResource(); } /** * Creates and sets native resource for current ChoiceGroup. * Override function in ItemLFImpl. * @param ownerId Owner screen's native resource id */ void createNativeResource(int ownerId) { nativeId = createNativeResource0(ownerId, cg.label, (cg.owner instanceof List ? -1 : cg.layout), cg.choiceType, cg.fitPolicy, cg.cgElements, cg.numOfEls, selectedIndex); } // ***************************************************** // Private methods // ***************************************************** /** * Read and save user selection from native resource. */ private void syncSelectedIndex() { if (cg.choiceType != Choice.MULTIPLE) { int newSelectedIndex = getSelectedIndex0(nativeId); if (selectedIndex != newSelectedIndex) { if (selectedIndex != -1) { cg.cgElements[selectedIndex].setSelected(false); } selectedIndex = newSelectedIndex; if (selectedIndex != -1) { cg.cgElements[selectedIndex].setSelected(true); } } } } /** * Read and save user selection from native resource. */ private void syncSelectedFlags() { if (cg.numOfEls > 0 && cg.choiceType == Choice.MULTIPLE) { boolean[] selectedArray_return = new boolean[cg.numOfEls]; getSelectedFlags0(nativeId, selectedArray_return, cg.numOfEls); for (int i = 0; i < cg.numOfEls; i++) { cg.cgElements[i].setSelected(selectedArray_return[i]); } } } /** * KNI function that creates native resource for current ChoiceGroup. * @param ownerId Owner screen's native resource id (MidpDisplayable *) * @param label string to be used as label for this ChoiceGroup * @param layout layout directive associated with this <code>Item</code> * @param choiceType should be EXCLUSIVE, MULTIPLE, IMPLICIT, POPUP * @param fitPolicy should be TEXT_WRAP_DEFAULT, TEXT_WRAP_ON, or * TEXT_WRAP_OFF * @param cgElements array of CGElement that stores such data as * image, text, font, selection state per element * @param numChoices number of valid elements in cgElements array * @param selectedIndex index of a currently selected element * (has no meaning for MULTIPLE ChoiceGroup) * @return native resource id (MidpItem *) of this ChoiceGroup */ private native int createNativeResource0(int ownerId, String label, int layout, int choiceType, int fitPolicy, CGElement []cgElements, int numChoices, int selectedIndex); /** * KNI function that notifies native resource of a new element * inserted prior to the element specified * * @param nativeId native resource id (MidpItem *) of this ChoiceGroup * @param elementNum the index of an element where insertion is to occur * @param stringPart the string part of the element to be inserted * @param imagePart the image part of the element to be inserted * @param selected the selected state of the element to be inserted */ private native void insert0(int nativeId, int elementNum, String stringPart, ImageData imagePart, boolean selected); /** * KNI function that notifies native resource of a specified element * being deleted in the corresponding ChoiceGroup. * * @param nativeId native resource id (MidpItem *) of this ChoiceGroup * @param elementNum the index of an element to be deleted * @param selectedIndex the index of an element to be selected after the * deletion is done (has no meaning for MULTIPLE ChoiceGroup) */ private native void delete0(int nativeId, int elementNum, int selectedIndex); /** * KNI function that notifies native resource that all elements were * deleted in the corresponding ChoiceGroup. * * @param nativeId native resource id (MidpItem *) of this ChoiceGroup */ private native void deleteAll0(int nativeId); /** * KNI function that notifies native resource of a specified element * being set in the corresponding ChoiceGroup. * * @param nativeId native resource id (MidpItem *) of this ChoiceGroup * @param elementNum the index of an element to be set * @param stringPart the string part of the element to be set * @param imagePart the image part of the element to be set * @param selected the selected state of the element to be set */ private native void set0(int nativeId, int elementNum, String stringPart, ImageData imagePart, boolean selected); /** * KNI function that notifies native resource of an element's new selected * state in the corresponding ChoiceGroup. * * @param nativeId native resource id (MidpItem *) of this ChoiceGroup * @param elementNum the index of an element which selected state changed * @param selected the new selected state */ private native void setSelectedIndex0(int nativeId, int elementNum, boolean selected); /** * KNI function that notifies native resource of new selected * states in the corresponding ChoiceGroup. * * @param nativeId native resource id (MidpItem *) of this ChoiceGroup * @param selectedArray array with new selected states * @param numSelectedArray number of elements in selectedArray to be used */ private native void setSelectedFlags0(int nativeId, boolean []selectedArray, int numSelectedArray); /** * KNI function that notifies native resource of fit policy change * in the corresponding ChoiceGroup. * * @param nativeId native resource id (MidpItem *) of this ChoiceGroup * @param fitPolicy new fit policy (can be TEXT_WRAP_OFF, TEXT_WRAP_ON, * or TEXT_WRAP_DEFAULT) */ private native void setFitPolicy0(int nativeId, int fitPolicy); /** * KNI function that notifies native resource of an element's new font * setting in the corresponding ChoiceGroup. * * @param nativeId native resource id (MidpItem *) of this ChoiceGroup * @param elementNum the index of an element which font has changed * @param face of the newly set font * @param style of the newly set font * @param size of newly set font */ private native void setFont0(int nativeId, int elementNum, int face, int style, int size); /** * KNI function that gets index of a currently selected index from * the ChoiceGroup's native resource. * * @param nativeId native resource id (MidpItem *) of this ChoiceGroup * @return index of the currently selected element */ private native int getSelectedIndex0(int nativeId); /** * KNI function that queries the state of all elements in the native * resource and returns it in the passed in selectedArray array. * * @param nativeId native resource id (MidpItem *) of this ChoiceGroup * @param selectedArray to contain the results * @param numOfEls number of elements in selectedArray * @return the number of elements selected in the native resource */ private native int getSelectedFlags0(int nativeId, boolean[] selectedArray, int numOfEls); /** * KNI function that queries the state of an element in the native * resource * * @param nativeId native resource id (MidpItem *) of this ChoiceGroup * @param elementNum the index of an element which state is queried * @return the current state of an element in the nativer resource */ private native boolean isSelected0(int nativeId, int elementNum); /** ChoiceGroup associated with this ChoiceGroupLF. */ ChoiceGroup cg; /** * The currently selected index of this ChoiceGroup (-1 by default). */ int selectedIndex = -1;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?