📄 horizontalchoiceview.java
字号:
}
//#endif
//#ifdef polish.css.horizontalview-arrow-color
Integer colorInt = style.getIntProperty("horizontalview-arrow-color");
if ( colorInt != null ) {
this.arrowColor = colorInt.intValue();
}
//#endif
//#ifdef polish.css.horizontalview-arrow-position
Integer positionInt = style.getIntProperty("horizontalview-arrow-position");
if ( positionInt != null ) {
this.arrowPosition = positionInt.intValue();
}
//#ifdef polish.css.horizontalview-arrow-padding
Integer arrowPaddingInt = style.getIntProperty("horizontalview-arrow-padding");
if (arrowPaddingInt != null) {
this.arrowPadding = arrowPaddingInt.intValue();
// } else {
// this.arrowPadding = style.paddingHorizontal;
}
//#endif
//#endif
//#ifdef polish.css.horizontalview-roundtrip
Boolean allowRoundTripBool = style.getBooleanProperty("horizontalview-roundtrip");
if (allowRoundTripBool != null) {
this.allowRoundTrip = allowRoundTripBool.booleanValue();
}
//#endif
}
/* (non-Javadoc)
* @see de.enough.polish.ui.ContainerView#paintContent(int, int, int, int, javax.microedition.lcdui.Graphics)
*/
protected void paintContent(int x, int y, int leftBorder, int rightBorder,
Graphics g)
{
//#debug
System.out.println("HorizontalView.start: x=" + x + ", y=" + y + ", leftBorder=" + leftBorder + ", rightBorder=" + rightBorder );
this.xStart = x;
int modifiedX = x;
//#ifdef polish.css.horizontalview-expand-background
if (this.expandBackground && this.background != null && this.focusedItem != null) {
this.focusedItem.background = null;
this.background.paint(x, y, this.contentWidth, this.contentHeight, g);
}
//#endif
//#ifdef polish.css.horizontalview-arrow-position
if (this.arrowPosition == POSITION_BOTH_SIDES ) {
//#endif
modifiedX += this.arrowWidth + this.paddingHorizontal;
leftBorder += this.arrowWidth + this.paddingHorizontal;
//#ifdef polish.css.horizontalview-arrow-position
} else if (this.arrowPosition == POSITION_LEFT ) {
modifiedX += (this.arrowWidth + this.paddingHorizontal) << 1;
leftBorder += (this.arrowWidth + this.paddingHorizontal) << 1;
}
//#endif
//#ifdef polish.css.horizontalview-arrow-position
if (this.arrowPosition == POSITION_BOTH_SIDES ) {
//#endif
rightBorder -= this.arrowWidth + this.paddingHorizontal;
//#ifdef polish.css.horizontalview-arrow-position
} else if (this.arrowPosition == POSITION_RIGHT ) {
rightBorder -= (this.arrowWidth + this.paddingHorizontal) << 1;
}
//#endif
//#debug
System.out.println("HorizontalChoiceView.item: x=" + modifiedX + ", y=" + y + ", leftBorder=" + leftBorder + ", rightBorder=" + rightBorder + ", availableWidth=" + (rightBorder - leftBorder) + ", itemWidth=" + this.focusedItem.itemWidth );
int clipX = g.getClipX();
int clipY = g.getClipY();
int clipWidth = g.getClipWidth();
int clipHeight = g.getClipHeight();
boolean setClip = this.contentWidth > rightBorder - leftBorder;
if (setClip) {
g.clipRect(modifiedX, clipY, rightBorder - modifiedX, clipHeight );
}
int itemX = modifiedX + this.xOffset;
int focusedX = 0;
int cHeight = this.contentHeight;
int vOffset = 0;
Item[] items = this.parentContainer.getItems();
for (int i = 0; i < items.length; i++) {
Item item = items[i];
if ( item == this.focusedItem ) {
focusedX = itemX;
} else {
//TODO allow explicit setting of top, vcenter and bottom for items (=layout)
vOffset = (cHeight - item.itemHeight) / 2;
item.paint(itemX, y + vOffset, leftBorder, rightBorder, g);
}
itemX += item.itemWidth + this.paddingHorizontal;
}
if (this.focusedItem != null) {
vOffset = (cHeight - this.focusedItem.itemHeight) / 2;
this.focusedItem.paint(focusedX, y + vOffset, leftBorder, rightBorder, g);
}
if (setClip) {
g.setClip( clipX, clipY, clipWidth, clipHeight );
}
//#ifdef polish.css.horizontalview-arrow-position
if (this.arrowPosition != POSITION_NONE ) {
//#endif
g.setColor( this.arrowColor );
//draw left arrow:
//#ifdef polish.css.horizontalview-roundtrip
if (this.allowRoundTrip || this.currentItemIndex > 0) {
//#else
//# if (this.currentItemIndex > 0) {
//#endif
// draw left arrow
int startX = x + this.leftArrowStartX;
Image image = null;
//#if polish.css.horizontalview-arrows-image
image = this.arrowsImage;
vOffset = this.yOffset;
//#endif
//#ifdef polish.css.horizontalview-left-arrow
if (image == null) {
image = this.leftArrow;
vOffset = this.leftYOffset;
}
//#endif
if (image != null) {
//System.out.println("Drawing left IMAGE arrow at " + startX );
g.drawImage( image, startX, y + vOffset, Graphics.LEFT | Graphics.TOP );
} else {
//#if polish.midp2
//System.out.println("Drawing left triangle arrow at " + startX );
g.fillTriangle(
startX, y + this.contentHeight/2,
startX + this.arrowWidth, y,
startX + this.arrowWidth, y + this.contentHeight );
//#else
int y1 = y + this.contentHeight / 2;
int x2 = startX + this.arrowWidth;
int y3 = y + this.contentHeight;
g.drawLine( startX, y1, x2, y );
g.drawLine( startX, y1, x2, y3 );
g.drawLine( x2, y, x2, y3 );
//#endif
}
}
// draw right arrow:
//#if polish.css.horizontalview-arrows-image
if (this.arrowsImage != null) {
return;
}
//#endif
//#ifdef polish.css.horizontalview-roundtrip
if (this.allowRoundTrip || (this.currentItemIndex < this.parentContainer.size() - 1) ) {
//#else
//# if (this.currentItemIndex < this.parentContainer.size() - 1) {
//#endif
// draw right arrow
int startX = x + this.rightArrowStartX;
//#ifdef polish.css.horizontalview-right-arrow
if (this.rightArrow != null) {
g.drawImage( this.rightArrow, startX, y + this.rightYOffset, Graphics.LEFT | Graphics.TOP );
} else {
//#endif
//#if polish.midp2
g.fillTriangle(
startX + this.arrowWidth, y + this.contentHeight/2,
startX, y,
startX, y + this.contentHeight );
//#else
int y1 = y + this.contentHeight / 2;
int x2 = startX + this.arrowWidth;
int y3 = y + this.contentHeight;
g.drawLine( x2, y1, startX, y );
g.drawLine( x2, y1, startX, y3 );
g.drawLine( startX, y, startX, y3 );
//#endif
//#ifdef polish.css.horizontalview-right-arrow
}
//#endif
}
//#ifdef polish.css.horizontalview-arrow-position
} // if (this.arrowPosition != POSITION_NONE ) {
//#endif
}
/* (non-Javadoc)
* @see de.enough.polish.ui.ContainerView#getNextItem(int, int)
*/
protected Item getNextItem(int keyCode, int gameAction) {
//#debug
System.out.println("ExclusiveSingleLineView: getNextItem()");
ChoiceGroup choiceGroup = (ChoiceGroup) this.parentContainer;
Item[] items = this.parentContainer.getItems();
ChoiceItem currentItem = (ChoiceItem) this.focusedItem;
if (currentItem == null) {
//#debug warn
System.out.println("HorizontalChoiceView: getNextItem(): no current item defined, it seems the initContent() has been skipped.");
this.currentItemIndex = choiceGroup.getSelectedIndex();
currentItem = (ChoiceItem) items[ this.currentItemIndex ];
this.focusedItem = currentItem;
}
ChoiceItem nextItem = null;
//#ifdef polish.css.horizontalview-roundtrip
if ( gameAction == Canvas.LEFT && (this.allowRoundTrip || this.currentItemIndex > 0 )) {
//#else
//# if ( gameAction == Canvas.LEFT && this.currentItemIndex > 0 ) {
//#endif
currentItem.select(false);
this.currentItemIndex--;
//#ifdef polish.css.horizontalview-roundtrip
if (this.currentItemIndex < 0) {
this.currentItemIndex = items.length - 1;
}
//#endif
nextItem = (ChoiceItem) items[ this.currentItemIndex ];
//nextItem.adjustProperties( lastItem );
//this.currentItem.select( true );
choiceGroup.setSelectedIndex( this.currentItemIndex, true );
choiceGroup.notifyStateChanged();
//#ifdef polish.css.horizontalview-roundtrip
} else if ( gameAction == Canvas.RIGHT && (this.allowRoundTrip || this.currentItemIndex < items.length - 1 )) {
//#else
} else if ( gameAction == Canvas.RIGHT && this.currentItemIndex < items.length - 1 ) {
//#endif
currentItem.select(false);
this.currentItemIndex++;
//#ifdef polish.css.horizontalview-roundtrip
if (this.currentItemIndex >= items.length) {
this.currentItemIndex = 0;
}
//#endif
nextItem = (ChoiceItem) items[ this.currentItemIndex ];
//nextItemItem.adjustProperties( lastItem );
choiceGroup.setSelectedIndex( this.currentItemIndex, true );
choiceGroup.notifyStateChanged();
//this.currentItem.select( true );
}
// in all other cases there is no next item:
return nextItem;
}
//#ifdef polish.hasPointerEvents
/**
* Handles pointer pressed events.
* This is an optional feature that doesn't need to be implemented by subclasses.
*
* @param x the x position of the event
* @param y the y position of the event
* @return true when the event has been handled. When false is returned the parent container
* will forward the event to the affected item.
*/
public boolean handlePointerPressed(int x, int y) {
Item[] items = this.parentContainer.getItems();
x -= this.xStart;
if (this.currentItemIndex > 0 && x >= this.leftArrowStartX && x <= this.leftArrowEndX ) {
this.currentItemIndex--;
} else {
this.currentItemIndex++;
if (this.currentItemIndex >= items.length ) {
this.currentItemIndex = 0;
}
}
((ChoiceItem)this.focusedItem).select( false );
this.focusedItem = (ChoiceItem) items[ this.currentItemIndex ];
//this.currentItem.select( true );
((ChoiceGroup) this.parentContainer).setSelectedIndex( this.currentItemIndex, true );
this.parentContainer.focus (this.currentItemIndex, this.focusedItem, 0);
return true;
}
//#endif
/* (non-Javadoc)
* @see de.enough.polish.ui.ContainerView#defocus(de.enough.polish.ui.Style)
*/
protected void defocus(Style originalStyle) {
if (this.parentBackground != null ) {
this.parentContainer.background = this.parentBackground;
this.parentBackground = null;
}
super.defocus(originalStyle);
//System.out.println("EXCLUSIVE: DEFOCUS!");
}
/* (non-Javadoc)
* @see de.enough.polish.ui.ContainerView#focus(de.enough.polish.ui.Style, int)
*/
public void focus(Style focusstyle, int direction) {
Background bg = this.parentContainer.background;
if (bg != null) {
this.parentBackground = bg;
this.parentContainer.background = null;
}
//System.out.println("EXCLUSIVE: FOCUS, parentBackround != null: " + (this.parentBackground != null));
super.focus(focusstyle, direction);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -