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.FillImage;
033: import nextapp.echo2.app.Component;
034: import nextapp.echo2.webcontainer.RenderContext;
035: import nextapp.echo2.webcontainer.image.ImageRenderSupport;
036: import nextapp.echo2.webcontainer.image.ImageTools;
037: import nextapp.echo2.webrender.ClientProperties;
038: import nextapp.echo2.webrender.output.CssStyle;
039:
040: /**
041: * Utility class for rendering <code>nextapp.echo2.FillImage</code>
042: * properties to CSS.
043: */
044: public class FillImageRender {
045:
046: /**
047: * A flag indicating that the 'fixed' property of the <code>FillImage</code>
048: * should be ignored.
049: */
050: public static final int FLAG_DISABLE_FIXED_MODE = 0x1;
051:
052: /**
053: * A flag indicating that the Internet Explorer 6.0 PNG AlphaImageLoader
054: * filter should be enabled for Internet Explorer clients that might
055: * "benefit" from it. Enabling this flag can however have serious
056: * unacceptable side-effects for Internet Explorer clients:
057: * If the flag is enabled, Images will be <b>SCALED</b> to span
058: * the entire region. IE will ignore any positioning/repeat information
059: * if this flag is enabled. Further, the browser may in fact not allow
060: * the user to click on any content within the region.
061: * Use of this flag is thus strongly discouraged in most all situations.
062: * <p>
063: * This flag has no effect for clients other than Internet Explorer 6.0.
064: */
065: public static final int FLAG_ENABLE_IE_PNG_ALPHA_FILTER = 0x2;
066:
067: /**
068: * Renders a <code>FillImage</code> to a CSS style.
069: *
070: * @param cssStyle the CSS style to be updated
071: * @param rc the relevant <code>RenderContext</code>
072: * @param irs a <code>ComponentSynchronizePeer</code> providing
073: * <code>ImageRenderSupport</code>
074: * @param component the relevant <code>Component</code>
075: * @param imageId the image id of the background image
076: * @param fillImage the <code>FillImage</code> property value
077: * @param flags optional image rendering flags (see <code>FLAG_XXX</code>
078: * constants)
079: */
080: public static void renderToStyle(CssStyle cssStyle,
081: RenderContext rc, ImageRenderSupport irs,
082: Component component, String imageId, FillImage fillImage,
083: int flags) {
084:
085: if (fillImage == null) {
086: return;
087: }
088: String imageUri = ImageTools
089: .getUri(rc, irs, component, imageId);
090:
091: if ((flags & FLAG_ENABLE_IE_PNG_ALPHA_FILTER) != 0
092: && rc
093: .getContainerInstance()
094: .getClientProperties()
095: .getBoolean(
096: ClientProperties.PROPRIETARY_IE_PNG_ALPHA_FILTER_REQUIRED)) {
097: cssStyle.setAttribute("background-image", "none");
098: cssStyle.setAttribute("filter",
099: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"
100: + imageUri + "', sizingMethod='scale')");
101: } else {
102: cssStyle.setAttribute("background-image", "url(" + imageUri
103: + ")");
104: }
105:
106: if (rc
107: .getContainerInstance()
108: .getClientProperties()
109: .getBoolean(
110: ClientProperties.QUIRK_CSS_BACKGROUND_ATTACHMENT_USE_FIXED)) {
111: cssStyle.setAttribute("background-attachment", "fixed");
112: }
113:
114: switch (fillImage.getRepeat()) {
115: case FillImage.NO_REPEAT:
116: cssStyle.setAttribute("background-repeat", "no-repeat");
117: break;
118: case FillImage.REPEAT_HORIZONTAL:
119: cssStyle.setAttribute("background-repeat", "repeat-x");
120: break;
121: case FillImage.REPEAT_VERTICAL:
122: cssStyle.setAttribute("background-repeat", "repeat-y");
123: break;
124: default:
125: cssStyle.setAttribute("background-repeat", "repeat");
126: }
127: if (fillImage.getHorizontalOffset() != null
128: || fillImage.getVerticalOffset() != null) {
129: StringBuffer positionText = new StringBuffer();
130: if (fillImage.getHorizontalOffset() == null) {
131: positionText.append("0px");
132: } else {
133: positionText.append(ExtentRender
134: .renderCssAttributeValue(fillImage
135: .getHorizontalOffset()));
136: }
137: positionText.append(" ");
138: if (fillImage.getVerticalOffset() == null) {
139: positionText.append("0px");
140: } else {
141: positionText.append(ExtentRender
142: .renderCssAttributeValue(fillImage
143: .getVerticalOffset()));
144: }
145: cssStyle.setAttribute("background-position", positionText
146: .toString());
147: }
148: }
149:
150: /** Non-instantiable class. */
151: private FillImageRender() {
152: }
153: }
|