📄 gauge.java
字号:
} else { //#endif int width = (this.image.getWidth() * this.value) / this.maxValue; int clipX = g.getClipX(); int clipY = g.getClipY(); int clipWidth = g.getClipWidth(); int clipHeight = g.getClipHeight(); g.clipRect(x, clipY, width, clipHeight); g.drawImage(this.image, x, y + this.imageYOffset, Graphics.TOP | Graphics.LEFT ); g.setClip(clipX, clipY, clipWidth, clipHeight); //#if polish.css.gauge-button-image } //#endif } } else { g.drawImage(this.indicatorImage, x, y, Graphics.TOP | Graphics.LEFT ); } if (this.showValue && !this.isValueLeft) { g.setFont( this.font ); g.setColor( this.fontColor ); g.drawString( this.valueString, rightBorder, y, Graphics.TOP | Graphics.RIGHT ); } } /* (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 { this.contentWidth = firstLineWidth; } // update other settings: if (this.isIndefinite) { if (this.value == CONTINUOUS_RUNNING) { Screen scr = getScreen(); if (scr != null) { // register this gauge at the current screen: scr.gauge = this; //} else { //System.out.println("unable to register gauge"); } } 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; } this.indicatorImage = Image.createImage( this.contentWidth - this.valueWidth, this.contentHeight ); updateIndefiniteIndicatorImage(); } 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("gauge-color"); if (gaugeColor != null) { this.color = gaugeColor.intValue(); } //#endif //#ifdef polish.css.gauge-width Integer width = style.getIntProperty( "gauge-width"); if (width != null) { this.preferredWidth = width.intValue(); } //#endif //#ifdef polish.css.gauge-height Integer height = style.getIntProperty( "gauge-height"); if (height != null) { this.preferredHeight = height.intValue(); } //#endif //#ifdef polish.css.gauge-mode Integer modeInt = style.getIntProperty( "gauge-mode"); 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( "gauge-gap-color"); if (gapColorInt != null) { this.gapColor = gapColorInt.intValue(); } //#endif //#ifdef polish.css.gauge-gap-width Integer gapWidthInt = style.getIntProperty( "gauge-gap-width"); if (gapWidthInt != null) { this.gapWidth = gapWidthInt.intValue(); } //#endif //#ifdef polish.css.gauge-chunk-width Integer chunkWidthInt = style.getIntProperty( "gauge-chunk-width"); if (chunkWidthInt != null) { this.chunkWidth = chunkWidthInt.intValue(); } //#endif //#ifdef polish.css.gauge-image String imageStr = style.getProperty( "gauge-image"); 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( "gauge-inactive-image"); 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("gauge-show-value"); 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( "gauge-value-align" ); 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( "gauge-animation-speed" ); if (animationSpeedInt != null) { this.animationSpeed = animationSpeedInt.intValue(); } //#endif //#if polish.css.gauge-animation-mode Integer animationModeInt = style.getIntProperty( "gauge-animation-mode" ); if (animationModeInt != null) { this.animationMode = animationModeInt.intValue(); } //#endif //#if polish.css.gauge-button-image String buttonImageUrl = style.getProperty("gauge-button-image"); 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("gauge-slider-image"); 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.isInitialised = 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) { 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() { if (this.isIndefinite && this.value == CONTINUOUS_RUNNING && this.isInitialised) { //#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; } } //updateIndefiniteIndicatorImage(); 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 false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -