=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.virtual_desktop.js' --- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.virtual_desktop.js 2015-09-10 19:27:07 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.virtual_desktop.js 2015-09-11 12:06:53 +0000 @@ -1165,6 +1165,7 @@ ctx.font = fontsManager.getFontName(TASK_BAR_FONT_ID); var xTextPos; var yTextPos; + var text; if (that.horizontalLayout) { var xShift = TEXT_MARGIN; @@ -1172,7 +1173,17 @@ { xShift += that.iconWidth + 2 * ICON_MARGIN; } - xTextPos = that.x + (that.width - TEXT_MARGIN - textWidth + xShift) / 2; + if (that.width - TEXT_MARGIN - xShift >= textWidth) + { + xTextPos = that.x + (that.width - TEXT_MARGIN - textWidth + xShift) / 2; + text = that.title; + } + else + { + xTextPos = that.x + xShift; + text = cutTextToFitWidth(that.title, textWidth, that.width - TEXT_MARGIN - xShift); + } + yTextPos = that.y + (that.height + textHeight) / 2; } else @@ -1183,7 +1194,16 @@ yShift += that.iconHeight + 2 * ICON_MARGIN; } xTextPos = that.x + (that.width - textHeight) / 2; - yTextPos = that.y + (that.height - TEXT_MARGIN - textWidth + yShift) / 2; + if (that.height - TEXT_MARGIN - yShift >= textWidth) + { + yTextPos = that.y + (that.height - TEXT_MARGIN - textWidth + yShift) / 2; + text = that.title; + } + else + { + yTextPos = that.y + yShift; + text = cutTextToFitWidth(that.title, textWidth, that.height - TEXT_MARGIN - yShift); + } ctx.translate(xTextPos, yTextPos); ctx.rotate(Math.PI / 2); xTextPos = 0; @@ -1201,12 +1221,42 @@ } canvasRenderer.drawText( - that.title, + text, xTextPos, yTextPos, false); ctx.restore(); } + /** + * Cuts the given text to fit the given width. + * + * @param {String} text + * The text to draw + * @param {Number} textWidth + * The text width in the current device metric. + * @param {Number} widthToFit + * The target width to which the trancated text should fit. + * + * @return {String} + * The truncated text that must fit the given width. + */ + function cutTextToFitWidth(text, textWidth, widthToFit) + { + var averageTextLen = Math.floor((widthToFit / (1.0 * textWidth)) * text.length); + if (averageTextLen > 3) + { + return text.substr(0, averageTextLen - 3) + "..."; + } + else if (averageTextLen > 1) + { + return text.substr(0, averageTextLen - 1) + "."; + } + else + { + return "."; + } + } + this.testMousePointerInside = testMousePointerInside; /**