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 org.netbeans.modules.visualweb.web.ui.dt.renderer;
042:
043: import java.io.IOException;
044: import javax.faces.component.UIComponent;
045: import javax.faces.context.FacesContext;
046: import javax.faces.context.ResponseWriter;
047: import javax.faces.render.Renderer;
048:
049: /**
050: * A delegating renderer for panel-like components. Outputs default minimum
051: * CSS width and height settings if panel contains no children.
052: *
053: * @author gjmurphy
054: */
055: public abstract class PanelDesignTimeRenderer extends
056: AbstractDesignTimeRenderer {
057:
058: /** Creates a new instance of PanelDesignTimeRenderer */
059: public PanelDesignTimeRenderer(Renderer renderer) {
060: super (renderer);
061: }
062:
063: abstract protected String getContainerElementName(
064: UIComponent component);
065:
066: abstract protected String getShadowText(UIComponent component);
067:
068: public void encodeBegin(FacesContext context, UIComponent component)
069: throws IOException {
070: if (component.getChildCount() == 0) {
071: ResponseWriter writer = context.getResponseWriter();
072: writer.startElement(getContainerElementName(component),
073: component);
074: String id = component.getId();
075: writer.writeAttribute("id", id, "id"); //NOI18N
076:
077: // Calculate CSS height and width style settings
078: UIComponent parentComponent = component.getParent();
079: StringBuffer sb = new StringBuffer();
080: String style = (String) component.getAttributes().get(
081: "style");
082: if ((style != null) && (style.length() > 0)) {
083: sb.append(style);
084: sb.append("; "); // NOI18N
085: }
086: if (style == null || style.indexOf("width:") == -1) {
087: sb.append("width: 128px; "); // NOI18N
088: }
089: if (style == null || style.indexOf("height:") == -1) {
090: if ("span".equals(getContainerElementName(component))) {
091: sb.append("height: 24px; "); // NOI18N
092: } else {
093: sb.append("height: 128px; "); // NOI18N
094: }
095: }
096: writer.writeAttribute("style", sb.toString(), null); //NOI18N
097: sb.setLength(0);
098:
099: // Calculate CSS style classes
100: String styleClass = (String) component.getAttributes().get(
101: "styleClass");
102: if ((styleClass != null) && (styleClass.length() > 0)) {
103: sb.append(styleClass);
104: sb.append(" ");
105: }
106: sb.append(UNINITITIALIZED_STYLE_CLASS);
107: sb.append(" ");
108: sb.append(BORDER_STYLE_CLASS);
109: writer.writeAttribute("class", sb.toString(), null); // NOI18
110:
111: writer.writeText(getShadowText(component), null);
112: writer.endElement(getContainerElementName(component));
113:
114: return;
115: }
116:
117: super .encodeBegin(context, component);
118: }
119:
120: public void encodeEnd(FacesContext context, UIComponent component)
121: throws IOException {
122: if (component.getChildCount() == 0) {
123: return;
124: }
125:
126: super.encodeEnd(context, component);
127: }
128:
129: }
|