001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.rave.web.ui.renderer;
042:
043: import java.io.IOException;
044: import java.util.Properties;
045:
046: import javax.faces.component.UIComponent;
047: import javax.faces.context.FacesContext;
048: import javax.faces.context.ResponseWriter;
049:
050: import com.sun.rave.web.ui.component.Legend;
051: import com.sun.rave.web.ui.component.util.Util;
052: import com.sun.rave.web.ui.theme.Theme;
053: import com.sun.rave.web.ui.theme.ThemeImages;
054: import com.sun.rave.web.ui.theme.ThemeStyles;
055: import com.sun.rave.web.ui.util.RenderingUtilities;
056: import com.sun.rave.web.ui.util.ThemeUtilities;
057:
058: /**
059: * <p>Renderer for an {@link Legend} component.</p>
060: *
061: */
062: public class LegendRenderer extends AbstractRenderer {
063:
064: // Default position.
065: private static final String DEFAULT_POSITION = "right";
066:
067: /** Creates a new instance of LegendRenderer */
068: public LegendRenderer() {
069: // default constructor
070: }
071:
072: /**
073: * Renders the legend.
074: *
075: * @param context The current FacesContext
076: * @param component The Legend object to use
077: * @param writer The current ResponseWriter
078: *
079: * @exception IOException if an input/output error occurss
080: */
081: protected void renderEnd(FacesContext context,
082: UIComponent component, ResponseWriter writer)
083: throws IOException {
084: if (context == null || component == null || writer == null) {
085: throw new NullPointerException();
086: }
087:
088: Legend legend = (Legend) component;
089:
090: if (!legend.isRendered()) {
091: return;
092: }
093:
094: // Render the outer div
095: renderOuterDiv(context, legend, writer);
096: // Render the legend image
097: RenderingUtilities.renderComponent(legend.getLegendImage(),
098: context);
099: writer.write(" "); // NOI18N
100: // Render the legend text
101: String text = (legend.getText() != null) ? legend.getText()
102: : getTheme().getMessage("Legend.requiredField"); //NOI18N
103: writer.writeText(text, null);
104: // Close the outer div
105: writer.endElement("div"); //NOI18N
106: }
107:
108: /**
109: * Renders the outer div which contains the legend.
110: *
111: * @param context The current FacesContext
112: * @param alert The Legend object to use
113: * @param writer The current ResponseWriter
114: *
115: * @exception IOException if an input/output error occurs
116: */
117: protected void renderOuterDiv(FacesContext context, Legend legend,
118: ResponseWriter writer) throws IOException {
119:
120: String style = legend.getStyle();
121: String id = legend.getClientId(context);
122: String divStyleClass = getTheme().getStyleClass(
123: ThemeStyles.LABEL_REQUIRED_DIV);
124: String align = (legend.getPosition() != null) ? legend
125: .getPosition() : DEFAULT_POSITION;
126:
127: writer.startElement("div", legend); //NOI18N
128: if (id != null) {
129: writer.writeAttribute("id", id, null); //NOI18N
130: }
131: writer.writeAttribute("align", align, null); //NOI18N
132: if (style != null) {
133: writer.writeAttribute("style", style, "style"); //NOI18N
134: }
135: RenderingUtilities.renderStyleClass(context, writer,
136: (UIComponent) legend, divStyleClass);
137: }
138:
139: /*
140: * Utility to get theme.
141: */
142: private Theme getTheme() {
143: return ThemeUtilities.getTheme(FacesContext
144: .getCurrentInstance());
145: }
146:
147: }
|