001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.component.outputchart;
035:
036: import com.icesoft.faces.component.ext.renderkit.FormRenderer;
037: import com.icesoft.faces.context.DOMContext;
038: import com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer;
039: import com.icesoft.faces.renderkit.dom_html_basic.HTML;
040: import org.w3c.dom.Element;
041:
042: import javax.faces.component.UIComponent;
043: import javax.faces.context.FacesContext;
044: import java.io.IOException;
045:
046: public class OutputChartRenderer extends DomBasicRenderer {
047:
048: public void encodeBegin(FacesContext facesContext,
049: UIComponent uiComponent) throws IOException {
050:
051: OutputChart outputChart = (OutputChart) uiComponent;
052: String clientId = outputChart.getClientId(facesContext);
053: DOMContext domContext = DOMContext.attachDOMContext(
054: facesContext, uiComponent);
055: if (!domContext.isInitialized()) {
056: Element table = domContext.createElement(HTML.TABLE_ELEM);
057: domContext.setRootNode(table);
058: setRootElementId(facesContext, table, uiComponent);
059: Element tr = (Element) domContext
060: .createElement(HTML.TR_ELEM);
061: Element td = (Element) domContext
062: .createElement(HTML.TD_ELEM);
063: table.setAttribute(HTML.CLASS_ATTR, outputChart
064: .getStyleClass());
065: String style = outputChart.getStyle();
066: if (style != null && style.length() > 0)
067: table.setAttribute(HTML.STYLE_ATTR, style);
068: else
069: table.removeAttribute(HTML.STYLE_ATTR);
070: table.appendChild(tr);
071: tr.appendChild(td);
072: }
073: FormRenderer.addHiddenField(facesContext, "iceChartComponent");
074: Element td = (Element) domContext.getRootNode(). //table
075: getFirstChild().//tr
076: getFirstChild();//td
077: DOMContext.removeChildren(td);
078: td.setAttribute(HTML.WIDTH_ATTR, outputChart.getWidth());
079: td.setAttribute(HTML.HEIGHT_ATTR, outputChart.getHeight());
080: Element image = (Element) domContext
081: .createElement(HTML.IMG_ELEM);
082:
083: image.setAttribute(HTML.SRC_ATTR, getResourceURL(facesContext,
084: "/" + outputChart.getFolder().getName() + "/"
085: + outputChart.getFileName()));
086: // image.setAttribute(HTML.WIDTH_ATTR, outputChart.getWidth());
087: // image.setAttribute(HTML.HEIGHT_ATTR, outputChart.getHeight());
088:
089: td.appendChild(image);
090: if (outputChart.isClientSideImageMap()) {
091: Element map = (Element) domContext
092: .createElement(HTML.MAP_ELEM);
093: map.setAttribute(HTML.NAME_ATTR, "map" + clientId);
094: image.setAttribute(HTML.USEMAP_ATTR, "#map" + clientId);
095: image.setAttribute(HTML.BORDER_ATTR, "0");
096: //render the clientSideImageMap if the component has an actionListener registered
097: outputChart.generateClientSideImageMap(domContext, map);
098: td.appendChild(map);
099: }
100: domContext.streamWrite(facesContext, uiComponent);
101: domContext.stepOver();
102: }
103: }
|