001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.webcontainer.propertyrender;
031:
032: import nextapp.echo2.app.Border;
033: import nextapp.echo2.webrender.output.CssStyle;
034:
035: /**
036: * Utility class for rendering <code>nextapp.echo2.app.Border</code>
037: * properties to CSS.
038: */
039: public class BorderRender {
040:
041: /**
042: * Returns the CSS border style value for a given
043: * Border.STYLE_XXX constant.
044: *
045: * @param style the style constant
046: * @return the CSS style value
047: */
048: public static final String getStyleValue(int style) {
049: switch (style) {
050: case Border.STYLE_NONE:
051: return "none";
052: case Border.STYLE_INSET:
053: return "inset";
054: case Border.STYLE_OUTSET:
055: return "outset";
056: case Border.STYLE_SOLID:
057: return "solid";
058: case Border.STYLE_DOTTED:
059: return "dotted";
060: case Border.STYLE_DASHED:
061: return "dashed";
062: case Border.STYLE_GROOVE:
063: return "groove";
064: case Border.STYLE_RIDGE:
065: return "ridge";
066: case Border.STYLE_DOUBLE:
067: return "double";
068: default:
069: return "none";
070: }
071: }
072:
073: /**
074: * Renders a <code>Border</code> property value to a CSS border attribute
075: * value.
076: *
077: * @param border the property value
078: * @return the CSS attribute value
079: */
080: public static String renderCssAttributeValue(Border border) {
081: StringBuffer out = new StringBuffer();
082: if (border.getSize() != null) {
083: out.append(ExtentRender.renderCssAttributeValue(border
084: .getSize()));
085: out.append(" ");
086: }
087: out.append(getStyleValue(border.getStyle()));
088: if (border.getColor() != null) {
089: out.append(" ");
090: out.append(ColorRender.renderCssAttributeValue(border
091: .getColor()));
092: }
093: return out.toString();
094: }
095:
096: /**
097: * Renders a <code>Border</code> property to the given CSS style.
098: * Null property values are ignored.
099: *
100: * @param cssStyle the target <code>CssStyle</code>
101: * @param border the property value
102: */
103: public static void renderToStyle(CssStyle cssStyle, Border border) {
104: if (border == null) {
105: return;
106: }
107: cssStyle
108: .setAttribute("border", renderCssAttributeValue(border));
109: }
110:
111: /** Non-instantiable class. */
112: private BorderRender() {
113: }
114: }
|