=== modified file 'src/com/goldencode/p2j/ui/chui/ChuiWidgetFactory.java' --- src/com/goldencode/p2j/ui/chui/ChuiWidgetFactory.java 2016-03-23 18:33:05 +0000 +++ src/com/goldencode/p2j/ui/chui/ChuiWidgetFactory.java 2016-05-13 01:07:40 +0000 @@ -34,6 +34,7 @@ ** 018 HC 20150831 Scrolling support overhaul. ** 019 IAS 20160227 Added new createScrollPane method as a synonym for the existing one ** 010 IAS 20160315 Support for the DEBUG-ALERT attribute +** 011 SBI 20160512 Changed the scrollable list type. */ package com.goldencode.p2j.ui.chui; @@ -195,10 +196,12 @@ * @return instance of UI-specific implementation of {@link ScrollableList}. */ @Override - public ScrollableListImpl createScrollableList(ComboBox parent, - ListModel model) + public ScrollableList> createScrollableList( + ComboBox parent, + ListModel model) { - return new ScrollableListImpl(parent, parent.model()); + return parent.create(parent.model()); } /** === modified file 'src/com/goldencode/p2j/ui/chui/ComboBoxImpl.java' --- src/com/goldencode/p2j/ui/chui/ComboBoxImpl.java 2016-01-14 04:50:32 +0000 +++ src/com/goldencode/p2j/ui/chui/ComboBoxImpl.java 2016-05-13 01:02:20 +0000 @@ -2,7 +2,7 @@ ** Module : ComboBoxImpl.java ** Abstract : chui implementation of the combo-box ** -** Copyright (c) 2011-2015, Golden Code Development Corporation. +** Copyright (c) 2011-2016, Golden Code Development Corporation. ** ALL RIGHTS RESERVED. Use is subject to license terms. ** ** Golden Code Development Corporation @@ -27,6 +27,7 @@ ** 009 IAS 20150924 Added AUTO-RESIZE attribute support ** 010 EVL 20151217 Drop-down approach rework. Separation ChUI specific drop-down registration ** and focus gaining. +** 011 SBI 20160512 Implemented to create the scrollable list factory method. */ package com.goldencode.p2j.ui.chui; @@ -34,6 +35,7 @@ import com.goldencode.p2j.ui.*; import com.goldencode.p2j.ui.client.*; import com.goldencode.p2j.ui.client.chui.driver.*; +import com.goldencode.p2j.ui.client.model.*; import com.goldencode.p2j.ui.client.widget.*; import com.goldencode.util.*; @@ -158,6 +160,21 @@ } /** + * Creates the scrollable list for this combobox based on the provided list model. + * + * @param model + * The scrollable list model. + * + * @return The scrollable list. + */ + @Override + public ScrollableList> create( + ListModel model) + { + return new ScrollableListImpl(this, model); + } + + /** * Registers drop-down frame in current window system. ChUI specific version. */ @Override === modified file 'src/com/goldencode/p2j/ui/chui/ScrollableListImpl.java' --- src/com/goldencode/p2j/ui/chui/ScrollableListImpl.java 2015-09-16 16:53:54 +0000 +++ src/com/goldencode/p2j/ui/chui/ScrollableListImpl.java 2016-05-13 01:13:53 +0000 @@ -17,6 +17,7 @@ ** 006 CA 20150603 Removed requestSync from drawCaret. ** 007 EVL 20150517 Adding api to set up the top row index. ** 008 HC 20150913 Scrolling support overhaul. +** 009 SBI 20160512 Changed to provide the generic combobox parameter. */ package com.goldencode.p2j.ui.chui; @@ -31,7 +32,7 @@ * CHUI-specific portion of ScrollableList. */ public class ScrollableListImpl -extends ScrollableList +extends ScrollableList { /** * Create component using given configuration and data model. @@ -41,7 +42,7 @@ * @param model * The data model that represents the contents of the list. */ - ScrollableListImpl(ComboBox box, ListModel model) + ScrollableListImpl(ComboBoxImpl box, ListModel model) { super(box, model); } === modified file 'src/com/goldencode/p2j/ui/client/ComboBox.java' --- src/com/goldencode/p2j/ui/client/ComboBox.java 2016-04-13 19:52:18 +0000 +++ src/com/goldencode/p2j/ui/client/ComboBox.java 2016-05-13 00:57:45 +0000 @@ -201,6 +201,7 @@ ** 102 IAS 20160303 Fixed RETURN processing. ** 103 HC 20160406 Fixed COMBO-BOX drop-down resource cleanup. ** 104 HC 20160413 Comment fix. +** 105 SBI 20160512 Added the scrollable list factory method. */ package com.goldencode.p2j.ui.client; @@ -288,6 +289,16 @@ } /** + * Creates the scrollable list for this combobox based on the provided list model. + * + * @param model + * The scrollable list model. + * + * @return The scrollable list. + */ + public abstract ScrollableList> create(ListModel model); + + /** * Replacement API for the logic which should exist in the widget's c'tor, but the logic * can't be executed as it depends on the widget being registered into the official registry. *

=== modified file 'src/com/goldencode/p2j/ui/client/DropDown.java' --- src/com/goldencode/p2j/ui/client/DropDown.java 2016-04-06 15:37:34 +0000 +++ src/com/goldencode/p2j/ui/client/DropDown.java 2016-05-13 01:39:04 +0000 @@ -43,6 +43,7 @@ ** 019 EVL 20160224 Javadoc fixes to make compatible with Oracle Java 8 for Solaris 10. ** 020 IAS 20160229 Change scrollpane creation. ** 021 HC 20160406 Fixed COMBO-BOX drop-down resource cleanup. +** 022 SBI 20160512 Changed the scrollable list type. */ package com.goldencode.p2j.ui.client; @@ -61,7 +62,7 @@ extends OuterFrame { /** The list instance to represent the drop-down content. */ - protected final ScrollableList list; + protected final ScrollableList> list; /** Wraps the list of items and handles scrolling. */ protected ScrollPane scrollpane; @@ -147,7 +148,7 @@ * * @return See above. */ - public ScrollableList getList() + public ScrollableList> getList() { return list; } === modified file 'src/com/goldencode/p2j/ui/client/ScrollPane.java' --- src/com/goldencode/p2j/ui/client/ScrollPane.java 2016-03-13 15:10:14 +0000 +++ src/com/goldencode/p2j/ui/client/ScrollPane.java 2016-05-13 01:38:11 +0000 @@ -97,6 +97,7 @@ ** duration of the drawing operation or other GUI API invocation which ** requires access to the underlying physical window. ** 050 HC 20160313 Fixed frame scroll layout calculation. +** 051 SBI 20160512 Changed the scrollable list type. */ package com.goldencode.p2j.ui.client; @@ -414,7 +415,7 @@ } else if (viewport().getScrollWidget() instanceof ScrollableList) { - offset = ((ScrollableList) viewport().getScrollWidget()).getCurrentRow() + 1; + offset = ((ScrollableList) viewport().getScrollWidget()).getCurrentRow() + 1; } if (offset <= 0) === modified file 'src/com/goldencode/p2j/ui/client/ScrollableList.java' --- src/com/goldencode/p2j/ui/client/ScrollableList.java 2016-04-20 12:23:53 +0000 +++ src/com/goldencode/p2j/ui/client/ScrollableList.java 2016-05-13 01:11:48 +0000 @@ -66,6 +66,7 @@ ** smaller than the parent's width. ** 20151110 GUI combo-box fixes. ** 032 VIG 20160420 Added isScrollPopupSupported implementation. +** 033 SBI 20160512 Changed to have a generic combobox parameter. */ package com.goldencode.p2j.ui.client; @@ -87,11 +88,11 @@ * "contents" inside the drop-down portion of a {@link ComboBox}. For the * general purpose selection list please use the {@link SelectionList} class. */ -public abstract class ScrollableList> +public abstract class ScrollableList, C extends ComboBox> extends DefaultList { /** ComboBox instance which this instance services. */ - protected ComboBox box = null; + protected C box = null; /** * Create component using given configuration and data model. @@ -101,7 +102,7 @@ * @param model * The data model that represents the contents of the list. */ - public ScrollableList(ComboBox box, ListModel model) + public ScrollableList(C box, ListModel model) { super(model); allowDeselect(false); @@ -281,7 +282,7 @@ * @return the {@link ComboBox} instance to which this drop-down * list is attached to. */ - public ComboBox getBox() + public C getBox() { return box; } === modified file 'src/com/goldencode/p2j/ui/client/driver/WidgetFactory.java' --- src/com/goldencode/p2j/ui/client/driver/WidgetFactory.java 2016-03-15 22:50:52 +0000 +++ src/com/goldencode/p2j/ui/client/driver/WidgetFactory.java 2016-05-13 01:04:43 +0000 @@ -32,6 +32,7 @@ ** 014 HC 20150831 Scrolling support overhaul. ** 015 IAS 20160217 Added new flavor for the createScrollPane method. ** 016 IAS 20160315 Support for the DEBUG-ALERT attribute +** 017 SBI 20160512 Changed the scrollable list type. */ package com.goldencode.p2j.ui.client.driver; @@ -134,7 +135,8 @@ * * @return instance of UI-specific implementation of {@link ScrollableList}. */ - ScrollableList createScrollableList(ComboBox parent, ListModel model); + ScrollableList> createScrollableList(ComboBox parent, + ListModel model); /** * Create UI-specific {@link DropDown} implementation. === modified file 'src/com/goldencode/p2j/ui/client/gui/ComboBoxGuiImpl.java' --- src/com/goldencode/p2j/ui/client/gui/ComboBoxGuiImpl.java 2016-05-02 13:37:02 +0000 +++ src/com/goldencode/p2j/ui/client/gui/ComboBoxGuiImpl.java 2016-05-13 01:17:36 +0000 @@ -60,7 +60,7 @@ ** 021 HC 20160406 COMBO-BOX drop-down resources cleanup. Various drop-down related fixes. ** 022 HC 20160413 Fixed COMBO-BOX focus management, this also resolves ENTER not confirming ** selected item in the drop-down. -** 023 SBI 20160502 Fixed the web combobox entry and drop down list items to be aligned within +** 023 SBI 20160512 Fixed the web combobox entry and drop down list items to be aligned within ** their boxes. */ @@ -79,6 +79,7 @@ import com.goldencode.p2j.ui.client.format.*; import com.goldencode.p2j.ui.client.gui.driver.*; import com.goldencode.p2j.ui.client.gui.GuiFontResolver.FontCache; +import com.goldencode.p2j.ui.client.model.*; import com.goldencode.p2j.ui.client.widget.*; import com.goldencode.p2j.ui.client.ScrollBar.Bars; import com.goldencode.p2j.util.*; @@ -1152,6 +1153,20 @@ } /** + * Creates the scrollable list for this combobox based on the provided list model. + * + * @param model + * The scrollable list model. + * + * @return The scrollable list. + */ + @Override + public ScrollableList> create(ListModel model) + { + return new ScrollableSelectionListGuiImpl(this, model); + } + + /** * Determine the mouse actions processed by this widget. * * @return See above. @@ -1291,7 +1306,9 @@ private void createSimpleList() { // create the drop-down box - simpleList = screen().getFactory().createScrollableList(this, this.model()); + // The direct cast is save due to the create factory method returns instances of this type + simpleList = (ScrollableSelectionListGuiImpl) screen().getFactory().createScrollableList( + this, this.model()); // register it as a new frame simpleListPane = screen().getFactory().createScrollPane(simpleList); @@ -1499,7 +1516,6 @@ int yt = orig.y + 1 + (dim.height + fnt.pointSize)/2; gd.setFontStyle(fnt.style); // enabled state controls text drawing - int boxWidth = dim.width - DROP_DOWN_BUTTON_SIZE; if (isEnabled()) { if (focused) @@ -1510,14 +1526,14 @@ { gd.setColor(gc.fgColor); } - gd.drawString(display, boxWidth, dim.height, xt, yt, 0, 0); + gd.drawString(display, xt, yt, w, h, orig.x, orig.y); } else { gd.setColor(lightShadow); - gd.drawString(display, boxWidth, dim.height, xt + 1, yt + 1, 1, 1); + gd.drawString(display, xt + 1, yt + 1, w, h, orig.x, orig.y); gd.setColor(darkShadow); - gd.drawString(display, boxWidth, dim.height, xt, yt, 0, 0); + gd.drawString(display, xt, yt, w, h, orig.x, orig.y); } // draw dotted rectangle around focused item text === modified file 'src/com/goldencode/p2j/ui/client/gui/GuiWidgetFactory.java' --- src/com/goldencode/p2j/ui/client/gui/GuiWidgetFactory.java 2016-03-15 22:50:52 +0000 +++ src/com/goldencode/p2j/ui/client/gui/GuiWidgetFactory.java 2016-05-13 01:08:24 +0000 @@ -44,6 +44,7 @@ ** 024 EVL 20160127 Adding support for slider widget creation. ** 025 IAS 20160217 Added new flavor for the createScrollPane method. ** 026 IAS 20160315 Support for the DEBUG-ALERT attribute +** 027 SBI 20160512 Changed the scrollable list type. */ package com.goldencode.p2j.ui.client.gui; @@ -212,10 +213,12 @@ * @return instance of UI-specific implementation of {@link ScrollableList}. */ @Override - public ScrollableSelectionListGuiImpl createScrollableList(ComboBox parent, - ListModel model) + public ScrollableList> createScrollableList( + ComboBox parent, + ListModel model) { - return new ScrollableSelectionListGuiImpl(parent, model); + return parent.create(model); } /** === modified file 'src/com/goldencode/p2j/ui/client/gui/ScrollableSelectionListGuiImpl.java' --- src/com/goldencode/p2j/ui/client/gui/ScrollableSelectionListGuiImpl.java 2016-05-02 13:37:02 +0000 +++ src/com/goldencode/p2j/ui/client/gui/ScrollableSelectionListGuiImpl.java 2016-05-13 01:13:42 +0000 @@ -46,8 +46,10 @@ ** 016 HC 20160406 COMBO-BOX drop-down resources cleanup. Various drop-down related fixes. ** 017 HC 20160413 Fixed COMBO-BOX focus management, this also resolves ENTER not confirming ** selected item in the drop-down. -** 018 SBI 20160502 Fixed the web combobox entry and drop down list items to be aligned within -** their boxes, fixed GuiFontResolver to have a correct top level window. +** 018 SBI 20160512 Fixed the web combobox entry and drop down list items to be aligned within +** their boxes, fixed GuiFontResolver to have a correct top level window, changed +** to provide the generic combobox parameter. +. */ package com.goldencode.p2j.ui.client.gui; @@ -72,7 +74,7 @@ */ @SuppressWarnings("unchecked") public class ScrollableSelectionListGuiImpl -extends ScrollableList +extends ScrollableList { /** Screen driver */ private GuiDriver gd; @@ -118,7 +120,7 @@ * @param model * The data model that represents the contents of the list. */ - ScrollableSelectionListGuiImpl(ComboBox box, ListModel model) + ScrollableSelectionListGuiImpl(ComboBoxGuiImpl box, ListModel model) { super(box, model); @@ -167,13 +169,13 @@ // get location and size NativePoint p = physicalLocation(); final NativeDimension d = physicalDimension(); - final int rowHeight = ((ComboBoxGuiImpl)box).getRowHeight(); + final int rowHeight = getBox().getRowHeight(); // TODO: remove this line and rely on the set size, modifying // the size here is very confusing and may lead // to unexpected results d.height = box.config().mode == ComboBoxConfig.Mode.SIMPLE - ? ((ComboBoxGuiImpl)box).getSimpleListVisibleHeight() + ? getBox().getSimpleListVisibleHeight() : rowsVisible * rowHeight; // set up clipping rectangle @@ -254,7 +256,7 @@ return; } - int rowHeight = ((ComboBoxGuiImpl)box).getRowHeight(); + int rowHeight = getBox().getRowHeight(); synchronized (this) { @@ -304,7 +306,7 @@ return; } - int rowHeight = ((ComboBoxGuiImpl)box).getRowHeight(); + int rowHeight = getBox().getRowHeight(); synchronized (this) { @@ -349,7 +351,7 @@ @Override public void processKeyEvent(KeyInput kvt) { - ComboBoxGuiImpl cbbRef = (ComboBoxGuiImpl) getBox(); + ComboBoxGuiImpl cbbRef = getBox(); int key = kvt.actionCode(); // disable ENTER key itself as event generator to avoid value change duplication @@ -699,11 +701,12 @@ } // draw item text - gd.drawString(getItemText(number), rw - ((ComboBoxGuiImpl)box).getDropDownScrollBarWidth(), - rh, + gd.drawString(getItemText(number), box != null && box.config().mode == ComboBoxConfig.Mode.SIMPLE ? x + ComboBoxGuiImpl.ENTRY_SHIFT : x + ComboBoxGuiImpl.TEXT_SHIFT, - y + 1 + (rh + fontSize)/2, 0, 0); + y + 1 + (rh + fontSize)/2, + rw - getBox().getDropDownScrollBarWidth() - ComboBoxGuiImpl.ENTRY_SHIFT, + rh, x, y); // draw the dotted line for selected item (not for SIMPLE mode of the combo-box) if (enabled && number == currentRow() && @@ -712,7 +715,7 @@ gd.setLineStroke(LineStroke.DOTTED_SMALL); gd.setColor(selectionDots); // take into account possible vertical scrollbar width - gd.drawRect(x, y, rw - 1 - ((ComboBoxGuiImpl)box).getDropDownScrollBarWidth(), rh - 1); + gd.drawRect(x, y, rw - 1 - getBox().getDropDownScrollBarWidth(), rh - 1); // restore default line style gd.setLineStroke(LineStroke.DEFAULT); } === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/AbstractGuiDriver.java' --- src/com/goldencode/p2j/ui/client/gui/driver/AbstractGuiDriver.java 2016-05-06 16:14:46 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/AbstractGuiDriver.java 2016-05-13 01:21:07 +0000 @@ -706,29 +706,26 @@ } /** - * Draw a string which can be centered within its box and can have an offset along horizontal - * and/or vertical. If the box is provided width its nonzero width and height, then x and y - * coordinates don't take into account and the given text is centered within the provided box - * and shifted along horizontal and/or vertical. + * Draw a string using the provided text box and text offset position. * - * @param text - * text string to draw. - * @param boxWidth - * The text box width, which needs to be matched when drawing. - * @param boxHeight - * The text box width, which needs to be matched when drawing. - * @param x - * The left position. - * @param y - * The top position. - * @param xOffset - * The horizontal text offset from its centered position. - * @param yOffset - * The vertical text offset from its centered position. + * @param text + * text string to draw. + * @param x + * The left text position. + * @param y + * The top text position. + * @param boxWidth + * The text box width, which needs to be matched when drawing. + * @param boxHeight + * The text box height, which needs to be matched when drawing. + * @param xBoxCoord + * The horizontal box position. + * @param yBoxCoord + * The vertical box position. */ @Override - public void drawString(String text, int boxWidth, int boxHeight, int x, int y, - int xOffset, int yOffset) + public void drawString(String text, int x, int y, int boxWidth, int boxHeight, + int xBoxCoord, int yBoxCoord) { if (isEmptyText(text)) { @@ -741,8 +738,8 @@ ps.y = y; ps.width = boxWidth; ps.height = boxHeight; - ps.xOffset = xOffset; - ps.yOffset = yOffset; + ps.xOffset = xBoxCoord; + ps.yOffset = yBoxCoord; ews.offer(ps); } === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/GuiDriver.java' --- src/com/goldencode/p2j/ui/client/gui/driver/GuiDriver.java 2016-05-02 13:05:43 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/GuiDriver.java 2016-05-13 01:20:09 +0000 @@ -178,28 +178,25 @@ public void drawStringCentered(String text, int legacyWidth, int legacyHeight, int x, int height); /** - * Draw a string which can be centered within its box and can have an offset along horizontal - * and/or vertical. If the box is provided width its nonzero width and height, then x and y - * coordinates don't take into account and the given text is centered within the provided box - * and shifted along horizontal and/or vertical. + * Draw a string using the provided text box and text offset position. * * @param text * text string to draw. + * @param x + * The left text position. + * @param y + * The top text position. * @param boxWidth * The text box width, which needs to be matched when drawing. * @param boxHeight - * The text box width, which needs to be matched when drawing. - * @param x - * The left position. - * @param y - * The top position. - * @param xOffset - * The horizontal text offset from its centered position. - * @param yOffset - * The vertical text offset from its centered position. + * The text box height, which needs to be matched when drawing. + * @param xBoxCoord + * The horizontal box position. + * @param yBoxCoord + * The vertical box position. */ - public void drawString(String text, int boxWidth, int boxHeight, int x, int y, - int xOffset, int yOffset); + public void drawString(String text, int x, int y, int boxWidth, int boxHeight, + int xBoxCoord, int yBoxCoord); /** * The method performs a layout operation on the supplied text and === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java' --- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2016-05-02 13:05:43 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2016-05-13 01:21:50 +0000 @@ -2540,30 +2540,27 @@ } /** - * Draw a string which can be centered within its box and can have an offset along horizontal - * and/or vertical. If the box is provided width its nonzero width and height, then x and y - * coordinates don't take into account and the given text is centered within the provided box - * and shifted along horizontal and/or vertical. + * Draw a string using the provided text box and text offset position. * * @param text * text string to draw. * @param centered * Flag indicating if the text is centered vertically. * @param x - * The left position. + * The left text position. * @param y - * The top position. + * The top text position. * @param boxWidth * The text box width, which needs to be matched when drawing. * @param boxHeight - * The text box width, which needs to be matched when drawing. - * @param xOffset - * The horizontal text offset from its centered position. - * @param yOffset - * The vertical text offset from its centered position. + * The text box height, which needs to be matched when drawing. + * @param xBoxCoord + * The horizontal box position. + * @param yBoxCoord + * The vertical box position. */ public void drawString(String text, boolean centered, int x, int y, int boxWidth, int boxHeight, - int xOffset, int yOffset) + int xBoxCoord, int yBoxCoord) { int length = text.length() * 2 + 33; byte[] message = allocateDrawingOp(PaintPrimitives.DRAW_STRING, length); @@ -2590,10 +2587,10 @@ writeMessageInt32(message, offset, boxHeight); offset += 4; - writeMessageInt32(message, offset, xOffset); + writeMessageInt32(message, offset, xBoxCoord); offset += 4; - writeMessageInt32(message, offset, yOffset); + writeMessageInt32(message, offset, yBoxCoord); offset += 4; } === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.canvas_renderer.js' --- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.canvas_renderer.js 2016-05-05 16:12:00 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.canvas_renderer.js 2016-05-13 00:50:26 +0000 @@ -27,8 +27,8 @@ ** SBI 20160213 Reduced putImageData invocations for horizontal and vertical lines. ** SBI 20160322 Changed to work around if the window canvas has a zero width or height. ** 006 SBI 20160415 Replaced logFormatted(...) by log(...). -** 007 SBI 20160502 Fixed the web combobox entry and drop down list items to be aligned within -** their boxes, added drawTextBoxAlligned. +** 007 SBI 20160512 Fixed the web combobox entry and drop down list items to be aligned within +** their boxes, added drawTextWithinBox. */ "use strict"; @@ -1778,63 +1778,47 @@ } /** - * Draw a string that can be centered within its box and can have an offset along horizontal - * and/or vertical. If the box is provided width its nonzero width and height, then x and y - * coordinates don't take into account and the given text is centered within the provided box - * and shifted along horizontal and/or vertical. + * Draw a string within its box. * * @param {String} text * The text to draw. * @param {Number} x - * The left position. + * The left text position. * @param {Number} y - * The top position. + * The top text position. * @param {Number} boxWidth - * The text box width, which needs to be matched when drawing. + * The text box width. * @param {Number} boxHeight - * The text box width, which needs to be matched when drawing. - * @param {Number} xOffset - * The horizontal text offset from its centered position. - * @param {Number} yOffset - * The vertical text offset from its centered position. + * The text box height. + * @param {Number} xBoxCoord + * The horizontal box position. + * @param {Number} yBoxCoord + * The vertical box position. */ -CanvasRenderer.prototype.drawTextBoxAlligned = function(text, x, y, boxWidth, boxHeight, - xOffset, yOffset) +CanvasRenderer.prototype.drawTextWithinBox = function(text, x, y, boxWidth, boxHeight, + xBoxCoord, yBoxCoord) { - var origY = y; - - var textWidth; - var cfont = p2j.screen.getCurrentFont(); - if (cfont) + var currentFont = p2j.screen.getCurrentFont(); + if (currentFont) { - textWidth = p2j.fonts.getTextWidth(cfont, text); - if (boxWidth > 0 && textWidth > 0 && boxWidth - x - textWidth <= 1) - { // ignore x padding and draw text centered. - x = (boxWidth - textWidth) / 2 + xOffset; - } - } + var lwidth = boxWidth - x + xBoxCoord; + var textHeight = this.fontsManager.getTextHeight(currentFont, text); + var textWidth = this.fontsManager.getTextWidth(currentFont, text); + + var widthScale = lwidth / textWidth; + + // scale drawing context to computed width + // this scales the desired structure.x as well so it needs adjusting + this.ctx.save(); + this.ctx.scale(widthScale, 1); + + this.ctx.textBaseline = 'bottom'; - this.ctx.textBaseline = 'bottom'; - - this.ctx.fillText(text, x, y); - - if (p2j.fonts.isUnderlined(cfont)) - { - // if the style is underline, draw a line under the text - var txtHeight = p2j.fonts.getTextHeight(cfont, text); - if (textWidth === undefined) - { - textWidth = p2j.fonts.getTextWidth(cfont, text); - } - - var x1 = x; - var x2 = x + textWidth; - var y1 = origY; - var y2 = y1; - - this.strokeLineSegment(x1, y1, x2, y2, this.rawColor); + this.ctx.fillText(text, x / widthScale, y); + this.ctx.restore(); } } + /** * Draws a given text at the given (x,y) position fitted to the given text rectangle. * === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js' --- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js 2016-05-06 16:14:46 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js 2016-05-13 00:51:36 +0000 @@ -48,11 +48,11 @@ ** 012 SBI 20160414 Fixed doWindowActivationChange(...) and activateTopVisibleWindow(...). ** SBI 20160422 The resize drawing operations must not be cached. ** 013 SBI 20160427 Added graphicsCached parameter to turn off the graphics cache for testing. -** 014 SBI 20160502 Fixed the web combobox entry and drop down list items to be aligned within -** their boxes, added drawTextBoxAlligned. -** SBI 20160505 Fixed canProcessWidget to return false if the event has been prevented by +** 014 SBI 20160505 Fixed canProcessWidget to return false if the event has been prevented by ** some mouse handler. ** SBI 20160506 Fixed to send the current window changes its minimized state. +** SBI 20160512 Fixed the web combobox entry and drop down list items to be aligned within +** their boxes, added drawTextWithinBox. */ "use strict"; @@ -1381,10 +1381,10 @@ var boxHeight = p2j.socket.readInt32BinaryMessage(message, idx + offset); offset = offset + 4; - var xOffset = p2j.socket.readInt32BinaryMessage(message, idx + offset); + var xBoxCoord = p2j.socket.readInt32BinaryMessage(message, idx + offset); offset = offset + 4; - var yOffset = p2j.socket.readInt32BinaryMessage(message, idx + offset); + var yBoxCoord = p2j.socket.readInt32BinaryMessage(message, idx + offset); offset = offset + 4; if (boxWidth === 0 || boxHeight === 0) @@ -1393,8 +1393,8 @@ } else { - this.canvasRenderer.drawTextBoxAlligned(text, x, y, boxWidth, boxHeight, - xOffset, yOffset); + this.canvasRenderer.drawTextWithinBox(text, x, y, boxWidth, boxHeight, + xBoxCoord, yBoxCoord); } extra = " text = " + text + "; x = " + x + "; y = " + y +