📄 gauge.java
字号:
/* (non-Javadoc)
* @see de.enough.polish.ui.Item#initItem()
*/
protected void initContent(int firstLineWidth, int lineWidth) {
this.valueWidth = 0;
int valueHeight = 0;
if (this.isIndefinite) {
this.showValue = false;
}
if ( this.showValue) {
if (this.font == null) {
this.font = Font.getDefaultFont();
}
valueHeight = this.font.getHeight();
this.valueWidth = this.font.stringWidth( "" + this.maxValue ) + this.paddingHorizontal;
}
// setting height:
if (this.preferredHeight > 0 ) {
this.contentHeight = this.preferredHeight;
if (this.image != null) {
int imageHeight = this.image.getHeight();
if ( (this.layout & LAYOUT_BOTTOM) == LAYOUT_BOTTOM ) {
this.imageYOffset = this.preferredHeight - imageHeight;
} else if ( (this.layout & LAYOUT_VCENTER) == LAYOUT_VCENTER ) {
this.imageYOffset = (this.preferredHeight - imageHeight) / 2;
}
}
} else if (this.image != null) {
this.contentHeight = this.image.getHeight();
} else {
this.contentHeight = 10;
}
if (this.contentHeight < valueHeight) {
this.contentHeight = valueHeight;
}
// setting width:
if (this.image != null
&& !this.isIndefinite
&& this.preferredWidth == 0 ) {
//#if polish.css.gauge-button-image
//# if (this.useImageAsButton) {
//#if polish.css.gauge-slider-image
//# if (this.sliderImage != null ) {
//# this.contentWidth = this.sliderImage.getWidth() + this.valueWidth;
//# this.sliderWidth = this.sliderImage.getWidth() - this.image.getWidth();
//# } else {
//#endif
//# if (this.preferredWidth > 0) {
//# this.contentWidth = this.preferredWidth + this.valueWidth;
//# } else if (this.isLayoutExpand) {
//# this.contentWidth = lineWidth;
//# } else {
//# this.contentWidth = firstLineWidth;
//# }
//# this.sliderWidth = this.contentWidth - (this.valueWidth + this.image.getWidth());
//#if polish.css.gauge-slider-image
//# }
//#endif
//# } else {
//#endif
this.contentWidth = this.image.getWidth() + this.valueWidth;
//#if polish.css.gauge-button-image
//# }
//#endif
} else if (this.preferredWidth > 0) {
this.contentWidth = this.preferredWidth + this.valueWidth;
} else if (this.isLayoutExpand) {
this.contentWidth = lineWidth;
} else if ((this.layout & LAYOUT_SHRINK) == LAYOUT_SHRINK) {
this.contentWidth = Math.max( lineWidth / 3, 10 );
} else {
this.contentWidth = firstLineWidth;
}
// update other settings:
if (this.isIndefinite) {
if (this.image != null ) {
if (this.value == CONTINUOUS_IDLE || this.value == CONTINUOUS_RUNNING ) {
this.maxValue = this.contentWidth;
} else {
this.maxValue = this.contentWidth / this.image.getWidth();
}
} else {
this.maxValue = 20;
}
int imageWidth = this.contentWidth - this.valueWidth; //Math.max( 1, this.contentWidth - this.valueWidth );
int imageHeight = this.contentHeight; // Math.max( 1, this.contentHeight );
if (imageWidth > 0 && imageHeight > 0) {
this.indicatorImage = Image.createImage( imageWidth, imageHeight );
updateIndefiniteIndicatorImage();
} else {
//#if polish.debug.error
//# throw new IllegalArgumentException( "invalid lineWidth for gauge: " + lineWidth );
//#else
throw new IllegalArgumentException();
//#endif
}
} else if (this.image == null){ // this is a definite gauge
createIndicatorImage();
}
}
//#ifdef polish.useDynamicStyles
//# /* (non-Javadoc)
//# * @see de.enough.polish.ui.Item#getCssSelector()
//# */
//# protected String createCssSelector() {
//# return "gauge";
//# }
//#endif
/* (non-Javadoc)
* @see de.enough.polish.ui.Item#setStyle(de.enough.polish.ui.Style)
*/
public void setStyle(Style style) {
super.setStyle(style);
//#ifdef polish.css.gauge-color
//# Integer gaugeColor = style.getIntProperty(18);
//# if (gaugeColor != null) {
//# this.color = gaugeColor.intValue();
//# }
//#endif
//#ifdef polish.css.gauge-width
//# Integer width = style.getIntProperty( 19);
//# if (width != null) {
//# this.preferredWidth = width.intValue();
//# }
//#endif
//#ifdef polish.css.gauge-height
//# Integer height = style.getIntProperty( 20);
//# if (height != null) {
//# this.preferredHeight = height.intValue();
//# }
//#endif
//#ifdef polish.css.gauge-mode
//# Integer modeInt = style.getIntProperty( 21);
//# if (modeInt != null) {
//# if (modeInt.intValue() == 0) {
//# this.mode = MODE_CHUNKED;
//# } else {
//# this.mode = MODE_CONTINUOUS;
//# }
//# }
//#endif
//#ifdef polish.css.gauge-gap-color
//# Integer gapColorInt = style.getIntProperty( 22);
//# if (gapColorInt != null) {
//# this.gapColor = gapColorInt.intValue();
//# }
//#endif
//#ifdef polish.css.gauge-gap-width
//# Integer gapWidthInt = style.getIntProperty( 23);
//# if (gapWidthInt != null) {
//# this.gapWidth = gapWidthInt.intValue();
//# }
//#endif
//#ifdef polish.css.gauge-chunk-width
//# Integer chunkWidthInt = style.getIntProperty( 24);
//# if (chunkWidthInt != null) {
//# this.chunkWidth = chunkWidthInt.intValue();
//# }
//#endif
//#ifdef polish.css.gauge-image
//# String imageStr = style.getProperty( 17);
//# if (imageStr != null) {
//# try {
//# this.image = StyleSheet.getImage( imageStr, this, false );
//# } catch (IOException e) {
//#debug error
//# System.out.println("unable to load gauge-image [" + imageStr + "]: " + e );
//# }
//# }
//#endif
//#ifdef polish.css.gauge-inactive-image
//# String inactiveImageStr = style.getProperty( 131);
//# if (inactiveImageStr != null) {
//# try {
//# this.inactiveImage = StyleSheet.getImage( inactiveImageStr, null, false );
//# } catch (IOException e) {
//#debug error
//# System.out.println("unable to load gauge-inactive-image [" + inactiveImageStr + "]: " + e );
//# }
//# }
//#endif
if (this.maxValue != INDEFINITE) {
//#ifdef polish.css.gauge-show-value
//# Boolean showValueBool = style.getBooleanProperty(25);
//# if (showValueBool != null) {
//# this.showValue = showValueBool.booleanValue();
//# }
//#endif
if (style.font != null) {
this.font = style.font;
}
this.fontColor = style.getFontColor();
//#ifdef polish.css.gauge-value-align
//# Integer valuePositionInt = style.getIntProperty( 26 );
//# if (valuePositionInt != null) {
//# if (valuePositionInt.intValue() == 0) {
//# this.isValueLeft = true;
//# } else {
//# this.isValueLeft = false;
//# }
//# }
//#endif
}
//#if polish.css.gauge-animation-speed
//# Integer animationSpeedInt = style.getIntProperty( 129 );
//# if (animationSpeedInt != null) {
//# this.animationSpeed = animationSpeedInt.intValue();
//# }
//#endif
//#if polish.css.gauge-animation-mode
//# Integer animationModeInt = style.getIntProperty( 130 );
//# if (animationModeInt != null) {
//# this.animationMode = animationModeInt.intValue();
//# }
//#endif
//#if polish.css.gauge-button-image
//# String buttonImageUrl = style.getProperty(151);
//# if (buttonImageUrl != null) {
//# try {
//# this.image = StyleSheet.getImage( buttonImageUrl, this, false );
//# this.useImageAsButton = true;
//# } catch (IOException e) {
//#debug error
//# System.out.println("unable to load gauge-button-image [" + buttonImageUrl + "]: " + e );
//# }
//# }
//#endif
//#if polish.css.gauge-slider-image
//# String sliderImageUrl = style.getProperty(152);
//# if (sliderImageUrl != null) {
//# try {
//# this.sliderImage = StyleSheet.getImage( sliderImageUrl, this, false );
//# } catch (IOException e) {
//#debug error
//# System.out.println("unable to load gauge-slider-image [" + sliderImageUrl + "]: " + e );
//# }
//# }
//#endif
}
//#ifdef polish.images.backgroundLoad
//# /* (non-Javadoc)
//# * @see de.enough.polish.ui.ImageConsumer#setImage(java.lang.String, javax.microedition.lcdui.Image)
//# */
//# public void setImage(String name, Image image) {
//# this.image = image;
//# this.isInitialized = false;
//# repaint();
//# }
//#endif
/* (non-Javadoc)
* @see de.enough.polish.ui.Item#handleKeyPressed(int, int)
*/
protected boolean handleKeyPressed(int keyCode, int gameAction) {
if (!this.isInteractive) {
return false;
}
if (gameAction == Canvas.RIGHT) {
if (this.value < this.maxValue) {
setValue( ++ this.value );
notifyStateChanged();
return true;
} else {
//#if polish.blackberry
//# return false;
//#else
// silently supress the event and stay in max position:
return true;
//#endif
}
} else if (gameAction == Canvas.LEFT) {
if (this.value > 0) {
setValue( -- this.value );
notifyStateChanged();
return true;
} else {
//#if polish.blackberry
//# return false;
//#else
// silently supress the event and stay in min position:
return true;
//#endif
}
} else {
return false;
}
}
//#ifdef polish.hasPointerEvents
//# /* (non-Javadoc)
//# * @see de.enough.polish.ui.Item#handlePointerPressed(int, int)
//# */
//# protected boolean handlePointerPressed(int x, int y) {
//# if (this.isIndefinite || !this.isInteractive || !isInItemArea(x, y)) {
//# return false;
//# }
//# int val = this.value;
//# if (val < this.maxValue) {
//# setValue( ++val );
//# } else {
//# setValue( 0 );
//# }
//# return true;
//# }
//#endif
/* (non-Javadoc)
* @see de.enough.polish.ui.Item#animate()
*/
public boolean animate() {
boolean animated = super.animate();
//#if polish.css.view-type
if (this.view != null) {
// skip animation when there is a view present in this gauge
return animated;
}
//#endif
if (this.isIndefinite && this.value == CONTINUOUS_RUNNING && this.isInitialized) {
//#if polish.css.gauge-animation-mode
//# if ( this.image != null && this.animationMode == ANIMATION_MODE_BACKANDFORTH ) {
//# if (this.animationDirectionDownwards) {
//#if polish.css.gauge-animation-speed
//# this.indefinitePos -= this.animationSpeed;
//#else
//# this.indefinitePos--;
//#endif
//# if (this.indefinitePos <= 0) {
//# this.indefinitePos = 0;
//# this.animationDirectionDownwards = false;
//# }
//# } else {
//#if polish.css.gauge-animation-speed
//# this.indefinitePos += this.animationSpeed;
//#else
//# this.indefinitePos++;
//#endif
//# if (this.indefinitePos >= this.contentWidth - this.image.getWidth()) {
//# this.indefinitePos = this.contentWidth - this.image.getWidth();
//# this.animationDirectionDownwards = true;
//# }
//# }
//# return true;
//# }
//#endif
//#if polish.css.gauge-animation-speed
//# this.indefinitePos += this.animationSpeed;
//#else
this.indefinitePos++;
//#endif
if (this.image == null) {
if (this.indefinitePos > (this.chunkWidth + this.gapWidth)) {
this.indefinitePos = 0;
}
updateIndefiniteIndicatorImage();
} else if (this.indefinitePos > this.maxValue) {
this.indefinitePos = -this.image.getWidth();
}
return true;
}
return animated;
}
/* (non-Javadoc)
* @see de.enough.polish.ui.FakeStringCustomItem#hideNotify()
*/
protected void hideNotify() {
super.hideNotify();
if (this.isIndefinite && this.value == CONTINUOUS_RUNNING) {
AnimationThread.removeAnimationItem( this );
}
this.isShown = false;
}
/* (non-Javadoc)
* @see de.enough.polish.ui.FakeStringCustomItem#showNotify()
*/
protected void showNotify() {
super.showNotify();
if (this.isIndefinite && this.value == CONTINUOUS_RUNNING) {
AnimationThread.addAnimationItem( this );
}
this.isShown = true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -