📄 choicegroup.java
字号:
*
* @param fitPolicy preferred content fit policy for choice elements
* @see Choice#setFitPolicy(int) in interface Choice
* @see #getFitPolicy()
* @since MIDP 2.0
*/
public void setFitPolicy(int fitPolicy)
{
//this.fitPolicy = fitPolicy;
// ignore hint
}
/**
* Gets the application's preferred policy for fitting
* <code>Choice</code> element contents to the available screen space. The value returned is the
* policy that had been set by the application, even if that value had
* been disregarded by the implementation.
*
* @return always Choice.TEXT_WRAP_ON
* @see Choice#getFitPolicy() in interface Choice
* @see #setFitPolicy(int)
* @since MIDP 2.0
*/
public int getFitPolicy()
{
return Choice.TEXT_WRAP_ON;
}
/**
* Sets the application's preferred font for
* rendering the specified element of this <code>Choice</code>.
* An element's font is a hint, and the implementation may disregard
* the application's preferred font.
* The J2ME Polish implementation uses the font defined by the appropriate
* CSS style and ignores the font which is set here.
*
* @param elementNum the index of the element, starting from zero
* @param font the preferred font to use to render the element
* @throws IndexOutOfBoundsException if elementNum is invalid
* @see Choice#setFont(int, Font) in interface Choice
* @see #getFont(int)
* @since MIDP 2.0
*/
public void setFont(int elementNum, Font font)
{
ChoiceItem item = (ChoiceItem) this.itemsList.get( elementNum );
item.setPreferredFont( font );
}
/**
* Gets the application's preferred font for
* rendering the specified element of this <code>Choice</code>. The
* value returned is the font that had been set by the application,
* even if that value had been disregarded by the implementation.
* If no font had been set by the application, or if the application
* explicitly set the font to <code>null</code>, the value is the default
* font chosen by the implementation.
*
* <p> The <code>elementNum</code> parameter must be within the range
* <code>[0..size()-1]</code>, inclusive.</p>
*
* @param elementNum the index of the element, starting from zero
* @return the preferred font to use to render the element
* @throws IndexOutOfBoundsException if elementNum is invalid
* @see Choice#getFont(int) in interface Choice
* @see #setFont(int elementNum, Font font)
* @since MIDP 2.0
*/
public Font getFont(int elementNum)
{
ChoiceItem item = (ChoiceItem) this.itemsList.get( elementNum );
Font font = item.preferredFont;
if (font == null) {
font = item.font;
}
return font;
}
//#ifdef polish.usePopupItem
//# protected void hideNotify() {
//# if (this.isPopup && !this.isPopupClosed) {
//# closePopup();
//# }
//# }
//#endif
//#ifdef polish.usePopupItem
//# /* (non-Javadoc)
//# * @see de.enough.polish.ui.Item#paint(int, int, javax.microedition.lcdui.Graphics)
//# */
//# public void paintContent(int x, int y, int leftBorder, int rightBorder, Graphics g) {
//#if tmp.supportViewType
//# if (this.containerView != null) {
//# super.paintContent(x, y, leftBorder, rightBorder, g);
//# return;
//# }
//#endif
//# if (this.isPopup && this.isPopupClosed) {
//# this.popupItem.paintContent(x, y, leftBorder, rightBorder, g);
//# } else {
//# super.paintContent(x, y, leftBorder, rightBorder, g );
//# }
//# }
//#endif
//#ifdef polish.usePopupItem
//# protected void init( int firstLineWidth, int lineWidth ) {
//# super.init(firstLineWidth, lineWidth);
//#if tmp.supportViewType
//# if (this.containerView != null) {
//# return;
//# }
//#endif
//# if (this.isPopup && !this.isPopupClosed) {
//# this.backgroundWidth += (this.originalContentWidth - this.contentWidth);
//# this.backgroundHeight += (this.originalContentHeight - this.contentHeight);
//# }
//# }
//#endif
//#ifdef polish.usePopupItem
//# /* (non-Javadoc)
//# * @see de.enough.polish.ui.Item#initItem()
//# */
//# protected void initContent(int firstLineWidth, int lineWidth) {
//# super.initContent(firstLineWidth, lineWidth);
//#if tmp.supportViewType
//# if (this.containerView != null) {
//# return;
//# }
//#endif
//# if (this.isPopup) {
//# if (this.popupItem.image == null) {
//# this.popupItem.setImage( createPopupImage() );
//# }
//# if (this.isPopupClosed) {
//# if (this.popupItem.getText() == null && this.itemsList.size() > 0) {
//# ChoiceItem selectedItem = (ChoiceItem) this.itemsList.get( 0 );
//# this.popupItem.setText( selectedItem.getText() );
//# }
//# if (!this.popupItem.isInitialized) {
//# int noneContentWidth = this.marginLeft + this.borderWidth + this.paddingLeft
//# + this.marginRight + this.borderWidth + this.paddingRight;
//# this.popupItem.init(firstLineWidth + noneContentWidth, lineWidth + noneContentWidth);
//# }
//# } else {
//# this.originalContentWidth = this.contentWidth;
//# this.originalContentHeight = this.contentHeight;
//# }
//# //this.contentWidth = this.popupItem.contentWidth;
//# this.contentHeight = this.popupItem.contentHeight;
//# }
//# }
//#endif
//#ifdef polish.useDynamicStyles
//# /* (non-Javadoc)
//# * @see de.enough.polish.ui.Item#getCssSelector()
//# */
//# protected String createCssSelector() {
//# return "choicegroup";
//# }
//#endif
//#ifdef polish.usePopupItem
//# private void closePopup() {
//# this.isPopupClosed = true;
//# if (this.parent instanceof Container) {
//# ((Container)this.parent).setScrollYOffset( this.popupParentOpenY );
//# this.internalX = -9999;
//# }
//# }
//#endif
//#ifdef polish.usePopupItem
//# private void openPopup() {
//# //this.popupOpenY = this.yTopPos;
//# if (this.parent instanceof Container) {
//# this.popupParentOpenY = ((Container)this.parent).getScrollYOffset();
//# }
//# this.isPopupClosed = false;
//# focus( this.selectedIndex );
//# // recalculate the internal positions of the selected choice:
//# Item item = this.items[ this.selectedIndex ];
//# if (item.isInitialized) {
//# this.internalY = item.relativeY;
//# this.internalHeight = item.itemHeight;
//# this.internalX = item.relativeX;
//# this.internalWidth = item.itemWidth;
//# } else {
//# this.internalX = 0;
//# this.internalY = 0;
//# this.internalHeight = this.itemHeight + 20;
//# this.internalWidth = this.itemWidth;
//# }
//# }
//#endif
/* (non-Javadoc)
* @see de.enough.polish.ui.Item#handleKeyPressed(int, int)
*/
protected boolean handleKeyPressed(int keyCode, int gameAction) {
if (this.itemsList.size() == 0) {
return super.handleKeyPressed(keyCode, gameAction);
}
//#if polish.ChoiceGroup.handleDefaultCommandFirst == true
//# if (gameAction == Canvas.FIRE) {
//#ifdef polish.usePopupItem
//# if (!this.isPopup || this.isPopupClosed) {
//#endif
//#ifndef tmp.suppressAllCommands
//# if (this.defaultCommand != null && this.additionalItemCommandListener != null) {
//# this.additionalItemCommandListener.commandAction( this.defaultCommand, this );
//# return true;
//# }
//#else
//# if (this.defaultCommand != null && this.itemCommandListener != null) {
//# this.itemCommandListener.commandAction( this.defaultCommand, this );
//# return true;
//# }
//#endif
//#ifdef polish.usePopupItem
//# }
//#endif
//# }
//#endif
boolean processed = false;
//#ifdef polish.usePopupItem
//# if (!(this.isPopup && this.isPopupClosed)) {
//# processed = super.handleKeyPressed(keyCode, gameAction);
//#debug
//# System.out.println("ChoiceGroup: container handled keyPressEvent: " + processed);
//# }
//# if (!processed) {
//# if ( gameAction == Canvas.FIRE && keyCode != Canvas.KEY_NUM5 ) {
//# if (this.isMultiple) {
//# ChoiceItem item = (ChoiceItem) this.focusedItem;
//# item.toggleSelect();
//# } else if (this.isPopup){
//# if (this.isPopupClosed) {
//# openPopup();
//# } else {
//# setSelectedIndex(this.focusedIndex, true);
//# closePopup();
//# }
//# requestInit();
//# } else {
//# setSelectedIndex(this.focusedIndex, true);
//# 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 );
//# }
//# }
//# }
//# if ( (this.choiceType != IMPLICIT)
//# && !(this.isPopup && !this.isPopupClosed)
//# && (this.getScreen() instanceof Form) ) {
//# notifyStateChanged();
//# }
//# return true;
//# } else {
//#if polish.Container.dontUseNumberKeys != true
//# if (keyCode >= Canvas.KEY_NUM1 && keyCode <= Canvas.KEY_NUM9) {
//# int index = keyCode - Canvas.KEY_NUM1;
//# if (index < this.itemsList.size()) {
//# if (!this.isPopup || !this.isPopupClosed) {
//# // either this is not a POPUP or the POPUP is opened:
//# setSelectedIndex( index, true );
//# if (this.isPopup) {
//# closePopup();
//# }
//# if ( (this.choiceType != IMPLICIT)
//# && (this.getScreen() instanceof Form) ) {
//# 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;
//# }
//# }
//# } else if (this.isPopup && (this.isPopupClosed == false)) {
//# closePopup();
//# return true;
//# }
//#endif
//# }
//# }
//#else
// no popup item is used by this application:
processed = super.handleKeyPressed(keyCode, gameAction);
if (!processed) {
if (gameAction == Canvas.FIRE && keyCode != Canvas.KEY_NUM5 && this.focusedIndex != -1 ) {
if (this.isMultiple) {
ChoiceItem item = (ChoiceItem) this.focusedItem;
item.toggleSelect();
} else {
setSelectedIndex(this.focusedIndex, true);
}
if ( (this.choiceType != IMPLICIT)
&& (this.getScreen() instanceof Form) )
{
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;
//#if polish.Container.dontUseNumberKeys != true
} else if ( (keyCode >= Canvas.KEY_NUM1) && (keyCode <= Canvas.KEY_NUM9) ) {
int index = keyCode - Canvas.KEY_NUM1;
if (index < this.itemsList.size()) {
setSelectedIndex( index, true );
if ((this.choiceType != IMPLICIT)
&& (this.getScreen() instanceof Form) )
{
notifyStateChanged();
}
if (this.isImplicit) {
// call command listener:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -