📄 item.java
字号:
this.border.paint(bX, bY, width, height, g); } } //#endif // paint label: if (this.label != null) { if (this.useSingleRow) { this.label.paint( x, y, leftBorder, rightBorder - (this.contentWidth + this.paddingHorizontal), g ); x += this.label.itemWidth; leftBorder += this.label.itemWidth; } else { this.label.paint( x, y, leftBorder, rightBorder, g ); y += this.label.itemHeight; } } leftBorder += (this.marginLeft + this.borderWidth + this.paddingLeft); //#ifdef polish.css.before leftBorder += this.beforeWidth; //#endif //System.out.println( this.style.name + ": increasing leftBorder by " + (this.marginLeft + this.borderWidth + this.paddingLeft)); rightBorder -= (this.marginRight + this.borderWidth + this.paddingRight); //#ifdef polish.css.after rightBorder -= this.afterWidth; //#endif //System.out.println( this.style.name + ": decreasing rightBorder by " + (this.marginRight + this.borderWidth + this.paddingRight)); if ( this.isLayoutCenter && availableWidth > this.itemWidth) { int difference = (availableWidth - this.itemWidth) / 2; x += difference; if (isLayoutShrink) { leftBorder += difference; rightBorder -= difference; //System.out.println("item " + this + ": (center) shrinking left border to " + leftBorder + ", right border to " + rightBorder); } } else if ( this.isLayoutRight && availableWidth > this.itemWidth) { // adjust the x-position so that the item is painted up to // the right border (when it starts at x): x += availableWidth - this.itemWidth; if (isLayoutShrink) { leftBorder += availableWidth - this.itemWidth; //System.out.println("item " + this + ": (right) shrinking left border to " + leftBorder); } } else if (isLayoutShrink && availableWidth > this.itemWidth) { rightBorder -= availableWidth - this.itemWidth; //System.out.println("item " + this + ": (left) shrinking right border to " + rightBorder); } // paint background: x += this.marginLeft; y += this.marginTop; //#if polish.css.include-label if (!this.includeLabel) { //#endif if (this.background != null) { this.background.paint(x, y + this.backgroundYOffset, this.backgroundWidth, this.backgroundHeight, g); } // paint border: if (this.border != null) { this.border.paint(x, y + this.backgroundYOffset, this.backgroundWidth, this.backgroundHeight, g); } //#if polish.css.include-label } //#endif x += this.borderWidth + this.paddingLeft; y += this.borderWidth + this.paddingTop; int originalContentY = y; // paint before element: //#if polish.css.before || polish.css.after || polish.css.min-height || polish.css.max-height boolean isVerticalCenter = (this.layout & LAYOUT_VCENTER) == LAYOUT_VCENTER; boolean isTop = !isVerticalCenter && (this.layout & LAYOUT_TOP) == LAYOUT_TOP; boolean isBottom = !isVerticalCenter && (this.layout & LAYOUT_BOTTOM) == LAYOUT_BOTTOM; //#endif //#if polish.css.min-height if (this.minimumHeight != 0) { int minHeight = this.minimumHeight - ( 2 * this.borderWidth + this.marginTop + this.marginBottom + this.paddingTop + this.paddingBottom); if ( isVerticalCenter ) {// System.out.println("vertical: adjusting contY by " + ((this.minimumHeight - this.contentHeight) / 2)// + ", contentHeight=" + this.contentHeight + ", minHeight=" + this.minimumHeight ); y += (minHeight - this.contentHeight) / 2; } else if ( isBottom ) { //System.out.println("bottom: adjusting contY by " + (this.minimumHeight - this.contentHeight) ); y += (minHeight - this.contentHeight); } } //#endif //#ifdef polish.css.before if (this.beforeImage != null) { int beforeY = y; int yAdjustment = this.beforeHeight - this.contentHeight; if ( this.beforeHeight < this.contentHeight) { if (isTop) { beforeY -= yAdjustment; } else if (isBottom) { beforeY += yAdjustment; } else { beforeY -= yAdjustment / 2; } } else { if (isTop) { // keep contY } else if (isBottom) { y += yAdjustment; } else { y += yAdjustment / 2; } //contY += (this.beforeHeight - this.contentHeight) / 2; } g.drawImage(this.beforeImage, x, beforeY, Graphics.TOP | Graphics.LEFT ); x += this.beforeWidth; } //#endif // paint after element: //#ifdef polish.css.after if (this.afterImage != null) { int afterY = originalContentY; int yAdjustment = this.afterHeight - this.contentHeight; if ( this.afterHeight < this.contentHeight) { if (isTop) { afterY -= yAdjustment; } else if (isBottom) { afterY += yAdjustment; } else { afterY -= yAdjustment / 2; } //afterY += (this.contentHeight - this.afterHeight) / 2; } else { //#ifdef polish.css.before if (this.afterHeight > this.beforeHeight) { //#endif if (isTop) { // keep contY } else if (isBottom) { y = originalContentY + yAdjustment; } else { y = originalContentY + yAdjustment / 2; } //contY = originalContentY + (this.afterHeight - this.contentHeight) / 2; //#ifdef polish.css.before } //#endif } g.drawImage(this.afterImage, rightBorder, afterY, Graphics.TOP | Graphics.LEFT ); } //#endif // paint content: this.contentX = x; this.contentY = y; paintContent( x, y, leftBorder, rightBorder, g ); } /** * Initialises this item. * * @param firstLineWidth the maximum width of the first line * @param lineWidth the maximum width of any following lines */ protected void init( int firstLineWidth, int lineWidth ) { //#debug System.out.println("intialising item " + this.getClass().getName() + " (" + this + ")"); if (this.style != null && !this.isStyleInitialised) { setStyle( this.style ); } //#ifdef polish.useDynamicStyles else if (this.style == null) { initStyle(); } //#else else if (this.style == null && !this.isStyleInitialised) { //#debug System.out.println("Setting default style for item " + getClass().getName() ); setStyle( StyleSheet.defaultStyle ); } //#endif int labelWidth = 0; int labelHeight = 0; if (this.label != null) { if (!this.label.isInitialised) { this.label.init( firstLineWidth, lineWidth ); } labelWidth = this.label.itemWidth; labelHeight = this.label.itemHeight; } // calculate content width and content height: int noneContentWidth = this.marginLeft + this.borderWidth + this.paddingLeft + this.paddingRight + this.borderWidth + this.marginRight; //#ifdef polish.css.before noneContentWidth += this.beforeWidth; //#endif //#ifdef polish.css.after noneContentWidth += this.afterWidth; //#endif /* if (noneContentWidth >= firstLineWidth) { System.out.println("INVALID NONE CONTENT WIDTH=" + noneContentWidth); } */ //#ifdef polish.css.max-width int firstLineAdjustedWidth = firstLineWidth; int lineAdjustedWidth = lineWidth; if (this.maximumWidth != 0 ) { if (firstLineAdjustedWidth > this.maximumWidth ) { firstLineAdjustedWidth = this.maximumWidth; } if (lineAdjustedWidth > this.maximumWidth ) { lineAdjustedWidth = this.maximumWidth; } } int firstLineContentWidth = firstLineAdjustedWidth - noneContentWidth; int availableContentWidth = lineAdjustedWidth - noneContentWidth; //#else //# int firstLineContentWidth = firstLineWidth - noneContentWidth; //# int availableContentWidth = lineWidth - noneContentWidth; //#endif // initialise content by subclass: initContent( firstLineContentWidth, availableContentWidth ); if (this.contentWidth == 0 && this.contentHeight == 0) { this.itemWidth = labelWidth; this.itemHeight = labelHeight; this.backgroundHeight = 0; this.backgroundWidth = 0; this.isInitialised = true; return; } this.itemWidth = noneContentWidth + this.contentWidth; //#ifdef polish.css.min-width if (this.itemWidth < this.minimumWidth ) { this.itemWidth = this.minimumWidth; } //#endif int cHeight = this.contentHeight; //#ifdef polish.css.before if (this.contentHeight < this.beforeHeight) { cHeight = this.beforeHeight; } //#endif //#ifdef polish.css.after if (this.contentHeight < this.afterHeight) { cHeight = this.afterHeight; } //#endif int noneContentHeight = this.marginTop + this.borderWidth + this.paddingTop + this.paddingBottom + this.borderWidth + this.marginBottom; if (this.itemWidth + labelWidth <= lineWidth) { // label and content fit on one row: this.itemWidth += labelWidth; this.useSingleRow = true; if (this.label != null) { if ( (this.label.layout & LAYOUT_NEWLINE_AFTER) != 0 || ((this.layout & LAYOUT_NEWLINE_BEFORE) == LAYOUT_NEWLINE_BEFORE )) { this.useSingleRow = false; cHeight += labelHeight; } } if ( cHeight + noneContentHeight < labelHeight ) { cHeight = labelHeight - noneContentHeight; } } else { this.useSingleRow = false; cHeight += labelHeight; } if ( this.isLayoutExpand ) { this.itemWidth = lineWidth; //#ifdef polish.css.max-width if (this.maximumWidth != 0 && lineWidth > this.maximumWidth ) { this.itemWidth = this.maximumWidth; } //#endif } else if (this.itemWidth > lineWidth) { this.itemWidth = lineWidth; } if (cHeight + noneContentHeight < this.minimumHeight) { cHeight = this.minimumHeight - noneContentHeight; } //#if polish.css.max-height if (this.maximumHeight != 0 && cHeight + noneContentHeight > this.maximumHeight) { cHeight = this.maximumHeight - noneContentHeight; } //#endif this.itemHeight = cHeight + noneContentHeight; if (this.useSingleRow) { this.backgroundWidth = this.itemWidth - this.marginLeft - this.marginRight - labelWidth; this.backgroundHeight = cHeight + noneContentHeight - this.marginTop - this.marginBottom; } else { this.backgroundWidth = this.itemWidth - this.marginLeft - this.marginRight; this.backgroundHeight = cHeight + noneContentHeight - this.marginTop - this.marginBottom - labelHeight; } this.isInitialised = true; //#debug System.out.println("Item.init(): contentWidth=" + this.contentWidth + ", itemWidth=" + this.itemWidth + ", backgroundWidth=" + this.backgroundWidth); } //#ifdef polish.useDynamicStyles /** * Initialises the appropriate style for this item. */ protected void initStyle() { //System.out.println("item [" + this.getClass().getName() + "/" + this.cssSelector + "/" + this.hashCode() + "] has been initalised: " + this.isStyleInitialised ); if (this.screen == null) { if (this.parent != null) { this.screen = getScreen(); } else { this.screen = StyleSheet.currentScreen; } } if (this.style == null) { this.cssSelector = createCssSelector(); //#debug System.out.println("getting style for item [" + this.cssSelector + "]."); setStyle( StyleSheet.getStyle( this ) ); } else { //System.out.println("item has already style [" + this.style.name + "]."); this.cssSelector = this.style.name; } this.isStyleInitialised = true; } //#endif /** * Initialises this item. * The implementation needs to calculate and set the contentWidth and * contentHeight fields. * The implementation should take the fields preferredWidth and preferredHeight * into account. * * * @param firstLineWidth the maximum width of the first line * @param lineWidth the maximum width of any following lines * @see #contentWidth * @see #contentHeight * @see #preferredWidth * @see #preferredHeight */ protected abstract void initContent(int firstLineWidth, int lineWidth); /** * Paints the content of this item. * The background has already been painted and the border will be added after * this method returns. * * @param x the left start position * @param y the upper start position * @param leftBorder the left border, nothing must be painted left of this position * @param rightBorder the right border, nothing must be painted right of this position * @param g the Graphics on which this item should be painted. */ protected abstract void paintContent( int x, int y, int leftBorder, int rightBorder, Graphics g ); //#ifdef polish.useDynamicStyles /** * Retrieves the CSS selector for this item. * The CSS selector is used for the dyn
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -