/** layout the component by default */ public void sublayout(int width, int height) { if (iconFocus == null && iconUnfocus == null) { super.sublayout(width, height); } else { int iconHeight = 0; AbstractTnImage tmpImage = iconFocus != null ? iconFocus : iconUnfocus; if ((style & AbstractTnGraphics.LEFT) != 0 || (style & AbstractTnGraphics.RIGHT) != 0) { int textWidth = FrogTextHelper.getWidth(this.textLine, this.font, this.boldFont); preferWidth = tmpImage.getWidth() + textWidth + leftPadding + rightPadding + gap; iconHeight = tmpImage.getHeight(); if (iconHeight > font.getHeight()) { preferHeight = iconHeight + topPadding + bottomPadding; } else { preferHeight = font.getHeight() + topPadding + bottomPadding; } } else if ((style & AbstractTnGraphics.TOP) != 0 || (style & AbstractTnGraphics.BOTTOM) != 0) { preferHeight = tmpImage.getHeight() + topPadding + bottomPadding; if (this.textLine != null) preferHeight += font.getHeight() + gap; int textWidth = FrogTextHelper.getWidth(this.textLine, this.font, this.boldFont); if (tmpImage.getWidth() > textWidth) { preferWidth = tmpImage.getWidth() + leftPadding + rightPadding; } else { preferWidth = textWidth + leftPadding + rightPadding; } } } }
protected void paint(AbstractTnGraphics graphics) { super.paint(graphics); if (badgeImage != null) { int oldBadgeImageWidth = badgeImage.getWidth(); int oldBadgeImageHeight = badgeImage.getHeight(); badgeImage.setWidth(badgeWidth); badgeImage.setHeight(badgeHeight); int left = 0; int y = 0; if ((this.badgePosition & AbstractTnGraphics.RIGHT) != 0) { int rightIconWidht = rightButtonIconFocus == null ? 0 : rightButtonIconFocus.getWidth(); left = this.getWidth() - this.getRightPadding() - rightIconWidht - this.getGap() - badgeWidth; y = (this.getHeight() - badgeHeight) / 2; if (y < this.getTopPadding()) y = this.getTopPadding(); graphics.drawImage(badgeImage, left, y, AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP); } else if ((this.badgePosition & AbstractTnGraphics.TOP) != 0) { // left = this.getWidth() - this.getRightPadding() - badgeImage.getWidth(); left = this.getWidth() / 2 + this.getFocusedIcon().getWidth() / 4; int fontHeight = font.getHeight() < boldFont.getHeight() ? boldFont.getHeight() : font.getHeight(); int iconY = topPadding + (this.getHeight() - topPadding - bottomPadding - getFocusedIcon().getHeight() - fontHeight - gap) / 2; int badageTopHeight = badgeHeight / 3; if (iconY < badageTopHeight) { y = iconY; } else { y = iconY - badageTopHeight; } graphics.drawImage(badgeImage, left, y, AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP); } else if (this.badgePosition == this.SAME_Y_AS_ICON) { left = this.getFocusedIcon().getWidth() * 5 / 8; y = topPadding; graphics.drawImage(badgeImage, left, y, AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP); } left += (badgeWidth - FrogTextHelper.getWidth(this.badge, badgeFont, this.boldFont)) / 2; y += (badgeHeight + 1) / 2; if (isFocused()) { graphics.setColor(badgeFocusedColor); } else { graphics.setColor(badgeBlurColor); } if (!"".equalsIgnoreCase(badge.getText())) { graphics.setFont(badgeFont); graphics.drawString( badge.getText(), left, y, AbstractTnGraphics.LEFT | AbstractTnGraphics.FONT_ABSOLUTE_VCENTER); } badgeImage.setWidth(oldBadgeImageWidth); badgeImage.setHeight(oldBadgeImageHeight); } }
/** * Paint the component to screen * * @param graphics (@link AbstractTnGraphics) */ protected void paint(AbstractTnGraphics graphics) { int y = 0; AbstractTnImage buttonIcon; if (isFocused()) { graphics.setColor(focusColor); buttonIcon = iconFocus; } else { graphics.setColor(unfocusColor); buttonIcon = iconUnfocus; } graphics.setFont(font); int left; if (buttonIcon != null) { if ((style & AbstractTnGraphics.LEFT) != 0) { left = leftPadding; y = (this.getHeight() - buttonIcon.getHeight()) / 2; if (y < topPadding) y = topPadding; graphics.drawImage(buttonIcon, left, y, AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP); left = leftPadding + buttonIcon.getWidth() + gap; if ((style & AbstractTnGraphics.HCENTER) != 0) { int textTypingWidth = this.getWidth() - leftPadding - buttonIcon.getWidth() - gap - rightPadding; left = buttonIcon.getWidth() + gap + leftPadding + (textTypingWidth - FrogTextHelper.getWidth(this.textLine, this.font, this.boldFont)) / 2; if (left < buttonIcon.getWidth() + gap + leftPadding) left = buttonIcon.getWidth() + gap + leftPadding; } y = (this.getHeight() - font.getHeight()) / 2; int scrollWidth = this.getWidth() - buttonIcon.getWidth() - leftPadding - rightPadding - gap; graphics.pushClip(left, y, scrollWidth, this.getHeight()); FrogTextHelper.paint( graphics, left - this.scrollX, y, this.textLine, font, boldFont, scrollWidth, !isFocused || !isScrollable); graphics.popClip(); } else if ((style & AbstractTnGraphics.RIGHT) != 0) { left = leftPadding; if ((style & AbstractTnGraphics.HCENTER) != 0) { int textTypingWidth = this.getWidth() - leftPadding - buttonIcon.getWidth() - gap - rightPadding; left = leftPadding + (textTypingWidth - FrogTextHelper.getWidth(this.textLine, this.font, this.boldFont)) / 2; if (left < leftPadding) left = leftPadding; } y = (this.getHeight() - font.getHeight()) / 2; int scrollWidth = this.getWidth() - buttonIcon.getWidth() - leftPadding - rightPadding - gap; graphics.pushClip(left, y, scrollWidth, this.getHeight()); FrogTextHelper.paint( graphics, left - this.scrollX, y, this.textLine, font, boldFont, scrollWidth, !isFocused || !isScrollable); graphics.popClip(); y = (this.getHeight() - buttonIcon.getHeight()) / 2; if (y < topPadding) y = topPadding; left = this.getWidth() - rightPadding - buttonIcon.getWidth(); graphics.drawImage(buttonIcon, left, y, AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP); left = this.getWidth() - rightPadding - buttonIcon.getWidth() - gap; } else if ((style & AbstractTnGraphics.TOP) != 0) { left = (this.getWidth() - buttonIcon.getWidth()) / 2; if (this.textLine != null) { int fontHeight = font.getHeight() < boldFont.getHeight() ? boldFont.getHeight() : font.getHeight(); y = topPadding + (this.getHeight() - topPadding - bottomPadding - buttonIcon.getHeight() - fontHeight - gap) / 2; if (y < 0) y = 0; graphics.drawImage(buttonIcon, left, y, AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP); left = (this.getWidth() - FrogTextHelper.getWidth(this.textLine, this.font, this.boldFont)) / 2; if (left < leftPadding) { left = leftPadding; } y += buttonIcon.getHeight() + gap; int scrollWidth = this.getWidth() - leftPadding - rightPadding; graphics.pushClip(left, y, scrollWidth, this.getHeight()); FrogTextHelper.paint( graphics, left - this.scrollX, y, this.textLine, font, boldFont, scrollWidth, !isFocused || !isScrollable); graphics.popClip(); } else { y = topPadding + (this.getHeight() - topPadding - bottomPadding - buttonIcon.getHeight()) / 2; if (y < topPadding) y = topPadding; left = (this.getWidth() - buttonIcon.getWidth()) / 2; if (left < leftPadding) left = leftPadding; graphics.drawImage(buttonIcon, left, y, AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP); } } else if ((style & AbstractTnGraphics.BOTTOM) != 0) { if (this.textLine != null) { left = (this.getWidth() - FrogTextHelper.getWidth(this.textLine, this.font, this.boldFont)) / 2; if (left < leftPadding) { left = leftPadding; } y = topPadding; int scrollWidth = this.getWidth() - leftPadding - rightPadding; graphics.pushClip(left, y, scrollWidth, this.getHeight()); FrogTextHelper.paint( graphics, left - this.scrollX, y, this.textLine, font, boldFont, scrollWidth, !isFocused || !isScrollable); graphics.popClip(); y = topPadding + gap + font.getHeight(); left = (this.getWidth() - buttonIcon.getWidth()) / 2; graphics.drawImage(buttonIcon, left, y, AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP); } else { y = topPadding + (this.getHeight() - topPadding - bottomPadding - buttonIcon.getHeight()) / 2; if (y < topPadding) y = topPadding; left = (this.getWidth() - buttonIcon.getWidth()) / 2; if (left < leftPadding) left = leftPadding; graphics.drawImage(buttonIcon, left, y, AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP); } } else { int leftStart = (getWidth() - FrogTextHelper.getWidth(this.textLine, this.font, this.boldFont) - gap - buttonIcon.getWidth()) / 2; if (leftStart < leftPadding) leftStart = leftPadding; left = leftStart; y = topPadding + (this.getHeight() - topPadding - bottomPadding - buttonIcon.getHeight()) / 2; graphics.drawImage(buttonIcon, left, y, AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP); left = left + buttonIcon.getWidth() + gap; y = (this.getHeight() - font.getHeight()) / 2; int scrollWidth = this.getWidth() - leftStart - buttonIcon.getWidth() - gap - rightPadding; graphics.pushClip(left, y, scrollWidth, this.getHeight()); FrogTextHelper.paint( graphics, left - this.scrollX, y, this.textLine, font, boldFont, scrollWidth, !isFocused || !isScrollable); graphics.popClip(); } } else { y = topPadding + (this.getHeight() - bottomPadding - topPadding - font.getHeight()) / 2; int textTypingWidth = this.getWidth() - leftPadding - rightPadding; left = leftPadding + (textTypingWidth - FrogTextHelper.getWidth(this.textLine, this.font, this.boldFont)) / 2; if (left < leftPadding) left = leftPadding; int scrollWidth = this.getWidth() - leftPadding - rightPadding; graphics.pushClip(left, y, scrollWidth, this.getHeight()); FrogTextHelper.paint( graphics, left - this.scrollX, y, this.textLine, font, boldFont, scrollWidth, !isFocused || !isScrollable); graphics.popClip(); } }