1 /* ************************************************************************
3 qooxdoo - the new era of web development
8 2006 by STZ-IDA, Germany, http://www.stz-ida.de
11 LGPL 2.1: http://www.gnu.org/licenses/lgpl.html
14 * Til Schneider (til132)
15 * Carsten Lergenmueller (carstenl)
17 ************************************************************************ */
19 /* ************************************************************************
23 ************************************************************************ */
26 * A data cell renderer for boolean values.
28 qx.OO.defineClass("qx.ui.table.IconDataCellRenderer", qx.ui.table.AbstractDataCellRenderer,
30 qx.ui.table.AbstractDataCellRenderer.call(this);
31 this.IMG_BLANK_URL = qx.manager.object.AliasManager.getInstance().resolvePath("static/image/blank.gif");
36 * Identifies the Image to show.
38 * @param cellInfo {Map} The information about the cell.
39 * See {@link #createDataCellHtml}.
40 * @return {Map} A map having the following attributes:
42 * <li>"url": (type string) must be the URL of the image to show.</li>
43 * <li>"imageWidth": (type int) the width of the image in pixels.</li>
44 * <li>"imageHeight": (type int) the height of the image in pixels.</li>
45 * <li>"tooltip": (type string) must be the image tooltip text.</li>
48 qx.Proto._identifyImage = function(cellInfo) {
49 throw new Error("_identifyImage is abstract");
54 * Retrieves the image infos.
56 * @param cellInfo {Map} The information about the cell.
57 * See {@link #createDataCellHtml}.
58 * @return {Map} Map with an "url" attribute (type string)
59 * holding the URL of the image to show
60 * and a "tooltip" attribute
61 * (type string) being the tooltip text (or null if none was specified)
64 qx.Proto._getImageInfos= function(cellInfo) {
65 // Query the subclass about image and tooltip
66 var urlAndTooltipMap = this._identifyImage(cellInfo);
68 // If subclass refuses to give map, construct it
69 if (urlAndTooltipMap == null || typeof urlAndTooltipMap == "string"){
70 urlAndTooltipMap = {url:urlAndTooltipMap, tooltip:null};
73 // If subclass gave null as url, replace with url to empty image
74 if (urlAndTooltipMap.url == null){
75 urlAndTooltipMap.url = this.IMG_BLANK_URL;
78 return urlAndTooltipMap;
82 qx.Proto._getCellStyle = function(cellInfo) {
83 var style = qx.ui.table.AbstractDataCellRenderer.prototype._getCellStyle(cellInfo);
84 style += qx.ui.table.IconDataCellRenderer.MAIN_DIV_STYLE;
90 qx.Proto._getContentHtml = function(cellInfo) {
91 var IconDataCellRenderer = qx.ui.table.IconDataCellRenderer;
93 var urlAndToolTip = this._getImageInfos(cellInfo);
94 var html = IconDataCellRenderer.IMG_START;
95 if (qx.sys.Client.getInstance().isMshtml() && /\.png$/i.test(urlAndToolTip.url)) {
96 html += qx.manager.object.AliasManager.getInstance().resolvePath("static/image/blank.gif")
97 + '" style="filter:' + "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + urlAndToolTip.url + "',sizingMethod='scale')";
99 html += urlAndToolTip.url + '" style="';
102 if (urlAndToolTip.imageWidth && urlAndToolTip.imageHeight) {
103 html += ';width:' + urlAndToolTip.imageWidth + 'px'
104 + ';height:' + urlAndToolTip.imageHeight + 'px';
107 var tooltip = urlAndToolTip.tooltip;
108 if (tooltip != null){
109 html += IconDataCellRenderer.IMG_TITLE_START + tooltip;
111 html += IconDataCellRenderer.IMG_END;
117 qx.Proto.updateDataCellElement = function(cellInfo, cellElement) {
118 // Set image and tooltip text
119 var urlAndToolTip = this._getImageInfos(cellInfo);
120 var img = cellElement.firstChild;
121 if (qx.sys.Client.getInstance().isMshtml()) {
122 if (/\.png$/i.test(urlAndToolTip.url)) {
123 img.src = qx.manager.object.AliasManager.getInstance().resolvePath("static/image/blank.gif");
124 img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + urlAndToolTip.url + "',sizingMethod='scale')";
126 img.src = urlAndToolTip.url;
127 img.style.filter = "";
130 img.src = urlAndToolTip.url;
133 if (urlAndToolTip.imageWidth && urlAndToolTip.imageHeight) {
134 img.style.width = urlAndToolTip.imageWidth + "px";
135 img.style.height = urlAndToolTip.imageHeight + "px";
138 if (urlAndToolTip.tooltip != null){
139 img.text = urlAndToolTip.tooltip;
145 qx.Proto._createCellStyle_array_join = function(cellInfo, htmlArr) {
146 qx.ui.table.AbstractDataCellRenderer.prototype._createCellStyle_array_join(cellInfo, htmlArr);
148 htmlArr.push(qx.ui.table.IconDataCellRenderer.MAIN_DIV_STYLE);
151 qx.Proto._createContentHtml_array_join = function(cellInfo, htmlArr) {
152 var IconDataCellRenderer = qx.ui.table.IconDataCellRenderer;
154 if (qx.ui.table.TablePane.USE_TABLE) {
155 htmlArr.push(IconDataCellRenderer.TABLE_DIV);
156 htmlArr.push(cellInfo.styleHeight - 2); // -1 for the border, -1 for the padding
157 htmlArr.push(IconDataCellRenderer.TABLE_DIV_CLOSE);
160 htmlArr.push(IconDataCellRenderer.IMG_START);
161 var urlAndToolTip = this._getImageInfos(cellInfo);
162 htmlArr.push(urlAndToolTip.url);
163 var tooltip = urlAndToolTip.tooltip;
164 if (tooltip != null){
165 IconDataCellRenderer.IMG_TITLE_START;
166 htmlArr.push(tooltip);
168 htmlArr.push(IconDataCellRenderer.IMG_END);
170 if (qx.ui.table.TablePane.USE_TABLE) {
171 htmlArr.push(IconDataCellRenderer.TABLE_DIV_END);
175 qx.Class.MAIN_DIV_STYLE = ';text-align:center;padding-top:1px;';
176 qx.Class.IMG_START = '<img src="';
177 qx.Class.IMG_END = '"/>';
178 qx.Class.IMG_TITLE_START = '" title="';
179 qx.Class.TABLE_DIV = '<div style="overflow:hidden;height:';
180 qx.Class.TABLE_DIV_CLOSE = 'px">';
181 qx.Class.TABLE_DIV_END = '</div>';